raz / commit 0d0c6bb1

commit
0d0c6bb15d751b263526485d6b142258ac4d319f
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
56f93056
The compiler: PTR(s) (report 2026-10.34, section 6.8)

Parse's ptrOf takes a slice, an array or a string, and Item's startOf
makes the address: a slice's first word, read as LEN reads its second,
with no check, so an empty slice gives what it holds; an array's or a
string's address, refused wherever a slice of all of it is. The
messages say what PTR is for and what to write: PTR(pa^) for a pointer
to an array, ADR(v^[0]) through a volatile pointer, nil for PTR([]);
and coerce's two mismatches on the way to it, a slice where a pointer
is wanted and the other way round, say PTR(s) and LEN(s), or p[0..n].

conform/ has a run of it and ten errors, with their messages in
test/msg; test/run/PtrPlaces what this compiler chooses. The editors
know PTR, and COPY, which they had missed; raz(7) has it.

The library can't use it yet: src/ is built by v0.19.0 against
today's lib/, so Sys's bytes, which PTR would replace, waits for the
release after this one.

patch · log

32 files changed, +368 -10

conform/err/PtrAsSlice.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module PtrAsSlice;
2+proc main*;
3+var a: [4]U8; s: []U8;
4+begin
5+ s := PTR(a);
6+end;
7+end PtrAsSlice.

conform/err/PtrElement.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module PtrElement;
2+proc main*;
3+var a: [4]U8; p: ^INT;
4+begin
5+ p := PTR(a);
6+end;
7+end PtrElement.

conform/err/PtrExport.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module PtrExport;
2+import Owner;
3+proc main*;
4+var p: ^INT;
5+begin
6+ p := PTR(Owner.a);
7+end;
8+end PtrExport.

conform/err/PtrInteger.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module PtrInteger;
2+proc main*;
3+var n: INT; p: ^INT;
4+begin
5+ n := 1;
6+ p := PTR(n);
7+end;
8+end PtrInteger.

conform/err/PtrLiteral.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module PtrLiteral;
2+proc main*;
3+var p: ^U8;
4+begin
5+ p := PTR([]);
6+end;
7+end PtrLiteral.

conform/err/PtrPacked.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module PtrPacked;
2+type R = packed record tag: U8; words: [3]I32; end;
3+proc main*;
4+var r: R; p: ^I32;
5+begin
6+ p := PTR(r.words);
7+end;
8+end PtrPacked.

conform/err/PtrPointer.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module PtrPointer;
2+proc main*;
3+var a: [4]U8; p, q: ^U8; pa: ^[4]U8;
4+begin
5+ p := ADR(a[0]); pa := ADR(a);
6+ q := PTR(p);
7+ q := PTR(pa);
8+end;
9+end PtrPointer.

conform/err/PtrView.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module PtrView;
2+proc main*;
3+var w: I64; p: ^U8;
4+begin
5+ w := 0;
6+ p := PTR(w.([8]U8));
7+end;
8+end PtrView.

conform/err/PtrVolatile.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module PtrVolatile;
2+var regs: [4]U32;
3+proc main*;
4+var v: ^VOLATILE [4]U32; p: ^U32;
5+begin
6+ v := ADR(regs);
7+ p := PTR(v^);
8+end;
9+end PtrVolatile.

conform/err/SliceAsPtr.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module SliceAsPtr;
2+proc put(_p: ^U8; _n: INT); begin end;
3+proc main*;
4+var a: [4]U8; s: []U8;
5+begin
6+ s := a[0..2];
7+ put(s, LEN(s));
8+end;
9+end SliceAsPtr.

conform/run/Ptr.expect (history) added +13 -0

@@ -0,0 +1,13 @@
1+hello
2+el
3+a slice: ADR(s[0])
4+an array: ADR(a[0])
5+a slice of it: ADR(a[2])
6+a call's slice
7+a slice as it starts: nil
8+[]: nil
9+0 bytes back
10+lo
11+a const parameter: in place
12+10 20 30
13+4

