raz / commit 3fee2db6

commit
3fee2db6752ed1761f1fa9c5ccef785b95187576
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
9a94d612
Buf, Files, Fmt and Str take the Buf by var (report 2026-10.33)

Buf.init, room, add, str, spare, cut, reset and done take var b: Buf,
and bytes takes it as a value, a few words; Files.load and read,
Fmt.write, Str.join and replace take var b: Buf.Buf. None kept the
pointer it was given. Every caller drops its ADR; the Bufs src/ holds by
pointer (Diag.say, Sym.typeName, X64's listing) are written b^. Helpers
that only lend the Buf on take var too: Sym.typeText, Opt's say,
usageOf, left and item, Doc's addLine and write, Widths' load, hex and
table, Sh's dollar and readLine. Fmt's own format and put keep the
pointer, since nil means standard output there.

A trace shows no var parameter, so BufCut, BufFull and BufInit's
standard error lose their b = 0x? lines. Volume 2, test/doc/Str and
the site's Fmt lesson say the new signatures.

patch · log

29 files changed, +314 -314

doc/raz-lib.md (history) modified +16 -16

@@ -602,8 +602,8 @@
602602 proc hexVal*(c: U8): INT; (* c's value as a hexadecimal digit, or -1 *)
603603 proc lower*(s: []U8); (* s's ASCII capitals made small, in place *)
604604 proc upper*(s: []U8); (* s's ASCII small letters made capitals, in place *)
605-proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
606-proc replace*(b: ^Buf.Buf; s, old, new: []U8); (* s added to b, with new for each old in it *)
605+proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
606+proc replace*(var b: Buf.Buf; s, old, new: []U8); (* s added to b, with new for each old in it *)
607607 proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *)
608608 proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *)
609609 proc decodeLast*(s: []U8): (I32, INT); (* the character s ends with, and its length in bytes *)
@@ -620,15 +620,15 @@
620620
621621 module Buf;
622622 type Buf* = record len*: INT; ... end;
623-proc init*(b: ^Buf; a: ^Mem.Allocator);
624-proc room*(b: ^Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *)
625-proc add*(b: ^Buf; c: U8);
626-proc str*(b: ^Buf; s: []U8);
627-proc spare*(b: ^Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
628-proc bytes*(b: ^Buf): []U8; (* what it holds, until it next grows *)
629-proc cut*(b: ^Buf; n: INT); (* only the first n bytes kept, its memory kept *)
630-proc reset*(b: ^Buf); (* emptied, its memory kept *)
631-proc done*(b: ^Buf); (* its memory given back *)
623+proc init*(var b: Buf; a: ^Mem.Allocator);
624+proc room*(var b: Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *)
625+proc add*(var b: Buf; c: U8);
626+proc str*(var b: Buf; s: []U8);
627+proc spare*(var b: Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
628+proc bytes*(b: Buf): []U8; (* what it holds, until it next grows *)
629+proc cut*(var b: Buf; n: INT); (* only the first n bytes kept, its memory kept *)
630+proc reset*(var b: Buf); (* emptied, its memory kept *)
631+proc done*(var b: Buf); (* its memory given back *)
632632
633633 module Fmt;
634634 type Arg* = variant
@@ -642,7 +642,7 @@
642642 end;
643643 proc print*(f: []U8; args: []Arg); (* to standard output *)
644644 proc eprint*(f: []U8; args: []Arg); (* to standard error, once Out is flushed *)
645-proc write*(b: ^Buf.Buf; f: []U8; args: []Arg); (* added to b *)
645+proc write*(var b: Buf.Buf; f: []U8; args: []Arg); (* added to b *)
646646
647647 module List(T);
648648 type
@@ -709,8 +709,8 @@
709709 failed check does, if the allocator has no room; `room` asks first. A
710710 program reads into a `Buf` through `spare`, then adds what it read to
711711 `len`: `s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n > 0 then
712-INC(b^.len, n); end;`. `cut` takes back what was added, to a length it
713-had: `start := b^.len; ...; Buf.cut(b, start);`; a length past `len`
712+INC(b.len, n); end;`. `cut` takes back what was added, to a length it
713+had: `start := b.len; ...; Buf.cut(b, start);`; a length past `len`
714714 stops the program, as an index past the end does. A `Vec` is `Buf` for any `T`: one block, which
715715 doubles when it is full, so `push` costs the same on average however
716716 long it grows. `all` gives the elements as a slice, indexed and
@@ -821,8 +821,8 @@
821821 ```
822822 module Files;
823823 proc arg*(i: INT): []U8; (* argument i; 0 is the program's name *)
824-proc read*(path: []U8; b: ^Buf.Buf): BOOL; (* the whole file added to b *)
825-proc load*(path: []U8; b: ^Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
824+proc read*(path: []U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
825+proc load*(path: []U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
826826 proc write*(path, data: []U8): BOOL; (* the file made to hold data *)
827827
828828 module Opt;

examples/Elf.raz (history) modified +4 -4

@@ -44,13 +44,13 @@
4444 proc main*;
4545 var b: Buf.Buf; f: []U8; h: Header; i, at, loaded, exec: INT; r: [3]U8;
4646 begin
47- Buf.init(ADR(b), Heap.heap);
48- defer Buf.done(ADR(b));
49- if not Files.read("/proc/self/exe", ADR(b)) then
47+ Buf.init(b, Heap.heap);
48+ defer Buf.done(b);
49+ if not Files.read("/proc/self/exe", b) then
5050 Out.str("can't read the program\n");
5151 return;
5252 end;
53- f := Buf.bytes(ADR(b));
53+ f := Buf.bytes(b);
5454
5555 (* the header, copied out of the bytes whole *)
5656 h := f[0].(Header);

examples/Sh.raz (history) modified +25 -25

@@ -47,12 +47,12 @@
4747 proc say(f: []U8; args: []Fmt.Arg);
4848 var b: Buf.Buf; _n: INT;
4949 begin
50- Buf.init(ADR(b), Heap.heap);
51- Fmt.write(ADR(b), "Sh: ", []);
52- Fmt.write(ADR(b), f, args);
53- Buf.add(ADR(b), 10);
54- _n := Sys.write(Sys.stderr, Buf.bytes(ADR(b)));
55- Buf.done(ADR(b));
50+ Buf.init(b, Heap.heap);
51+ Fmt.write(b, "Sh: ", []);
52+ Fmt.write(b, f, args);
53+ Buf.add(b, 10);
54+ _n := Sys.write(Sys.stderr, Buf.bytes(b));
55+ Buf.done(b);
5656 end;
5757
5858 proc special(c: U8): BOOL;
@@ -65,7 +65,7 @@
6565
6666 (* $NAME or $? at s[at], its value added to b; a $ before anything else
6767 is itself. *)
68-proc dollar(b: ^Buf.Buf);
68+proc dollar(var b: Buf.Buf);
6969 var start: INT;
7070 begin
7171 INC(at);
@@ -85,34 +85,34 @@
8585 proc readWord;
8686 var b: Buf.Buf; q: U8;
8787 begin
88- Buf.init(ADR(b), ADR(arena.base));
88+ Buf.init(b, ADR(arena.base));
8989 while (at < LEN(s)) and not special(s[at]) do
9090 q := s[at];
9191 match q of
9292 | 39: (* '...': every character as it is *)
9393 INC(at);
94- while (at < LEN(s)) and (s[at] # 39) do Buf.add(ADR(b), s[at]); INC(at); end;
94+ while (at < LEN(s)) and (s[at] # 39) do Buf.add(b, s[at]); INC(at); end;
9595 INC(at);
9696 | '"': (* "...": dollars, and \" and \\ *)
9797 INC(at);
9898 while (at < LEN(s)) and (s[at] # '"') do
99- if s[at] = '$' then dollar(ADR(b));
99+ if s[at] = '$' then dollar(b);
100100 else
101101 if (s[at] = '\\') and (at + 1 < LEN(s)) and ((s[at + 1] = '"') or (s[at + 1] = '\\')) then INC(at); end;
102- Buf.add(ADR(b), s[at]);
102+ Buf.add(b, s[at]);
103103 INC(at);
104104 end;
105105 end;
106106 INC(at);
107107 | '$':
108- dollar(ADR(b));
108+ dollar(b);
109109 | else:
110110 if (q = '\\') and (at + 1 < LEN(s)) then INC(at); end;
111- Buf.add(ADR(b), s[at]);
111+ Buf.add(b, s[at]);
112112 INC(at);
113113 end;
114114 end;
115- text := Buf.bytes(ADR(b));
115+ text := Buf.bytes(b);
116116 end;
117117
118118 proc next: Token;
@@ -185,10 +185,10 @@
185185 if (i = LEN(path)) or (path[i] = ':') then
186186 dir := path[start..i];
187187 start := i + 1;
188- Buf.init(ADR(b), ADR(arena.base));
189- Fmt.write(ADR(b), "{}/{}", [Fmt.str(dir), Fmt.str(name)]);
190- info, err := Sys.info(Buf.bytes(ADR(b)));
191- if (err = 0) and info.file and (info.mode & 49H # 0) then return Buf.bytes(ADR(b)), true; end;
188+ Buf.init(b, ADR(arena.base));
189+ Fmt.write(b, "{}/{}", [Fmt.str(dir), Fmt.str(name)]);
190+ info, err := Sys.info(Buf.bytes(b));
191+ if (err = 0) and info.file and (info.mode & 49H # 0) then return Buf.bytes(b), true; end;
192192 end;
193193 end;
194194 return "", false;
@@ -314,7 +314,7 @@
314314
315315 (* A line from standard input, a byte at a time, so that what follows
316316 it is left for the programs the line starts; false at its end. *)
317-proc readLine(b: ^Buf.Buf): BOOL;
317+proc readLine(var b: Buf.Buf): BOOL;
318318 var c: [1]U8;
319319 begin
320320 Buf.reset(b);
@@ -349,10 +349,10 @@
349349 group := Sys.pid();
350350 _ok := Sys.foreground(Sys.stdin, group) = 0;
351351 end;
352- Buf.init(ADR(line), Heap.heap);
352+ Buf.init(line, Heap.heap);
353353 if interactive then reap; show("$ ", []); end;
354- while readLine(ADR(line)) do
355- run(Buf.bytes(ADR(line)));
354+ while readLine(line) do
355+ run(Buf.bytes(line));
356356 if interactive then reap; show("$ ", []); end;
357357 end;
358358 if interactive then show("\n", []); end;
@@ -372,9 +372,9 @@
372372 if given then
373373 run(script);
374374 elsif found then
375- Buf.init(ADR(b), Heap.heap);
376- if not Files.read(file, ADR(b)) then say("{}: can't read it", [Fmt.str(file)]); return 127; end;
377- run(Buf.bytes(ADR(b)));
375+ Buf.init(b, Heap.heap);
376+ if not Files.read(file, b) then say("{}: can't read it", [Fmt.str(file)]); return 127; end;
377+ run(Buf.bytes(b));
378378 else
379379 interact;
380380 end;

lib/Buf.raz (history) modified +48 -48

@@ -10,20 +10,20 @@
1010 end;
1111
1212 (* An empty buffer, which takes its memory from a. *)
13-proc init*(b: ^Buf; a: ^Mem.Allocator);
13+proc init*(var b: Buf; a: ^Mem.Allocator);
1414 begin
15- b^ := {a: a};
15+ b := {a: a};
1616 end;
1717
1818 (* Room for n more bytes; false if the allocator has none. *)
19-proc room*(b: ^Buf; n: INT): BOOL;
19+proc room*(var b: Buf; n: INT): BOOL;
2020 var cap: INT; p: ^U8;
2121 begin
22- if b^.len + n <= b^.cap then return true; end;
23- cap := b^.cap * 2;
22+ if b.len + n <= b.cap then return true; end;
23+ cap := b.cap * 2;
2424 if cap < 64 then cap := 64; end;
25- while cap < b^.len + n do cap := cap * 2; end;
26- if b^.a = nil then
25+ while cap < b.len + n do cap := cap * 2; end;
26+ if b.a = nil then
2727 (* a zero Buf has no allocator: the core has no heap to assume,
2828 so init must give it one. Said plainly, with the calls under
2929 way, rather than as a nil pointer in Mem.alloc *)
@@ -31,19 +31,19 @@
3131 Rt.trace;
3232 Rt.exit(2);
3333 end;
34- p := Mem.alloc(b^.a, cap, 1);
34+ p := Mem.alloc(b.a, cap, 1);
3535 if p = nil then return false; end;
36- if b^.len > 0 then COPY(p[0..b^.len], b^.data[0..b^.len]); end;
37- if b^.data # nil then Mem.free(b^.a, b^.data); end;
38- b^.data := p;
39- b^.cap := cap;
36+ if b.len > 0 then COPY(p[0..b.len], b.data[0..b.len]); end;
37+ if b.data # nil then Mem.free(b.a, b.data); end;
38+ b.data := p;
39+ b.cap := cap;
4040 return true;
4141 end;
4242
4343 (* Room for n more bytes, or the program stops: a buffer that went on
4444 short of what was added to it would be wrong data, and nothing would
4545 say so. A program that can do better asks room first. *)
46-proc need(b: ^Buf; n: INT);
46+proc need(var b: Buf; n: INT);
4747 begin
4848 if not room(b, n) then
4949 _ := Sys.write(Sys.stderr, "Buf: out of memory\n");
@@ -53,64 +53,64 @@
5353 end;
5454
5555 (* Adds the byte c at the end. *)
56-proc add*(b: ^Buf; c: U8);
56+proc add*(var b: Buf; c: U8);
5757 begin
5858 need(b, 1);
59- b^.data[b^.len] := c;
60- INC(b^.len);
59+ b.data[b.len] := c;
60+ INC(b.len);
6161 end;
6262
6363 (* Adds the bytes of s at the end. *)
64-proc str*(b: ^Buf; s: []U8);
64+proc str*(var b: Buf; s: []U8);
6565 begin
6666 need(b, LEN(s));
67- COPY(b^.data[b^.len..b^.len + LEN(s)], s);
68- INC(b^.len, LEN(s));
67+ COPY(b.data[b.len..b.len + LEN(s)], s);
68+ INC(b.len, LEN(s));
6969 end;
7070
7171 (* Room for n more bytes, and those bytes, for a read to fill: the
7272 program then adds to len what it filled. Good until the buffer next
7373 grows, as bytes is. *)
74-proc spare*(b: ^Buf; n: INT): []U8;
74+proc spare*(var b: Buf; n: INT): []U8;
7575 begin
7676 if n = 0 then return ""; end; (* a new buffer has no data to slice *)
7777 need(b, n);
78- return b^.data[b^.len..b^.len + n];
78+ return b.data[b.len..b.len + n];
7979 end;
8080
8181 (* What the buffer holds, until it next grows. *)
82-proc bytes*(b: ^Buf): []U8;
82+proc bytes*(b: Buf): []U8;
8383 begin
84- if b^.len = 0 then return ""; end;
85- return b^.data[0..b^.len];
84+ if b.len = 0 then return ""; end;
85+ return b.data[0..b.len];
8686 end;
8787
8888 (* Keeps only the first n bytes, and the memory, for what comes next.
8989 An n past what the buffer holds is the program's mistake, and stops
9090 it, as an index past the end does. *)
91-proc cut*(b: ^Buf; n: INT);
91+proc cut*(var b: Buf; n: INT);
9292 begin
93- if (n < 0) or (n > b^.len) then
93+ if (n < 0) or (n > b.len) then
9494 _ := Sys.write(Sys.stderr, "Buf.cut past the end\n");
9595 Rt.trace;
9696 Rt.exit(2);
9797 end;
98- b^.len := n;
98+ b.len := n;
9999 end;
100100
101101 (* Empties the buffer, keeping its memory for what comes next. *)
102-proc reset*(b: ^Buf);
102+proc reset*(var b: Buf);
103103 begin
104104 cut(b, 0);
105105 end;
106106
107107 (* Gives the buffer's memory back, leaving it empty. *)
108-proc done*(b: ^Buf);
108+proc done*(var b: Buf);
109109 begin
110- if b^.data # nil then Mem.free(b^.a, b^.data); end;
111- b^.data := nil;
112- b^.len := 0;
113- b^.cap := 0;
110+ if b.data # nil then Mem.free(b.a, b.data); end;
111+ b.data := nil;
112+ b.len := 0;
113+ b.cap := 0;
114114 end;
115115
116116 (* The module's test, over an arena. *)
@@ -118,26 +118,26 @@
118118 var ar: Arena.Arena; b: Buf; i: INT; s: []U8;
119119 begin
120120 if not Arena.init(ADR(ar), 1 shl 20) then Rt.stop("Buf: no arena"); end;
121- init(ADR(b), ADR(ar.base));
122- if LEN(bytes(ADR(b))) # 0 then Rt.stop("Buf: not empty"); end;
123- for i := 0 to 9999 do add(ADR(b), U8(i mod 251)); end;
124- str(ADR(b), "end");
125- s := bytes(ADR(b));
121+ init(b, ADR(ar.base));
122+ if LEN(bytes(b)) # 0 then Rt.stop("Buf: not empty"); end;
123+ for i := 0 to 9999 do add(b, U8(i mod 251)); end;
124+ str(b, "end");
125+ s := bytes(b);
126126 if (LEN(s) # 10003) or (s[9998] # U8(9998 mod 251)) or (s[10000..10003] # "end") then
127127 Rt.stop("Buf: contents");
128128 end;
129- reset(ADR(b));
130- str(ADR(b), "again");
131- if bytes(ADR(b)) # "again" then Rt.stop("Buf.reset"); end;
132- cut(ADR(b), 2);
133- str(ADR(b), "ain");
134- cut(ADR(b), 5);
135- if bytes(ADR(b)) # "again" then Rt.stop("Buf.cut"); end;
136- s := spare(ADR(b), 3);
129+ reset(b);
130+ str(b, "again");
131+ if bytes(b) # "again" then Rt.stop("Buf.reset"); end;
132+ cut(b, 2);
133+ str(b, "ain");
134+ cut(b, 5);
135+ if bytes(b) # "again" then Rt.stop("Buf.cut"); end;
136+ s := spare(b, 3);
137137 COPY(s, "abc");
138138 INC(b.len, 2);
139- if (LEN(s) # 3) or (bytes(ADR(b)) # "againab") then Rt.stop("Buf.spare"); end;
140- done(ADR(b));
139+ if (LEN(s) # 3) or (bytes(b) # "againab") then Rt.stop("Buf.spare"); end;
140+ done(b);
141141 Arena.done(ADR(ar));
142142 end;
143143

lib/Files.raz (history) modified +10 -10

@@ -17,21 +17,21 @@
1717 the read that failed, as Sys gives them: -2 (ENOENT) for no such
1818 file, -13 (EACCES) for one not allowed, -21 (EISDIR) for a
1919 directory. What was read before a read failed stays in b. *)
20-proc load*(path: []U8; b: ^Buf.Buf): INT;
20+proc load*(path: []U8; var b: Buf.Buf): INT;
2121 var fd, n: INT;
2222 begin
2323 fd := Sys.openRead(path);
2424 if fd < 0 then return fd; end;
2525 repeat
2626 n := Sys.read(fd, Buf.spare(b, 65536)); (* straight into b *)
27- if n > 0 then INC(b^.len, n); end;
27+ if n > 0 then INC(b.len, n); end;
2828 until (n <= 0) and (n # Sys.errIntr); (* a signal Sys.handle took; read again *)
2929 Sys.close(fd);
3030 return n;
3131 end;
3232
3333 (* Adds the file at path to b; false if it can't be read. *)
34-proc read*(path: []U8; b: ^Buf.Buf): BOOL;
34+proc read*(path: []U8; var b: Buf.Buf): BOOL;
3535 begin
3636 return load(path, b) = 0;
3737 end;
@@ -57,15 +57,15 @@
5757 proc main*;
5858 var b: Buf.Buf;
5959 begin
60- Buf.init(ADR(b), Heap.heap);
60+ Buf.init(b, Heap.heap);
6161 if not write("/tmp/raz-files-test", "abc") then Rt.stop("Files.write"); end;
62- if (load("/tmp/raz-files-test", ADR(b)) # 0) or (Buf.bytes(ADR(b)) # "abc") then Rt.stop("Files.load"); end;
63- if not read("/tmp/raz-files-test", ADR(b)) or (Buf.bytes(ADR(b)) # "abcabc") then Rt.stop("Files.read"); end;
62+ if (load("/tmp/raz-files-test", b) # 0) or (Buf.bytes(b) # "abc") then Rt.stop("Files.load"); end;
63+ if not read("/tmp/raz-files-test", b) or (Buf.bytes(b) # "abcabc") then Rt.stop("Files.read"); end;
6464 _ := Sys.remove("/tmp/raz-files-test");
65- if load("/tmp/raz-files-test", ADR(b)) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end;
66- if load("/", ADR(b)) # -21 then Rt.stop("Files.load: a directory"); end;
67- if read("/", ADR(b)) or (b.len # 6) then Rt.stop("Files.read: a directory"); end;
68- Buf.done(ADR(b));
65+ if load("/tmp/raz-files-test", b) # Sys.errNoEntry then Rt.stop("Files.load: no such file"); end;
66+ if load("/", b) # -21 then Rt.stop("Files.load: a directory"); end;
67+ if read("/", b) or (b.len # 6) then Rt.stop("Files.read: a directory"); end;
68+ Buf.done(b);
6969 end;
7070
7171 end Files.

lib/Fmt.raz (history) modified +17 -17

@@ -37,7 +37,7 @@
3737 (* Where the pieces go: to b, or to standard output if b is nil. *)
3838 proc put(b: ^Buf.Buf; s: []U8);
3939 begin
40- if b = nil then Out.str(s); else Buf.str(b, s); end;
40+ if b = nil then Out.str(s); else Buf.str(b^, s); end;
4141 end;
4242
4343 (* x as Arg's real says. The whole part and the fraction are taken
@@ -135,9 +135,9 @@
135135 begin
136136 Out.flush;
137137 if not Arena.init(ADR(ar), 1 shl 20) then Rt.stop("Fmt.eprint: no arena"); end;
138- Buf.init(ADR(b), ADR(ar.base));
138+ Buf.init(b, ADR(ar.base));
139139 format(ADR(b), f, args);
140- s := Buf.bytes(ADR(b));
140+ s := Buf.bytes(b);
141141 while LEN(s) > 0 do
142142 n := Sys.write(Sys.stderr, s);
143143 if n > 0 then s := s[n..LEN(s)];
@@ -148,9 +148,9 @@
148148 end;
149149
150150 (* Appends f to b, each {} replaced by the next of args. *)
151-proc write*(b: ^Buf.Buf; f: []U8; args: []Arg);
151+proc write*(var b: Buf.Buf; f: []U8; args: []Arg);
152152 begin
153- format(b, f, args);
153+ format(ADR(b), f, args); (* format's nil is standard output *)
154154 end;
155155
156156 (* The module's test: formats into a buffer over an arena. *)
@@ -158,21 +158,21 @@
158158 var ar: Arena.Arena; b: Buf.Buf; zero: F64;
159159 begin
160160 if not Arena.init(ADR(ar), 1 shl 16) then Rt.stop("Fmt: no arena"); end;
161- Buf.init(ADR(b), ADR(ar.base));
162- write(ADR(b), "{} {} {} {}|{}{}{} {{}}", [int(-42), uint(0FFFFFFFFFFFFFFFFH), hex(48879),
161+ Buf.init(b, ADR(ar.base));
162+ write(b, "{} {} {} {}|{}{}{} {{}}", [int(-42), uint(0FFFFFFFFFFFFFFFFH), hex(48879),
163163 str("s"), char('c'), bool(true), int(0)]);
164- if Buf.bytes(ADR(b)) # "-42 18446744073709551615 BEEF s|ctrue0 {}" then Rt.stop("Fmt.write"); end;
165- Buf.reset(ADR(b));
166- write(ADR(b), "{} and {}", [int(1)]);
167- if Buf.bytes(ADR(b)) # "1 and " then Rt.stop("Fmt: too few arguments"); end;
168- Buf.reset(ADR(b));
169- write(ADR(b), "{} {} {} {} {} {} {} {}", [real(3.14159, 2), real(-2.5, 0), real(0.999, 2), real(0.05, 1),
164+ if Buf.bytes(b) # "-42 18446744073709551615 BEEF s|ctrue0 {}" then Rt.stop("Fmt.write"); end;
165+ Buf.reset(b);
166+ write(b, "{} and {}", [int(1)]);
167+ if Buf.bytes(b) # "1 and " then Rt.stop("Fmt: too few arguments"); end;
168+ Buf.reset(b);
169+ write(b, "{} {} {} {} {} {} {} {}", [real(3.14159, 2), real(-2.5, 0), real(0.999, 2), real(0.05, 1),
170170 real(1.0, 12), real(-0.001, 2), real(123.0, 0), real(999999999999999.9, 0)]);
171- if Buf.bytes(ADR(b)) # "3.14 -3 1.00 0.1 1.000000000 -0.00 123 1000000000000000" then Rt.stop("Fmt.real"); end;
172- Buf.reset(ADR(b));
173- write(ADR(b), "{} {} {} {} {} {}", [real(1.5E17, 2), real(-9.999E20, 2), real(1.0E15, 0), real(1.7976931348623157E308, 3),
171+ if Buf.bytes(b) # "3.14 -3 1.00 0.1 1.000000000 -0.00 123 1000000000000000" then Rt.stop("Fmt.real"); end;
172+ Buf.reset(b);
173+ write(b, "{} {} {} {} {} {}", [real(1.5E17, 2), real(-9.999E20, 2), real(1.0E15, 0), real(1.7976931348623157E308, 3),
174174 real(1.0 / zero, 2), real(zero / zero, 2)]);
175- if Buf.bytes(ADR(b)) # "1.50e17 -1.00e21 1e15 1.798e308 inf nan" then Rt.stop("Fmt.real: an exponent"); end;
175+ if Buf.bytes(b) # "1.50e17 -1.00e21 1e15 1.798e308 inf nan" then Rt.stop("Fmt.real: an exponent"); end;
176176 Arena.done(ADR(ar));
177177 end;
178178

lib/Opt.raz (history) modified +30 -30

@@ -38,7 +38,7 @@
3838 const largest = 9223372036854775807; (* the largest I64, a number with no top *)
3939
4040 (* b written whole to fd, then freed. *)
41-proc say(fd: INT; b: ^Buf.Buf);
41+proc say(fd: INT; var b: Buf.Buf);
4242 var s: []U8; n: INT;
4343 begin
4444 s := Buf.bytes(b);
@@ -62,7 +62,7 @@
6262 (* The scope's synopsis lines, as the help and the mistakes begin:
6363 "usage: " and the first, the others under it; or, for a scope with
6464 none, "usage: keep start". *)
65-proc usageOf(p: ^Parser; b: ^Buf.Buf);
65+proc usageOf(p: ^Parser; var b: Buf.Buf);
6666 var i, lines: INT; c: U8;
6767 begin
6868 for i := 0 to LEN(p^.table) - 1 do
@@ -93,12 +93,12 @@
9393 proc mistake(p: ^Parser; f: []U8; args: []Fmt.Arg);
9494 var b: Buf.Buf;
9595 begin
96- Buf.init(ADR(b), Heap.heap);
97- Fmt.write(ADR(b), "{}: ", [Fmt.str(p^.name)]);
98- Fmt.write(ADR(b), f, args);
99- Buf.add(ADR(b), 10);
100- usageOf(p, ADR(b));
101- say(Sys.stderr, ADR(b));
96+ Buf.init(b, Heap.heap);
97+ Fmt.write(b, "{}: ", [Fmt.str(p^.name)]);
98+ Fmt.write(b, f, args);
99+ Buf.add(b, 10);
100+ usageOf(p, b);
101+ say(Sys.stderr, b);
102102 Rt.exit(2);
103103 end;
104104
@@ -119,7 +119,7 @@
119119 (* The left column of a row in the help, as "-b, --bar label", or, for
120120 a value that may be left out, "-c, --color[=when]", as grep's help
121121 has it. *)
122-proc left(b: ^Buf.Buf; r: ^Row);
122+proc left(var b: Buf.Buf; r: ^Row);
123123 begin
124124 match r^ of
125125 | sub(_s, name, _help): Buf.str(b, name);
@@ -140,16 +140,16 @@
140140 proc leftWidth(r: ^Row): INT;
141141 var b: Buf.Buf; n: INT;
142142 begin
143- Buf.init(ADR(b), Heap.heap);
144- left(ADR(b), r);
145- n := LEN(Buf.bytes(ADR(b)));
146- Buf.done(ADR(b));
143+ Buf.init(b, Heap.heap);
144+ left(b, r);
145+ n := LEN(Buf.bytes(b));
146+ Buf.done(b);
147147 return n;
148148 end;
149149
150150 (* A line of the list: the left column, padded to width and three
151151 spaces more, and the line of help. *)
152-proc item(b: ^Buf.Buf; r: ^Row; width: INT);
152+proc item(var b: Buf.Buf; r: ^Row; width: INT);
153153 var i: INT;
154154 begin
155155 Buf.str(b, " ");
@@ -198,9 +198,9 @@
198198 h := 'h';
199199 if ownsH(p) then h := 0; end;
200200 own := option(p^.scope, h, "help", "", "print this and exit");
201- Buf.init(ADR(b), Heap.heap);
202- usageOf(p, ADR(b));
203- Buf.add(ADR(b), 10);
201+ Buf.init(b, Heap.heap);
202+ usageOf(p, b);
203+ Buf.add(b, 10);
204204 width := leftWidth(ADR(own));
205205 for i := 0 to LEN(p^.table) - 1 do
206206 r := ADR(p^.table[i]);
@@ -209,19 +209,19 @@
209209 for i := 0 to LEN(p^.table) - 1 do
210210 r := ADR(p^.table[i]);
211211 match r^ of
212- | sub(s, _name, _help): if s = p^.scope then item(ADR(b), r, width); end;
212+ | sub(s, _name, _help): if s = p^.scope then item(b, r, width); end;
213213 | else:
214214 end;
215215 end;
216216 for i := 0 to LEN(p^.table) - 1 do
217217 r := ADR(p^.table[i]);
218218 match r^ of
219- | option(s, _l, _long, _v, _help): if s = p^.scope then item(ADR(b), r, width); end;
219+ | option(s, _l, _long, _v, _help): if s = p^.scope then item(b, r, width); end;
220220 | else:
221221 end;
222222 end;
223- item(ADR(b), ADR(own), width);
224- say(Sys.stdout, ADR(b));
223+ item(b, ADR(own), width);
224+ say(Sys.stdout, b);
225225 Rt.exit(0);
226226 end;
227227
@@ -315,9 +315,9 @@
315315 proc badTable(p: ^Parser; row: INT; why: []U8);
316316 var b: Buf.Buf;
317317 begin
318- Buf.init(ADR(b), Heap.heap);
319- Fmt.write(ADR(b), "{}: option table, row {}: {}\n", [Fmt.str(p^.name), Fmt.int(row), Fmt.str(why)]);
320- say(Sys.stderr, ADR(b));
318+ Buf.init(b, Heap.heap);
319+ Fmt.write(b, "{}: option table, row {}: {}\n", [Fmt.str(p^.name), Fmt.int(row), Fmt.str(why)]);
320+ say(Sys.stderr, b);
321321 Rt.exit(1);
322322 end;
323323
@@ -431,9 +431,9 @@
431431 proc fail*(p: ^Parser; text: []U8);
432432 var b: Buf.Buf;
433433 begin
434- Buf.init(ADR(b), Heap.heap);
435- Fmt.write(ADR(b), "{}: {}\n", [Fmt.str(p^.name), Fmt.str(text)]);
436- say(Sys.stderr, ADR(b));
434+ Buf.init(b, Heap.heap);
435+ Fmt.write(b, "{}: {}\n", [Fmt.str(p^.name), Fmt.str(text)]);
436+ say(Sys.stderr, b);
437437 Rt.exit(2);
438438 end;
439439
@@ -463,9 +463,9 @@
463463 w, ok := operand(ADR(p));
464464 if not ok then fail(ADR(p), "no command; see keep -h"); end;
465465 if w # "start" then
466- Buf.init(ADR(b), Heap.heap);
467- Fmt.write(ADR(b), "no command {}; see keep -h", [Fmt.str(w)]);
468- fail(ADR(p), Buf.bytes(ADR(b)));
466+ Buf.init(b, Heap.heap);
467+ Fmt.write(b, "no command {}; see keep -h", [Fmt.str(w)]);
468+ fail(ADR(p), Buf.bytes(b));
469469 end;
470470 scope(ADR(p), "start");
471471 while next(ADR(p)) do

lib/Str.raz (history) modified +14 -14

@@ -219,7 +219,7 @@
219219 end;
220220
221221 (* The parts added to b, with sep between each two. *)
222-proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8);
222+proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8);
223223 var i: INT;
224224 begin
225225 for i := 0 to LEN(parts) - 1 do
@@ -230,7 +230,7 @@
230230
231231 (* s added to b, with new for each old in it, from the left, none
232232 overlapping another; s as it is if old is empty. *)
233-proc replace*(b: ^Buf.Buf; s, old, new: []U8);
233+proc replace*(var b: Buf.Buf; s, old, new: []U8);
234234 var i: INT;
235235 begin
236236 i := -1;
@@ -547,18 +547,18 @@
547547 if up # "AB-Z9" then Rt.stop("Str.upper"); end;
548548 lower(up);
549549 if up # "ab-z9" then Rt.stop("Str.lower"); end;
550- Buf.init(ADR(b), Heap.heap);
551- join(ADR(b), ["a", "b", "c"], ", ");
552- if Buf.bytes(ADR(b)) # "a, b, c" then Rt.stop("Str.join"); end;
553- Buf.reset(ADR(b));
554- join(ADR(b), [], "-");
555- replace(ADR(b), "a.b..c", ".", "::");
556- if Buf.bytes(ADR(b)) # "a::b::::c" then Rt.stop("Str.replace"); end;
557- Buf.reset(ADR(b));
558- replace(ADR(b), "aaa", "aa", "b");
559- replace(ADR(b), "xy", "", "-");
560- if Buf.bytes(ADR(b)) # "baxy" then Rt.stop("Str.replace: overlapping, empty"); end;
561- Buf.done(ADR(b));
550+ Buf.init(b, Heap.heap);
551+ join(b, ["a", "b", "c"], ", ");
552+ if Buf.bytes(b) # "a, b, c" then Rt.stop("Str.join"); end;
553+ Buf.reset(b);
554+ join(b, [], "-");
555+ replace(b, "a.b..c", ".", "::");
556+ if Buf.bytes(b) # "a::b::::c" then Rt.stop("Str.replace"); end;
557+ Buf.reset(b);
558+ replace(b, "aaa", "aa", "b");
559+ replace(b, "xy", "", "-");
560+ if Buf.bytes(b) # "baxy" then Rt.stop("Str.replace: overlapping, empty"); end;
561+ Buf.done(b);
562562 end;
563563
564564 proc testChars;

site/content/advanced/01-fmt.txt (history) modified +7 -7

@@ -67,7 +67,7 @@
6767 import Out, Buf, Fmt, Heap;
6868
6969 (* "name (age n)", built in a Buf the caller owns *)
70-proc describe(b: ^Buf.Buf; name: []U8; age: INT);
70+proc describe(var b: Buf.Buf; name: []U8; age: INT);
7171 begin
7272 Fmt.write(b, "{} (age {})", [Fmt.str(name), Fmt.int(age)]);
7373 end;
@@ -75,12 +75,12 @@
7575 proc main*;
7676 var b: Buf.Buf;
7777 begin
78- Buf.init(ADR(b), Heap.heap);
79- defer Buf.done(ADR(b));
80- describe(ADR(b), "Ada", 36);
81- Buf.str(ADR(b), "; ");
82- describe(ADR(b), "Grace", 45);
83- Out.str(Buf.bytes(ADR(b))); Out.ln;
78+ Buf.init(b, Heap.heap);
79+ defer Buf.done(b);
80+ describe(b, "Ada", 36);
81+ Buf.str(b, "; ");
82+ describe(b, "Grace", 45);
83+ Out.str(Buf.bytes(b)); Out.ln;
8484 Out.int(b.len); Out.str(" bytes\n");
8585 end;
8686

site/content/advanced/04-files.txt (history) modified +12 -12

@@ -17,15 +17,15 @@
1717 begin
1818 ok := Files.write("notes.txt", "first line\nsecond line\n");
1919 if not ok then Out.str("can't write\n"); return; end;
20- Buf.init(ADR(b), Heap.heap);
21- defer Buf.done(ADR(b));
22- ok := Files.read("notes.txt", ADR(b));
20+ Buf.init(b, Heap.heap);
21+ defer Buf.done(b);
22+ ok := Files.read("notes.txt", b);
2323 if ok then
24- Out.int(b.len); Out.str(" bytes: "); Out.str(Buf.bytes(ADR(b)));
24+ Out.int(b.len); Out.str(" bytes: "); Out.str(Buf.bytes(b));
2525 end;
26- ok := Files.read("missing.txt", ADR(b));
26+ ok := Files.read("missing.txt", b);
2727 if not ok then Out.str("missing.txt: not there\n"); end;
28- if Files.load("missing.txt", ADR(b)) = -2 then Out.str("missing.txt: ENOENT\n"); end;
28+ if Files.load("missing.txt", b) = -2 then Out.str("missing.txt: ENOENT\n"); end;
2929 end;
3030
3131 end Notes.
@@ -119,12 +119,12 @@
119119 end;
120120 Sys.closeDir(ADR(d));
121121 Order.sort(names[0..n]);
122- Buf.init(ADR(path), Heap.heap);
122+ Buf.init(path, Heap.heap);
123123 for i := 0 to n - 1 do
124- Buf.reset(ADR(path));
125- Buf.str(ADR(path), "proj/");
126- Buf.str(ADR(path), names[i]);
127- info, err := Sys.info(Buf.bytes(ADR(path)));
124+ Buf.reset(path);
125+ Buf.str(path, "proj/");
126+ Buf.str(path, names[i]);
127+ info, err := Sys.info(Buf.bytes(path));
128128 Out.str(names[i]);
129129 if err < 0 then Out.str(" ?");
130130 elsif info.dir then Out.str("/");
@@ -133,7 +133,7 @@
133133 Out.ln;
134134 Mem.free(Heap.heap, ^U8(ADR(names[i][0])));
135135 end;
136- Buf.done(ADR(path));
136+ Buf.done(path);
137137 end;
138138
139139 end Tree.

site/content/advanced/05-processes.txt (history) modified +4 -4

@@ -109,16 +109,16 @@
109109 p.fds[1] := wr;
110110 pid := Sys.spawn(p);
111111 Sys.close(wr); (* only the child writes now *)
112- Buf.init(ADR(b), Heap.heap);
113- defer Buf.done(ADR(b));
112+ Buf.init(b, Heap.heap);
113+ defer Buf.done(b);
114114 n := Sys.read(rd, chunk);
115115 while n > 0 do
116- Buf.str(ADR(b), chunk[0..n]);
116+ Buf.str(b, chunk[0..n]);
117117 n := Sys.read(rd, chunk);
118118 end;
119119 Sys.close(rd);
120120 _, how, status := Sys.wait(pid, true);
121- Out.str("captured: "); Out.str(Buf.bytes(ADR(b)));
121+ Out.str("captured: "); Out.str(Buf.bytes(b));
122122 Out.str("status "); Out.int(status); Out.ln;
123123 if how = Sys.exited then Out.str("(a normal exit)\n"); end;
124124 end;

site/content/advanced/06-allocators.txt (history) modified +3 -3

@@ -147,11 +147,11 @@
147147 var c: Counted.Counted; b: Buf.Buf; l: Names.List; i: INT; p: ^U8;
148148 begin
149149 Counted.init(ADR(c), Heap.heap);
150- Buf.init(ADR(b), ADR(c.base));
151- for i := 1 to 200 do Buf.str(ADR(b), "0123456789"); end;
150+ Buf.init(b, ADR(c.base));
151+ for i := 1 to 200 do Buf.str(b, "0123456789"); end;
152152 Fmt.print("a buffer of {} bytes took {} allocations\n",
153153 [Fmt.int(b.len), Fmt.int(c.allocs)]);
154- Buf.done(ADR(b));
154+ Buf.done(b);
155155
156156 Names.init(ADR(l), ADR(c.base));
157157 for i := 1 to 10 do _ := Names.push(ADR(l), "x"); end;

site/content/tour/09-memory.txt (history) modified +12 -12

@@ -100,21 +100,21 @@
100100 proc main*;
101101 var b: Buf.Buf; i: INT;
102102 begin
103- Buf.init(ADR(b), Heap.heap);
104- defer Buf.done(ADR(b));
103+ Buf.init(b, Heap.heap);
104+ defer Buf.done(b);
105105 for i := 1 to 5 do
106- Buf.str(ADR(b), "item ");
107- Buf.add(ADR(b), U8('0' + i));
108- Buf.add(ADR(b), ',');
106+ Buf.str(b, "item ");
107+ Buf.add(b, U8('0' + i));
108+ Buf.add(b, ',');
109109 end;
110- Out.str(Buf.bytes(ADR(b))); Out.ln;
110+ Out.str(Buf.bytes(b)); Out.ln;
111111 Out.int(b.len); Out.str(" bytes\n");
112- Buf.reset(ADR(b));
113- Str.join(ADR(b), ["red", "green", "blue"], ", ");
114- Out.str(Buf.bytes(ADR(b))); Out.ln;
115- Buf.reset(ADR(b));
116- Str.replace(ADR(b), "a-b-c", "-", " and ");
117- Out.str(Buf.bytes(ADR(b))); Out.ln;
112+ Buf.reset(b);
113+ Str.join(b, ["red", "green", "blue"], ", ");
114+ Out.str(Buf.bytes(b)); Out.ln;
115+ Buf.reset(b);
116+ Str.replace(b, "a-b-c", "-", " and ");
117+ Out.str(Buf.bytes(b)); Out.ln;
118118 end;
119119
120120 end Build.

site/content/tour/11-defer.txt (history) modified +7 -7

@@ -79,16 +79,16 @@
7979 var b: Buf.Buf;
8080 begin
8181 if n < 0 then return false; end;
82- Buf.init(ADR(b), Heap.heap);
83- defer Buf.done(ADR(b)); (* freed on every way out below *)
84- Buf.str(ADR(b), "n is ");
82+ Buf.init(b, Heap.heap);
83+ defer Buf.done(b); (* freed on every way out below *)
84+ Buf.str(b, "n is ");
8585 if n > 9 then
86- Buf.str(ADR(b), "large");
87- Out.str(Buf.bytes(ADR(b))); Out.ln;
86+ Buf.str(b, "large");
87+ Out.str(Buf.bytes(b)); Out.ln;
8888 return true;
8989 end;
90- Buf.str(ADR(b), "small");
91- Out.str(Buf.bytes(ADR(b))); Out.ln;
90+ Buf.str(b, "small");
91+ Out.str(Buf.bytes(b)); Out.ln;
9292 return true;
9393 end;
9494

src/Diag.raz (history) modified +13 -13

@@ -71,12 +71,12 @@
7171 if not cwdKnown then
7272 d, err := Sys.workDir();
7373 if err = 0 then
74- Buf.str(ADR(cwd), d);
75- Buf.add(ADR(cwd), '/');
74+ Buf.str(cwd, d);
75+ Buf.add(cwd, '/');
7676 end;
7777 cwdKnown := true;
7878 end;
79- c := Buf.bytes(ADR(cwd));
79+ c := Buf.bytes(cwd);
8080 if (LEN(c) > 0) and Str.hasPrefix(path, c) then return path[LEN(c)..LEN(path)]; end;
8181 return path;
8282 end;
@@ -127,17 +127,17 @@
127127
128128 proc put(s: []U8);
129129 begin
130- Buf.str(ADR(out), s);
130+ Buf.str(out, s);
131131 end;
132132
133133 proc putc(c: U8);
134134 begin
135- Buf.add(ADR(out), c);
135+ Buf.add(out, c);
136136 end;
137137
138138 proc putNum(n: INT);
139139 begin
140- Fmt.write(ADR(out), "{}", [Fmt.int(n)]);
140+ Fmt.write(out, "{}", [Fmt.int(n)]);
141141 end;
142142
143143 (* The text of a number *)
@@ -145,9 +145,9 @@
145145 var b: ^Buf.Buf;
146146 begin
147147 b := ^Buf.Buf(grab(SIZE(Buf.Buf)));
148- Buf.init(b, Heap.heap);
149- Fmt.write(b, f, args);
150- return Buf.bytes(b);
148+ Buf.init(b^, Heap.heap);
149+ Fmt.write(b^, f, args);
150+ return Buf.bytes(b^);
151151 end;
152152
153153 (* c, when colour is on *)
@@ -172,13 +172,13 @@
172172 proc flush;
173173 var s: []U8; n: INT;
174174 begin
175- s := Buf.bytes(ADR(out));
175+ s := Buf.bytes(out);
176176 while LEN(s) > 0 do
177177 n := Sys.write(Sys.stderr, s);
178178 if n <= 0 then break; end;
179179 s := s[n..LEN(s)];
180180 end;
181- Buf.reset(ADR(out));
181+ Buf.reset(out);
182182 end;
183183
184184 (* Positions *)
@@ -405,6 +405,6 @@
405405 end;
406406
407407 begin
408- Buf.init(ADR(cwd), Heap.heap);
409- Buf.init(ADR(out), Heap.heap);
408+ Buf.init(cwd, Heap.heap);
409+ Buf.init(out, Heap.heap);
410410 end Diag.

src/Parse.raz (history) modified +11 -11

@@ -3603,10 +3603,10 @@
36033603 proc moduleParams(m: PModule): ERROR;
36043604 var i: INT; o, a: PObj; sig: PType; s: Buf.Buf; at: Diag.Pos; text: []U8;
36053605 begin
3606- Buf.init(ADR(s), Heap.heap);
3606+ Buf.init(s, Heap.heap);
36073607 i := 0;
3608- Buf.str(ADR(s), nameOf(m^.name));
3609- Buf.add(ADR(s), '(');
3608+ Buf.str(s, nameOf(m^.name));
3609+ Buf.add(s, '(');
36103610 Scan.next;
36113611 repeat
36123612 if Scan.tok # Scan.sIdent then return expected("a name"); end;
@@ -3619,8 +3619,8 @@
36193619 o := Sym.newObj(Sym.oType, Scan.id, m^.args.t[i]);
36203620 o^.used := true; (* a parameter of the module, not a declaration *)
36213621 try declare(o);
3622- Buf.str(ADR(s), Sym.typeName(m^.args.t[i]));
3623- Buf.add(ADR(s), ',');
3622+ Buf.str(s, Sym.typeName(m^.args.t[i]));
3623+ Buf.add(s, ',');
36243624 INC(i);
36253625 Scan.next;
36263626 if Scan.tok # Scan.sComma then break; end;
@@ -3650,20 +3650,20 @@
36503650 o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext;
36513651 o^.used := true;
36523652 try declare(o);
3653- Buf.str(ADR(s), nameOf(a^.home^.name));
3654- Buf.add(ADR(s), '.');
3655- Buf.str(ADR(s), nameOf(a^.name));
3656- Buf.add(ADR(s), ',');
3653+ Buf.str(s, nameOf(a^.home^.name));
3654+ Buf.add(s, '.');
3655+ Buf.str(s, nameOf(a^.name));
3656+ Buf.add(s, ',');
36573657 INC(i);
36583658 end;
36593659 try expect(Scan.sRparen);
36603660 if i # m^.args.n then
36613661 return Scan.markAt(m^.args.at, say1("too many type arguments for {}", nameOf(m^.name)));
36623662 end;
3663- text := Buf.bytes(ADR(s));
3663+ text := Buf.bytes(s);
36643664 text[LEN(text) - 1] := ')';
36653665 m^.sname := internName(text);
3666- Buf.done(ADR(s));
3666+ Buf.done(s);
36673667 return nil;
36683668 end;
36693669

src/Sym.raz (history) modified +4 -4

@@ -510,7 +510,7 @@
510510
511511 (* What a type is called, added to b: the names a program gives it, else
512512 what it is made of *)
513-proc typeText(b: ^Buf.Buf; t: ^Type);
513+proc typeText(var b: Buf.Buf; t: ^Type);
514514 var f: ^Obj;
515515 begin
516516 if t = nil then Buf.str(b, "nothing"); return; end;
@@ -574,9 +574,9 @@
574574 var b: ^Buf.Buf;
575575 begin
576576 b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf)));
577- Buf.init(b, Heap.heap);
578- typeText(b, t);
579- return Buf.bytes(b);
577+ Buf.init(b^, Heap.heap);
578+ typeText(b^, t);
579+ return Buf.bytes(b^);
580580 end;
581581
582582 (* A fingerprint of what a declaration exports, for the interface

src/X64.raz (history) modified +12 -12

@@ -293,22 +293,22 @@
293293 var b: ^Buf.Buf;
294294 begin
295295 b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf)));
296- Buf.init(b, Heap.heap);
297- if size = 1 then Buf.str(b, "byte ");
298- elsif size = 2 then Buf.str(b, "word ");
299- elsif size = 4 then Buf.str(b, "dword ");
300- elsif size = 8 then Buf.str(b, "qword ");
296+ Buf.init(b^, Heap.heap);
297+ if size = 1 then Buf.str(b^, "byte ");
298+ elsif size = 2 then Buf.str(b^, "word ");
299+ elsif size = 4 then Buf.str(b^, "dword ");
300+ elsif size = 8 then Buf.str(b^, "qword ");
301301 end;
302- Buf.str(b, "[");
303- if m.base = RIP then Buf.str(b, Chunk.chunkName(m.chunk)); else Buf.str(b, rn(m.base)); end;
304- if m.index # NoIndex then Fmt.write(b, " + {} * {}", [Fmt.str(rn(m.index)), Fmt.int(m.scale)]); end;
302+ Buf.str(b^, "[");
303+ if m.base = RIP then Buf.str(b^, Chunk.chunkName(m.chunk)); else Buf.str(b^, rn(m.base)); end;
304+ if m.index # NoIndex then Fmt.write(b^, " + {} * {}", [Fmt.str(rn(m.index)), Fmt.int(m.scale)]); end;
305305 if m.disp > 0 then
306- Fmt.write(b, " + {}", [Fmt.int(m.disp)]);
306+ Fmt.write(b^, " + {}", [Fmt.int(m.disp)]);
307307 elsif m.disp < 0 then
308- Fmt.write(b, " - {}", [Fmt.int(-m.disp)]);
308+ Fmt.write(b^, " - {}", [Fmt.int(-m.disp)]);
309309 end;
310- Buf.str(b, "]");
311- return Buf.bytes(b);
310+ Buf.str(b^, "]");
311+ return Buf.bytes(b^);
312312 end;
313313
314314 proc mn(m: Mem): []U8;

test/doc/Str.expect (history) modified +2 -2

@@ -84,10 +84,10 @@
8484 proc upper*(s: []U8);
8585 s's small ASCII letters made capitals, in place.
8686
87-proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8);
87+proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8);
8888 The parts added to b, with sep between each two.
8989
90-proc replace*(b: ^Buf.Buf; s, old, new: []U8);
90+proc replace*(var b: Buf.Buf; s, old, new: []U8);
9191 s added to b, with new for each old in it, from the left, none
9292 overlapping another; s as it is if old is empty.
9393

test/run/BufCut.raz (history) modified +3 -3

@@ -6,9 +6,9 @@
66 proc main*;
77 var b: Buf.Buf;
88 begin
9- Buf.init(ADR(b), Heap.heap);
10- Buf.str(ADR(b), "hello");
11- Buf.cut(ADR(b), 6);
9+ Buf.init(b, Heap.heap);
10+ Buf.str(b, "hello");
11+ Buf.cut(b, 6);
1212 end;
1313
1414 end BufCut.

test/run/BufCut.stderr (history) modified +1 -1

@@ -1,3 +1,3 @@
11 Buf.cut past the end
2- in Buf.cut at lib/Buf.raz:95:9: b = 0x?, n = 6
2+ in Buf.cut at lib/Buf.raz:95:9: n = 6
33 in BufCut.main at test/run/BufCut.raz:11:5

test/run/BufFull.raz (history) modified +2 -2

@@ -7,8 +7,8 @@
77 var ar: Arena.Arena; b: Buf.Buf; big: [10000]U8;
88 begin
99 if not Arena.init(ADR(ar), 4096) then Rt.stop("no arena"); end;
10- Buf.init(ADR(b), ADR(ar.base));
11- Buf.str(ADR(b), big);
10+ Buf.init(b, ADR(ar.base));
11+ Buf.str(b, big);
1212 end;
1313
1414 end BufFull.

test/run/BufFull.stderr (history) modified +2 -2

@@ -1,4 +1,4 @@
11 Buf: out of memory
2- in Buf.need at lib/Buf.raz:50:9: b = 0x?, n = 10000
3- in Buf.str at lib/Buf.raz:66:5: b = 0x?
2+ in Buf.need at lib/Buf.raz:50:9: n = 10000
3+ in Buf.str at lib/Buf.raz:66:5
44 in BufFull.main at test/run/BufFull.raz:11:5

test/run/BufInit.raz (history) modified +1 -1

@@ -6,7 +6,7 @@
66 proc main*;
77 var b: Buf.Buf;
88 begin
9- Buf.str(ADR(b), "hello");
9+ Buf.str(b, "hello");
1010 end;
1111
1212 end BufInit.

test/run/BufInit.stderr (history) modified +3 -3

@@ -1,5 +1,5 @@
11 Buf used before Buf.init
2- in Buf.room at lib/Buf.raz:31:9: b = 0x?, n = 5, cap = 64, p = nil
3- in Buf.need at lib/Buf.raz:48:5: b = 0x?, n = 5
4- in Buf.str at lib/Buf.raz:66:5: b = 0x?
2+ in Buf.room at lib/Buf.raz:31:9: n = 5, cap = 64, p = nil
3+ in Buf.need at lib/Buf.raz:48:5: n = 5
4+ in Buf.str at lib/Buf.raz:66:5
55 in BufInit.main at test/run/BufInit.raz:9:5

tools/Doc.raz (history) modified +14 -14

@@ -304,9 +304,9 @@
304304 proc document(path: []U8);
305305 var b: Buf.Buf; start, ds, de: INT;
306306 begin
307- Buf.init(ADR(b), Heap.heap);
308- if not Files.read(path, ADR(b)) then Rt.stop("Doc: can't read the file"); end;
309- src := Buf.bytes(ADR(b));
307+ Buf.init(b, Heap.heap);
308+ if not Files.read(path, b) then Rt.stop("Doc: can't read the file"); end;
309+ src := Buf.bytes(b);
310310 Scan.init(ADR(sc), src);
311311 next;
312312 while (sc.kind # Scan.eof) and not is("module") do next; end;
@@ -336,7 +336,7 @@
336336 (* line, from the report or a manual page's literal block, added to b
337337 as the program has it: in a page, \e is a backslash, \(ga a
338338 backquote and \& nothing. *)
339-proc addLine(b: ^Buf.Buf; line: []U8; page: BOOL);
339+proc addLine(var b: Buf.Buf; line: []U8; page: BOOL);
340340 var i: INT;
341341 begin
342342 i := 0;
@@ -357,7 +357,7 @@
357357 end;
358358
359359 (* text written to the file dir/name and ext, its path made in out *)
360-proc write(out: ^Buf.Buf; dir, name, ext, text: []U8);
360+proc write(var out: Buf.Buf; dir, name, ext, text: []U8);
361361 begin
362362 Buf.reset(out);
363363 Buf.str(out, dir); Buf.str(out, "/"); Buf.str(out, name); Buf.str(out, ext);
@@ -374,11 +374,11 @@
374374 b, out, prog: Buf.Buf; s, line, first, last, name, shows: []U8;
375375 i, k, n, after: INT; inBlock, whole, page, fence: BOOL;
376376 begin
377- Buf.init(ADR(b), Heap.heap);
378- Buf.init(ADR(out), Heap.heap);
379- Buf.init(ADR(prog), Heap.heap);
380- if not Files.read(path, ADR(b)) then Rt.stop("Doc: can't read the examples' file"); end;
381- s := Buf.bytes(ADR(b));
377+ Buf.init(b, Heap.heap);
378+ Buf.init(out, Heap.heap);
379+ Buf.init(prog, Heap.heap);
380+ if not Files.read(path, b) then Rt.stop("Doc: can't read the examples' file"); end;
381+ s := Buf.bytes(b);
382382 page := (LEN(path) < 3) or (path[LEN(path) - 3..LEN(path)] # ".md");
383383 inBlock := false;
384384 after := -1;
@@ -394,22 +394,22 @@
394394 n := 0;
395395 while (n < LEN(name)) and Scan.isWord(name[n]) do INC(n); end;
396396 name := name[0..n];
397- write(ADR(out), dir, name, ".raz", Buf.bytes(ADR(prog)));
397+ write(out, dir, name, ".raz", Buf.bytes(prog));
398398 Out.str(name); Out.ln;
399399 after := k + 1;
400400 elsif LEN(shows) > 0 then
401- write(ADR(out), dir, shows, ".shown", Buf.bytes(ADR(prog)));
401+ write(out, dir, shows, ".shown", Buf.bytes(prog));
402402 end;
403403 inBlock := false;
404404 elsif not inBlock and (fence or page and Str.hasPrefix(line, ".Bd -literal")) then
405405 inBlock := true;
406406 shows := "";
407407 if page and (i = after) then shows := name; end;
408- Buf.reset(ADR(prog));
408+ Buf.reset(prog);
409409 first := ""; last := "";
410410 whole := true;
411411 elsif inBlock then
412- addLine(ADR(prog), line, page);
412+ addLine(prog, line, page);
413413 if Str.trim(line) = "..." then whole := false; end;
414414 if LEN(Str.trim(line)) > 0 then
415415 if LEN(first) = 0 then first := Str.trim(line); end;

tools/Mutate.raz (history) modified +3 -3

@@ -62,9 +62,9 @@
6262 var buf: Buf.Buf; n, op, i: INT; a, b, c: Scan.Scanner;
6363 begin
6464 if ARGC() # 3 then Rt.stop("usage: Mutate File.raz seed"); end;
65- Buf.init(ADR(buf), Heap.heap);
66- if not Files.read(Files.arg(1), ADR(buf)) then Rt.stop("Mutate: can't read the file"); end;
67- src := Buf.bytes(ADR(buf));
65+ Buf.init(buf, Heap.heap);
66+ if not Files.read(Files.arg(1), buf) then Rt.stop("Mutate: can't read the file"); end;
67+ src := Buf.bytes(buf);
6868 seed(Files.arg(2));
6969 n := count();
7070 if n < 2 then Out.str(src); return; end;

tools/Pretty.raz (history) modified +18 -18

@@ -55,14 +55,14 @@
5555
5656 proc spaces(n: INT);
5757 begin
58- while n > 0 do Buf.add(ADR(out), ' '); DEC(n); end;
58+ while n > 0 do Buf.add(out, ' '); DEC(n); end;
5959 end;
6060
6161 (* Drops the spaces at the end of the line in out. *)
6262 proc trim;
6363 var s: []U8;
6464 begin
65- s := Buf.bytes(ADR(out));
65+ s := Buf.bytes(out);
6666 while (out.len > lineAt) and ((s[out.len - 1] = ' ') or (s[out.len - 1] = '\t')) do
6767 DEC(out.len);
6868 end;
@@ -71,7 +71,7 @@
7171 proc newLine;
7272 begin
7373 trim;
74- Buf.add(ADR(out), '\n');
74+ Buf.add(out, '\n');
7575 lineAt := out.len;
7676 end;
7777
@@ -215,12 +215,12 @@
215215 if (n < 1) and (sc.start > last) then n := 1; end;
216216 spaces(n);
217217 elsif afterComment then
218- Buf.str(ADR(out), src[last..sc.start]);
218+ Buf.str(out, src[last..sc.start]);
219219 elsif Scan.is(ADR(sc), ",") or Scan.is(ADR(sc), ";") then
220220 elsif Scan.is(ADR(prev), ",") or Scan.is(ADR(prev), ";") or binaryNow or prevBinary then
221221 if not prevUnary then spaces(1); end;
222222 elsif not prevUnary then
223- Buf.str(ADR(out), src[last..sc.start]);
223+ Buf.str(out, src[last..sc.start]);
224224 end;
225225 end;
226226
@@ -233,7 +233,7 @@
233233 i := sc.start;
234234 while i < sc.stop do
235235 if (src[i] = '\n') and (sc.kind = Scan.literal) then
236- Buf.add(ADR(out), '\n');
236+ Buf.add(out, '\n');
237237 lineAt := out.len;
238238 INC(i);
239239 elsif src[i] = '\n' then
@@ -243,7 +243,7 @@
243243 if (k < sc.stop) and (src[k] # '\n') then spaces(k - (i + 1) + lineDelta); end;
244244 i := k;
245245 else
246- Buf.add(ADR(out), src[i]);
246+ Buf.add(out, src[i]);
247247 INC(i);
248248 end;
249249 end;
@@ -289,7 +289,7 @@
289289 var b: BOOL;
290290 begin
291291 src := text;
292- Buf.reset(ADR(out));
292+ Buf.reset(out);
293293 lineAt := 0;
294294 depth := 0;
295295 brackets := 0;
@@ -325,23 +325,23 @@
325325 proc main*;
326326 var b: Buf.Buf; i: INT; path: []U8;
327327 begin
328- Buf.init(ADR(b), Heap.heap);
329- Buf.init(ADR(out), Heap.heap);
328+ Buf.init(b, Heap.heap);
329+ Buf.init(out, Heap.heap);
330330 if (ARGC() >= 3) and (Files.arg(1) = "-w") then
331331 for i := 2 to ARGC() - 1 do
332332 path := Files.arg(i);
333- Buf.reset(ADR(b));
334- if not Files.read(path, ADR(b)) then Rt.stop("Pretty: can't read a file"); end;
335- format(Buf.bytes(ADR(b)));
336- if Buf.bytes(ADR(out)) # Buf.bytes(ADR(b)) then
337- if not Files.write(path, Buf.bytes(ADR(out))) then Rt.stop("Pretty: can't write a file"); end;
333+ Buf.reset(b);
334+ if not Files.read(path, b) then Rt.stop("Pretty: can't read a file"); end;
335+ format(Buf.bytes(b));
336+ if Buf.bytes(out) # Buf.bytes(b) then
337+ if not Files.write(path, Buf.bytes(out)) then Rt.stop("Pretty: can't write a file"); end;
338338 Out.str(path); Out.ln;
339339 end;
340340 end;
341341 elsif ARGC() = 2 then
342- if not Files.read(Files.arg(1), ADR(b)) then Rt.stop("Pretty: can't read the file"); end;
343- format(Buf.bytes(ADR(b)));
344- Out.str(Buf.bytes(ADR(out)));
342+ if not Files.read(Files.arg(1), b) then Rt.stop("Pretty: can't read the file"); end;
343+ format(Buf.bytes(b));
344+ Out.str(Buf.bytes(out));
345345 else
346346 Rt.stop("usage: Pretty Module.raz, or Pretty -w File.raz...");
347347 end;

tools/Widths.raz (history) modified +16 -16

@@ -20,7 +20,7 @@
2020 w: [Last + 1]U8; (* each character's width, 1 unless a file says *)
2121
2222 (* The whole file at path. *)
23-proc load(path: []U8; b: ^Buf.Buf): []U8;
23+proc load(path: []U8; var b: Buf.Buf): []U8;
2424 begin
2525 Buf.init(b, Heap.heap);
2626 if not Files.read(path, b) then
@@ -116,7 +116,7 @@
116116 end;
117117
118118 (* c as a constant of raz: 0, six hexadecimal digits and H. *)
119-proc hex(b: ^Buf.Buf; c: INT);
119+proc hex(var b: Buf.Buf; c: INT);
120120 const Digits = "0123456789ABCDEF";
121121 var i: INT;
122122 begin
@@ -127,7 +127,7 @@
127127
128128 (* The constant name, the ranges of characters whose width is width,
129129 each its first and last, four ranges to a line. *)
130-proc table(b: ^Buf.Buf; name: []U8; width: U8);
130+proc table(var b: Buf.Buf; name: []U8; width: U8);
131131 var c, lo, n: INT;
132132 begin
133133 Buf.str(b, " "); Buf.str(b, name); Buf.str(b, ": []I32 = [");
@@ -153,7 +153,7 @@
153153 Out.str("usage: Widths lib/Width.raz EastAsianWidth.txt UnicodeData.txt PropList.txt\n");
154154 Rt.exit(2);
155155 end;
156- s := load(Files.arg(1), ADR(src));
156+ s := load(Files.arg(1), src);
157157 before, after, ok := Str.cut(s, Start);
158158 if ok then _, after, ok := Str.cut(after, Stop); end;
159159 if not ok then
@@ -161,22 +161,22 @@
161161 Rt.exit(1);
162162 end;
163163 mark(0, Last, 1);
164- version := eastAsian(load(Files.arg(2), ADR(eaw)));
165- categories(load(Files.arg(3), ADR(ucd)));
166- concatenation(load(Files.arg(4), ADR(props)));
164+ version := eastAsian(load(Files.arg(2), eaw));
165+ categories(load(Files.arg(3), ucd));
166+ concatenation(load(Files.arg(4), props));
167167 mark(1160H, 11FFH, 0); (* Hangul's medial and final jamo *)
168168 mark(0D7B0H, 0D7FFH, 0);
169169 mark(3164H, 3164H, 0); (* the Hangul fillers, which draw nothing *)
170170 mark(0FFA0H, 0FFA0H, 0);
171- Buf.init(ADR(out), Heap.heap);
172- Buf.str(ADR(out), before);
173- Buf.str(ADR(out), Start);
174- Buf.str(ADR(out), "(* Unicode "); Buf.str(ADR(out), version); Buf.str(ADR(out), " *)\nconst\n");
175- table(ADR(out), "Zero", 0);
176- table(ADR(out), "Wide", 2);
177- Buf.str(ADR(out), Stop);
178- Buf.str(ADR(out), after);
179- if not Files.write(Files.arg(1), Buf.bytes(ADR(out))) then
171+ Buf.init(out, Heap.heap);
172+ Buf.str(out, before);
173+ Buf.str(out, Start);
174+ Buf.str(out, "(* Unicode "); Buf.str(out, version); Buf.str(out, " *)\nconst\n");
175+ table(out, "Zero", 0);
176+ table(out, "Wide", 2);
177+ Buf.str(out, Stop);
178+ Buf.str(out, after);
179+ if not Files.write(Files.arg(1), Buf.bytes(out)) then
180180 Out.str(Files.arg(1)); Out.str(": can't be written\n");
181181 Rt.exit(1);
182182 end;