raz / test / run / PtrPlaces.raz

23 lines · 751 B · raw · history · last change 264716cb

1(* PTR(s) where the report leaves the address to the implementation:
2 an empty slice cut from another keeps its place there, and a string
3 constant, even "", has a place in read-only data. A slice kept in
4 registers in a loop gives its pointer's register. *)
5module PtrPlaces;
6import Out;
7import SYSTEM;
8
9proc main*;
10var a: [4]U8; s, e: []U8; p: ^U8; i, n: INT;
11begin
12 a := [1, 2, 3, 4];
13 s := a[0..4];
14 e := s[2..2];
15 if SYSTEM.PTR(e) = SYSTEM.PTR(s) + 2 then Out.str("cut empty: at its place\n"); end;
16 p := SYSTEM.PTR("");
17 if p # nil then Out.str("\"\": not nil\n"); end;
18 n := 0;
19 for i := 0 to 3 do s := a[i..4]; n := n + INT(SYSTEM.PTR(s) - SYSTEM.PTR(a)); end;
20 Out.int(n); Out.str("\n");
21end;
22
23end PtrPlaces.