conform/run/Ptr.raz (history) added +65 -0

@@ -0,0 +1,65 @@
1+(* PTR(s), the address a slice starts at (report section 6.8): ADR(s[0])
2+ when s isn't empty; nil for a slice as it starts and for []; and, of
3+ an array, the address of its first element. *)
4+module Ptr;
5+import Out;
6+
7+type Value = record n: INT; p: ^U8; end;
8+
9+const Digits: [4]INT = [1, 2, 3, 4];
10+
11+var kept: []U8;
12+
13+(* a slice as a pointer and a length, with no test for the empty one *)
14+proc valueOf(s: []U8): Value;
15+begin
16+ return {n: LEN(s), p: PTR(s)};
17+end;
18+
19+(* and back: empty when n is 0, whatever p is *)
20+proc bytes(v: Value): []U8;
21+begin
22+ return v.p[0..v.n];
23+end;
24+
25+proc same(s: []U8): []U8;
26+begin
27+ return s;
28+end;
29+
30+proc first(const a: [3]I64): ^I64;
31+begin
32+ return PTR(a);
33+end;
34+
35+proc main*;
36+var
37+ a: [6]U8; s, none: []U8; v: Value; w: [3]I64; ws: []I64; q: ^I64;
38+ d: ^INT; i: INT;
39+begin
40+ a := [104, 101, 108, 108, 111, 10];
41+ s := a[0..6];
42+ Out.str(bytes(valueOf(s)));
43+ Out.str(bytes(valueOf(s[1..3]))); Out.str("\n");
44+ if PTR(s) = ADR(s[0]) then Out.str("a slice: ADR(s[0])\n"); end;
45+ if PTR(a) = ADR(a[0]) then Out.str("an array: ADR(a[0])\n"); end;
46+ if PTR(s[2..5]) = ADR(a[2]) then Out.str("a slice of it: ADR(a[2])\n"); end;
47+ if PTR(same(s)) = ADR(a[0]) then Out.str("a call's slice\n"); end;
48+ v := valueOf(none);
49+ if v.p = nil then Out.str("a slice as it starts: nil\n"); end;
50+ v := valueOf([]);
51+ if v.p = nil then Out.str("[]: nil\n"); end;
52+ Out.int(LEN(bytes(v))); Out.str(" bytes back\n");
53+ kept := s[3..5];
54+ Out.str(PTR(kept)[0..2]); Out.str("\n");
55+ w := [10, 20, 30];
56+ if first(w) = ADR(w[0]) then Out.str("a const parameter: in place\n"); end;
57+ ws := w[0..3];
58+ q := PTR(ws);
59+ for i := 0 to 2 do Out.int(q[i]); Out.str(" "); end;
60+ Out.str("\n");
61+ d := PTR(Digits);
62+ Out.int(d[3]); Out.str("\n");
63+end;
64+
65+end Ptr.

doc/compiler.md (history) modified +16 -0

@@ -1594,6 +1594,22 @@
15941594 parses its own arguments, since `SIZE` takes a type and `INC` a
15951595 variable.
15961596
1597+`PTR(s)` (report 2026-10.34) is `ptrOf`, which refuses what isn't a
1598+slice, an array or a string with a message that says what PTR is for
1599+(and, for a pointer, what to write), and Item's `startOf`, which makes
1600+it. Of a slice it is the first of its two words, read as `LEN` reads
1601+the second, with no check, so that an empty slice gives what it holds;
1602+a call's slice, in two words on the stack (`mWords`), drops its length.
1603+Of an array or a string it is the address, refused wherever `slice`
1604+would refuse the slice of all of it:
1605+
1606+ ADR(s[0]) check 0 < LEN(s), then s's first word (stops on "")
1607+ PTR(s) s's first word (no check)
1608+
1609+Two mismatches in `coerce` that people meet on the way to it, a slice
1610+where its element's pointer is wanted and a pointer where a slice is,
1611+come with help that says what to write (`mismatchHelp`).
1612+
15971613 **Register variables.** One pass can't know whether a variable's
15981614 address will be taken before its code is made, so `chooseRegs` reads
15991615 the body ahead, as `instancesFor` does, and counts each variable's

