raz / commit 04d8e1a9

commit
04d8e1a94e24d89a4236114b2c12a8438fa5f4a4
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
a9d35a84
src/ held to report 2026-10.37 whole: import SYSTEM where it reaches memory so

Every module but none indexes or converts a pointer, so each imports
SYSTEM; X64.isReg and operand and Elf.sizeTables take var where they
took ADR. The compiler compiles itself under -strict -Werror, and makes
the same bytes as before for every program tried.

patch · log

11 files changed, +66 -55

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

@@ -18,6 +18,7 @@
1818 end do what the seed's other units do to these. *)
1919 module Chunk;
2020 import Fmt, Diag, Scan;
21+import SYSTEM;
2122
2223 type
2324 Section* = (secText, secRodata, secBss);
@@ -151,7 +152,7 @@
151152 chunks := ^Chunk(Scan.regrab(^U8(chunks), numChunks * SIZE(Chunk), chunkCap * 2 * SIZE(Chunk)));
152153 chunkCap := chunkCap * 2;
153154 end;
154- c := ADR(chunks[numChunks]);
155+ c := SYSTEM.ADR(chunks[numChunks]);
155156 c^ := {};
156157 c^.sec := sec;
157158 c^.home := home;

src/Diag.raz (history) modified +3 -2

@@ -16,6 +16,7 @@
1616 made only where it is about to be shown. *)
1717 module Diag;
1818 import Sys, Rt, Heap, Mem, Buf, Fmt, Str;
19+import SYSTEM;
1920
2021 type
2122 (* A stretch of a source file: bytes a up to but not including b.
@@ -249,7 +250,7 @@
249250 return;
250251 end;
251252 line, start := locate(p);
252- f := ADR(files[p.f]);
253+ f := SYSTEM.ADR(files[p.f]);
253254 buf := f^.buf;
254255 paintOn(Bold);
255256 put(f^.path); put(":"); putNum(line); put(":"); putNum(chars(buf, start, p.a) + 1); put(":");
@@ -322,7 +323,7 @@
322323 begin
323324 want := shownPath(path);
324325 for i := 0 to numFiles - 1 do
325- f := ADR(files[i]);
326+ f := SYSTEM.ADR(files[i]);
326327 if f^.path = want then
327328 k := 0;
328329 n := 1;

src/Elf.raz modified +7 -6

@@ -26,6 +26,7 @@
2626 setMainPath and setStripped do it. *)
2727 module Elf;
2828 import Sys, Files, Fmt, Diag, Scan, Chunk, Link;
29+import SYSTEM;
2930
3031 var
3132 needed: [32]INT; (* the libraries to load, names interned *)
@@ -166,7 +167,7 @@
166167
167168 proc putStr(s: []const U8);
168169 begin
169- putBytes(PTR(s), LEN(s));
170+ putBytes(SYSTEM.PTR(s), LEN(s));
170171 putN(0, 1);
171172 end;
172173
@@ -230,7 +231,7 @@
230231 end;
231232
232233 (* The sizes of the loader's tables: what linkAll must leave room for. *)
233-proc sizeTables(roExtra, dynSize: ^INT);
234+proc sizeTables(var roExtra, dynSize: INT);
234235 var c, i: INT;
235236 begin
236237 nsym := 1;
@@ -246,8 +247,8 @@
246247 relaAt := symAt + nsym * 24;
247248 hashAt := relaAt + (nsym - 1) * 24;
248249 strAt := hashAt + 4 * (3 + nsym);
249- roExtra^ := strAt + strLen;
250- dynSize^ := (numNeeded + 10) * 16;
250+ roExtra := strAt + strLen;
251+ dynSize := (numNeeded + 10) * 16;
251252 end;
252253
253254 (* The loader's tables in the room at the end of rodata, which the
@@ -324,7 +325,7 @@
324325 len := 0;
325326 dyn := numNeeded > 0;
326327 roExtra := 0; dynSize := 0;
327- if dyn then sizeTables(ADR(roExtra), ADR(dynSize)); end;
328+ if dyn then sizeTables(roExtra, dynSize); end;
328329 (* room for the most program headers either kind of program has *)
329330 Link.linkAll(64 + 6 * 56, roExtra, dynSize);
330331 if dyn then
@@ -409,7 +410,7 @@
409410 strOff := len;
410411 putBytes(strs, strsLen);
411412 shstrOff := len;
412- putBytes(ADR(ShNames[0]), LEN(ShNames));
413+ putBytes(SYSTEM.PTR(ShNames), LEN(ShNames));
413414 if stripped or (Link.placesChunk < 0) then
414415 for c := 0 to 2 do dbgOff[c] := len; dbgSize[c] := 0; end;
415416 else

src/Gen.raz modified +3 -2

@@ -57,6 +57,7 @@
5757 takes, is `CallInfo`. *)
5858 module Gen;
5959 import Fmt, Diag, Scan, Sym, Chunk, X := X64;
60+import SYSTEM;
6061
6162 const
6263 NoLabel* = -1;
@@ -293,7 +294,7 @@
293294 var c: INT;
294295 begin
295296 c := Chunk.newChunk(Chunk.secRodata, -1, -1);
296- Chunk.setData(c, ^U8(ADR(v)), 8, 8);
297+ Chunk.setData(c, ^U8(SYSTEM.ADR(v)), 8, 8);
297298 return X.memRip(c, 0);
298299 end;
299300
@@ -1575,7 +1576,7 @@
15751576 (* The name s, interned *)
15761577 proc internStr(s: []const U8): INT;
15771578 begin
1578- return Scan.intern(PTR(s), LEN(s));
1579+ return Scan.intern(SYSTEM.PTR(s), LEN(s));
15791580 end;
15801581
15811582 (* The program goes on if the condition cc holds, and otherwise stops

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

@@ -25,6 +25,7 @@
2525 in lower case. *)
2626 module Item;
2727 import Fmt, Diag, Scan, Sym, Chunk, Gen;
28+import SYSTEM;
2829
2930 type
3031 Mode* = (mConst, mVar, mStack, mProc, mType, mStr, mBuiltin, mCase, mNone, mCond,
@@ -173,7 +174,7 @@
173174 var p: ^F64;
174175 begin
175176 makeConst(x, Sym.tRConst, 0);
176- p := ^F64(ADR(x.val));
177+ p := ^F64(SYSTEM.ADR(x.val));
177178 p^ := r;
178179 end;
179180
@@ -186,7 +187,7 @@
186187 var v: I64; p: ^F64;
187188 begin
188189 v := x.val;
189- p := ^F64(ADR(v));
190+ p := ^F64(SYSTEM.ADR(v));
190191 return p^;
191192 end;
192193
@@ -385,7 +386,7 @@
385386 if (x.typ^.form = Sym.fError) and (x.val > 0) then Gen.pushAdr(globalAdr(INT(x.val) - 1));
386387 elsif isF32(x.typ) then
387388 f := F32(realOf(x));
388- p := ^U32(ADR(f));
389+ p := ^U32(SYSTEM.ADR(f));
389390 Gen.pushConst(Gen.kF32, I64(p^));
390391 else Gen.pushConst(Gen.kindOf(x.typ), x.val); end;
391392 | mVar:

src/Link.raz (history) modified +1 -0

@@ -17,6 +17,7 @@
1717 Leaves out: the file format; that is Elf. *)
1818 module Link;
1919 import Fmt, Diag, Scan, Chunk;
20+import SYSTEM;
2021
2122 const
2223 Page* = 4096;

src/Parse.raz (history) modified +6 -5

@@ -27,6 +27,7 @@
2727 holds. *)
2828 module Parse;
2929 import Fmt, Diag, Scan, Sym, Chunk, Gen, Item, Sys, Str, Buf, Heap;
30+import SYSTEM;
3031
3132 type
3233 PType = ^Sym.Type;
@@ -183,7 +184,7 @@
183184 (* The name number of s, which isn't empty *)
184185 proc internName(s: []const U8): INT;
185186 begin
186- return Scan.intern(PTR(s), LEN(s));
187+ return Scan.intern(SYSTEM.PTR(s), LEN(s));
187188 end;
188189
189190 proc say1(f, a: []const U8): []const U8;
@@ -2101,7 +2102,7 @@
21012102 lp.cont := Gen.NoLabel;
21022103 lp.base := numDefers;
21032104 old := curLoop;
2104- curLoop := ADR(lp);
2105+ curLoop := SYSTEM.ADR(lp);
21052106 end;
21062107
21072108 (* Runs the deferred statements in force above base, newest first. *)
@@ -3640,7 +3641,7 @@
36403641 proc putBytes(off, n: INT; v: I64);
36413642 var src: ^U8;
36423643 begin
3643- src := ^U8(ADR(v));
3644+ src := ^U8(SYSTEM.ADR(v));
36443645 COPY(constBytes[off..off + n], src[0..n]);
36453646 end;
36463647
@@ -3839,7 +3840,7 @@
38393840 return Scan.markAt(e.pos, "a constant pointer is nil");
38403841 elsif (t^.form = Sym.fReal) and (t^.size = 4) then
38413842 r := F32(Item.realOf(e));
3842- src := ^U8(ADR(r));
3843+ src := ^U8(SYSTEM.ADR(r));
38433844 COPY(constBytes[off..off + 4], src[0..4]);
38443845 else
38453846 putBytes(off, INT(t^.size), e.val);
@@ -4312,7 +4313,7 @@
43124313 if LEN(path) >= 4096 then return 0, 0; end;
43134314 COPY(a[0..LEN(path)], path);
43144315 a[LEN(path)] := 0;
4315- if SYSCALL(4, ADR(a[0]), ADR(st)) < 0 then return 0, 0; end;
4316+ if SYSTEM.SYSCALL(4, SYSTEM.ADR(a[0]), SYSTEM.ADR(st)) < 0 then return 0, 0; end;
43164317 return st[0], st[1];
43174318 end;
43184319

src/Raz.raz (history) modified +4 -3

@@ -30,6 +30,7 @@
3030 write, and this only reads the command line and runs them in order. *)
3131 module Raz;
3232 import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Item, Parse, Link, Elf;
33+import SYSTEM;
3334
3435 const
3536 Report = "2026-10.37"; (* the version of doc/raz.md it follows *)
@@ -51,7 +52,7 @@
5152 (* The number of the name s *)
5253 proc internStr(s: []const U8): INT;
5354 begin
54- return Scan.intern(PTR(s), LEN(s));
55+ return Scan.intern(SYSTEM.PTR(s), LEN(s));
5556 end;
5657
5758 (* The modules the program uses: the main module, Rt, and every module
@@ -410,11 +411,11 @@
410411 Elf.setMainPath(path);
411412 if run then
412413 (* argv from Main.raz on is the program's, ending in nil as it must *)
413- fd := SYSCALL(MemfdCreate, cstr("raz"), MfdCloexec);
414+ fd := SYSTEM.SYSCALL(MemfdCreate, cstr("raz"), MfdCloexec);
414415 if fd < 0 then Diag.fatal("can't create a memfd"); end;
415416 outPath := Diag.say("/proc/self/fd/{}", [Fmt.int(fd)]);
416417 Elf.writeElf(outPath, entry);
417- _ := SYSCALL(Execve, cstr(outPath), ARGV() + first, ARGV() + (ARGC() + 1));
418+ _ := SYSTEM.SYSCALL(Execve, cstr(outPath), SYSTEM.ARGV() + first, SYSTEM.ARGV() + (ARGC() + 1));
418419 Diag.fatal(say1("can't run {}", path));
419420 end;
420421 Elf.writeElf(outPath, entry);

src/Scan.raz (history) modified +4 -3

@@ -13,6 +13,7 @@
1313 back Failed, which it passes up with try to where it can read on. *)
1414 module Scan;
1515 import Sys, Heap, Mem, Fmt, Str, Diag;
16+import SYSTEM;
1617
1718 type
1819 NamePtr = ^U8;
@@ -116,7 +117,7 @@
116117 chunk of it: an empty string has bytes to point at, though none to index *)
117118 proc strWithZero*: ^U8;
118119 begin
119- return ADR(sbuf[0]);
120+ return SYSTEM.ADR(sbuf[0]);
120121 end;
121122
122123 (* Memory, or the end of the compile when there is none *)
@@ -897,7 +898,7 @@
897898 else
898899 b := q; (* below the least normal, e is -1074 *)
899900 end;
900- bits := ^F64(ADR(b));
901+ bits := ^F64(SYSTEM.ADR(b));
901902 return bits^, true;
902903 end;
903904
@@ -1165,5 +1166,5 @@
11651166 nameHash := ^INT(grab(nameCap * SIZE(INT)));
11661167 tableMask := 2 * nameCap - 1;
11671168 table := words64(tableMask + 1);
1168- for i := 0 to NumWords - 1 do _ := intern(PTR(words[i]), LEN(words[i])); end;
1169+ for i := 0 to NumWords - 1 do _ := intern(SYSTEM.PTR(words[i]), LEN(words[i])); end;
11691170 end Scan.

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

