From 04d8e1a94e24d89a4236114b2c12a8438fa5f4a4 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:28:49 +0000 Subject: [PATCH] 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. --- diff --git a/src/Chunk.raz b/src/Chunk.raz index a4651a1..e48479f 100644 --- a/src/Chunk.raz +++ b/src/Chunk.raz @@ -18,6 +18,7 @@ end do what the seed's other units do to these. *) module Chunk; import Fmt, Diag, Scan; +import SYSTEM; type Section* = (secText, secRodata, secBss); @@ -151,7 +152,7 @@ chunks := ^Chunk(Scan.regrab(^U8(chunks), numChunks * SIZE(Chunk), chunkCap * 2 * SIZE(Chunk))); chunkCap := chunkCap * 2; end; - c := ADR(chunks[numChunks]); + c := SYSTEM.ADR(chunks[numChunks]); c^ := {}; c^.sec := sec; c^.home := home; diff --git a/src/Diag.raz b/src/Diag.raz index 60db14f..8d8bca3 100644 --- a/src/Diag.raz +++ b/src/Diag.raz @@ -16,6 +16,7 @@ made only where it is about to be shown. *) module Diag; import Sys, Rt, Heap, Mem, Buf, Fmt, Str; +import SYSTEM; type (* A stretch of a source file: bytes a up to but not including b. @@ -249,7 +250,7 @@ return; end; line, start := locate(p); - f := ADR(files[p.f]); + f := SYSTEM.ADR(files[p.f]); buf := f^.buf; paintOn(Bold); put(f^.path); put(":"); putNum(line); put(":"); putNum(chars(buf, start, p.a) + 1); put(":"); @@ -322,7 +323,7 @@ begin want := shownPath(path); for i := 0 to numFiles - 1 do - f := ADR(files[i]); + f := SYSTEM.ADR(files[i]); if f^.path = want then k := 0; n := 1; diff --git a/src/Elf.raz b/src/Elf.raz index 1d3b58d..f747135 100644 --- a/src/Elf.raz +++ b/src/Elf.raz @@ -26,6 +26,7 @@ setMainPath and setStripped do it. *) module Elf; import Sys, Files, Fmt, Diag, Scan, Chunk, Link; +import SYSTEM; var needed: [32]INT; (* the libraries to load, names interned *) @@ -166,7 +167,7 @@ proc putStr(s: []const U8); begin - putBytes(PTR(s), LEN(s)); + putBytes(SYSTEM.PTR(s), LEN(s)); putN(0, 1); end; @@ -230,7 +231,7 @@ end; (* The sizes of the loader's tables: what linkAll must leave room for. *) -proc sizeTables(roExtra, dynSize: ^INT); +proc sizeTables(var roExtra, dynSize: INT); var c, i: INT; begin nsym := 1; @@ -246,8 +247,8 @@ relaAt := symAt + nsym * 24; hashAt := relaAt + (nsym - 1) * 24; strAt := hashAt + 4 * (3 + nsym); - roExtra^ := strAt + strLen; - dynSize^ := (numNeeded + 10) * 16; + roExtra := strAt + strLen; + dynSize := (numNeeded + 10) * 16; end; (* The loader's tables in the room at the end of rodata, which the @@ -324,7 +325,7 @@ len := 0; dyn := numNeeded > 0; roExtra := 0; dynSize := 0; - if dyn then sizeTables(ADR(roExtra), ADR(dynSize)); end; + if dyn then sizeTables(roExtra, dynSize); end; (* room for the most program headers either kind of program has *) Link.linkAll(64 + 6 * 56, roExtra, dynSize); if dyn then @@ -409,7 +410,7 @@ strOff := len; putBytes(strs, strsLen); shstrOff := len; - putBytes(ADR(ShNames[0]), LEN(ShNames)); + putBytes(SYSTEM.PTR(ShNames), LEN(ShNames)); if stripped or (Link.placesChunk < 0) then for c := 0 to 2 do dbgOff[c] := len; dbgSize[c] := 0; end; else diff --git a/src/Gen.raz b/src/Gen.raz index 9079995..123528c 100644 --- a/src/Gen.raz +++ b/src/Gen.raz @@ -57,6 +57,7 @@ takes, is `CallInfo`. *) module Gen; import Fmt, Diag, Scan, Sym, Chunk, X := X64; +import SYSTEM; const NoLabel* = -1; @@ -293,7 +294,7 @@ var c: INT; begin c := Chunk.newChunk(Chunk.secRodata, -1, -1); - Chunk.setData(c, ^U8(ADR(v)), 8, 8); + Chunk.setData(c, ^U8(SYSTEM.ADR(v)), 8, 8); return X.memRip(c, 0); end; @@ -1575,7 +1576,7 @@ (* The name s, interned *) proc internStr(s: []const U8): INT; begin - return Scan.intern(PTR(s), LEN(s)); + return Scan.intern(SYSTEM.PTR(s), LEN(s)); end; (* The program goes on if the condition cc holds, and otherwise stops diff --git a/src/Item.raz b/src/Item.raz index a8df9cf..9dcfd65 100644 --- a/src/Item.raz +++ b/src/Item.raz @@ -25,6 +25,7 @@ in lower case. *) module Item; import Fmt, Diag, Scan, Sym, Chunk, Gen; +import SYSTEM; type Mode* = (mConst, mVar, mStack, mProc, mType, mStr, mBuiltin, mCase, mNone, mCond, @@ -173,7 +174,7 @@ var p: ^F64; begin makeConst(x, Sym.tRConst, 0); - p := ^F64(ADR(x.val)); + p := ^F64(SYSTEM.ADR(x.val)); p^ := r; end; @@ -186,7 +187,7 @@ var v: I64; p: ^F64; begin v := x.val; - p := ^F64(ADR(v)); + p := ^F64(SYSTEM.ADR(v)); return p^; end; @@ -385,7 +386,7 @@ if (x.typ^.form = Sym.fError) and (x.val > 0) then Gen.pushAdr(globalAdr(INT(x.val) - 1)); elsif isF32(x.typ) then f := F32(realOf(x)); - p := ^U32(ADR(f)); + p := ^U32(SYSTEM.ADR(f)); Gen.pushConst(Gen.kF32, I64(p^)); else Gen.pushConst(Gen.kindOf(x.typ), x.val); end; | mVar: diff --git a/src/Link.raz b/src/Link.raz index a283c22..5e0630c 100644 --- a/src/Link.raz +++ b/src/Link.raz @@ -17,6 +17,7 @@ Leaves out: the file format; that is Elf. *) module Link; import Fmt, Diag, Scan, Chunk; +import SYSTEM; const Page* = 4096; diff --git a/src/Parse.raz b/src/Parse.raz index dbaead8..0e2d5b7 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -27,6 +27,7 @@ holds. *) module Parse; import Fmt, Diag, Scan, Sym, Chunk, Gen, Item, Sys, Str, Buf, Heap; +import SYSTEM; type PType = ^Sym.Type; @@ -183,7 +184,7 @@ (* The name number of s, which isn't empty *) proc internName(s: []const U8): INT; begin - return Scan.intern(PTR(s), LEN(s)); + return Scan.intern(SYSTEM.PTR(s), LEN(s)); end; proc say1(f, a: []const U8): []const U8; @@ -2101,7 +2102,7 @@ lp.cont := Gen.NoLabel; lp.base := numDefers; old := curLoop; - curLoop := ADR(lp); + curLoop := SYSTEM.ADR(lp); end; (* Runs the deferred statements in force above base, newest first. *) @@ -3640,7 +3641,7 @@ proc putBytes(off, n: INT; v: I64); var src: ^U8; begin - src := ^U8(ADR(v)); + src := ^U8(SYSTEM.ADR(v)); COPY(constBytes[off..off + n], src[0..n]); end; @@ -3839,7 +3840,7 @@ return Scan.markAt(e.pos, "a constant pointer is nil"); elsif (t^.form = Sym.fReal) and (t^.size = 4) then r := F32(Item.realOf(e)); - src := ^U8(ADR(r)); + src := ^U8(SYSTEM.ADR(r)); COPY(constBytes[off..off + 4], src[0..4]); else putBytes(off, INT(t^.size), e.val); @@ -4312,7 +4313,7 @@ if LEN(path) >= 4096 then return 0, 0; end; COPY(a[0..LEN(path)], path); a[LEN(path)] := 0; - if SYSCALL(4, ADR(a[0]), ADR(st)) < 0 then return 0, 0; end; + if SYSTEM.SYSCALL(4, SYSTEM.ADR(a[0]), SYSTEM.ADR(st)) < 0 then return 0, 0; end; return st[0], st[1]; end; diff --git a/src/Raz.raz b/src/Raz.raz index 6578e38..6f22dae 100644 --- a/src/Raz.raz +++ b/src/Raz.raz @@ -30,6 +30,7 @@ write, and this only reads the command line and runs them in order. *) module Raz; import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Item, Parse, Link, Elf; +import SYSTEM; const Report = "2026-10.37"; (* the version of doc/raz.md it follows *) @@ -51,7 +52,7 @@ (* The number of the name s *) proc internStr(s: []const U8): INT; begin - return Scan.intern(PTR(s), LEN(s)); + return Scan.intern(SYSTEM.PTR(s), LEN(s)); end; (* The modules the program uses: the main module, Rt, and every module @@ -410,11 +411,11 @@ Elf.setMainPath(path); if run then (* argv from Main.raz on is the program's, ending in nil as it must *) - fd := SYSCALL(MemfdCreate, cstr("raz"), MfdCloexec); + fd := SYSTEM.SYSCALL(MemfdCreate, cstr("raz"), MfdCloexec); if fd < 0 then Diag.fatal("can't create a memfd"); end; outPath := Diag.say("/proc/self/fd/{}", [Fmt.int(fd)]); Elf.writeElf(outPath, entry); - _ := SYSCALL(Execve, cstr(outPath), ARGV() + first, ARGV() + (ARGC() + 1)); + _ := SYSTEM.SYSCALL(Execve, cstr(outPath), SYSTEM.ARGV() + first, SYSTEM.ARGV() + (ARGC() + 1)); Diag.fatal(say1("can't run {}", path)); end; Elf.writeElf(outPath, entry); diff --git a/src/Scan.raz b/src/Scan.raz index 8515fa2..3e63fe0 100644 --- a/src/Scan.raz +++ b/src/Scan.raz @@ -13,6 +13,7 @@ back Failed, which it passes up with try to where it can read on. *) module Scan; import Sys, Heap, Mem, Fmt, Str, Diag; +import SYSTEM; type NamePtr = ^U8; @@ -116,7 +117,7 @@ chunk of it: an empty string has bytes to point at, though none to index *) proc strWithZero*: ^U8; begin - return ADR(sbuf[0]); + return SYSTEM.ADR(sbuf[0]); end; (* Memory, or the end of the compile when there is none *) @@ -897,7 +898,7 @@ else b := q; (* below the least normal, e is -1074 *) end; - bits := ^F64(ADR(b)); + bits := ^F64(SYSTEM.ADR(b)); return bits^, true; end; @@ -1165,5 +1166,5 @@ nameHash := ^INT(grab(nameCap * SIZE(INT))); tableMask := 2 * nameCap - 1; table := words64(tableMask + 1); - for i := 0 to NumWords - 1 do _ := intern(PTR(words[i]), LEN(words[i])); end; + for i := 0 to NumWords - 1 do _ := intern(SYSTEM.PTR(words[i]), LEN(words[i])); end; end Scan. diff --git a/src/Sym.raz b/src/Sym.raz index 3af9f49..c3a1524 100644 --- a/src/Sym.raz +++ b/src/Sym.raz @@ -17,6 +17,7 @@ its `home`, an object's `link` its `chain`. *) module Sym; import Mem, Heap, Buf, Fmt, Diag, Scan; +import SYSTEM; type Form* = (fNone, fBool, fInt, fReal, fConst, fNil, fStr, fPtr, fArray, @@ -705,7 +706,7 @@ begin t := newType(form, size, size); t^.signed := signed; - o := newObj(oType, Scan.intern(PTR(name), LEN(name)), t); + o := newObj(oType, Scan.intern(SYSTEM.PTR(name), LEN(name)), t); o^.exported := true; t^.obj := o; _ := insert(o, 0); @@ -715,7 +716,7 @@ (* The name s, interned *) proc internOf(s: []const U8): INT; begin - return Scan.intern(PTR(s), LEN(s)); + return Scan.intern(SYSTEM.PTR(s), LEN(s)); end; (* Declares name in the scope s, exported, as a built-in is *) diff --git a/src/X64.raz b/src/X64.raz index b4dc6e8..6d70cd5 100644 --- a/src/X64.raz +++ b/src/X64.raz @@ -14,6 +14,7 @@ an error back from; the compile ends with the error shown. *) module X64; import Out, Fmt, Heap, Buf, Str, Diag, Scan, Chunk; +import SYSTEM; const RAX* = 0; RCX* = 1; RDX* = 2; RBX* = 3; RSP* = 4; RBP* = 5; RSI* = 6; RDI* = 7; @@ -980,27 +981,27 @@ (* Whether w names a register: rax, eax, ax, al and so on, or xmm0 to xmm15 (size 16); r and size are set if so *) -proc isReg(w: []const U8; r, size: ^INT): BOOL; +proc isReg(w: []const U8; var r, size: INT): BOOL; const Sizes: [4]INT = [8, 4, 2, 1]; var i, j, n, d: INT; begin for i := 0 to 3 do for j := 0 to 15 do - if RegNames[i][j] = w then r^ := j; size^ := Sizes[i]; return true; end; + if RegNames[i][j] = w then r := j; size := Sizes[i]; return true; end; end; end; - size^ := 16; + size := 16; if not Str.hasPrefix(w, "xmm") or (LEN(w) <= 3) then return false; end; (* the seed read the two bytes after xmm as a number, whatever follows *) n := LEN(w) - 3; if n > 2 then n := 2; end; - r^ := 0; + r := 0; for i := 0 to n - 1 do d := INT(w[3 + i]) - 48; if (d < 0) or (d > 9) then return false; end; - r^ := r^ * 10 + d; + r := r * 10 + d; end; - return r^ <= 15; + return r <= 15; end; (* Which word of list, a list of words each with a space either side, @@ -1046,10 +1047,10 @@ return -1; end; -proc operand(o: ^Operand; constExpr: ConstFn): ERROR; +proc operand(var o: Operand; constExpr: ConstFn): ERROR; var w: []const U8; r, size, sz: INT; st: Scan.State; v: I64; isR, wasMinus: BOOL; begin - o^ := {}; + o := {}; w := asmWord(); sz := 0; if w = "byte" then sz := 1; @@ -1061,50 +1062,50 @@ if Scan.tok = Scan.sLbrak then (* [base + index * scale + disp], the displacement last *) Scan.next; - o^.kind := oMem; o^.size := sz; - o^.m := mem(NoBase, 0); + o.kind := oMem; o.size := sz; + o.m := mem(NoBase, 0); repeat - if isReg(asmWord(), ADR(r), ADR(size)) and (size = 8) then + if isReg(asmWord(), r, size) and (size = 8) then Scan.next; (* the scale is a single number or constant: a whole expression would take in the displacement after it, as 4 + 16 in [rdi + rsi * 4 + 16] *) if Scan.tok = Scan.sTimes then Scan.next; - o^.m.index := r; + o.m.index := r; v := try constExpr(false); - o^.m.scale := INT(v); - elsif o^.m.base = NoBase then - o^.m.base := r; + o.m.scale := INT(v); + elsif o.m.base = NoBase then + o.m.base := r; else - o^.m.index := r; o^.m.scale := 1; + o.m.index := r; o.m.scale := 1; end; else v := try constExpr(true); - o^.m.disp := o^.m.disp + INT(v); + o.m.disp := o.m.disp + INT(v); end; if (Scan.tok # Scan.sPlus) and (Scan.tok # Scan.sMinus) then break; end; wasMinus := Scan.tok = Scan.sMinus; Scan.saveScan(st); Scan.next; - isR := isReg(asmWord(), ADR(r), ADR(size)); + isR := isReg(asmWord(), r, size); if not isR and wasMinus then Scan.restoreScan(st); end; until false; - if (Scan.tok # Scan.sRbrak) or (o^.m.base = NoBase) - or not ((o^.m.scale = 1) or (o^.m.scale = 2) or (o^.m.scale = 4) or (o^.m.scale = 8)) then + if (Scan.tok # Scan.sRbrak) or (o.m.base = NoBase) + or not ((o.m.scale = 1) or (o.m.scale = 2) or (o.m.scale = 4) or (o.m.scale = 8)) then return Scan.mark("expected a memory operand, [base + index * scale + disp]"); end; Scan.next; elsif (w = "cr0") or (w = "cr2") or (w = "cr3") or (w = "cr4") or (w = "cr8") then (* a control register, for mov to and from a general one *) - o^.kind := oCr; o^.r := INT(w[2]) - 48; o^.size := 8; + o.kind := oCr; o.r := INT(w[2]) - 48; o.size := 8; Scan.next; - elsif isReg(w, ADR(o^.r), ADR(o^.size)) then - if o^.size = 16 then o^.kind := oXmm; else o^.kind := oReg; end; + elsif isReg(w, o.r, o.size) then + if o.size = 16 then o.kind := oXmm; else o.kind := oReg; end; Scan.next; else - o^.kind := oImm; - o^.v := try constExpr(true); + o.kind := oImm; + o.v := try constExpr(true); end; return nil; end; @@ -1434,7 +1435,7 @@ proc atRegister(): BOOL; var r, size: INT; begin - return isReg(asmWord(), ADR(r), ADR(size)); + return isReg(asmWord(), r, size); end; (* One instruction or label, as assemble reads it *) @@ -1448,7 +1449,7 @@ Scan.next; if Scan.tok = Scan.sColon then sayAt(Chunk.pc, Diag.say("{}:", [Fmt.str(aw)])); - k := try lab(Scan.intern(PTR(aw), LEN(aw))); + k := try lab(Scan.intern(SYSTEM.PTR(aw), LEN(aw))); if lplaces[k] >= 0 then return Scan.markAt(aat, Diag.say("label {} is defined twice", [Fmt.str(aw)])); end; @@ -1494,7 +1495,7 @@ if Scan.tok # Scan.sSemicolon then repeat if an > 2 then return Scan.mark("too many operands"); end; - try operand(ADR(ao[an]), constExpr); + try operand(ao[an], constExpr); INC(an); if Scan.tok # Scan.sComma then break; end; Scan.next;