doc/raz.7 (history) modified +11 -0

@@ -419,6 +419,17 @@
419419 .Ar x .
420420 .It Fn LEN a
421421 The length of an array, a string constant or a slice.
422+.It Fn PTR s
423+The address the slice
424+.Ar s
425+starts at, a
426+.Li ^T
427+for a
428+.Li []T ,
429+unchecked: for an empty slice what it holds,
430+.Dv nil
431+for one never set.
432+Of an array, the address of its first element.
422433 .It Fn NEW p a
423434 .Ar p
424435 set to a fresh, zeroed

editor/emacs/raz-mode.el (history) modified +2 -2

@@ -32,8 +32,8 @@
3232 '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR"))
3333
3434 (defconst raz-builtins
35- '("SIZE" "ADR" "LEN" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD"
36- "ARGC" "ARGV" "INC" "DEC"))
35+ '("SIZE" "ADR" "LEN" "PTR" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD"
36+ "ARGC" "ARGV" "INC" "DEC" "COPY"))
3737
3838 (defvar raz-mode-syntax-table
3939 (let ((st (make-syntax-table)))

editor/vim/syntax/raz.vim (history) modified +2 -2

@@ -14,8 +14,8 @@
1414 syntax keyword razKeyword repeat return set shl shr then to try type until
1515 syntax keyword razKeyword var variant VOLATILE while xor
1616 syntax keyword razType I8 I16 I32 I64 INT UINT U8 U16 U32 U64 BOOL F32 F64 ERROR
17-syntax keyword razBuiltin SIZE ADR LEN NEW MSG SYSCALL FENCE CAS XCHG XADD
18-syntax keyword razBuiltin ARGC ARGV INC DEC
17+syntax keyword razBuiltin SIZE ADR LEN PTR NEW MSG SYSCALL FENCE CAS XCHG XADD
18+syntax keyword razBuiltin ARGC ARGV INC DEC COPY
1919 syntax keyword razConstant true false nil
2020
2121 " 123, 0FFH, 1.5, 2.0E-3

src/Item.raz (history) modified +64 -4

@@ -564,17 +564,24 @@
564564 return nil;
565565 end;
566566
567-(* An error in x's type; if x is an argument, a note at the parameter
568- it goes to. *)
569-proc mismatch(x: Item; text: []U8): ERROR;
567+(* An error in x's type, with help that says what to write instead
568+ unless hint is empty; if x is an argument, a note at the parameter it
569+ goes to. *)
570+proc mismatchHelp(x: Item; text, hint: []U8): ERROR;
570571 begin
571572 Diag.error(x.pos, text);
573+ if LEN(hint) > 0 then Diag.help(hint); end;
572574 if (passing # nil) and (x.pos.f = passingAt.f) and (x.pos.a = passingAt.a) and (x.pos.b = passingAt.b) then
573575 Diag.note(passing^.pos, say1("it goes to {}, declared here", Scan.nameOf(passing^.name)));
574576 end;
575577 return Scan.Failed;
576578 end;
577579
580+proc mismatch(x: Item; text: []U8): ERROR;
581+begin
582+ return mismatchHelp(x, text, "");
583+end;
584+
578585 (* An error at x, which is a view, or part of one, and so has no
579586 address: text, and help that says what to do instead. *)
580587 proc noAddress*(x: Item; text: []U8): ERROR;
@@ -583,7 +590,7 @@
583590 end;
584591
585592 proc coerce*(var x: Item; t: ^Sym.Type): ERROR;
586-var s: ^Sym.Type; tmp: I64; inFrame: BOOL;
593+var s: ^Sym.Type; tmp: I64; inFrame: BOOL; hint: []U8;
587594 begin
588595 if x.mode = mCond then try value(x); end;
589596 s := x.typ;
@@ -641,6 +648,15 @@
641648 return Scan.markHelp(x.pos, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)),
642649 Diag.say("{} widens to {} only as written, {}({})", [Fmt.str(Sym.typeName(s)),
643650 Fmt.str(Sym.typeName(t)), Fmt.str(Sym.typeName(t)), Fmt.str(Diag.source(x.pos))]));
651+ elsif (s^.form in {Sym.fSlice, Sym.fArray}) and (t^.form = Sym.fPtr) and Sym.same(s^.base, t^.base) then
652+ (* the pointer and the length of a slice are two things *)
653+ return mismatchHelp(x, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)),
654+ Diag.say("PTR({}) is the address it starts at, a {}, and LEN({}) how many it has",
655+ [Fmt.str(Diag.source(x.pos)), Fmt.str(Sym.typeName(t)), Fmt.str(Diag.source(x.pos))]));
656+ elsif (s^.form = Sym.fPtr) and (t^.form = Sym.fSlice) and Sym.same(s^.base, t^.base) then
657+ if x.mode = mVar then hint := say1("{}[0..n]", Diag.source(x.pos)); else hint := "p[0..n], for a pointer p,"; end;
658+ return mismatchHelp(x, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)),
659+ say1("a pointer has no length: {} is the slice of the n elements it starts", hint));
644660 elsif widens(t, s) then
645661 (* the other way, an I64 into an INT, is written: it may drop bits *)
646662 return Scan.markHelp(x.pos, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)),
@@ -810,6 +826,50 @@
810826 st^.base := t^.base;
811827 tempItem(x, st, tmp);
812828 x.frame := inFrame;
829+ return nil;
830+end;
831+
832+(* PTR(x), the address the slice x starts at, as the pointer type t
833+ (report section 6.8). Of a slice it is its first word, read with no
834+ check, so that an empty one gives what it holds, nil or an end, where
835+ ADR(x[0]) would stop the program:
836+
837+ PTR(s) s's first word, as LEN(s) is its second
838+
839+ Of an array or a string it is the address of its first element, and
840+ may be taken where slice above would make a slice of all of it. *)
841+proc startOf*(var x: Item; t: ^Sym.Type): ERROR;
842+begin
843+ if x.typ^.form = Sym.fSlice then
844+ if x.mode = mWords then
845+ Gen.drop(); (* a call's two words: the length, on top, goes *)
846+ x.mode := mStack;
847+ else
848+ if x.mode # mVar then try copyToTemp(x); end;
849+ x.typ := t;
850+ try value(x);
851+ end;
852+ x.typ := t;
853+ x.frame := false;
854+ return nil;
855+ end;
856+ if x.vol then
857+ return Scan.markHelp(x.pos, "PTR can't take an array through a volatile pointer",
858+ Diag.say("ADR({}[0]) is the address of its first element, a ^VOLATILE {}",
859+ [Fmt.str(Diag.source(x.pos)), Fmt.str(Sym.typeName(t^.base))]));
860+ end;
861+ if x.odd then return Scan.markAt(x.pos, "PTR can't take a field of a packed record, which has no address"); end;
862+ if x.view then return noAddress(x, "PTR can't take a view"); end;
863+ if x.ro and not onlyRead(x) then
864+ (* as in slice: another module's array isn't lent to be written *)
865+ _ := notReadOnly(x);
866+ Diag.help("a pointer to it could change it, as a slice of it could: copy it to a variable here first");
867+ return Scan.Failed;
868+ end;
869+ try address(x);
870+ x.mode := mStack;
871+ x.typ := t;
872+ x.frame := false;
813873 return nil;
814874 end;
815875

src/Parse.raz (history) modified +33 -0

@@ -960,6 +960,30 @@
960960 return "INC";
961961 end;
962962
963+(* PTR(x): the item x, a slice, an array or a string, made the address
964+ its elements start at by Item's startOf. Anything else is an error
965+ that says what PTR is for, and for a pointer what to write. *)
966+proc ptrOf(var x: TItem): ERROR;
967+var e: PType; s: []U8;
968+begin
969+ if x.mode = Item.mStr then
970+ e := Sym.tU8;
971+ elsif x.typ^.form in {Sym.fSlice, Sym.fArray} then
972+ e := x.typ^.base;
973+ else
974+ s := say1("PTR needs a slice or an array, found {}", Item.what(x));
975+ if (x.typ^.form = Sym.fPtr) and (x.typ^.base # nil) and (x.typ^.base^.form = Sym.fArray) then
976+ return Scan.markHelp(x.pos, s, Diag.say("write PTR({}^) for the address of the array's first element, a ^{}",
977+ [Fmt.str(Diag.source(x.pos)), Fmt.str(Sym.typeName(x.typ^.base^.base))]));
978+ elsif x.typ^.form = Sym.fPtr then
979+ return Scan.markHelp(x.pos, s, say1("{} is a pointer already, which is what PTR gives of a slice or an array",
980+ Diag.source(x.pos)));
981+ end;
982+ return Scan.markAt(x.pos, s);
983+ end;
984+ return Item.startOf(x, newPtr(e, false));
985+end;
986+
963987 proc builtin(var x: TItem): ERROR;
964988 var which, n: INT; y: TItem; t: PType;
965989 begin
@@ -1009,6 +1033,15 @@
10091033 else
10101034 return Scan.markAt(y.pos, say1("LEN needs an array or a slice, found {}", Item.what(y)));
10111035 end;
1036+ | Sym.bPtr:
1037+ if Scan.tok = Scan.sLbrak then
1038+ (* a literal takes its type from where it stands, and here nothing gives one *)
1039+ return Scan.markHelp(Scan.tokPos(), "PTR can't take an array literal, which has no type here",
1040+ "PTR([]) would be nil, the empty slice's pointer; give any other literal a variable first");
1041+ end;
1042+ try expression(y, nil);
1043+ try ptrOf(y);
1044+ x := y;
10121045 | Sym.bSyscall:
10131046 n := 0;
10141047 repeat

src/Raz.raz (history) modified +1 -1

@@ -31,7 +31,7 @@
3131 import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf;
3232
3333 const
34- Report = "2026-10.33"; (* the version of doc/raz.md it follows *)
34+ Report = "2026-10.34"; (* the version of doc/raz.md it follows *)
3535 MemfdCreate = 319; (* the system call *)
3636 MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *)
3737 Execve = 59;

src/Sym.raz (history) modified +2 -1

@@ -131,7 +131,7 @@
131131 (* built-in procedures *)
132132 bSize* = 0; bAdr* = 1; bLen* = 2; bNew* = 3; bMsg* = 4; bSyscall* = 5;
133133 bFence* = 6; bCas* = 7; bXchg* = 8; bXadd* = 9; bArgc* = 10; bArgv* = 11;
134- bInc* = 12; bDec* = 13; bCopy* = 14;
134+ bInc* = 12; bDec* = 13; bCopy* = 14; bPtr* = 15;
135135
136136 MaxDepth* = 64; (* scopes open at once *)
137137
@@ -697,6 +697,7 @@
697697 enter("SIZE", oBuiltin, nil, bSize);
698698 enter("ADR", oBuiltin, nil, bAdr);
699699 enter("LEN", oBuiltin, nil, bLen);
700+ enter("PTR", oBuiltin, nil, bPtr);
700701 enter("NEW", oBuiltin, nil, bNew);
701702 enter("MSG", oBuiltin, nil, bMsg);
702703 enter("SYSCALL", oBuiltin, nil, bSyscall);

test/msg/PtrAsSlice.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/PtrAsSlice.raz:5:10: error: can't use ^U8 as []U8
2+ 5 | s := PTR(a);
3+ | ^^^^^^
4+help: a pointer has no length: p[0..n], for a pointer p, is the slice of the n elements it starts
5+raz: 1 error

test/msg/PtrElement.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/PtrElement.raz:5:10: error: can't use ^U8 as ^INT
2+ 5 | p := PTR(a);
3+ | ^^^^^^
4+raz: 1 error

test/msg/PtrExport.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/PtrExport.raz:6:14: error: Owner.a is Owner's, and can't be changed outside it
2+ 6 | p := PTR(Owner.a);
3+ | ^^^^^^^
4+help: a pointer to it could change it, as a slice of it could: copy it to a variable here first
5+raz: 1 error

test/msg/PtrInteger.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/PtrInteger.raz:6:14: error: PTR needs a slice or an array, found INT
2+ 6 | p := PTR(n);
3+ | ^
4+raz: 1 error

test/msg/PtrLiteral.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/PtrLiteral.raz:5:14: error: PTR can't take an array literal, which has no type here
2+ 5 | p := PTR([]);
3+ | ^
4+help: PTR([]) would be nil, the empty slice's pointer; give any other literal a variable first
5+raz: 1 error

test/msg/PtrPacked.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/PtrPacked.raz:6:14: error: PTR can't take a field of a packed record, which has no address
2+ 6 | p := PTR(r.words);
3+ | ^^^^^^^
4+raz: 1 error

test/msg/PtrPointer.err (history) added +9 -0

@@ -0,0 +1,9 @@
1+conform/err/PtrPointer.raz:6:14: error: PTR needs a slice or an array, found ^U8
2+ 6 | q := PTR(p);
3+ | ^
4+help: p is a pointer already, which is what PTR gives of a slice or an array
5+conform/err/PtrPointer.raz:7:14: error: PTR needs a slice or an array, found ^[4]U8
6+ 7 | q := PTR(pa);
7+ | ^^
8+help: write PTR(pa^) for the address of the array's first element, a ^U8
9+raz: 2 errors

test/msg/PtrView.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/PtrView.raz:6:14: error: PTR can't take a view
2+ 6 | p := PTR(w.([8]U8));
3+ | ^^^^^^^^^
4+help: a view has no address, since it may be misaligned: copy it to a variable
5+raz: 1 error

test/msg/PtrVolatile.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/PtrVolatile.raz:7:14: error: PTR can't take an array through a volatile pointer
2+ 7 | p := PTR(v^);
3+ | ^^
4+help: ADR(v^[0]) is the address of its first element, a ^VOLATILE U32
5+raz: 1 error

test/msg/SliceAsPtr.err (history) added +8 -0

@@ -0,0 +1,8 @@
1+conform/err/SliceAsPtr.raz:7:9: error: can't use []U8 as ^U8
2+ 7 | put(s, LEN(s));
3+ | ^
4+help: PTR(s) is the address it starts at, a ^U8, and LEN(s) how many it has
5+conform/err/SliceAsPtr.raz:2:10: note: it goes to _p, declared here
6+ 2 | proc put(_p: ^U8; _n: INT); begin end;
7+ | ^^
8+raz: 1 error

test/run/PtrPlaces.expect (history) added +3 -0

@@ -0,0 +1,3 @@
1+cut empty: at its place
2+"": not nil
3+6

test/run/PtrPlaces.raz (history) added +22 -0

@@ -0,0 +1,22 @@
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. *)
5+module PtrPlaces;
6+import Out;
7+
8+proc main*;
9+var a: [4]U8; s, e: []U8; p: ^U8; i, n: INT;
10+begin
11+ a := [1, 2, 3, 4];
12+ s := a[0..4];
13+ e := s[2..2];
14+ if PTR(e) = PTR(s) + 2 then Out.str("cut empty: at its place\n"); end;
15+ p := PTR("");
16+ if p # nil then Out.str("\"\": not nil\n"); end;
17+ n := 0;
18+ for i := 0 to 3 do s := a[i..4]; n := n + INT(PTR(s) - PTR(a)); end;
19+ Out.int(n); Out.str("\n");
20+end;
21+
22+end PtrPlaces.