@@ -17,6 +17,7 @@
1717 its `home`, an object's `link` its `chain`. *)
1818 module Sym;
1919 import Mem, Heap, Buf, Fmt, Diag, Scan;
20+import SYSTEM;
2021
2122 type
2223 Form* = (fNone, fBool, fInt, fReal, fConst, fNil, fStr, fPtr, fArray,
@@ -705,7 +706,7 @@
705706 begin
706707 t := newType(form, size, size);
707708 t^.signed := signed;
708- o := newObj(oType, Scan.intern(PTR(name), LEN(name)), t);
709+ o := newObj(oType, Scan.intern(SYSTEM.PTR(name), LEN(name)), t);
709710 o^.exported := true;
710711 t^.obj := o;
711712 _ := insert(o, 0);
@@ -715,7 +716,7 @@
715716 (* The name s, interned *)
716717 proc internOf(s: []const U8): INT;
717718 begin
718- return Scan.intern(PTR(s), LEN(s));
719+ return Scan.intern(SYSTEM.PTR(s), LEN(s));
719720 end;
720721
721722 (* Declares name in the scope s, exported, as a built-in is *)

src/X64.raz (history) modified +29 -28

@@ -14,6 +14,7 @@
1414 an error back from; the compile ends with the error shown. *)
1515 module X64;
1616 import Out, Fmt, Heap, Buf, Str, Diag, Scan, Chunk;
17+import SYSTEM;
1718
1819 const
1920 RAX* = 0; RCX* = 1; RDX* = 2; RBX* = 3; RSP* = 4; RBP* = 5; RSI* = 6; RDI* = 7;
@@ -980,27 +981,27 @@
980981
981982 (* Whether w names a register: rax, eax, ax, al and so on, or xmm0 to
982983 xmm15 (size 16); r and size are set if so *)
983-proc isReg(w: []const U8; r, size: ^INT): BOOL;
984+proc isReg(w: []const U8; var r, size: INT): BOOL;
984985 const Sizes: [4]INT = [8, 4, 2, 1];
985986 var i, j, n, d: INT;
986987 begin
987988 for i := 0 to 3 do
988989 for j := 0 to 15 do
989- if RegNames[i][j] = w then r^ := j; size^ := Sizes[i]; return true; end;
990+ if RegNames[i][j] = w then r := j; size := Sizes[i]; return true; end;
990991 end;
991992 end;
992- size^ := 16;
993+ size := 16;
993994 if not Str.hasPrefix(w, "xmm") or (LEN(w) <= 3) then return false; end;
994995 (* the seed read the two bytes after xmm as a number, whatever follows *)
995996 n := LEN(w) - 3;
996997 if n > 2 then n := 2; end;
997- r^ := 0;
998+ r := 0;
998999 for i := 0 to n - 1 do
9991000 d := INT(w[3 + i]) - 48;
10001001 if (d < 0) or (d > 9) then return false; end;
1001- r^ := r^ * 10 + d;
1002+ r := r * 10 + d;
10021003 end;
1003- return r^ <= 15;
1004+ return r <= 15;
10041005 end;
10051006
10061007 (* Which word of list, a list of words each with a space either side,
@@ -1046,10 +1047,10 @@
10461047 return -1;
10471048 end;
10481049
1049-proc operand(o: ^Operand; constExpr: ConstFn): ERROR;
1050+proc operand(var o: Operand; constExpr: ConstFn): ERROR;
10501051 var w: []const U8; r, size, sz: INT; st: Scan.State; v: I64; isR, wasMinus: BOOL;
10511052 begin
1052- o^ := {};
1053+ o := {};
10531054 w := asmWord();
10541055 sz := 0;
10551056 if w = "byte" then sz := 1;
@@ -1061,50 +1062,50 @@
10611062 if Scan.tok = Scan.sLbrak then
10621063 (* [base + index * scale + disp], the displacement last *)
10631064 Scan.next;
1064- o^.kind := oMem; o^.size := sz;
1065- o^.m := mem(NoBase, 0);
1065+ o.kind := oMem; o.size := sz;
1066+ o.m := mem(NoBase, 0);
10661067 repeat
1067- if isReg(asmWord(), ADR(r), ADR(size)) and (size = 8) then
1068+ if isReg(asmWord(), r, size) and (size = 8) then
10681069 Scan.next;
10691070 (* the scale is a single number or constant: a whole expression
10701071 would take in the displacement after it, as 4 + 16 in
10711072 [rdi + rsi * 4 + 16] *)
10721073 if Scan.tok = Scan.sTimes then
10731074 Scan.next;
1074- o^.m.index := r;
1075+ o.m.index := r;
10751076 v := try constExpr(false);
1076- o^.m.scale := INT(v);
1077- elsif o^.m.base = NoBase then
1078- o^.m.base := r;
1077+ o.m.scale := INT(v);
1078+ elsif o.m.base = NoBase then
1079+ o.m.base := r;
10791080 else
1080- o^.m.index := r; o^.m.scale := 1;
1081+ o.m.index := r; o.m.scale := 1;
10811082 end;
10821083 else
10831084 v := try constExpr(true);
1084- o^.m.disp := o^.m.disp + INT(v);
1085+ o.m.disp := o.m.disp + INT(v);
10851086 end;
10861087 if (Scan.tok # Scan.sPlus) and (Scan.tok # Scan.sMinus) then break; end;
10871088 wasMinus := Scan.tok = Scan.sMinus;
10881089 Scan.saveScan(st);
10891090 Scan.next;
1090- isR := isReg(asmWord(), ADR(r), ADR(size));
1091+ isR := isReg(asmWord(), r, size);
10911092 if not isR and wasMinus then Scan.restoreScan(st); end;
10921093 until false;
1093- if (Scan.tok # Scan.sRbrak) or (o^.m.base = NoBase)
1094- or not ((o^.m.scale = 1) or (o^.m.scale = 2) or (o^.m.scale = 4) or (o^.m.scale = 8)) then
1094+ if (Scan.tok # Scan.sRbrak) or (o.m.base = NoBase)
1095+ or not ((o.m.scale = 1) or (o.m.scale = 2) or (o.m.scale = 4) or (o.m.scale = 8)) then
10951096 return Scan.mark("expected a memory operand, [base + index * scale + disp]");
10961097 end;
10971098 Scan.next;
10981099 elsif (w = "cr0") or (w = "cr2") or (w = "cr3") or (w = "cr4") or (w = "cr8") then
10991100 (* a control register, for mov to and from a general one *)
1100- o^.kind := oCr; o^.r := INT(w[2]) - 48; o^.size := 8;
1101+ o.kind := oCr; o.r := INT(w[2]) - 48; o.size := 8;
11011102 Scan.next;
1102- elsif isReg(w, ADR(o^.r), ADR(o^.size)) then
1103- if o^.size = 16 then o^.kind := oXmm; else o^.kind := oReg; end;
1103+ elsif isReg(w, o.r, o.size) then
1104+ if o.size = 16 then o.kind := oXmm; else o.kind := oReg; end;
11041105 Scan.next;
11051106 else
1106- o^.kind := oImm;
1107- o^.v := try constExpr(true);
1107+ o.kind := oImm;
1108+ o.v := try constExpr(true);
11081109 end;
11091110 return nil;
11101111 end;
@@ -1434,7 +1435,7 @@
14341435 proc atRegister(): BOOL;
14351436 var r, size: INT;
14361437 begin
1437- return isReg(asmWord(), ADR(r), ADR(size));
1438+ return isReg(asmWord(), r, size);
14381439 end;
14391440
14401441 (* One instruction or label, as assemble reads it *)
@@ -1448,7 +1449,7 @@
14481449 Scan.next;
14491450 if Scan.tok = Scan.sColon then
14501451 sayAt(Chunk.pc, Diag.say("{}:", [Fmt.str(aw)]));
1451- k := try lab(Scan.intern(PTR(aw), LEN(aw)));
1452+ k := try lab(Scan.intern(SYSTEM.PTR(aw), LEN(aw)));
14521453 if lplaces[k] >= 0 then
14531454 return Scan.markAt(aat, Diag.say("label {} is defined twice", [Fmt.str(aw)]));
14541455 end;
@@ -1494,7 +1495,7 @@
14941495 if Scan.tok # Scan.sSemicolon then
14951496 repeat
14961497 if an > 2 then return Scan.mark("too many operands"); end;
1497- try operand(ADR(ao[an]), constExpr);
1498+ try operand(ao[an], constExpr);
14981499 INC(an);
14991500 if Scan.tok # Scan.sComma then break; end;
15001501 Scan.next;