The tests, conform/, examples/ and the docs' examples held to report 2026-10.37 whole import SYSTEM where a program reaches memory other than through a variable, []const U8 where a string is only read, atomics on the variable; err tests keep their point, their messages moved by the added import line. make check passes as it is and with RAZ_STRICT=1.
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module ArrayConstAdr; |
| 2 | +import SYSTEM; | |
| 2 | 3 | const P: [2]I64 = [1, 2]; |
| 3 | 4 | proc main*; |
| 4 | 5 | var p: ^[2]I64; |
| 5 | 6 | begin |
| 6 | - p := ADR(P); | |
| 7 | + p := SYSTEM.ADR(P); | |
| 7 | 8 | end; |
| 8 | 9 | end ArrayConstAdr. |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module AtPAdr; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var p: ^I64; |
| 4 | 5 | begin |
| 5 | - p := ADR(1); | |
| 6 | + p := SYSTEM.ADR(1); | |
| 6 | 7 | end; |
| 7 | 8 | end AtPAdr. |
| @@ -2,6 +2,6 @@ | ||
| 2 | 2 | proc main*; |
| 3 | 3 | var n: I64; _ok: BOOL; |
| 4 | 4 | begin |
| 5 | - _ok := CAS(ADR(n), 0, 1); | |
| 5 | + _ok := CAS(n, 0, 1); | |
| 6 | 6 | end; |
| 7 | 7 | end AtomicI64. |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module BytesVolatile; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type Regs = record ctrl: U32; status: U32; end; |
| 3 | 4 | proc main*; |
| 4 | 5 | var r: ^VOLATILE Regs; b: []U8; |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module ConstAdr; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = record n: INT; end; |
| 3 | 4 | proc f(const r: R): ^R; |
| 4 | 5 | begin |
| 5 | - return ADR(r); | |
| 6 | + return SYSTEM.ADR(r); | |
| 6 | 7 | end; |
| 7 | 8 | proc main*; |
| 8 | 9 | var r: R; |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module ExportAdr; |
| 2 | 2 | import Owner; |
| 3 | +import SYSTEM; | |
| 3 | 4 | proc main*; |
| 4 | 5 | var _p: ^INT; |
| 5 | 6 | begin |
| 6 | - _p := ADR(Owner.n); | |
| 7 | + _p := SYSTEM.ADR(Owner.n); | |
| 7 | 8 | end; |
| 8 | 9 | end ExportAdr. |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module GenDotsRecord; |
| 2 | 2 | import C; |
| 3 | +import SYSTEM; | |
| 3 | 4 | type R = record a, b: I64; end; |
| 4 | 5 | proc main*; |
| 5 | 6 | var r: R; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module PackedAddress; |
| 2 | +import SYSTEM; | |
| 2 | 3 | (* A field of a packed record may be misaligned: it has no address, |
| 3 | 4 | and no volatile access *) |
| 4 | 5 | type |
| @@ -12,12 +13,12 @@ | ||
| 12 | 13 | proc main*; |
| 13 | 14 | var h: Header; p: ^U32; q: ^VOLATILE Header; k: ^U8; s: []U16; |
| 14 | 15 | begin |
| 15 | - p := ADR(h.len); | |
| 16 | + p := SYSTEM.ADR(h.len); | |
| 16 | 17 | put(h.len); |
| 17 | 18 | s := h.vals[0..1]; |
| 18 | - q := ADR(h); | |
| 19 | + q := SYSTEM.ADR(h); | |
| 19 | 20 | q^.len := 2; |
| 20 | - k := ADR(h.tag); | |
| 21 | + k := SYSTEM.ADR(h.tag); | |
| 21 | 22 | h.len := 3; |
| 22 | 23 | end; |
| 23 | 24 |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module PtrArray; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var a: [4]I64; p: ^[4]I64; |
| 4 | 5 | begin |
| 5 | - p := ADR(a); | |
| 6 | + p := SYSTEM.ADR(a); | |
| 6 | 7 | p[1] := 0; |
| 7 | 8 | end; |
| 8 | 9 | end PtrArray. |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module PtrAsSlice; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var a: [4]U8; s: []U8; |
| 4 | 5 | begin |
| 5 | - s := PTR(a); | |
| 6 | + s := SYSTEM.PTR(a); | |
| 6 | 7 | end; |
| 7 | 8 | end PtrAsSlice. |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module PtrElement; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var a: [4]U8; p: ^INT; |
| 4 | 5 | begin |
| 5 | - p := PTR(a); | |
| 6 | + p := SYSTEM.PTR(a); | |
| 6 | 7 | end; |
| 7 | 8 | end PtrElement. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module PtrExport; |
| 2 | 2 | import Owner; |
| 3 | +import SYSTEM; | |
| 3 | 4 | proc main*; |
| 4 | 5 | var p: ^INT; |
| 5 | 6 | begin |
| 6 | - p := PTR(Owner.a); | |
| 7 | + p := SYSTEM.PTR(Owner.a); | |
| 7 | 8 | end; |
| 8 | 9 | end PtrExport. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module PtrInteger; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var n: INT; p: ^INT; |
| 4 | 5 | begin |
| 5 | 6 | n := 1; |
| 6 | - p := PTR(n); | |
| 7 | + p := SYSTEM.PTR(n); | |
| 7 | 8 | end; |
| 8 | 9 | end PtrInteger. |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module PtrLiteral; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var p: ^U8; |
| 4 | 5 | begin |
| 5 | - p := PTR([]); | |
| 6 | + p := SYSTEM.PTR([]); | |
| 6 | 7 | end; |
| 7 | 8 | end PtrLiteral. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module PtrPacked; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = packed record tag: U8; words: [3]I32; end; |
| 3 | 4 | proc main*; |
| 4 | 5 | var r: R; p: ^I32; |
| 5 | 6 | begin |
| 6 | - p := PTR(r.words); | |
| 7 | + p := SYSTEM.PTR(r.words); | |
| 7 | 8 | end; |
| 8 | 9 | end PtrPacked. |
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | module PtrPointer; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var a: [4]U8; p, q: ^U8; pa: ^[4]U8; |
| 4 | 5 | begin |
| 5 | - p := ADR(a[0]); pa := ADR(a); | |
| 6 | - q := PTR(p); | |
| 7 | - q := PTR(pa); | |
| 6 | + p := SYSTEM.ADR(a[0]); pa := SYSTEM.ADR(a); | |
| 7 | + q := SYSTEM.PTR(p); | |
| 8 | + q := SYSTEM.PTR(pa); | |
| 8 | 9 | end; |
| 9 | 10 | end PtrPointer. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module PtrView; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var w: I64; p: ^U8; |
| 4 | 5 | begin |
| 5 | 6 | w := 0; |
| 6 | - p := PTR(w.([8]U8)); | |
| 7 | + p := SYSTEM.PTR(w.([8]U8)); | |
| 7 | 8 | end; |
| 8 | 9 | end PtrView. |
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | module PtrVolatile; |
| 2 | +import SYSTEM; | |
| 2 | 3 | var regs: [4]U32; |
| 3 | 4 | proc main*; |
| 4 | 5 | var v: ^VOLATILE [4]U32; p: ^U32; |
| 5 | 6 | begin |
| 6 | - v := ADR(regs); | |
| 7 | - p := PTR(v^); | |
| 7 | + v := SYSTEM.ADR(regs); | |
| 8 | + p := SYSTEM.PTR(v^); | |
| 8 | 9 | end; |
| 9 | 10 | end PtrVolatile. |
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | module SliceLiteralPart; |
| 2 | -const Rows: [][]INT = [[1, 2], 3]; | |
| 2 | +const Rows: []const []const INT = [[1, 2], 3]; | |
| 3 | 3 | end SliceLiteralPart. |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | module SliceLiteralRecord; |
| 2 | -type Rule = record name: []U8; keys: []INT; end; | |
| 2 | +type Rule = record name: []const U8; keys: []const INT; end; | |
| 3 | 3 | const Rules: [1]Rule = [{name: "up", keys: [[1]]}]; |
| 4 | 4 | end SliceLiteralRecord. |
| @@ -1,3 +1,4 @@ | ||
| 1 | 1 | module StmtVarOrProc; |
| 2 | +import SYSTEM; | |
| 2 | 3 | extern 5; |
| 3 | 4 | end StmtVarOrProc. |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module ViewAdr; |
| 2 | +import SYSTEM; | |
| 2 | 3 | var mem: [16]U8; p: ^I64; |
| 3 | 4 | proc main*; |
| 4 | 5 | begin |
| 5 | - p := ADR(mem[0].(I64)); | |
| 6 | + p := SYSTEM.ADR(mem[0].(I64)); | |
| 6 | 7 | end; |
| 7 | 8 | end ViewAdr. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module Volatile; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var x: I64; p: ^VOLATILE I64; q: ^I64; |
| 4 | 5 | begin |
| 5 | - p := ADR(x); | |
| 6 | + p := SYSTEM.ADR(x); | |
| 6 | 7 | q := p; |
| 7 | 8 | end; |
| 8 | 9 | end Volatile. |
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | module Args; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | proc main*: INT; |
| 5 | 6 | var i, n: INT; a: ^^U8; s: ^U8; |
| 6 | 7 | begin |
| 7 | - a := ARGV(); | |
| 8 | + a := SYSTEM.ARGV(); | |
| 8 | 9 | for i := 1 to ARGC() - 1 do |
| 9 | 10 | s := a[i]; |
| 10 | 11 | n := 0; |
| @@ -8,12 +8,12 @@ | ||
| 8 | 8 | |
| 9 | 9 | var g: I64; |
| 10 | 10 | |
| 11 | -proc show(s: []U8; n: I64); | |
| 11 | +proc show(s: []const U8; n: I64); | |
| 12 | 12 | begin |
| 13 | 13 | Out.str(s); Out.str(" "); Out.int(n); Out.ln; |
| 14 | 14 | end; |
| 15 | 15 | |
| 16 | -proc showb(s: []U8; t: BOOL); | |
| 16 | +proc showb(s: []const U8; t: BOOL); | |
| 17 | 17 | begin |
| 18 | 18 | if t then show(s, 1); else show(s, 0); end; |
| 19 | 19 | end; |
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | Mixes: [2]set of Color = [{red, blue}, {}]; |
| 14 | 14 | Neg: [3]I16 = [-1, -32768, 32767]; |
| 15 | 15 | |
| 16 | -proc sum(a: []I64): I64; | |
| 16 | +proc sum(a: []const I64): I64; | |
| 17 | 17 | var s: I64; i: INT; |
| 18 | 18 | begin |
| 19 | 19 | for i := 0 to LEN(a) - 1 do s := s + a[i]; end; |
| @@ -1,17 +1,17 @@ | ||
| 1 | 1 | module ArrayConstLen; |
| 2 | 2 | import Out, Widths; |
| 3 | 3 | |
| 4 | -type Rule = record class: []U8; tag: INT; end; | |
| 4 | +type Rule = record class: []const U8; tag: INT; end; | |
| 5 | 5 | |
| 6 | 6 | const |
| 7 | - Primes: []I64 = [2, 3, 5, 7, 11]; | |
| 8 | - Rules: []Rule = [{class: "firefox", tag: 2}, {class: "mpv", tag: 3}]; | |
| 9 | - Names: [][]U8 = ["one", "two", "three"]; | |
| 7 | + Primes: []const I64 = [2, 3, 5, 7, 11]; | |
| 8 | + Rules: []const Rule = [{class: "firefox", tag: 2}, {class: "mpv", tag: 3}]; | |
| 9 | + Names: []const []const U8 = ["one", "two", "three"]; | |
| 10 | 10 | Count = LEN(Primes); (* a constant *) |
| 11 | 11 | |
| 12 | 12 | var buf: [Count]I64; |
| 13 | 13 | |
| 14 | -proc sum(a: []I64): I64; | |
| 14 | +proc sum(a: []const I64): I64; | |
| 15 | 15 | var s: I64; i: INT; |
| 16 | 16 | begin |
| 17 | 17 | for i := 0 to LEN(a) - 1 do s := s + a[i]; end; |
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | end; |
| 29 | 29 | |
| 30 | 30 | proc main*; |
| 31 | -const Local: []U8 = [1, 2, 3, 4]; | |
| 31 | +const Local: []const U8 = [1, 2, 3, 4]; | |
| 32 | 32 | var i: INT; |
| 33 | 33 | begin |
| 34 | 34 | Out.int(LEN(Primes)); Out.str(" "); Out.int(sum(Primes)); Out.str(" "); |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module ArrayEq; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | type Colour = (red, green, blue); |
| 5 | 6 | |
| @@ -30,8 +31,8 @@ | ||
| 30 | 31 | say(f[0..1] = f[2..3]); say(f[0..1] = [true, false]); |
| 31 | 32 | m := [{red}, {green, blue}]; n := m; |
| 32 | 33 | say(m = n); n[1] := {blue}; say(m = n); |
| 33 | - p := [ADR(x), nil]; q := p; | |
| 34 | - say(p = q); q[1] := ADR(x); say(p = q); | |
| 34 | + p := [SYSTEM.ADR(x), nil]; q := p; | |
| 35 | + say(p = q); q[1] := SYSTEM.ADR(x); say(p = q); | |
| 35 | 36 | t := [104, 101, 108, 108, 111]; |
| 36 | 37 | say(t = "hello"); say("hello" = t[0..5]); say("hell" = t[0..4]); |
| 37 | 38 | say("help" # t[0..4]); say("" = t[0..0]); |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | with a view of the same place, which is the target's order too. *) |
| 7 | 7 | module BytesOf; |
| 8 | 8 | import Out; |
| 9 | +import SYSTEM; | |
| 9 | 10 | |
| 10 | 11 | type |
| 11 | 12 | Header = record magic: U32; count: U16; flags: U8; end; |
| @@ -62,7 +63,7 @@ | ||
| 62 | 63 | Out.int(LEN(BYTES(none))); Out.str(" "); Out.int(LEN(BYTES(g[2..2]))); Out.ln; |
| 63 | 64 | Out.int(LEN(gBytes())); Out.str(" "); Out.int(I64(gBytes()[4].(I32))); Out.ln; |
| 64 | 65 | |
| 65 | - p := ADR(h); | |
| 66 | + p := SYSTEM.ADR(h); | |
| 66 | 67 | n := 0; |
| 67 | 68 | for i := 0 to OFFSET(Header, flags) do (* not the padding after *) |
| 68 | 69 | INC(n, I32(BYTES(p^)[i])); |
| @@ -23,13 +23,13 @@ | ||
| 23 | 23 | end; |
| 24 | 24 | |
| 25 | 25 | (* The array in r, as a slice *) |
| 26 | -proc bytes(const r: R): []U8; | |
| 26 | +proc bytes(const r: R): []const U8; | |
| 27 | 27 | begin |
| 28 | 28 | return r.a[0..8]; |
| 29 | 29 | end; |
| 30 | 30 | |
| 31 | 31 | proc main*; |
| 32 | -var s, t, u, v: []U8; i: INT; | |
| 32 | +var s, t, u, v: []const U8; i: INT; | |
| 33 | 33 | begin |
| 34 | 34 | s := name('a')[0..8]; |
| 35 | 35 | t := name('b')[0..8]; |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | Big = record a: [100]INT; name: []U8; n: INT; end; |
| 6 | 6 | Shape = variant circle(r: INT); rect(w, h: INT); end; |
| 7 | 7 | |
| 8 | -const Ten: Big = {n: 10, name: "ten"}; | |
| 8 | +const Ten: Big = {n: 10}; | |
| 9 | 9 | |
| 10 | 10 | var g: Big; |
| 11 | 11 | |
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | return s; |
| 18 | 18 | end; |
| 19 | 19 | |
| 20 | -proc first(const s: []U8): U8; | |
| 20 | +proc first(const s: []const U8): U8; | |
| 21 | 21 | begin |
| 22 | 22 | return s[0]; |
| 23 | 23 | end; |
| @@ -8,12 +8,12 @@ | ||
| 8 | 8 | |
| 9 | 9 | var line: Line; |
| 10 | 10 | |
| 11 | -proc used(const l: Line): []U8; | |
| 11 | +proc used(const l: Line): []const U8; | |
| 12 | 12 | begin |
| 13 | 13 | return l.text[0..l.len]; |
| 14 | 14 | end; |
| 15 | 15 | |
| 16 | -proc make(s: []U8): Line; | |
| 16 | +proc make(s: []const U8): Line; | |
| 17 | 17 | var l: Line; |
| 18 | 18 | begin |
| 19 | 19 | COPY(l.text, s); |
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | end; |
| 23 | 23 | |
| 24 | 24 | proc main*; |
| 25 | -var s: []U8; | |
| 25 | +var s: []const U8; | |
| 26 | 26 | begin |
| 27 | 27 | line := make("hello"); |
| 28 | 28 | s := used(line); |
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | end; |
| 25 | 25 | |
| 26 | 26 | proc main*; |
| 27 | -var a: [5]U8; w: []U8; r, b: []const U8; shapes: [2]Shape; cs: []const Shape; | |
| 27 | +var a: [5]U8; w: []const U8; r, b: []const U8; shapes: [2]Shape; cs: []const Shape; | |
| 28 | 28 | begin |
| 29 | 29 | a := "hello"; |
| 30 | 30 | w := a; |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | import Out; |
| 7 | 7 | |
| 8 | 8 | proc main*; |
| 9 | -var i, j, n: INT; t: []U8; | |
| 9 | +var i, j, n: INT; t: []const U8; | |
| 10 | 10 | begin |
| 11 | 11 | for i := 1 to 10 do |
| 12 | 12 | if i mod 3 = 0 then continue; end; (* a lone continue *) |
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | cases, wrong: INT; |
| 12 | 12 | |
| 13 | 13 | (* Says where a copy came out wrong. *) |
| 14 | -proc fail(kind: []U8; d, s, n: INT); | |
| 14 | +proc fail(kind: []const U8; d, s, n: INT); | |
| 15 | 15 | begin |
| 16 | 16 | Out.str(kind); Out.str(" wrong: d "); Out.int(I64(d)); Out.str(" s "); Out.int(I64(s)); |
| 17 | 17 | Out.str(" n "); Out.int(I64(n)); Out.ln; |
| @@ -5,12 +5,12 @@ | ||
| 5 | 5 | |
| 6 | 6 | var depth: I64; |
| 7 | 7 | |
| 8 | -proc enter(s: []U8); | |
| 8 | +proc enter(s: []const U8); | |
| 9 | 9 | begin |
| 10 | 10 | Out.str(s); INC(depth); |
| 11 | 11 | end; |
| 12 | 12 | |
| 13 | -proc leave(s: []U8); | |
| 13 | +proc leave(s: []const U8); | |
| 14 | 14 | begin |
| 15 | 15 | Out.str(s); DEC(depth); |
| 16 | 16 | end; |
| @@ -4,16 +4,16 @@ | ||
| 4 | 4 | (* A constant typed []T whose literal is [] is the empty slice, used as |
| 5 | 5 | a slice is: as a table with nothing in it, or a part of a constant *) |
| 6 | 6 | |
| 7 | -type Prop = record name: []U8; runs: [][2]I32; end; | |
| 7 | +type Prop = record name: []const U8; runs: []const [2]I32; end; | |
| 8 | 8 | |
| 9 | 9 | const |
| 10 | - None: []I64 = []; | |
| 11 | - Wide: [][2]I32 = [[1100H, 115FH]]; | |
| 12 | - Narrow: [][2]I32 = []; | |
| 13 | - Props: []Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []}, | |
| 10 | + None: []const I64 = []; | |
| 11 | + Wide: []const [2]I32 = [[1100H, 115FH]]; | |
| 12 | + Narrow: []const [2]I32 = []; | |
| 13 | + Props: []const Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []}, | |
| 14 | 14 | {name: "Widths.Wide", runs: Widths.Wide}, {name: "Widths.Narrow", runs: Widths.Narrow}]; |
| 15 | 15 | |
| 16 | -proc sum(a: []I64): I64; | |
| 16 | +proc sum(a: []const I64): I64; | |
| 17 | 17 | var s: I64; i: INT; |
| 18 | 18 | begin |
| 19 | 19 | for i := 0 to LEN(a) - 1 do s := s + a[i]; end; |
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | end; |
| 22 | 22 | |
| 23 | 23 | proc main*; |
| 24 | -var s: []I64; i: INT; | |
| 24 | +var s: []const I64; i: INT; | |
| 25 | 25 | begin |
| 26 | 26 | s := None; |
| 27 | 27 | Out.int(LEN(None)); Out.str(" "); Out.int(sum(None)); Out.str(" "); Out.int(LEN(s)); Out.str(" "); |
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | One: ERROR = "same"; |
| 9 | 9 | Two: ERROR = "same"; |
| 10 | 10 | |
| 11 | -proc yes(name: []U8; b: BOOL); | |
| 11 | +proc yes(name: []const U8; b: BOOL); | |
| 12 | 12 | begin |
| 13 | 13 | Out.str(name); |
| 14 | 14 | if b then Out.str(" true"); else Out.str(" false"); end; |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | import Out; |
| 4 | 4 | |
| 5 | 5 | proc main*; |
| 6 | -var s: []U8; i: INT; | |
| 6 | +var s: []const U8; i: INT; | |
| 7 | 7 | begin |
| 8 | 8 | s := "\xaF\xAF\u{1f600}\u{1F600}\x41\u{e9}"; |
| 9 | 9 | for i := 0 to LEN(s) - 1 do |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | U64s := Filled(U64), I8s := Filled(I8), Bools := Filled(BOOL), Ptrs := Filled(^I64), |
| 4 | 4 | Sets := Filled(FillKinds.Colours), Colours := Filled(FillKinds.Colour), |
| 5 | 5 | Rgbs := Filled(FillKinds.Rgb), Spans := Filled(FillKinds.Span); |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | var |
| 8 | 9 | calls: INT; (* how many times next has been called *) |
| @@ -47,7 +48,7 @@ | ||
| 47 | 48 | U64s.check("U64", 0123456789ABCDEFH, 1); |
| 48 | 49 | I8s.check("I8", -2, 3); |
| 49 | 50 | Bools.check("BOOL", true, false); |
| 50 | - Ptrs.check("pointer", ADR(x), ADR(y)); | |
| 51 | + Ptrs.check("pointer", SYSTEM.ADR(x), SYSTEM.ADR(y)); | |
| 51 | 52 | Sets.check("set", {FillKinds.red, FillKinds.blue}, {FillKinds.green}); |
| 52 | 53 | Colours.check("enumeration", FillKinds.blue, FillKinds.green); |
| 53 | 54 | Rgbs.check("3-byte record", {r: 1, g: 2, b: 3}, {r: 9, g: 9, b: 9}); |
| @@ -74,13 +75,13 @@ | ||
| 74 | 75 | FILL(s[1..8], 0); |
| 75 | 76 | Out.int(sum(a)); Out.char(' '); |
| 76 | 77 | for i := 0 to 99 do big[i] := U64(i); end; |
| 77 | - p := ADR(big); | |
| 78 | + p := SYSTEM.ADR(big); | |
| 78 | 79 | FILL(p^[10..100], 0); |
| 79 | 80 | t := 0; |
| 80 | 81 | for i := 0 to 99 do INC(t, I64(big[i])); end; |
| 81 | 82 | Out.int(t); Out.char(' '); |
| 82 | 83 | FILL(p^, 0); |
| 83 | - FILL(ps, ADR(x)); | |
| 84 | + FILL(ps, SYSTEM.ADR(x)); | |
| 84 | 85 | FILL(ps, nil); |
| 85 | 86 | if (big[1] = 0) and (ps[2] = nil) then Out.str("zero"); end; |
| 86 | 87 | Out.ln; |
| @@ -1,15 +1,16 @@ | ||
| 1 | 1 | module FirstUse; |
| 2 | 2 | import Out, Str, Table := Table([]const U8, Colour, Str.hash, Str.eq), |
| 3 | 3 | Ints := Pile(I64), More := Pile(I64), Never := Loud(I64), Ones := Loud(U8); |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | type Colour = (red, green, blue); |
| 6 | 7 | |
| 7 | 8 | var names: Table.Table; (* Table is made here, after Colour *) |
| 8 | 9 | |
| 9 | -proc show(k: []U8); | |
| 10 | +proc show(k: []const U8); | |
| 10 | 11 | var c: Colour; found: BOOL; |
| 11 | 12 | begin |
| 12 | - c, found := Table.get(ADR(names), k); | |
| 13 | + c, found := Table.get(SYSTEM.ADR(names), k); | |
| 13 | 14 | Out.str(k); |
| 14 | 15 | if not found then Out.str(" -"); elsif c = red then Out.str(" red"); else Out.str(" not red"); end; |
| 15 | 16 | Out.ln; |
| @@ -28,6 +29,6 @@ | ||
| 28 | 29 | end; |
| 29 | 30 | |
| 30 | 31 | begin |
| 31 | - _ := Table.put(ADR(names), "rose", red); | |
| 32 | - _ := Table.put(ADR(names), "sky", blue); | |
| 32 | + _ := Table.put(SYSTEM.ADR(names), "rose", red); | |
| 33 | + _ := Table.put(SYSTEM.ADR(names), "sky", blue); | |
| 33 | 34 | end FirstUse. |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Generic; |
| 2 | -import Out, Stack, Ints := Pile(I64), More := Pile(I64), Strs := Pile([]U8); | |
| 2 | +import Out, Stack, Ints := Pile(I64), More := Pile(I64), Strs := Pile([]const U8); | |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | proc yes(b: BOOL); |
| 5 | 6 | begin |
| @@ -7,19 +8,19 @@ | ||
| 7 | 8 | end; |
| 8 | 9 | |
| 9 | 10 | proc main*; |
| 10 | -var l: Strs.Pile; v: I64; s: []U8; ok: BOOL; | |
| 11 | +var l: Strs.Pile; v: I64; s: []const U8; ok: BOOL; | |
| 11 | 12 | begin |
| 12 | 13 | ok := Ints.push(Stack.p, 7); |
| 13 | 14 | ok := More.push(Stack.p, 8); (* two imports, one instance: one pile *) |
| 14 | 15 | Out.int(Stack.top()); Out.char(' '); Out.int(Stack.p^.len); Out.char(' '); yes(ok); Out.ln; |
| 15 | 16 | v, ok := Ints.pop(Stack.p); |
| 16 | 17 | Out.int(v); Out.char(' '); Out.int(Stack.p^.len); Out.ln; |
| 17 | - ok := Strs.push(ADR(l), "b"); | |
| 18 | - ok := Strs.push(ADR(l), "a"); | |
| 19 | - s, ok := Strs.pop(ADR(l)); | |
| 20 | - Out.str(s); Out.str(Strs.top(ADR(l))); yes(ok); Out.ln; | |
| 21 | - s, ok := Strs.pop(ADR(l)); | |
| 22 | - s, ok := Strs.pop(ADR(l)); | |
| 18 | + ok := Strs.push(SYSTEM.ADR(l), "b"); | |
| 19 | + ok := Strs.push(SYSTEM.ADR(l), "a"); | |
| 20 | + s, ok := Strs.pop(SYSTEM.ADR(l)); | |
| 21 | + Out.str(s); Out.str(Strs.top(SYSTEM.ADR(l))); yes(ok); Out.ln; | |
| 22 | + s, ok := Strs.pop(SYSTEM.ADR(l)); | |
| 23 | + s, ok := Strs.pop(SYSTEM.ADR(l)); | |
| 23 | 24 | Out.char('['); Out.str(s); Out.str("] "); yes(ok); Out.ln; |
| 24 | 25 | end; |
| 25 | 26 |
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | return incr(n); |
| 74 | 74 | end; |
| 75 | 75 | |
| 76 | -proc second(s: []U8): U8; | |
| 76 | +proc second(s: []const U8): U8; | |
| 77 | 77 | begin |
| 78 | 78 | return s[1]; |
| 79 | 79 | end; |
| @@ -91,13 +91,13 @@ | ||
| 91 | 91 | return (n # 0) and even(n - 1); |
| 92 | 92 | end; |
| 93 | 93 | |
| 94 | -proc show(s: []U8; n: INT); | |
| 94 | +proc show(s: []const U8; n: INT); | |
| 95 | 95 | begin |
| 96 | 96 | Out.str(s); Out.str(" "); Out.int(n); Out.ln; |
| 97 | 97 | end; |
| 98 | 98 | |
| 99 | 99 | proc main*; |
| 100 | -var i, n: INT; s: []U8; p: Pair; f: proc(a, b: INT): INT; c: U8; | |
| 100 | +var i, n: INT; s: []const U8; p: Pair; f: proc(a, b: INT): INT; c: U8; | |
| 101 | 101 | begin |
| 102 | 102 | show("sub", sub(note(10), note(3))); |
| 103 | 103 | show("order", trace[0] * 10 + trace[1]); |
| @@ -27,14 +27,14 @@ | ||
| 27 | 27 | return three(); |
| 28 | 28 | end; |
| 29 | 29 | |
| 30 | -proc show(label: []U8; v: I64); | |
| 30 | +proc show(label: []const U8; v: I64); | |
| 31 | 31 | begin |
| 32 | 32 | Out.str(label); Out.str(" "); Out.int(v); Out.str("\n"); |
| 33 | 33 | end; |
| 34 | 34 | |
| 35 | 35 | proc main*; |
| 36 | 36 | var |
| 37 | - a, b, c, i: I64; n: INT; s: []U8; u: U64; w: UINT; | |
| 37 | + a, b, c, i: I64; n: INT; s: []const U8; u: U64; w: UINT; | |
| 38 | 38 | begin |
| 39 | 39 | s := "hello"; |
| 40 | 40 | n := -2; |
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | Word = ("sat" + " ") + "on"; |
| 9 | 9 | |
| 10 | 10 | proc main*; |
| 11 | -var w: []U8; | |
| 11 | +var w: []const U8; | |
| 12 | 12 | begin |
| 13 | 13 | Out.str(Line); |
| 14 | 14 | Out.str(Both); Out.ln; |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | Color* = (red, green, blue, black); |
| 6 | 6 | Colors* = set of Color; |
| 7 | 7 | Cell = record ch: U8; attr: U8; fg: Color; end; |
| 8 | - Point = record x, y: I64; name: []U8; end; | |
| 8 | + Point = record x, y: I64; name: []const U8; end; | |
| 9 | 9 | Line = record a, b: Point; end; |
| 10 | 10 | |
| 11 | 11 | var log: [8]U8; nlog: I64; |
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | Out.str(" "); |
| 26 | 26 | end; |
| 27 | 27 | |
| 28 | -proc name(c: Color): []U8; | |
| 28 | +proc name(c: Color): []const U8; | |
| 29 | 29 | begin |
| 30 | 30 | match c of |
| 31 | 31 | | red: return "red"; |
| @@ -2,10 +2,11 @@ | ||
| 2 | 2 | (* A procedure type's parameter or result may name a type declared later |
| 3 | 3 | in its type section, however passed (report, 4 and 5.9). *) |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | type |
| 7 | 8 | Lines = record |
| 8 | - each: proc(var r: Lines; s: []U8); | |
| 9 | + each: proc(var r: Lines; s: []const U8); | |
| 9 | 10 | look: proc(const r: Lines): INT; |
| 10 | 11 | copy: proc(r: Lines): Lines; |
| 11 | 12 | at: proc(p: ^Lines): (INT, Lines); |
| @@ -29,7 +30,7 @@ | ||
| 29 | 30 | name: [8]U8; |
| 30 | 31 | end; |
| 31 | 32 | |
| 32 | -proc count(var r: Lines; s: []U8); | |
| 33 | +proc count(var r: Lines; s: []const U8); | |
| 33 | 34 | begin |
| 34 | 35 | INC(r.n, LEN(s)); |
| 35 | 36 | end; |
| @@ -76,7 +77,7 @@ | ||
| 76 | 77 | Out.int(r.look(r)); Out.ln; |
| 77 | 78 | c := r.copy(r); |
| 78 | 79 | Out.int(c.n); Out.char(' '); Out.int(r.n); Out.ln; |
| 79 | - k, c := r.at(ADR(r)); | |
| 80 | + k, c := r.at(SYSTEM.ADR(r)); | |
| 80 | 81 | Out.int(k); Out.char(' '); Out.int(c.n); Out.ln; |
| 81 | 82 | pi.hit := hit; po.back := back; |
| 82 | 83 | Out.int(pi.hit(po)); Out.char(' '); Out.int(pi.hit(po)); Out.ln; |
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | end; |
| 39 | 39 | |
| 40 | 40 | proc main*; |
| 41 | -var i: INT; s: []U8; | |
| 41 | +var i: INT; s: []const U8; | |
| 42 | 42 | begin |
| 43 | 43 | s := "a1 _Z\t9?"; |
| 44 | 44 | for i := 0 to LEN(s) - 1 do Out.int(kind(s[i])); end; |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | type Op = (none, add, sub, mul); |
| 8 | 8 | |
| 9 | -proc op(word: []U8): Op; | |
| 9 | +proc op(word: []const U8): Op; | |
| 10 | 10 | begin |
| 11 | 11 | match word of |
| 12 | 12 | | "add", Plus, `+`: return add; |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | end; |
| 19 | 19 | |
| 20 | 20 | proc main*; |
| 21 | -var a: [3]U8; s: []U8; | |
| 21 | +var a: [3]U8; s: []const U8; | |
| 22 | 22 | begin |
| 23 | 23 | Out.int(I64(op("add"))); Out.int(I64(op("plus"))); Out.int(I64(op("+"))); |
| 24 | 24 | Out.int(I64(op("sub"))); Out.int(I64(op("-"))); Out.int(I64(op("mul"))); |
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | Typed = U8(OFFSET(Mixed, e) + 250); (* 24 + 250 wraps to 18 *) |
| 21 | 21 | |
| 22 | 22 | (* name, then the offset and the size of a field *) |
| 23 | -proc row(name: []U8; off, size: INT); | |
| 23 | +proc row(name: []const U8; off, size: INT); | |
| 24 | 24 | begin |
| 25 | 25 | Out.str(name); Out.str(" "); Out.int(off); Out.str(" "); Out.int(size); Out.ln; |
| 26 | 26 | end; |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | module PackedFields; |
| 2 | 2 | (* A packed record's fields are read and written wherever they sit *) |
| 3 | 3 | import Out; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | type |
| 6 | 7 | Header = packed record kind: U8; len: U32; big: I64; tag: U8; end; |
| @@ -16,7 +17,7 @@ | ||
| 16 | 17 | Out.hex(U64(g.len), 8); Out.str(" "); |
| 17 | 18 | Out.int(g.big); Out.str(" "); |
| 18 | 19 | Out.int(I64(g.tag)); Out.ln; |
| 19 | - b := ADR(g.kind); | |
| 20 | + b := SYSTEM.ADR(g.kind); | |
| 20 | 21 | Out.int(I64(b[1])); Out.ln; |
| 21 | 22 | end; |
| 22 | 23 |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | var bad: I64; |
| 7 | 7 | |
| 8 | -proc check(s: []U8; x, got, want: I64); | |
| 8 | +proc check(s: []const U8; x, got, want: I64); | |
| 9 | 9 | begin |
| 10 | 10 | if got # want then |
| 11 | 11 | Out.str(s); Out.str(" "); Out.int(x); Out.str(": "); |
| @@ -1,8 +1,9 @@ | ||
| 1 | -(* PTR(s), the address a slice starts at (report section 6.8): ADR(s[0]) | |
| 1 | +(* SYSTEM.PTR(s), the address a slice starts at (report section 6.8): SYSTEM.ADR(s[0]) | |
| 2 | 2 | when s isn't empty; nil for a slice as it starts and for []; and, of |
| 3 | 3 | an array, the address of its first element. *) |
| 4 | 4 | module Ptr; |
| 5 | 5 | import Out; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | type Value = record n: INT; p: ^U8; end; |
| 8 | 9 | |
| @@ -13,7 +14,7 @@ | ||
| 13 | 14 | (* a slice as a pointer and a length, with no test for the empty one *) |
| 14 | 15 | proc valueOf(s: []U8): Value; |
| 15 | 16 | begin |
| 16 | - return {n: LEN(s), p: PTR(s)}; | |
| 17 | + return {n: LEN(s), p: SYSTEM.PTR(s)}; | |
| 17 | 18 | end; |
| 18 | 19 | |
| 19 | 20 | (* and back: empty when n is 0, whatever p is *) |
| @@ -29,7 +30,7 @@ | ||
| 29 | 30 | |
| 30 | 31 | proc first(const a: [3]I64): ^I64; |
| 31 | 32 | begin |
| 32 | - return PTR(a); | |
| 33 | + return SYSTEM.PTR(a); | |
| 33 | 34 | end; |
| 34 | 35 | |
| 35 | 36 | proc main*; |
| @@ -41,24 +42,24 @@ | ||
| 41 | 42 | s := a[0..6]; |
| 42 | 43 | Out.str(bytes(valueOf(s))); |
| 43 | 44 | 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; | |
| 45 | + if SYSTEM.PTR(s) = SYSTEM.ADR(s[0]) then Out.str("a slice: ADR(s[0])\n"); end; | |
| 46 | + if SYSTEM.PTR(a) = SYSTEM.ADR(a[0]) then Out.str("an array: ADR(a[0])\n"); end; | |
| 47 | + if SYSTEM.PTR(s[2..5]) = SYSTEM.ADR(a[2]) then Out.str("a slice of it: ADR(a[2])\n"); end; | |
| 48 | + if SYSTEM.PTR(same(s)) = SYSTEM.ADR(a[0]) then Out.str("a call's slice\n"); end; | |
| 48 | 49 | v := valueOf(none); |
| 49 | 50 | if v.p = nil then Out.str("a slice as it starts: nil\n"); end; |
| 50 | 51 | v := valueOf([]); |
| 51 | 52 | if v.p = nil then Out.str("[]: nil\n"); end; |
| 52 | 53 | Out.int(LEN(bytes(v))); Out.str(" bytes back\n"); |
| 53 | 54 | kept := s[3..5]; |
| 54 | - Out.str(PTR(kept)[0..2]); Out.str("\n"); | |
| 55 | + Out.str(SYSTEM.PTR(kept)[0..2]); Out.str("\n"); | |
| 55 | 56 | w := [10, 20, 30]; |
| 56 | - if first(w) = ADR(w[0]) then Out.str("a const parameter: in place\n"); end; | |
| 57 | + if first(w) = SYSTEM.ADR(w[0]) then Out.str("a const parameter: in place\n"); end; | |
| 57 | 58 | ws := w[0..3]; |
| 58 | - q := PTR(ws); | |
| 59 | + q := SYSTEM.PTR(ws); | |
| 59 | 60 | for i := 0 to 2 do Out.int(q[i]); Out.str(" "); end; |
| 60 | 61 | Out.str("\n"); |
| 61 | - d := PTR(Digits); | |
| 62 | + d := SYSTEM.PTR(Digits); | |
| 62 | 63 | Out.int(d[3]); Out.str("\n"); |
| 63 | 64 | end; |
| 64 | 65 |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* Pointers compare with = # < <= > >=, as unsigned addresses. *) |
| 2 | 2 | module PtrOrder; |
| 3 | 3 | import Out; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | proc yes(b: BOOL); |
| 6 | 7 | begin |
| @@ -10,10 +11,10 @@ | ||
| 10 | 11 | proc main*; |
| 11 | 12 | var a: [3]I64; p, q: ^I64; |
| 12 | 13 | begin |
| 13 | - p := ADR(a[0]); | |
| 14 | - q := ADR(a[2]); | |
| 14 | + p := SYSTEM.ADR(a[0]); | |
| 15 | + q := SYSTEM.ADR(a[2]); | |
| 15 | 16 | yes(p < q); yes(p <= q); yes(p > q); yes(p >= q); yes(p = q); yes(p # q); |
| 16 | - q := ADR(a[0]); | |
| 17 | + q := SYSTEM.ADR(a[0]); | |
| 17 | 18 | yes(p <= q); yes(p >= q); yes(p < q); |
| 18 | 19 | Out.ln; |
| 19 | 20 | end; |
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | -v say what is done |
| 10 | 10 | `; |
| 11 | 11 | Joined = `back` + "`" + `quote`; |
| 12 | - Names: [2][]U8 = [`one`, `two`]; | |
| 12 | + Names: [2][]const U8 = [`one`, `two`]; | |
| 13 | 13 | |
| 14 | -proc show(s: []U8); | |
| 14 | +proc show(s: []const U8); | |
| 15 | 15 | begin |
| 16 | 16 | Out.int(LEN(s)); Out.str(" |"); Out.str(s); Out.str("|\n"); |
| 17 | 17 | end; |
| @@ -2,11 +2,12 @@ | ||
| 2 | 2 | bits, for numbers a reader of decimals easily gets one off. *) |
| 3 | 3 | module RealRead; |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc bits(x: F64): U64; |
| 7 | 8 | var p: ^U64; |
| 8 | 9 | begin |
| 9 | - p := ^U64(ADR(x)); | |
| 10 | + p := ^U64(SYSTEM.ADR(x)); | |
| 10 | 11 | return p^; |
| 11 | 12 | end; |
| 12 | 13 |
| @@ -2,12 +2,12 @@ | ||
| 2 | 2 | import Out; |
| 3 | 3 | type |
| 4 | 4 | Act = (quit, focus, spawn); |
| 5 | - Rule = record cls: []U8; tag: INT; float: BOOL; end; | |
| 5 | + Rule = record cls: []const U8; tag: INT; float: BOOL; end; | |
| 6 | 6 | Key = record mods: U8; sym: U32; act: Act; arg: [8]U8; run: proc(n: INT); end; |
| 7 | 7 | const |
| 8 | 8 | Rules: [3]Rule = [{cls: "firefox", tag: 2}, {cls: "mpv", float: true}, {}]; |
| 9 | 9 | Nums: [3]I64 = [10, 20, 30]; |
| 10 | - Lists: [2][]I64 = [Nums, Nums]; | |
| 10 | + Lists: [2][]const I64 = [Nums, Nums]; | |
| 11 | 11 | Home: Rule = {cls: "home", tag: 7}; |
| 12 | 12 | Grid: [2][2]U8 = [[1, 2], [3, 4]]; |
| 13 | 13 | proc hello(n: INT); |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | anonymous one. *) |
| 4 | 4 | module Sameness; |
| 5 | 5 | import Out; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | type |
| 8 | 9 | Node = record v: I64; end; |
| @@ -14,11 +15,11 @@ | ||
| 14 | 15 | var r: Node; p1: P1; p2: P2; n: ^Node; q: NodePtr; |
| 15 | 16 | begin |
| 16 | 17 | r.v := 7; |
| 17 | - n := ADR(r); | |
| 18 | + n := SYSTEM.ADR(r); | |
| 18 | 19 | p1 := n; |
| 19 | 20 | n := p1; |
| 20 | 21 | p2 := n; |
| 21 | - q := ADR(r); | |
| 22 | + q := SYSTEM.ADR(r); | |
| 22 | 23 | Out.int(p2^.v + q^.v); Out.ln; |
| 23 | 24 | end; |
| 24 | 25 |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | type Empty = record end; |
| 7 | 7 | |
| 8 | -proc line(name: []U8; b: BOOL); | |
| 8 | +proc line(name: []const U8; b: BOOL); | |
| 9 | 9 | begin |
| 10 | 10 | Out.str(name); |
| 11 | 11 | if b then Out.str(" yes"); else Out.str(" NO"); end; |
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | line("UINT is an address", SIZE(UINT) = SIZE(^U8)); |
| 22 | 22 | line("procedure is an address", SIZE(proc) = SIZE(^U8)); |
| 23 | 23 | line("ERROR is an address", SIZE(ERROR) = SIZE(^U8)); |
| 24 | - line("slice is two", SIZE([]U8) = 2 * SIZE(^U8)); | |
| 24 | + line("slice is two", SIZE([]const U8) = 2 * SIZE(^U8)); | |
| 25 | 25 | line("empty record", SIZE(Empty) = 0); |
| 26 | 26 | end; |
| 27 | 27 |
| @@ -5,17 +5,17 @@ | ||
| 5 | 5 | import Out; |
| 6 | 6 | |
| 7 | 7 | type |
| 8 | - Rule = record name: []U8; keys: []INT; end; | |
| 9 | - Shape = variant dot; poly(xs: []INT); end; | |
| 8 | + Rule = record name: []const U8; keys: []const INT; end; | |
| 9 | + Shape = variant dot; poly(xs: []const INT); end; | |
| 10 | 10 | |
| 11 | 11 | const |
| 12 | - Rows: [][]INT = [[1, 2], [3], []]; | |
| 13 | - Deep: [][][]U8 = [[['a', 'b'], "cd"], [], [['e']]]; | |
| 14 | - Rules: []Rule = [{name: "up", keys: [107, 65]}, {name: "none", keys: []}]; | |
| 12 | + Rows: []const []const INT = [[1, 2], [3], []]; | |
| 13 | + Deep: []const []const []const U8 = [[['a', 'b'], "cd"], [], [['e']]]; | |
| 14 | + Rules: []const Rule = [{name: "up", keys: [107, 65]}, {name: "none", keys: []}]; | |
| 15 | 15 | Shapes: [2]Shape = [poly([1, 2, 3]), dot]; |
| 16 | - Words: [][]U8 = [['h', 'i'], "there"]; | |
| 16 | + Words: []const []const U8 = [['h', 'i'], "there"]; | |
| 17 | 17 | |
| 18 | -proc sum(xs: []INT): INT; | |
| 18 | +proc sum(xs: []const INT): INT; | |
| 19 | 19 | var i, s: INT; |
| 20 | 20 | begin |
| 21 | 21 | s := 0; |
| @@ -2,11 +2,12 @@ | ||
| 2 | 2 | (* A slice of a pointer isn't checked against a length, but it can't |
| 3 | 3 | run backwards *) |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var a: [8]U8; p: ^U8; hi: I64; |
| 8 | 9 | begin |
| 9 | - p := ADR(a[0]); | |
| 10 | + p := SYSTEM.ADR(a[0]); | |
| 10 | 11 | for hi := 4 to 0 by -2 do |
| 11 | 12 | Out.int(LEN(p[2..hi])); |
| 12 | 13 | Out.str(" "); |
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | end; |
| 29 | 29 | |
| 30 | 30 | proc main*; |
| 31 | -var s: []U8; a, b: U8; c: I8; w: U16; n, i: INT; u: UINT; | |
| 31 | +var s: []const U8; a, b: U8; c: I8; w: U16; n, i: INT; u: UINT; | |
| 32 | 32 | begin |
| 33 | 33 | s := "7319"; |
| 34 | 34 | for i := 0 to LEN(s) - 1 do n := n * 10 + s[i] - '0'; end; |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module Sorted; |
| 4 | 4 | import Out, Rt, Ints := Order(I64, below), ByAge := Order(Person, younger); |
| 5 | 5 | |
| 6 | -type Person = record name: []U8; age: I64; end; | |
| 6 | +type Person = record name: []const U8; age: I64; end; | |
| 7 | 7 | |
| 8 | 8 | proc below(a, b: I64): BOOL; |
| 9 | 9 | begin |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | var buf: [8]U8; |
| 7 | 7 | |
| 8 | -proc count(xs: []I64): I64; | |
| 8 | +proc count(xs: []const I64): I64; | |
| 9 | 9 | var i: INT; s: I64; |
| 10 | 10 | begin |
| 11 | 11 | s := 0; |
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | end; |
| 15 | 15 | |
| 16 | 16 | proc main*; |
| 17 | -var a: []U8; b: [5]U8; c: [3]I64; d: [][]U8; | |
| 17 | +var a: []const U8; b: [5]U8; c: [3]I64; d: [][]const U8; | |
| 18 | 18 | begin |
| 19 | 19 | a := "hello"; |
| 20 | 20 | if a = greeting then Out.str("eq "); end; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | (* INT and UINT: what gives them, where they widen, shifts modulo the |
| 3 | 3 | width, and another module's variables read but not changed *) |
| 4 | 4 | import Out, Shared; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | var cells: [10]I32; |
| 7 | 8 | |
| @@ -11,7 +12,7 @@ | ||
| 11 | 12 | end; |
| 12 | 13 | |
| 13 | 14 | (* an INT returned as an I64 *) |
| 14 | -proc len(s: []U8): I64; | |
| 15 | +proc len(s: []const U8): I64; | |
| 15 | 16 | begin |
| 16 | 17 | return LEN(s); |
| 17 | 18 | end; |
| @@ -30,8 +31,8 @@ | ||
| 30 | 31 | Out.int(i); Out.str(" "); Out.int(I64(b)); Out.str(" "); Out.int(len("abc")); |
| 31 | 32 | Out.str(" "); Out.int(I64(w)); Out.ln; |
| 32 | 33 | |
| 33 | - p := ADR(cells[2]); | |
| 34 | - q := ADR(cells[9]); | |
| 34 | + p := SYSTEM.ADR(cells[2]); | |
| 35 | + q := SYSTEM.ADR(cells[9]); | |
| 35 | 36 | n := q - p; (* an INT *) |
| 36 | 37 | u := UINT(q) - UINT(p); |
| 37 | 38 | Out.int(n); Out.str(" "); Out.int(I64(u)); Out.str(" "); |
| @@ -141,7 +141,7 @@ | ||
| 141 | 141 | return 0; |
| 142 | 142 | end; |
| 143 | 143 | |
| 144 | -proc show(what: []U8; v: INT; e: ERROR); | |
| 144 | +proc show(what: []const U8; v: INT; e: ERROR); | |
| 145 | 145 | begin |
| 146 | 146 | Out.str(what); Out.str(": "); Out.int(v); |
| 147 | 147 | if e = nil then Out.str(" ok"); else Out.str(" "); Out.str(MSG(e)); end; |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | on, through a procedure value, run off the end, and with a call in |
| 5 | 5 | the second. *) |
| 6 | 6 | import Out; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | var log: INT; |
| 9 | 10 | |
| @@ -34,7 +35,7 @@ | ||
| 34 | 35 | return nested(n); |
| 35 | 36 | end; |
| 36 | 37 | |
| 37 | -proc tail(s: []U8; i: INT): []U8; | |
| 38 | +proc tail(s: []const U8; i: INT): []const U8; | |
| 38 | 39 | begin |
| 39 | 40 | defer note; |
| 40 | 41 | return s[i..LEN(s)]; |
| @@ -60,7 +61,7 @@ | ||
| 60 | 61 | _, v := nested(3); Out.int(v); Out.str(" "); Out.int(log); Out.ln; |
| 61 | 62 | (* in order: the second result is the one left *) |
| 62 | 63 | v, v := nested(4); Out.int(v); Out.ln; |
| 63 | - pv := ADR(q); pv^, p := nested(5); Out.int(q); Out.str(" "); Out.int(p); Out.ln; | |
| 64 | + pv := SYSTEM.ADR(q); pv^, p := nested(5); Out.int(q); Out.str(" "); Out.int(p); Out.ln; | |
| 64 | 65 | (* three results, which come back in memory, some dropped *) |
| 65 | 66 | _, p, q := three(1); Out.int(p); Out.str(" "); Out.int(q); Out.ln; |
| 66 | 67 | p, _, _ := three(7); Out.int(p); Out.ln; |
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | import Out; |
| 3 | 3 | |
| 4 | 4 | type |
| 5 | - Shape = variant circle(r: F64); rect(w, h: INT); dot; named(name: []U8; n: U8); end; | |
| 5 | + Shape = variant circle(r: F64); rect(w, h: INT); dot; named(name: []const U8; n: U8); end; | |
| 6 | 6 | Rule = record tag: INT; s: Shape; end; |
| 7 | 7 | |
| 8 | 8 | const |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | bytes are written here a byte at a time where order matters. *) |
| 5 | 5 | module Views; |
| 6 | 6 | import Out, ViewData; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | type |
| 9 | 10 | Header = record magic: U32; count: U32; end; |
| @@ -13,7 +14,7 @@ | ||
| 13 | 14 | mem: [64]U8; (* a module's array *) |
| 14 | 15 | regs: [4]U64; |
| 15 | 16 | |
| 16 | -proc show(label: []U8; v: I64); | |
| 17 | +proc show(label: []const U8; v: I64); | |
| 17 | 18 | begin |
| 18 | 19 | Out.str(label); Out.str(" "); Out.int(v); Out.ln; |
| 19 | 20 | end; |
| @@ -25,7 +26,7 @@ | ||
| 25 | 26 | end; |
| 26 | 27 | |
| 27 | 28 | (* a slice parameter's element, viewed *) |
| 28 | -proc sum(s: []U8): I64; | |
| 29 | +proc sum(s: []const U8): I64; | |
| 29 | 30 | var i, t: INT; |
| 30 | 31 | begin |
| 31 | 32 | t := 0; |
| @@ -74,7 +75,7 @@ | ||
| 74 | 75 | (* a packed record, and a pointer read from bytes, then followed *) |
| 75 | 76 | mem[40].(Pair) := {tag: 1, value: 300}; |
| 76 | 77 | show("Pair's value", I64(mem[41].(I32))); |
| 77 | - p := ADR(n); | |
| 78 | + p := SYSTEM.ADR(n); | |
| 78 | 79 | mem[48].(^I64) := p; |
| 79 | 80 | mem[48].(^I64)^ := 77; |
| 80 | 81 | show("n through a pointer from bytes", n); |
| @@ -10,17 +10,17 @@ | ||
| 10 | 10 | Shape = variant first(x: I64); second(y: I64); end; |
| 11 | 11 | |
| 12 | 12 | var |
| 13 | - n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []U8; | |
| 13 | + n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []const U8; | |
| 14 | 14 | c: Colour; fl: Flags; r: Rec; a: [3]I64; v: Shape; |
| 15 | 15 | |
| 16 | -proc line(name: []U8; zero: BOOL); | |
| 16 | +proc line(name: []const U8; zero: BOOL); | |
| 17 | 17 | begin |
| 18 | 18 | Out.str(name); |
| 19 | 19 | if zero then Out.str(" zero"); else Out.str(" NOT ZERO"); end; |
| 20 | 20 | Out.ln; |
| 21 | 21 | end; |
| 22 | 22 | |
| 23 | -proc which(name: []U8; v: Shape); | |
| 23 | +proc which(name: []const U8; v: Shape); | |
| 24 | 24 | begin |
| 25 | 25 | Out.str(name); |
| 26 | 26 | match v of |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | |
| 40 | 40 | proc locals; |
| 41 | 41 | var |
| 42 | - n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []U8; | |
| 42 | + n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []const U8; | |
| 43 | 43 | c: Colour; fl: Flags; r: Rec; a: [3]I64; v: Shape; |
| 44 | 44 | begin |
| 45 | 45 | line("local number", (n = 0) and (u = 0)); |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | may be a record, which = doesn't compare. *) |
| 5 | 5 | module Filled(T); |
| 6 | 6 | import Out; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | (* The lengths of the slices filled *) |
| 9 | 10 | const Lens: [7]INT = [0, 1, 2, 7, 8, 9, 100]; |
| @@ -24,7 +25,7 @@ | ||
| 24 | 25 | wrong: INT; (* elements that hold what they shouldn't *) |
| 25 | 26 | |
| 26 | 27 | (* The bytes of the T at p: BYTES takes no BOOL, set or enumeration *) |
| 27 | -proc bytesAt(p: ^T): []U8; | |
| 28 | +proc bytesAt(p: ^T): []const U8; | |
| 28 | 29 | var q: ^U8; |
| 29 | 30 | begin |
| 30 | 31 | q := ^U8(p); |
| @@ -36,7 +37,7 @@ | ||
| 36 | 37 | var i: INT; |
| 37 | 38 | begin |
| 38 | 39 | for i := 0 to LEN(a) - 1 do |
| 39 | - if bytesAt(ADR(a[i])) # bytesAt(ADR(v)) then INC(wrong); end; | |
| 40 | + if bytesAt(SYSTEM.ADR(a[i])) # bytesAt(SYSTEM.ADR(v)) then INC(wrong); end; | |
| 40 | 41 | end; |
| 41 | 42 | end; |
| 42 | 43 | |
| @@ -81,7 +82,7 @@ | ||
| 81 | 82 | |
| 82 | 83 | (* Fills slices and arrays with v, around s, and says how many elements |
| 83 | 84 | were filled and how many are wrong, after name *) |
| 84 | -proc check*(name: []U8; v, s: T); | |
| 85 | +proc check*(name: []const U8; v, s: T); | |
| 85 | 86 | begin |
| 86 | 87 | filled := 0; |
| 87 | 88 | wrong := 0; |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Stack; |
| 2 | 2 | import Ints := Pile(I64); |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | var |
| 5 | 6 | s: Ints.Pile; |
| @@ -11,5 +12,5 @@ | ||
| 11 | 12 | end; |
| 12 | 13 | |
| 13 | 14 | begin |
| 14 | - p := ADR(s); | |
| 15 | + p := SYSTEM.ADR(s); | |
| 15 | 16 | end Stack. |
| @@ -211,7 +211,7 @@ | ||
| 211 | 211 | |
| 212 | 212 | ``` |
| 213 | 213 | module Both; |
| 214 | -import Out, C; (* C: printf, fflush and C's FILE *stdout *) | |
| 214 | +import Out, C, SYSTEM; (* C: printf, fflush and C's FILE *stdout *) | |
| 215 | 215 | |
| 216 | 216 | proc main*; |
| 217 | 217 | begin |
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | |
| 75 | 75 | var count*: INT; (* the greetings so far *) |
| 76 | 76 | |
| 77 | -proc hello*(name: []U8); | |
| 77 | +proc hello*(name: []const U8); | |
| 78 | 78 | begin |
| 79 | 79 | Out.str("hello, "); |
| 80 | 80 | Out.str(name); |
| @@ -540,7 +540,7 @@ | ||
| 540 | 540 | |
| 541 | 541 | type Span = record p: ^U8; n: INT; end; |
| 542 | 542 | |
| 543 | -proc spanOf(s: []U8): Span; | |
| 543 | +proc spanOf(s: []const U8): Span; | |
| 544 | 544 | begin |
| 545 | 545 | return {p: SYSTEM.PTR(s), n: LEN(s)}; |
| 546 | 546 | end; |
| @@ -847,7 +847,7 @@ | ||
| 847 | 847 | TooBig*: ERROR = "not a number up to 1000"; |
| 848 | 848 | |
| 849 | 849 | (* the number s holds, up to 1000 *) |
| 850 | -proc number(s: []U8): (INT, ERROR); | |
| 850 | +proc number(s: []const U8): (INT, ERROR); | |
| 851 | 851 | var n: I64; ok: BOOL; |
| 852 | 852 | begin |
| 853 | 853 | if LEN(s) = 0 then return 0, Empty; end; |
| @@ -857,7 +857,7 @@ | ||
| 857 | 857 | end; |
| 858 | 858 | |
| 859 | 859 | (* the sum of the numbers in words: the first error ends it *) |
| 860 | -proc total(words: [][]U8): (INT, ERROR); | |
| 860 | +proc total(words: [][]const U8): (INT, ERROR); | |
| 861 | 861 | var i, sum: INT; |
| 862 | 862 | begin |
| 863 | 863 | for i := 0 to LEN(words) - 1 do |
| @@ -867,7 +867,7 @@ | ||
| 867 | 867 | end; |
| 868 | 868 | |
| 869 | 869 | proc main*; |
| 870 | -var words: [3][]U8; i, n: INT; err: ERROR; | |
| 870 | +var words: [3][]const U8; i, n: INT; err: ERROR; | |
| 871 | 871 | begin |
| 872 | 872 | words := ["42", "", "12345"]; |
| 873 | 873 | for i := 0 to 2 do |
| @@ -949,7 +949,7 @@ | ||
| 949 | 949 | end; |
| 950 | 950 | |
| 951 | 951 | (* the lines of the file at path, or -1 if it can't be read *) |
| 952 | -proc lines(path: []U8): INT; | |
| 952 | +proc lines(path: []const U8): INT; | |
| 953 | 953 | var fd, n, i, count: INT; buf: [4096]U8; |
| 954 | 954 | begin |
| 955 | 955 | fd := Sys.openRead(path); |
| @@ -1077,7 +1077,7 @@ | ||
| 1077 | 1077 | end; |
| 1078 | 1078 | end; |
| 1079 | 1079 | |
| 1080 | -proc kind(c: I32): []U8; | |
| 1080 | +proc kind(c: I32): []const U8; | |
| 1081 | 1081 | begin |
| 1082 | 1082 | match c of |
| 1083 | 1083 | | ' ', '\et', '\en': return "space"; |
| @@ -1087,7 +1087,7 @@ | ||
| 1087 | 1087 | end; |
| 1088 | 1088 | end; |
| 1089 | 1089 | |
| 1090 | -proc colour(name: []U8): Colour; | |
| 1090 | +proc colour(name: []const U8): Colour; | |
| 1091 | 1091 | begin |
| 1092 | 1092 | match name of |
| 1093 | 1093 | | "red", "rose": return red; |
| @@ -1178,14 +1178,14 @@ | ||
| 1178 | 1178 | .Bd -literal -offset indent |
| 1179 | 1179 | module Generics; |
| 1180 | 1180 | import Out, Ints := Biggest(INT, before), |
| 1181 | - Words := Biggest([]U8, shorter), Order := Sort(INT, before); | |
| 1181 | + Words := Biggest([]const U8, shorter), Order := Sort(INT, before); | |
| 1182 | 1182 | |
| 1183 | 1183 | proc before(a, b: INT): BOOL; |
| 1184 | 1184 | begin |
| 1185 | 1185 | return a < b; |
| 1186 | 1186 | end; |
| 1187 | 1187 | |
| 1188 | -proc shorter(a, b: []U8): BOOL; | |
| 1188 | +proc shorter(a, b: []const U8): BOOL; | |
| 1189 | 1189 | begin |
| 1190 | 1190 | return LEN(a) < LEN(b); |
| 1191 | 1191 | end; |
| @@ -1535,7 +1535,7 @@ | ||
| 1535 | 1535 | import Sys, Out; |
| 1536 | 1536 | |
| 1537 | 1537 | (* Prints the first line of the file at path. *) |
| 1538 | -proc head(path: []U8): BOOL; | |
| 1538 | +proc head(path: []const U8): BOOL; | |
| 1539 | 1539 | var fd, n, i: INT; buf: [256]U8; |
| 1540 | 1540 | begin |
| 1541 | 1541 | fd := Sys.openRead(path); |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* Prints its arguments, one per line, and exits with how many. *) |
| 2 | 2 | module Args; |
| 3 | 3 | import Out; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | (* The length of a C string. *) |
| 6 | 7 | proc len(s: ^U8): INT; |
| @@ -15,7 +16,7 @@ | ||
| 15 | 16 | var i: INT; s: ^U8; |
| 16 | 17 | begin |
| 17 | 18 | for i := 1 to ARGC() - 1 do |
| 18 | - s := ARGV()[i]; | |
| 19 | + s := SYSTEM.ARGV()[i]; | |
| 19 | 20 | Out.str(s[0..len(s)]); |
| 20 | 21 | Out.ln; |
| 21 | 22 | end; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | other procedure. cpuid's vendor string, from leaf 0. *) |
| 3 | 3 | module Cpu; |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | (* cpuid leaf 0: puts the 12 bytes of the vendor in buf, rdi. *) |
| 7 | 8 | proc vendor(buf: ^U8); |
| @@ -20,7 +21,7 @@ | ||
| 20 | 21 | proc main*; |
| 21 | 22 | var buf: [12]U8; i: INT; ok: BOOL; |
| 22 | 23 | begin |
| 23 | - vendor(ADR(buf[0])); | |
| 24 | + vendor(SYSTEM.ADR(buf[0])); | |
| 24 | 25 | ok := true; |
| 25 | 26 | for i := 0 to 11 do |
| 26 | 27 | if (buf[i] < ' ') or (buf[i] > '~') then ok := false; end; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | a buffer of its own, so each is flushed before the other writes. *) |
| 3 | 3 | module Printf; |
| 4 | 4 | import Out, C; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var i: INT; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | and using the heap and Out, which lock themselves. *) |
| 3 | 3 | module Pthreads; |
| 4 | 4 | import Out, C, Heap, Mem; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | const |
| 7 | 8 | Workers = 4; |
| @@ -35,7 +36,7 @@ | ||
| 35 | 36 | for i := 0 to N - 1 do numbers^[i] := i + 1; end; |
| 36 | 37 | for i := 0 to Workers - 1 do |
| 37 | 38 | parts[i] := {lo: i * N div Workers, hi: (i + 1) * N div Workers}; |
| 38 | - if C.pthread_create(ADR(t[i]), nil, work, ^U8(ADR(parts[i]))) # 0 then | |
| 39 | + if C.pthread_create(SYSTEM.ADR(t[i]), nil, work, ^U8(SYSTEM.ADR(parts[i]))) # 0 then | |
| 39 | 40 | Out.str("can't start a thread\n"); |
| 40 | 41 | return 1; |
| 41 | 42 | end; |
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | bg), assignments, globs, $(...), if and while. *) |
| 14 | 14 | module Sh; |
| 15 | 15 | import Opt, Files, Sys, Str, Buf, Fmt, Out, Arena, Heap, Rt; |
| 16 | +import SYSTEM; | |
| 16 | 17 | |
| 17 | 18 | const |
| 18 | 19 | maxWords = 64; (* of a command *) |
| @@ -85,7 +86,7 @@ | ||
| 85 | 86 | proc readWord; |
| 86 | 87 | var b: Buf.Buf; q: U8; |
| 87 | 88 | begin |
| 88 | - Buf.init(b, ADR(arena.base)); | |
| 89 | + Buf.init(b, SYSTEM.ADR(arena.base)); | |
| 89 | 90 | while (at < LEN(s)) and not special(s[at]) do |
| 90 | 91 | q := s[at]; |
| 91 | 92 | match q of |
| @@ -148,7 +149,7 @@ | ||
| 148 | 149 | var t: Token; c: ^Command; |
| 149 | 150 | begin |
| 150 | 151 | p^ := {n: 1}; |
| 151 | - c := ADR(p^.cmds[0]); | |
| 152 | + c := SYSTEM.ADR(p^.cmds[0]); | |
| 152 | 153 | t := next(); |
| 153 | 154 | while (t # sep) and (t # amp) and (t # eof) do |
| 154 | 155 | if t = word then |
| @@ -157,7 +158,7 @@ | ||
| 157 | 158 | INC(c^.n); |
| 158 | 159 | elsif t = pipe then |
| 159 | 160 | if (c^.n = 0) or (p^.n = maxCmds) then say("a | without a command", []); return t, false; end; |
| 160 | - c := ADR(p^.cmds[p^.n]); | |
| 161 | + c := SYSTEM.ADR(p^.cmds[p^.n]); | |
| 161 | 162 | INC(p^.n); |
| 162 | 163 | else |
| 163 | 164 | if next() # word then say("a redirection without a file", []); return t, false; end; |
| @@ -185,7 +186,7 @@ | ||
| 185 | 186 | if (i = LEN(path)) or (path[i] = ':') then |
| 186 | 187 | dir := path[start..i]; |
| 187 | 188 | start := i + 1; |
| 188 | - Buf.init(b, ADR(arena.base)); | |
| 189 | + Buf.init(b, SYSTEM.ADR(arena.base)); | |
| 189 | 190 | Fmt.write(b, "{}/{}", [Fmt.str(dir), Fmt.str(name)]); |
| 190 | 191 | info, err := Sys.info(Buf.bytes(b)); |
| 191 | 192 | if (err = 0) and info.file and (info.mode & 49H # 0) then return Buf.bytes(b), true; end; |
| @@ -246,11 +247,11 @@ | ||
| 246 | 247 | pids: [maxCmds]INT; fds: [3]INT; i, j, inNext, r, w, leader, joins, how, _pid: INT; |
| 247 | 248 | c: ^Command; path: []const U8; found, _ok: BOOL; st: Sys.Status; |
| 248 | 249 | begin |
| 249 | - if (p^.n = 1) and not p^.background and builtin(ADR(p^.cmds[0])) then return; end; | |
| 250 | + if (p^.n = 1) and not p^.background and builtin(SYSTEM.ADR(p^.cmds[0])) then return; end; | |
| 250 | 251 | leader := 0; |
| 251 | 252 | inNext := 0; |
| 252 | 253 | for i := 0 to p^.n - 1 do |
| 253 | - c := ADR(p^.cmds[i]); | |
| 254 | + c := SYSTEM.ADR(p^.cmds[i]); | |
| 254 | 255 | fds := [inNext, 0, 0]; |
| 255 | 256 | inNext := 0; |
| 256 | 257 | if i < p^.n - 1 then r, w := Sys.pipe(); fds[1] := w; inNext := r; end; |
| @@ -306,9 +307,9 @@ | ||
| 306 | 307 | s := script; |
| 307 | 308 | at := 0; |
| 308 | 309 | repeat |
| 309 | - t, ok := parse(ADR(p)); | |
| 310 | + t, ok := parse(SYSTEM.ADR(p)); | |
| 310 | 311 | if not ok then status := 2; return; end; |
| 311 | - if p.cmds[0].n > 0 then start(ADR(p)); end; | |
| 312 | + if p.cmds[0].n > 0 then start(SYSTEM.ADR(p)); end; | |
| 312 | 313 | until t = eof; |
| 313 | 314 | end; |
| 314 | 315 |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | size, in the order written. *) |
| 5 | 5 | module Volatile; |
| 6 | 6 | import Out; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | type |
| 9 | 10 | Uart = record |
| @@ -17,7 +18,7 @@ | ||
| 17 | 18 | proc main*; |
| 18 | 19 | var dev: ^VOLATILE Uart; i: INT; |
| 19 | 20 | begin |
| 20 | - dev := ^VOLATILE Uart(ADR(page)); | |
| 21 | + dev := ^VOLATILE Uart(SYSTEM.ADR(page)); | |
| 21 | 22 | dev^.control := 1; |
| 22 | 23 | dev^.status := 0FFH; |
| 23 | 24 | for i := 0 to 2 do |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | check, not run: it needs a display. *) |
| 5 | 5 | module Window; |
| 6 | 6 | import Out; |
| 7 | +import SYSTEM; | |
| 7 | 8 | link "libX11.so.6"; |
| 8 | 9 | |
| 9 | 10 | const |
| @@ -56,12 +57,12 @@ | ||
| 56 | 57 | _ := XSelectInput(d, w, ExposureMask + KeyPressMask); |
| 57 | 58 | _ := XMapWindow(d, w); |
| 58 | 59 | repeat |
| 59 | - _ := XNextEvent(d, ^U8(ADR(ev))); | |
| 60 | + _ := XNextEvent(d, ^U8(SYSTEM.ADR(ev))); | |
| 60 | 61 | if I32(ev[0]) = Expose then |
| 61 | 62 | _ := XDrawString(d, w, XDefaultGC(d, s), 20, 45, text, I32(LEN(text))); |
| 62 | 63 | end; |
| 63 | 64 | until I32(ev[0]) = KeyPress; |
| 64 | - key := ^KeyEvent(ADR(ev)); | |
| 65 | + key := ^KeyEvent(SYSTEM.ADR(ev)); | |
| 65 | 66 | Out.str("key "); Out.int(INT(key^.keycode)); Out.ln; |
| 66 | 67 | _ := XCloseDisplay(d); |
| 67 | 68 | return 0; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | from a shared counter and add up their results under a Mutex. *) |
| 3 | 3 | module Workers; |
| 4 | 4 | import Out, Thread; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | const |
| 7 | 8 | Workers = 4; |
| @@ -24,13 +25,13 @@ | ||
| 24 | 25 | proc work(_arg: ^U8); |
| 25 | 26 | var n, r: INT; |
| 26 | 27 | begin |
| 27 | - n := XADD(ADR(next), 1); | |
| 28 | + n := XADD(next, 1); | |
| 28 | 29 | while n < Jobs do |
| 29 | 30 | r := job(n * 1000); |
| 30 | 31 | Thread.lock(m); |
| 31 | 32 | total := total + r; |
| 32 | 33 | Thread.unlock(m); |
| 33 | - n := XADD(ADR(next), 1); | |
| 34 | + n := XADD(next, 1); | |
| 34 | 35 | end; |
| 35 | 36 | end; |
| 36 | 37 |
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | whole only where both are. *) |
| 9 | 9 | module Grep; |
| 10 | 10 | import Out; |
| 11 | +import SYSTEM; | |
| 11 | 12 | check off; |
| 12 | 13 | |
| 13 | 14 | const |
| @@ -42,7 +43,7 @@ | ||
| 42 | 43 | begin |
| 43 | 44 | i := 0; |
| 44 | 45 | while i + 8 <= LEN(s) do |
| 45 | - p := ^U64(ADR(s[i])); | |
| 46 | + p := ^U64(SYSTEM.ADR(s[i])); | |
| 46 | 47 | m := zeros(p^ xor 0A0A0A0A0A0A0A0AH); |
| 47 | 48 | if m # 0 then return i + lowest(m); end; |
| 48 | 49 | i := i + 8; |
| @@ -60,8 +61,8 @@ | ||
| 60 | 61 | wb := U64(Word[B]) * Ones; |
| 61 | 62 | i := 0; |
| 62 | 63 | while i + 7 <= last do |
| 63 | - p := ^U64(ADR(s[i + A])); | |
| 64 | - q := ^U64(ADR(s[i + B])); | |
| 64 | + p := ^U64(SYSTEM.ADR(s[i + A])); | |
| 65 | + q := ^U64(SYSTEM.ADR(s[i + B])); | |
| 65 | 66 | m := zeros(p^ xor wa) & zeros(q^ xor wb); |
| 66 | 67 | while m # 0 do |
| 67 | 68 | j := i + lowest(m); |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* A heap sort of pseudo-random numbers. *) |
| 2 | 2 | module Heapsort; |
| 3 | 3 | import Out; |
| 4 | +import SYSTEM; | |
| 4 | 5 | check off; |
| 5 | 6 | |
| 6 | 7 | const |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | neighbours, the edges held. *) |
| 3 | 3 | module Jacobi; |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | check off; |
| 6 | 7 | |
| 7 | 8 | const |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | IndexByte, which is assembly, and a counting loop. *) |
| 4 | 4 | module Lines; |
| 5 | 5 | import Out, Bytes; |
| 6 | +import SYSTEM; | |
| 6 | 7 | check off; |
| 7 | 8 | |
| 8 | 9 | const |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | inner loop. *) |
| 4 | 4 | module NBody; |
| 5 | 5 | import Out, Math; |
| 6 | +import SYSTEM; | |
| 6 | 7 | check off; |
| 7 | 8 | |
| 8 | 9 | const |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | turn, over a text of four letters. *) |
| 3 | 3 | module Search; |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | check off; |
| 6 | 7 | |
| 7 | 8 | const |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* A sum over a slice: the loop of a procedure that takes one. *) |
| 2 | 2 | module Sum; |
| 3 | 3 | import Out; |
| 4 | +import SYSTEM; | |
| 4 | 5 | check off; |
| 5 | 6 | |
| 6 | 7 | const |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmControl.raz:4:5: error: can't assemble mov with these operands | |
| 2 | - 4 | mov eax, cr0; | |
| 1 | +test/err/AsmControl.raz:5:5: error: can't assemble mov with these operands | |
| 2 | + 5 | mov eax, cr0; | |
| 3 | 3 | | ^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmControl; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | mov eax, cr0; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmJccRegister.raz:4:5: error: unknown instruction jz | |
| 2 | - 4 | jz rax; | |
| 1 | +test/err/AsmJccRegister.raz:5:5: error: unknown instruction jz | |
| 2 | + 5 | jz rax; | |
| 3 | 3 | | ^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmJccRegister; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | jz rax; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmLabel.raz:4:9: error: label nowhere isn't defined | |
| 2 | - 4 | jmp nowhere; | |
| 1 | +test/err/AsmLabel.raz:5:9: error: label nowhere isn't defined | |
| 2 | + 5 | jmp nowhere; | |
| 3 | 3 | | ^^^^^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmLabel; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | jmp nowhere; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmMemory.raz:4:16: error: expected a memory operand, [base + index * scale + disp] | |
| 2 | - 4 | mov rax, [8]; | |
| 1 | +test/err/AsmMemory.raz:5:16: error: expected a memory operand, [base + index * scale + disp] | |
| 2 | + 5 | mov rax, [8]; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmMemory; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | mov rax, [8]; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmOperands.raz:4:5: error: can't assemble lea with these operands | |
| 2 | - 4 | lea rax, rbx; | |
| 1 | +test/err/AsmOperands.raz:5:5: error: can't assemble lea with these operands | |
| 2 | + 5 | lea rax, rbx; | |
| 3 | 3 | | ^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmOperands; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | lea rax, rbx; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AsmUnknown.raz:4:5: error: unknown instruction frob | |
| 2 | - 4 | frob rax; | |
| 1 | +test/err/AsmUnknown.raz:5:5: error: unknown instruction frob | |
| 2 | + 5 | frob rax; | |
| 3 | 3 | | ^^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AsmUnknown; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f; |
| 3 | 4 | code |
| 4 | 5 | frob rax; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/AtPByte.raz:4:11: error: expected a byte from 0 to 255, found 300 | |
| 2 | - 4 | db 1, 300; | |
| 1 | +test/err/AtPByte.raz:5:11: error: expected a byte from 0 to 255, found 300 | |
| 2 | + 5 | db 1, 300; | |
| 3 | 3 | | ^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module AtPByte; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f(a: I64); |
| 3 | 4 | code |
| 4 | 5 | db 1, 300; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module BareC; |
| 2 | +import SYSTEM; | |
| 2 | 3 | extern proc getpid(): I32; |
| 3 | 4 | proc main*; |
| 4 | 5 | begin |
| @@ -1,5 +1,5 @@ | ||
| 1 | -test/err/ConvDeref.raz:4:15: error: a conversion can't be dereferenced | |
| 2 | - 4 | b := ^INT(a)^ | |
| 1 | +test/err/ConvDeref.raz:5:15: error: a conversion can't be dereferenced | |
| 2 | + 5 | b := ^INT(a)^ | |
| 3 | 3 | | ^ |
| 4 | 4 | help: convert into a pointer variable, then dereference that |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module ConvDeref; |
| 2 | +import SYSTEM; | |
| 2 | 3 | var a, b: INT; |
| 3 | 4 | begin |
| 4 | 5 | b := ^INT(a)^ |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeclAtomicSize.raz:8:15: error: expected an INT or a UINT variable, found ^U8 | |
| 2 | - 8 | n := XADD(p, 1); | |
| 1 | +test/err/DeclAtomicSize.raz:9:15: error: expected an INT or a UINT variable, found ^U8 | |
| 2 | + 9 | n := XADD(p, 1); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | module DeclAtomicSize; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var b: U8; |
| 4 | 5 | var p: ^U8; |
| 5 | 6 | var n: I64; |
| 6 | 7 | begin |
| 7 | - p := ADR(b); | |
| 8 | + p := SYSTEM.ADR(b); | |
| 8 | 9 | n := XADD(p, 1); |
| 9 | 10 | end; |
| 10 | 11 | end DeclAtomicSize. |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeclSyscallArg.raz:5:21: error: expected an integer or a pointer, found 1.5 | |
| 2 | - 5 | n := SYSCALL(1, 1.5); | |
| 3 | - | ^^^ | |
| 1 | +test/err/DeclSyscallArg.raz:6:28: error: expected an integer or a pointer, found 1.5 | |
| 2 | + 6 | n := SYSTEM.SYSCALL(1, 1.5); | |
| 3 | + | ^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | module DeclSyscallArg; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc main*; |
| 3 | 4 | var n: I64; |
| 4 | 5 | begin |
| 5 | - n := SYSCALL(1, 1.5); | |
| 6 | + n := SYSTEM.SYSCALL(1, 1.5); | |
| 6 | 7 | end; |
| 7 | 8 | end DeclSyscallArg. |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/ExprJoinStrings.raz:7:13: error: + doesn't join []U8 | |
| 1 | +test/err/ExprJoinStrings.raz:7:13: error: + doesn't join []const U8 | |
| 2 | 2 | 7 | Out.str(s + "def"); |
| 3 | 3 | | ^ |
| 4 | 4 | help: strings are joined in a Buf: Buf.str(b, s) |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | module ExprJoinStrings; |
| 2 | 2 | import Out; |
| 3 | 3 | proc main*; |
| 4 | -var s: []U8; | |
| 4 | +var s: []const U8; | |
| 5 | 5 | begin |
| 6 | 6 | s := "abc"; |
| 7 | 7 | Out.str(s + "def"); |
| @@ -1,9 +1,9 @@ | ||
| 1 | -test/err/ExprNoField.raz:7:10: error: expected a record, found ^R | |
| 2 | - 7 | n := p.x; | |
| 1 | +test/err/ExprNoField.raz:8:10: error: expected a record, found ^R | |
| 2 | + 8 | n := p.x; | |
| 3 | 3 | | ^ |
| 4 | 4 | help: through a pointer, write p^.x |
| 5 | -test/err/ExprNoField.raz:8:10: error: expected a record, found []U8 | |
| 6 | - 8 | n := s.len; | |
| 5 | +test/err/ExprNoField.raz:9:10: error: expected a record, found []U8 | |
| 6 | + 9 | n := s.len; | |
| 7 | 7 | | ^ |
| 8 | 8 | help: its length is LEN(s) |
| 9 | 9 | raz: 2 errors |
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | module ExprNoField; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = record x: I64; end; |
| 3 | 4 | proc main*; |
| 4 | 5 | var r: R; p: ^R; s: []U8; n: I64; |
| 5 | 6 | begin |
| 6 | - p := ADR(r); | |
| 7 | + p := SYSTEM.ADR(r); | |
| 7 | 8 | n := p.x; |
| 8 | 9 | n := s.len; |
| 9 | 10 | end; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/ExternRec.raz:5:13: error: C takes integers, BOOL, reals, pointers and procedures | |
| 2 | - 5 | extern proc f(r: R); | |
| 1 | +test/err/ExternRec.raz:6:13: error: C takes integers, BOOL, reals, pointers and procedures | |
| 2 | + 6 | extern proc f(r: R); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module ExternRec; |
| 2 | +import SYSTEM; | |
| 2 | 3 | |
| 3 | 4 | type R = record a, b: I64; end; |
| 4 | 5 |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/F32Dots.raz:8:22: error: an F32 goes to ... as F64(x) | |
| 2 | - 8 | C.printf("%f\n", x); | |
| 1 | +test/err/F32Dots.raz:9:22: error: an F32 goes to ... as F64(x) | |
| 2 | + 9 | C.printf("%f\n", x); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module F32Dots; |
| 2 | 2 | import C; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | proc main*; |
| 5 | 6 | var x: F32; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/GenCodeValue.raz:6:10: error: a code procedure with two results can only be called | |
| 2 | - 6 | f := Two; | |
| 1 | +test/err/GenCodeValue.raz:7:10: error: a code procedure with two results can only be called | |
| 2 | + 7 | f := Two; | |
| 3 | 3 | | ^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module GenCodeValue; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type F = proc(): (I64, I64); proc Two(): (I64, I64); code ret; end; |
| 3 | 4 | proc main*; |
| 4 | 5 | var f: F; |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Static; |
| 2 | 2 | import Bare, C; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | proc main*; |
| 5 | 6 | begin |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCReturns.raz:3:13: error: C returns a single value | |
| 2 | - 3 | extern proc f(): R; | |
| 1 | +test/err/StmtCReturns.raz:4:13: error: C returns a single value | |
| 2 | + 4 | extern proc f(): R; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCReturns; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = record a: I64; end; |
| 3 | 4 | extern proc f(): R; |
| 4 | 5 | end StmtCReturns. |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCodeParams.raz:2:6: error: too many parameters for a code procedure | |
| 2 | - 2 | proc f(a, b, c, d, e, f, g: I64); | |
| 1 | +test/err/StmtCodeParams.raz:3:6: error: too many parameters for a code procedure | |
| 2 | + 3 | proc f(a, b, c, d, e, f, g: I64); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCodeParams; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f(a, b, c, d, e, f, g: I64); |
| 3 | 4 | code ret; end; |
| 4 | 5 | end StmtCodeParams. |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCodeResult.raz:3:6: error: a code procedure returns a single value | |
| 2 | - 3 | proc f: R; | |
| 1 | +test/err/StmtCodeResult.raz:4:6: error: a code procedure returns a single value | |
| 2 | + 4 | proc f: R; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCodeResult; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = record a: I64; end; |
| 3 | 4 | proc f: R; |
| 4 | 5 | code ret; end; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCodeSlices.raz:2:6: error: too many parameters for a code procedure | |
| 2 | - 2 | proc f(a, b, c, d, e: I64; s: []U8); | |
| 1 | +test/err/StmtCodeSlices.raz:3:6: error: too many parameters for a code procedure | |
| 2 | + 3 | proc f(a, b, c, d, e: I64; s: []U8); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCodeSlices; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f(a, b, c, d, e: I64; s: []U8); |
| 3 | 4 | code ret; end; |
| 4 | 5 | end StmtCodeSlices. |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCodeTakes.raz:3:6: error: a code procedure takes integers, BOOL, reals, pointers, procedures and slices | |
| 2 | - 3 | proc f(r: R); | |
| 1 | +test/err/StmtCodeTakes.raz:4:6: error: a code procedure takes integers, BOOL, reals, pointers, procedures and slices | |
| 2 | + 4 | proc f(r: R); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCodeTakes; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type R = record a: I64; end; |
| 3 | 4 | proc f(r: R); |
| 4 | 5 | code ret; end; |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/StmtCodeTwo.raz:2:6: error: a code procedure returns two results only in rax and rdx | |
| 2 | - 2 | proc f: (F64, I64); | |
| 1 | +test/err/StmtCodeTwo.raz:3:6: error: a code procedure returns two results only in rax and rdx | |
| 2 | + 3 | proc f: (F64, I64); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module StmtCodeTwo; |
| 2 | +import SYSTEM; | |
| 2 | 3 | proc f: (F64, I64); |
| 3 | 4 | code ret; end; |
| 4 | 5 | end StmtCodeTwo. |
| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | module VarGivenAddress; |
| 2 | +import SYSTEM; | |
| 2 | 3 | type B = record n: INT; end; |
| 3 | 4 | proc f(var b: B); begin b.n := 1; end; |
| 4 | 5 | proc g(const b: B): INT; begin return b.n; end; |
| 5 | 6 | proc main*; |
| 6 | 7 | var b: B; p: ^B; |
| 7 | 8 | begin |
| 8 | - p := ADR(b); | |
| 9 | - f(ADR(b)); | |
| 9 | + p := SYSTEM.ADR(b); | |
| 10 | + f(SYSTEM.ADR(b)); | |
| 10 | 11 | f(p); |
| 11 | - _ := g(ADR(b)); | |
| 12 | + _ := g(SYSTEM.ADR(b)); | |
| 12 | 13 | end; |
| 13 | 14 | end VarGivenAddress. |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | module ZeroDigit; |
| 2 | 2 | (* \0 before a digit is a warning; \x00, \0 at the end, \0 before a |
| 3 | 3 | letter, an escaped backslash before 0 and a raw string are quiet. *) |
| 4 | -var s*: []U8; c*: U8; | |
| 4 | +var s*: []const U8; c*: U8; | |
| 5 | 5 | proc main*; |
| 6 | 6 | begin |
| 7 | 7 | s := "a\x0012"; |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | (* A module that needs a program without C. *) |
| 2 | 2 | module Bare; |
| 3 | +import SYSTEM; | |
| 3 | 4 | link static; |
| 4 | 5 | |
| 5 | 6 | proc f*: I64; |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | joined, is -3. ThreadSignal is the same, without C; this copy runs over |
| 5 | 5 | the C library's Sys. *) |
| 6 | 6 | import Thread, Sys, Fmt, C; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | var |
| 9 | 10 | r, got, done: INT; |
| @@ -12,7 +13,7 @@ | ||
| 12 | 13 | var buf: [16]U8; |
| 13 | 14 | begin |
| 14 | 15 | got := Sys.read(r, buf); |
| 15 | - _ := XCHG(ADR(done), 1); | |
| 16 | + _ := XCHG(done, 1); | |
| 16 | 17 | end; |
| 17 | 18 | |
| 18 | 19 | proc quick(_arg: ^U8); |
| @@ -28,7 +29,7 @@ | ||
| 28 | 29 | t, e := Thread.spawn(reader, nil); |
| 29 | 30 | if e # nil then Fmt.print("no thread\n", []); return; end; |
| 30 | 31 | (* again until it lands: the first may come before the read begins *) |
| 31 | - while (XADD(ADR(done), 0) = 0) and (tries < 1000) do | |
| 32 | + while (XADD(done, 0) = 0) and (tries < 1000) do | |
| 32 | 33 | k := Thread.signal(t, Sys.sigUsr1); |
| 33 | 34 | if k # 0 then Fmt.print("signal: {}\n", [Fmt.int(k)]); end; |
| 34 | 35 | Sys.sleep(5); |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | writes out what Out holds. *) |
| 4 | 4 | module Through; |
| 5 | 5 | import Out, Heap, Mem; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | type Node = record next: ^Node; n: I64; end; |
| 8 | 9 |
| @@ -1,2 +1,2 @@ | ||
| 1 | -test/libc/Through.raz:30:7: index 3 is out of range for a length of 3 | |
| 2 | - in Through.main at test/libc/Through.raz:30:7: p = nil, list = nil, i = 3, sum = 500500 | |
| 1 | +test/libc/Through.raz:31:7: index 3 is out of range for a length of 3 | |
| 2 | + in Through.main at test/libc/Through.raz:31:7: p = nil, list = nil, i = 3, sum = 500500 |
| @@ -4,13 +4,13 @@ | ||
| 4 | 4 | 4 ret |
| 5 | 5 | |
| 6 | 6 | Listing.main: |
| 7 | - 17 proc main*; | |
| 7 | + 18 proc main*; | |
| 8 | 8 | 0 push rbp |
| 9 | 9 | 1 mov rbp, rsp |
| 10 | 10 | 4 sub rsp, 32 |
| 11 | 11 | 11 mov [rbp - 8], rbx |
| 12 | 12 | 15 xor ebx, ebx |
| 13 | - 20 for i := 1 to 3 do | |
| 13 | + 21 for i := 1 to 3 do | |
| 14 | 14 | 17 mov rbx, 1 |
| 15 | 15 | 22 cmp rbx, 3 |
| 16 | 16 | 26 jg 168 |
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | 53 nop |
| 21 | 21 | 61 nop |
| 22 | 22 | 64 add rbx, 1 |
| 23 | - 21 if i # 2 then total := add(total, twice(i)); end; | |
| 23 | + 22 if i # 2 then total := add(total, twice(i)); end; | |
| 24 | 24 | 68 cmp rbx, 2 |
| 25 | 25 | 72 je 134 |
| 26 | 26 | 78 mov r8, [Listing.total] |
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | 154 add rbx, 1 |
| 44 | 44 | 158 cmp rbx, 3 |
| 45 | 45 | 162 jle 68 |
| 46 | - 23 end main; | |
| 46 | + 24 end main; | |
| 47 | 47 | 168 mov rbx, [rbp - 8] |
| 48 | 48 | 172 leave |
| 49 | 49 | 173 ret |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Listing; |
| 2 | 2 | (* raz -S: each line of source, and the instructions made for it *) |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | var total: I64; |
| 5 | 6 |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/ArrayConstAdr.raz:6:14: error: ADR needs a variable | |
| 2 | - 6 | p := ADR(P); | |
| 3 | - | ^ | |
| 1 | +conform/err/ArrayConstAdr.raz:7:21: error: ADR needs a variable | |
| 2 | + 7 | p := SYSTEM.ADR(P); | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/AtPAdr.raz:5:14: error: ADR needs a variable | |
| 2 | - 5 | p := ADR(1); | |
| 3 | - | ^ | |
| 1 | +conform/err/AtPAdr.raz:6:21: error: ADR needs a variable | |
| 2 | + 6 | p := SYSTEM.ADR(1); | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/AtomicI64.raz:5:16: error: expected a pointer to an INT, a UINT or a pointer, found ^I64 | |
| 2 | - 5 | _ok := CAS(ADR(n), 0, 1); | |
| 3 | - | ^^^^^^ | |
| 1 | +conform/err/AtomicI64.raz:5:16: error: expected an INT, a UINT or a pointer variable, found I64 | |
| 2 | + 5 | _ok := CAS(n, 0, 1); | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +1,5 @@ | ||
| 1 | -conform/err/BytesVolatile.raz:7:16: error: BYTES can't take a volatile variable | |
| 2 | - 7 | b := BYTES(r^); | |
| 1 | +conform/err/BytesVolatile.raz:8:16: error: BYTES can't take a volatile variable | |
| 2 | + 8 | b := BYTES(r^); | |
| 3 | 3 | | ^^ |
| 4 | 4 | help: reading and writing its bytes through a slice wouldn't be volatile accesses |
| 5 | 5 | raz: 1 error |
| @@ -1,5 +1,5 @@ | ||
| 1 | -conform/err/ConstAdr.raz:5:16: error: r is only read here, and can't be changed | |
| 2 | - 5 | return ADR(r); | |
| 3 | - | ^ | |
| 1 | +conform/err/ConstAdr.raz:6:23: error: r is only read here, and can't be changed | |
| 2 | + 6 | return SYSTEM.ADR(r); | |
| 3 | + | ^ | |
| 4 | 4 | help: a const parameter, a constant, and the names a match gives their fields, are only read: take a var parameter to change it |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/ExportAdr.raz:6:15: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | - 6 | _p := ADR(Owner.n); | |
| 3 | - | ^^^^^^^ | |
| 1 | +conform/err/ExportAdr.raz:7:22: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | + 7 | _p := SYSTEM.ADR(Owner.n); | |
| 3 | + | ^^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/GenDotsRecord.raz:7:20: error: only a single value goes to ... | |
| 2 | - 7 | C.printf("%d", r); | |
| 1 | +conform/err/GenDotsRecord.raz:8:20: error: only a single value goes to ... | |
| 2 | + 8 | C.printf("%d", r); | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,13 +1,13 @@ | ||
| 1 | -conform/err/PackedAddress.raz:15:14: error: a field of a packed record has no address | |
| 2 | - 15 | p := ADR(h.len); | |
| 3 | - | ^^^^^ | |
| 4 | -conform/err/PackedAddress.raz:16:9: error: a field of a packed record can't be a var parameter | |
| 5 | - 16 | put(h.len); | |
| 1 | +conform/err/PackedAddress.raz:16:21: error: a field of a packed record has no address | |
| 2 | + 16 | p := SYSTEM.ADR(h.len); | |
| 3 | + | ^^^^^ | |
| 4 | +conform/err/PackedAddress.raz:17:9: error: a field of a packed record can't be a var parameter | |
| 5 | + 17 | put(h.len); | |
| 6 | 6 | | ^^^^^ |
| 7 | -conform/err/PackedAddress.raz:17:10: error: can't make a slice of a field of a packed record | |
| 8 | - 17 | s := h.vals[0..1]; | |
| 7 | +conform/err/PackedAddress.raz:18:10: error: can't make a slice of a field of a packed record | |
| 8 | + 18 | s := h.vals[0..1]; | |
| 9 | 9 | | ^^^^^^ |
| 10 | -conform/err/PackedAddress.raz:19:5: error: a field of a packed record can't be volatile | |
| 11 | - 19 | q^.len := 2; | |
| 10 | +conform/err/PackedAddress.raz:20:5: error: a field of a packed record can't be volatile | |
| 11 | + 20 | q^.len := 2; | |
| 12 | 12 | | ^^ |
| 13 | 13 | raz: 4 errors |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/PtrArray.raz:6:5: error: a pointer to an array is indexed as p^[i] | |
| 2 | - 6 | p[1] := 0; | |
| 1 | +conform/err/PtrArray.raz:7:5: error: a pointer to an array is indexed as p^[i] | |
| 2 | + 7 | p[1] := 0; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +1,5 @@ | ||
| 1 | -conform/err/PtrAsSlice.raz:5:10: error: can't use ^U8 as []U8 | |
| 2 | - 5 | s := PTR(a); | |
| 3 | - | ^^^^^^ | |
| 1 | +conform/err/PtrAsSlice.raz:6:10: error: can't use ^U8 as []U8 | |
| 2 | + 6 | s := SYSTEM.PTR(a); | |
| 3 | + | ^^^^^^^^^^^^^ | |
| 4 | 4 | help: a pointer has no length: p[0..n], for a pointer p, is the slice of the n elements it starts |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/PtrElement.raz:5:10: error: can't use ^U8 as ^INT | |
| 2 | - 5 | p := PTR(a); | |
| 3 | - | ^^^^^^ | |
| 1 | +conform/err/PtrElement.raz:6:10: error: can't use ^U8 as ^INT | |
| 2 | + 6 | p := SYSTEM.PTR(a); | |
| 3 | + | ^^^^^^^^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +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 | - | ^^^^^^^ | |
| 1 | +conform/err/PtrExport.raz:7:21: error: Owner.a is Owner's, and can't be changed outside it | |
| 2 | + 7 | p := SYSTEM.PTR(Owner.a); | |
| 3 | + | ^^^^^^^ | |
| 4 | 4 | help: a pointer to it could change it, as a slice of it could: copy it to a variable here first |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +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 | - | ^ | |
| 1 | +conform/err/PtrInteger.raz:7:21: error: PTR needs a slice or an array, found INT | |
| 2 | + 7 | p := SYSTEM.PTR(n); | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +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 | - | ^ | |
| 1 | +conform/err/PtrLiteral.raz:6:21: error: PTR can't take an array literal, which has no type here | |
| 2 | + 6 | p := SYSTEM.PTR([]); | |
| 3 | + | ^ | |
| 4 | 4 | help: PTR([]) would be nil, the empty slice's pointer; give any other literal a variable first |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +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 | - | ^^^^^^^ | |
| 1 | +conform/err/PtrPacked.raz:7:21: error: PTR can't take a field of a packed record, which has no address | |
| 2 | + 7 | p := SYSTEM.PTR(r.words); | |
| 3 | + | ^^^^^^^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,9 +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 | - | ^ | |
| 1 | +conform/err/PtrPointer.raz:7:21: error: PTR needs a slice or an array, found ^U8 | |
| 2 | + 7 | q := SYSTEM.PTR(p); | |
| 3 | + | ^ | |
| 4 | 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 | - | ^^ | |
| 5 | +conform/err/PtrPointer.raz:8:21: error: PTR needs a slice or an array, found ^[4]U8 | |
| 6 | + 8 | q := SYSTEM.PTR(pa); | |
| 7 | + | ^^ | |
| 8 | 8 | help: write PTR(pa^) for the address of the array's first element, a ^U8 |
| 9 | 9 | raz: 2 errors |
| @@ -1,5 +1,5 @@ | ||
| 1 | -conform/err/PtrView.raz:6:14: error: PTR can't take a view | |
| 2 | - 6 | p := PTR(w.([8]U8)); | |
| 3 | - | ^^^^^^^^^ | |
| 1 | +conform/err/PtrView.raz:7:21: error: PTR can't take a view | |
| 2 | + 7 | p := SYSTEM.PTR(w.([8]U8)); | |
| 3 | + | ^^^^^^^^^ | |
| 4 | 4 | help: a view has no address, since it may be misaligned: copy it to a variable |
| 5 | 5 | raz: 1 error |
| @@ -1,5 +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 | - | ^^ | |
| 1 | +conform/err/PtrVolatile.raz:8:21: error: PTR can't take an array through a volatile pointer | |
| 2 | + 8 | p := SYSTEM.PTR(v^); | |
| 3 | + | ^^ | |
| 4 | 4 | help: ADR(v^[0]) is the address of its first element, a ^VOLATILE U32 |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/SliceLiteralPart.raz:2:32: error: a constant slice is a string, an array constant or literal of its elements, or [], found 3 | |
| 2 | - 2 | const Rows: [][]INT = [[1, 2], 3]; | |
| 3 | - | ^ | |
| 1 | +conform/err/SliceLiteralPart.raz:2:44: error: a constant slice is a string, an array constant or literal of its elements, or [], found 3 | |
| 2 | + 2 | const Rows: []const []const INT = [[1, 2], 3]; | |
| 3 | + | ^ | |
| 4 | 4 | raz: 1 error |
| @@ -1,2 +1,2 @@ | ||
| 1 | -conform/run/SlicePtrBackwards.raz:11:23: slice 2..0 runs backwards | |
| 2 | - in SlicePtrBackwards.main at conform/run/SlicePtrBackwards.raz:11:23: p = 0x?, hi = 0 | |
| 1 | +conform/run/SlicePtrBackwards.raz:12:23: slice 2..0 runs backwards | |
| 2 | + in SlicePtrBackwards.main at conform/run/SlicePtrBackwards.raz:12:23: p = 0x?, hi = 0 |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/StmtVarOrProc.raz:2:8: error: expected "proc" or "var", found a number | |
| 2 | - 2 | extern 5; | |
| 1 | +conform/err/StmtVarOrProc.raz:3:8: error: expected "proc" or "var", found a number | |
| 2 | + 3 | extern 5; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +1,5 @@ | ||
| 1 | -conform/err/ViewAdr.raz:5:14: error: ADR can't take a view | |
| 2 | - 5 | p := ADR(mem[0].(I64)); | |
| 3 | - | ^^^^^^^^^^^^ | |
| 1 | +conform/err/ViewAdr.raz:6:21: error: ADR can't take a view | |
| 2 | + 6 | p := SYSTEM.ADR(mem[0].(I64)); | |
| 3 | + | ^^^^^^^^^^^^ | |
| 4 | 4 | help: a view has no address, since it may be misaligned: copy it to a variable |
| 5 | 5 | raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/Volatile.raz:6:10: error: can't use ^VOLATILE I64 as ^I64 | |
| 2 | - 6 | q := p; | |
| 1 | +conform/err/Volatile.raz:7:10: error: can't use ^VOLATILE I64 as ^I64 | |
| 2 | + 7 | q := p; | |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Alloc; |
| 2 | 2 | import Out, Mem, Arena, Heap; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | type |
| 5 | 6 | Node = record next: ^Node; val: I64; pad: [5]I64; end; |
| @@ -52,12 +53,12 @@ | ||
| 52 | 53 | Out.int(b^.data[999] + b^.data[0]); Out.ln; |
| 53 | 54 | Mem.free(Heap.heap, ^U8(b)); |
| 54 | 55 | if not Arena.init(ar, 8192) then Out.str("no arena"); end; |
| 55 | - l := build(ADR(ar.base), 100); | |
| 56 | + l := build(SYSTEM.ADR(ar.base), 100); | |
| 56 | 57 | Out.int(sum(l)); Out.ln; |
| 57 | - l := build(ADR(ar.base), 1000); | |
| 58 | + l := build(SYSTEM.ADR(ar.base), 1000); | |
| 58 | 59 | if l = nil then Out.str("nil "); end; |
| 59 | 60 | Arena.reset(ar); |
| 60 | - NEW(again, ADR(ar.base)); | |
| 61 | + NEW(again, SYSTEM.ADR(ar.base)); | |
| 61 | 62 | if again # nil then Out.str("again "); Out.int(again^.val); end; |
| 62 | 63 | Out.ln; |
| 63 | 64 | Arena.done(ar); |
| @@ -2,12 +2,13 @@ | ||
| 2 | 2 | (* a mark from before the arena's present position is released; one past |
| 3 | 3 | where the arena stands stops the program *) |
| 4 | 4 | import Arena, Mem, Rt; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var ar: Arena.Arena; m: INT; |
| 8 | 9 | begin |
| 9 | 10 | if not Arena.init(ar, 4096) then Rt.stop("no arena"); end; |
| 10 | - _ := Mem.alloc(ADR(ar.base), 10, 1); | |
| 11 | + _ := Mem.alloc(SYSTEM.ADR(ar.base), 10, 1); | |
| 11 | 12 | m := Arena.mark(ar); |
| 12 | 13 | Arena.release(ar, 0); |
| 13 | 14 | Arena.release(ar, m); |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | (* Code procedures in assembly: the instructions the assembler knows, |
| 3 | 3 | each checked by what it computes *) |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | const |
| 7 | 8 | Seven = 7; |
| @@ -154,10 +155,10 @@ | ||
| 154 | 155 | begin |
| 155 | 156 | Out.int(tens(4, 2)); Out.ln; |
| 156 | 157 | a := [1, 20, 300, 4000]; |
| 157 | - Out.int(sum(ADR(a[0]), 4)); Out.str(" "); Out.int(sum(ADR(a[0]), 0)); Out.str(" "); | |
| 158 | - Out.int(around(ADR(a[0]), 1)); Out.ln; | |
| 158 | + Out.int(sum(SYSTEM.ADR(a[0]), 4)); Out.str(" "); Out.int(sum(SYSTEM.ADR(a[0]), 0)); Out.str(" "); | |
| 159 | + Out.int(around(SYSTEM.ADR(a[0]), 1)); Out.ln; | |
| 159 | 160 | s := "abc"; |
| 160 | - Out.int(swapByte(ADR(s[0]), 1, 'z')); Out.str(" "); Out.str(s[0..3]); Out.ln; | |
| 161 | + Out.int(swapByte(SYSTEM.ADR(s[0]), 1, 'z')); Out.str(" "); Out.str(s[0..3]); Out.ln; | |
| 161 | 162 | q, r := udivmod(1000, 7); |
| 162 | 163 | Out.int(I64(q)); Out.str(" "); Out.int(I64(r)); Out.ln; |
| 163 | 164 | Out.int(max(-5, 3)); Out.str(" "); Out.int(max(9, 3)); Out.str(" "); |
| @@ -166,7 +167,7 @@ | ||
| 166 | 167 | Out.int(I64(real(1.0, 3.0))); Out.ln; |
| 167 | 168 | Out.int(mix(5)); Out.ln; |
| 168 | 169 | c := 40; |
| 169 | - Out.int(fetchAdd(ADR(c), 2)); Out.str(" "); Out.int(c); Out.ln; | |
| 170 | + Out.int(fetchAdd(SYSTEM.ADR(c), 2)); Out.str(" "); Out.int(c); Out.ln; | |
| 170 | 171 | Out.int(I64(two() * 21.0)); Out.str(" "); Out.int(answer()); Out.ln; |
| 171 | 172 | Out.int(through(answer)); Out.ln; |
| 172 | 173 | t := "abcdef"; |
| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | back from the procedure they are made in, since they can't run in |
| 4 | 4 | user mode. Each was checked against GNU as. *) |
| 5 | 5 | import Out; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | const |
| 8 | 9 | Count = 36; |
| 9 | - Names: [Count][]U8 = ["cli", "sti", "iretq", "swapgs", | |
| 10 | + Names: [Count][]const U8 = ["cli", "sti", "iretq", "swapgs", | |
| 10 | 11 | "rdmsr", "wrmsr", "wbinvd", "lgdt [rdi]", |
| 11 | 12 | "lidt [rsi + 8]", "invlpg [rax]", "invlpg [r12 + rcx * 8 + 400]", "xsave [rdi]", |
| 12 | 13 | "xrstor [r9]", "ltr ax", "ltr r10w", "mov cr0, rax", |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Atomic; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | var counter: INT; flag: UINT; p: ^INT; |
| 5 | 6 | |
| @@ -13,24 +14,24 @@ | ||
| 13 | 14 | proc main*; |
| 14 | 15 | var old: INT; ok: BOOL; v: ^VOLATILE INT; x: INT; |
| 15 | 16 | begin |
| 16 | - old := XADD(ADR(counter), 5); | |
| 17 | - old := XADD(ADR(counter), 2); | |
| 17 | + old := XADD(counter, 5); | |
| 18 | + old := XADD(counter, 2); | |
| 18 | 19 | Out.int(old); Out.str(" "); Out.int(counter); Out.ln; |
| 19 | - ok := CAS(ADR(counter), 7, 100); | |
| 20 | + ok := CAS(counter, 7, 100); | |
| 20 | 21 | if ok then Out.str("cas1 "); end; |
| 21 | - ok := CAS(ADR(counter), 7, 200); | |
| 22 | + ok := CAS(counter, 7, 200); | |
| 22 | 23 | if not ok then Out.str("cas2 "); end; |
| 23 | 24 | Out.int(counter); Out.ln; |
| 24 | - Out.int(I64(XCHG(ADR(flag), 9))); Out.str(" "); | |
| 25 | - Out.int(I64(XCHG(ADR(flag), 3))); Out.ln; | |
| 25 | + Out.int(I64(XCHG(flag, 9))); Out.str(" "); | |
| 26 | + Out.int(I64(XCHG(flag, 3))); Out.ln; | |
| 26 | 27 | FENCE; |
| 27 | 28 | FENCE(); |
| 28 | 29 | Out.int(add3(1, 20, 300)); Out.ln; |
| 29 | - v := ADR(x); | |
| 30 | + v := SYSTEM.ADR(x); | |
| 30 | 31 | v^ := 5; |
| 31 | 32 | v^ := v^ + 1; |
| 32 | 33 | Out.int(x); Out.ln; |
| 33 | - v := ^VOLATILE INT(ADR(counter)); | |
| 34 | + v := ^VOLATILE INT(SYSTEM.ADR(counter)); | |
| 34 | 35 | Out.int(v^); Out.ln; |
| 35 | 36 | end; |
| 36 | 37 |
| @@ -2,12 +2,13 @@ | ||
| 2 | 2 | (* a Buf whose allocator runs out stops the program, with the calls |
| 3 | 3 | under way, rather than dropping what it was given *) |
| 4 | 4 | import Buf, Arena, Rt; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var ar: Arena.Arena; b: Buf.Buf; big: [10000]U8; |
| 8 | 9 | begin |
| 9 | 10 | if not Arena.init(ar, 4096) then Rt.stop("no arena"); end; |
| 10 | - Buf.init(b, ADR(ar.base)); | |
| 11 | + Buf.init(b, SYSTEM.ADR(ar.base)); | |
| 11 | 12 | Buf.str(b, big); |
| 12 | 13 | end; |
| 13 | 14 |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | Buf: out of memory |
| 2 | 2 | in Buf.need at lib/Buf.raz:51:9: n = 10000 |
| 3 | 3 | in Buf.str at lib/Buf.raz:67:5 |
| 4 | - in BufFull.main at test/run/BufFull.raz:11:5 | |
| 4 | + in BufFull.main at test/run/BufFull.raz:12:5 |
| @@ -3,12 +3,13 @@ | ||
| 3 | 3 | Unchecked reads past an array, into the field after it, and makes a |
| 4 | 4 | slice past its string's end; then this module's own index fails *) |
| 5 | 5 | import Out, Unchecked; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | proc main*; |
| 8 | 9 | var p: Unchecked.Pair; i: INT; |
| 9 | 10 | begin |
| 10 | 11 | p.b := 42; |
| 11 | - Out.int(Unchecked.get(ADR(p), 2)); Out.str(" "); | |
| 12 | + Out.int(Unchecked.get(SYSTEM.ADR(p), 2)); Out.str(" "); | |
| 12 | 13 | Out.int(Unchecked.width("abc", 1, 5)); Out.ln; |
| 13 | 14 | Out.flush; |
| 14 | 15 | i := 2; |
| @@ -1,2 +1,2 @@ | ||
| 1 | -test/run/CheckOff.raz:15:17: index 2 is out of range for a length of 2 | |
| 2 | - in CheckOff.main at test/run/CheckOff.raz:15:17: i = 2 | |
| 1 | +test/run/CheckOff.raz:16:17: index 2 is out of range for a length of 2 | |
| 2 | + in CheckOff.main at test/run/CheckOff.raz:16:17: i = 2 |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module ConstOfConst; |
| 4 | 4 | import Sys; |
| 5 | 5 | |
| 6 | -type R = record a: INT; s: []U8; end; | |
| 6 | +type R = record a: INT; s: []const U8; end; | |
| 7 | 7 | |
| 8 | 8 | const X: R = {a: 1, s: "one"}; |
| 9 | 9 | const Row: [2]INT = [3, 4]; |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Data; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | type |
| 5 | 6 | Cell = record ch: U8; attr: U8; end; |
| @@ -40,15 +41,15 @@ | ||
| 40 | 41 | Out.int(I64(cells[2].ch)); Out.str(" "); Out.int(I64(cells[2].attr)); Out.ln; |
| 41 | 42 | for i := 0 to 4 do |
| 42 | 43 | nodes[i].val := i * i; |
| 43 | - if i < 4 then nodes[i].next := ADR(nodes[i + 1]); end; | |
| 44 | + if i < 4 then nodes[i].next := SYSTEM.ADR(nodes[i + 1]); end; | |
| 44 | 45 | end; |
| 45 | - Out.int(sum(ADR(nodes[0]))); Out.ln; | |
| 46 | + Out.int(sum(SYSTEM.ADR(nodes[0]))); Out.ln; | |
| 46 | 47 | for i := 0 to 2 do |
| 47 | 48 | for j := 0 to 3 do grid[i][j] := I32(i * 10 + j); end; |
| 48 | 49 | end; |
| 49 | 50 | Out.int(I64(grid[2][3])); Out.str(" "); Out.int(I64(grid[1][0])); Out.ln; |
| 50 | 51 | for i := 0 to 7 do arr[i] := i * 100; end; |
| 51 | - p := ADR(arr[0]); | |
| 52 | + p := SYSTEM.ADR(arr[0]); | |
| 52 | 53 | q := p + 5; |
| 53 | 54 | Out.int(q^); Out.str(" "); Out.int(q - p); Out.str(" "); Out.int(p[3]); Out.ln; |
| 54 | 55 | s := arr[2..6]; |
| @@ -65,8 +66,8 @@ | ||
| 65 | 66 | Out.int(gp.x); Out.str(" "); Out.int(gp.y); Out.ln; |
| 66 | 67 | m.a := 1; m.b := -2; m.c := 65535; |
| 67 | 68 | Out.int(m.b); Out.str(" "); Out.int(I64(m.c)); Out.ln; |
| 68 | - bp := ^U8(ADR(m)); | |
| 69 | - Out.int(INT(ADR(m.c)) - INT(bp)); Out.ln; | |
| 69 | + bp := ^U8(SYSTEM.ADR(m)); | |
| 70 | + Out.int(INT(SYSTEM.ADR(m.c)) - INT(bp)); Out.ln; | |
| 70 | 71 | end; |
| 71 | 72 | |
| 72 | 73 | end Data. |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Deep; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | (* Expressions deeper than the registers of the stack, with calls, |
| 5 | 6 | and, or, constants on the left and system calls among them. *) |
| @@ -48,10 +49,10 @@ | ||
| 48 | 49 | u := 250; u := u + U8(c * 5) + U8(d); Out.int(I64(u)); Out.ln; |
| 49 | 50 | (* array elements and pointers among deep values *) |
| 50 | 51 | for d := 0 to 7 do s[d] := d * d; end; |
| 51 | - p := ADR(s[3]); | |
| 52 | + p := SYSTEM.ADR(s[3]); | |
| 52 | 53 | Out.int(s[a] + (s[c] * (s[e] - (p^ + s[s[2]] * (s[7] - s[6]))))); Out.ln; |
| 53 | 54 | (* a system call under values *) |
| 54 | - Out.int(a + (c * n(SYSCALL(39) > 0) + d)); Out.ln; | |
| 55 | + Out.int(a + (c * n(SYSTEM.SYSCALL(39) > 0) + d)); Out.ln; | |
| 55 | 56 | end; |
| 56 | 57 | |
| 57 | 58 | end Deep. |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | module Edge; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | type |
| 5 | - Inner = record vals: [4]I64; name: []U8; end; | |
| 6 | + Inner = record vals: [4]I64; name: []const U8; end; | |
| 6 | 7 | Outer = record items: [3]Inner; n: I64; end; |
| 7 | 8 | |
| 8 | 9 | var g: Outer; calls: I64; |
| @@ -55,7 +56,7 @@ | ||
| 55 | 56 | o.items[0].vals[0] := -1; |
| 56 | 57 | Out.int(g.items[0].vals[0]); Out.str(" "); Out.int(o.items[0].vals[0]); Out.ln; |
| 57 | 58 | Out.int(sumInner(g.items)); Out.str(" "); Out.int(sumInner(g.items[1..3])); Out.ln; |
| 58 | - pa := ADR(a); | |
| 59 | + pa := SYSTEM.ADR(a); | |
| 59 | 60 | pa^[4] := 44; |
| 60 | 61 | Out.int(a[4]); Out.str(" "); Out.int(LEN(pa^)); Out.ln; |
| 61 | 62 | i := 2; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | C variables, raz procedures as C's callbacks. *) |
| 3 | 3 | module Extern; |
| 4 | 4 | import Out, C; |
| 5 | +import SYSTEM; | |
| 5 | 6 | link "libm.so.6"; |
| 6 | 7 | |
| 7 | 8 | extern proc strlen(s: ^U8): U64; |
| @@ -36,13 +37,13 @@ | ||
| 36 | 37 | Out.int(I64(sqrt(2.0) * 1000.0)); Out.ln; |
| 37 | 38 | |
| 38 | 39 | a := [5, -3, 9, 0, 12, 1]; |
| 39 | - qsort(^U8(ADR(a)), 6, 8, cmp); | |
| 40 | + qsort(^U8(SYSTEM.ADR(a)), 6, 8, cmp); | |
| 40 | 41 | for i := 0 to 5 do Out.int(a[i]); Out.char(' '); end; |
| 41 | 42 | Out.ln; |
| 42 | 43 | if calls > 0 then Out.str("cmp called\n"); end; |
| 43 | 44 | |
| 44 | 45 | (* nine arguments after the format: some go on the stack *) |
| 45 | - n := snprintf(ADR(buf[0]), 64, "%d %d %d %d %d %d %d %s|%.3f %g", | |
| 46 | + n := snprintf(SYSTEM.ADR(buf[0]), 64, "%d %d %d %d %d %d %d %s|%.3f %g", | |
| 46 | 47 | 1, 2, 3, 4, 5, 6, 7, "eight", 3.14159, 0.5); |
| 47 | 48 | Out.str(buf[0..I64(n)]); Out.ln; |
| 48 | 49 |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | when a block is freed twice. *) |
| 3 | 3 | module HeapCheck; |
| 4 | 4 | import Out, Heap, Mem; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc show(p: ^U8); |
| 7 | 8 | begin |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | (* in debug mode, a write one byte past a block's end is found when the |
| 3 | 3 | block is freed, and stops the program *) |
| 4 | 4 | import Heap, Mem; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var p: ^U8; |
| @@ -4,4 +4,4 @@ | ||
| 4 | 4 | in Heap.freeDebug at lib/Heap.raz:221:31: h = 0x?, out = nil, p = nil, i = 0, size = 0, b = nil |
| 5 | 5 | in Heap.free at lib/Heap.raz:253:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0 |
| 6 | 6 | in Mem.free at lib/Mem.raz:40:5: a = 0x?, p = 0x? |
| 7 | - in HeapDebugEnd.main at test/run/HeapDebugEnd.raz:12:5: p = 0x? | |
| 7 | + in HeapDebugEnd.main at test/run/HeapDebugEnd.raz:13:5: p = 0x? |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | (* in debug mode, a write to a freed block is found when the block |
| 3 | 3 | leaves the quarantine, 1,024 frees later, and stops the program *) |
| 4 | 4 | import Heap, Mem; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var p, q: ^U8; i: INT; |
| @@ -4,4 +4,4 @@ | ||
| 4 | 4 | in Heap.freeDebug at lib/Heap.raz:235:36: h = 0x?, out = 0x?, p = 0x?, i = 0, size = 20, b = nil |
| 5 | 5 | in Heap.free at lib/Heap.raz:253:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0 |
| 6 | 6 | in Mem.free at lib/Mem.raz:40:5: a = 0x?, p = 0x? |
| 7 | - in HeapDebugFree.main at test/run/HeapDebugFree.raz:15:9: p = 0x?, q = 0x?, i = 1023 | |
| 7 | + in HeapDebugFree.main at test/run/HeapDebugFree.raz:16:9: p = 0x?, q = 0x?, i = 1023 |
| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | (* Freeing what the heap never gave out stops the program. *) |
| 2 | 2 | module HeapStray; |
| 3 | 3 | import Out, Heap, Mem; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | var a: [4]I64; |
| 6 | 7 | |
| 7 | 8 | proc main*; |
| 8 | 9 | begin |
| 9 | 10 | Out.str("freeing a stray pointer\n"); |
| 10 | - Mem.free(Heap.heap, ^U8(ADR(a[2]))); | |
| 11 | + Mem.free(Heap.heap, ^U8(SYSTEM.ADR(a[2]))); | |
| 11 | 12 | Out.str("not reached\n"); |
| 12 | 13 | end; |
| 13 | 14 |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | procedure that keeps it. *) |
| 3 | 3 | module KeptNil; |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | type Rec = record x: INT; end; |
| 7 | 8 | |
| @@ -16,7 +17,7 @@ | ||
| 16 | 17 | begin |
| 17 | 18 | r.x := 1; |
| 18 | 19 | f := get; |
| 19 | - Out.int(f(ADR(r), 2)); Out.ln; | |
| 20 | + Out.int(f(SYSTEM.ADR(r), 2)); Out.ln; | |
| 20 | 21 | Out.int(f(nil, 5)); Out.ln; |
| 21 | 22 | end; |
| 22 | 23 |
| @@ -1,3 +1,3 @@ | ||
| 1 | -test/run/KeptNil.raz:10:5: stopped by a nil pointer | |
| 2 | - in KeptNil.get at test/run/KeptNil.raz:10:5: p = nil, k = 5 | |
| 3 | - in KeptNil.main at test/run/KeptNil.raz:20:5: f = 0x? | |
| 1 | +test/run/KeptNil.raz:11:5: stopped by a nil pointer | |
| 2 | + in KeptNil.get at test/run/KeptNil.raz:11:5: p = nil, k = 5 | |
| 3 | + in KeptNil.main at test/run/KeptNil.raz:21:5: f = 0x? |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | counts its blocks; the map empty after, and used again. *) |
| 3 | 3 | module MapDone; |
| 4 | 4 | import Fmt, Heap, Mem, Str, Names := Map([]const U8, INT, Str.hash, Str.eq); |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | var counting: Mem.Allocator; live: INT; |
| 7 | 8 | |
| @@ -18,11 +19,11 @@ | ||
| 18 | 19 | end; |
| 19 | 20 | |
| 20 | 21 | proc main*; |
| 21 | -var m: Names.Map; i, v: INT; found, _ok: BOOL; keys: [3][]U8; | |
| 22 | +var m: Names.Map; i, v: INT; found, _ok: BOOL; keys: [3][]const U8; | |
| 22 | 23 | begin |
| 23 | 24 | counting := {alloc: alloc, free: free}; |
| 24 | 25 | keys := ["node_modules", "target", "build"]; |
| 25 | - Names.init(m, ADR(counting)); | |
| 26 | + Names.init(m, SYSTEM.ADR(counting)); | |
| 26 | 27 | Names.done(m); (* nothing taken yet *) |
| 27 | 28 | for i := 0 to 99 do _ok := Names.put(m, keys[i mod 3], i); end; |
| 28 | 29 | Fmt.print("{} entries, {} block\n", [Fmt.int(m.len), Fmt.int(live)]); |
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | registers in a loop gives its pointer's register. *) |
| 5 | 5 | module PtrPlaces; |
| 6 | 6 | import Out; |
| 7 | +import SYSTEM; | |
| 7 | 8 | |
| 8 | 9 | proc main*; |
| 9 | 10 | var a: [4]U8; s, e: []U8; p: ^U8; i, n: INT; |
| @@ -11,11 +12,11 @@ | ||
| 11 | 12 | a := [1, 2, 3, 4]; |
| 12 | 13 | s := a[0..4]; |
| 13 | 14 | e := s[2..2]; |
| 14 | - if PTR(e) = PTR(s) + 2 then Out.str("cut empty: at its place\n"); end; | |
| 15 | - p := PTR(""); | |
| 15 | + if SYSTEM.PTR(e) = SYSTEM.PTR(s) + 2 then Out.str("cut empty: at its place\n"); end; | |
| 16 | + p := SYSTEM.PTR(""); | |
| 16 | 17 | if p # nil then Out.str("\"\": not nil\n"); end; |
| 17 | 18 | n := 0; |
| 18 | - for i := 0 to 3 do s := a[i..4]; n := n + INT(PTR(s) - PTR(a)); end; | |
| 19 | + for i := 0 to 3 do s := a[i..4]; n := n + INT(SYSTEM.PTR(s) - SYSTEM.PTR(a)); end; | |
| 19 | 20 | Out.int(n); Out.str("\n"); |
| 20 | 21 | end; |
| 21 | 22 |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | module Results; |
| 2 | 2 | import Out; |
| 3 | +import SYSTEM; | |
| 3 | 4 | |
| 4 | 5 | const |
| 5 | 6 | NotFound*: ERROR = "not found"; |
| @@ -24,7 +25,7 @@ | ||
| 24 | 25 | return -1, NotFound; |
| 25 | 26 | end; |
| 26 | 27 | |
| 27 | -proc mixed(x: F64): (F64, []U8, Pair, BOOL); | |
| 28 | +proc mixed(x: F64): (F64, []const U8, Pair, BOOL); | |
| 28 | 29 | var p: Pair; |
| 29 | 30 | begin |
| 30 | 31 | p.a := 1; p.b := 2; |
| @@ -48,7 +49,7 @@ | ||
| 48 | 49 | end; |
| 49 | 50 | |
| 50 | 51 | proc main*; |
| 51 | -var q, r, i: I64; e: ERROR; x: F64; s: []U8; p: Pair; ok: BOOL; a: [3]I64; u: U8; | |
| 52 | +var q, r, i: I64; e: ERROR; x: F64; s: []const U8; p: Pair; ok: BOOL; a: [3]I64; u: U8; | |
| 52 | 53 | begin |
| 53 | 54 | q, r := divmod(17, 5); |
| 54 | 55 | Out.int(q); Out.str(" "); Out.int(r); Out.ln; |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | Shape* = variant |
| 6 | 6 | circle(r: F64); |
| 7 | 7 | rect(w, h: F64); |
| 8 | - label(text: []U8; size: I64); | |
| 8 | + label(text: []const U8; size: I64); | |
| 9 | 9 | dot; |
| 10 | 10 | end; |
| 11 | 11 |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | (* Code procedures with SSE2 and the bit scans: a search sixteen bytes |
| 3 | 3 | at a time, and the counts of bits *) |
| 4 | 4 | import Out; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | (* the first place of b in s, or -1: its address in rdi, its length in rsi, b in dl *) |
| 7 | 8 | proc index(s: []U8; b: U8): INT; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | that take either type, calls to C and to code. *) |
| 3 | 3 | module Single; |
| 4 | 4 | import Out, C; |
| 5 | +import SYSTEM; | |
| 5 | 6 | link "libm.so.6"; |
| 6 | 7 | |
| 7 | 8 | const |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | every thread at once, and join. *) |
| 3 | 3 | module Spawn; |
| 4 | 4 | import Out, Thread, Heap, Mem; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | const |
| 7 | 8 | Workers = 8; |
| @@ -21,7 +22,7 @@ | ||
| 21 | 22 | Thread.lock(m); |
| 22 | 23 | INC(count); |
| 23 | 24 | Thread.unlock(m); |
| 24 | - _ := XADD(ADR(atomic), 1); | |
| 25 | + _ := XADD(atomic, 1); | |
| 25 | 26 | NEW(p, Heap.heap); |
| 26 | 27 | p^.next := list; |
| 27 | 28 | list := p; |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | every thread at once, and join. *) |
| 4 | 4 | module SpawnC; |
| 5 | 5 | import Out, Thread, Heap, Mem, C; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | const |
| 8 | 9 | Workers = 8; |
| @@ -22,7 +23,7 @@ | ||
| 22 | 23 | Thread.lock(m); |
| 23 | 24 | INC(count); |
| 24 | 25 | Thread.unlock(m); |
| 25 | - _ := XADD(ADR(atomic), 1); | |
| 26 | + _ := XADD(atomic, 1); | |
| 26 | 27 | NEW(p, Heap.heap); |
| 27 | 28 | p^.next := list; |
| 28 | 29 | list := p; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | its job at once after spawn, and the threads' copies are not changed. *) |
| 3 | 3 | module TaskTest; |
| 4 | 4 | import Check, Jobs := Task(Job), Rt, Thread; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | const Threads = 8; |
| 7 | 8 | |
| @@ -21,11 +22,11 @@ | ||
| 21 | 22 | var t: [Threads]^Thread.Thread; j: Job; i: INT; err: ERROR; |
| 22 | 23 | begin |
| 23 | 24 | for i := 0 to Threads - 1 do |
| 24 | - j := {n: i + 1, out: ADR(results[i])}; | |
| 25 | + j := {n: i + 1, out: SYSTEM.ADR(results[i])}; | |
| 25 | 26 | t[i], err := Jobs.spawn(work, j); |
| 26 | 27 | if err # nil then Rt.stop("Task.spawn failed"); end; |
| 27 | 28 | j.n := 1000; (* the thread must not see this *) |
| 28 | - j.out := ADR(results[0]); | |
| 29 | + j.out := SYSTEM.ADR(results[0]); | |
| 29 | 30 | end; |
| 30 | 31 | for i := 0 to Threads - 1 do Thread.join(t[i]); end; |
| 31 | 32 | for i := 0 to Threads - 1 do |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | handled: the read fails with -4. A thread that has ended, not yet |
| 4 | 4 | joined, is -3. ThreadSignalC is the same, over C. *) |
| 5 | 5 | import Thread, Sys, Fmt; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | var |
| 8 | 9 | r, got, done: INT; |
| @@ -11,7 +12,7 @@ | ||
| 11 | 12 | var buf: [16]U8; |
| 12 | 13 | begin |
| 13 | 14 | got := Sys.read(r, buf); |
| 14 | - _ := XCHG(ADR(done), 1); | |
| 15 | + _ := XCHG(done, 1); | |
| 15 | 16 | end; |
| 16 | 17 | |
| 17 | 18 | proc quick(_arg: ^U8); |
| @@ -26,7 +27,7 @@ | ||
| 26 | 27 | t, e := Thread.spawn(reader, nil); |
| 27 | 28 | if e # nil then Fmt.print("no thread\n", []); return; end; |
| 28 | 29 | (* again until it lands: the first may come before the read begins *) |
| 29 | - while (XADD(ADR(done), 0) = 0) and (tries < 1000) do | |
| 30 | + while (XADD(done, 0) = 0) and (tries < 1000) do | |
| 30 | 31 | k := Thread.signal(t, Sys.sigUsr1); |
| 31 | 32 | if k # 0 then Fmt.print("signal: {}\n", [Fmt.int(k)]); end; |
| 32 | 33 | Sys.sleep(5); |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | handled: the read fails with -4. A thread that has ended, not yet |
| 4 | 4 | joined, is -3. ThreadSignal is the same, without C. *) |
| 5 | 5 | import Thread, Sys, Fmt, C; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | var |
| 8 | 9 | r, got, done: INT; |
| @@ -11,7 +12,7 @@ | ||
| 11 | 12 | var buf: [16]U8; |
| 12 | 13 | begin |
| 13 | 14 | got := Sys.read(r, buf); |
| 14 | - _ := XCHG(ADR(done), 1); | |
| 15 | + _ := XCHG(done, 1); | |
| 15 | 16 | end; |
| 16 | 17 | |
| 17 | 18 | proc quick(_arg: ^U8); |
| @@ -27,7 +28,7 @@ | ||
| 27 | 28 | t, e := Thread.spawn(reader, nil); |
| 28 | 29 | if e # nil then Fmt.print("no thread\n", []); return; end; |
| 29 | 30 | (* again until it lands: the first may come before the read begins *) |
| 30 | - while (XADD(ADR(done), 0) = 0) and (tries < 1000) do | |
| 31 | + while (XADD(done, 0) = 0) and (tries < 1000) do | |
| 31 | 32 | k := Thread.signal(t, Sys.sigUsr1); |
| 32 | 33 | if k # 0 then Fmt.print("signal: {}\n", [Fmt.int(k)]); end; |
| 33 | 34 | Sys.sleep(5); |
| @@ -2,12 +2,13 @@ | ||
| 2 | 2 | (* a Vec whose allocator runs out stops the program, with the calls |
| 3 | 3 | under way, rather than dropping what it was given *) |
| 4 | 4 | import Arena, Rt, Ints := Vec(INT); |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var ar: Arena.Arena; v: Ints.Vec; i: INT; |
| 8 | 9 | begin |
| 9 | 10 | if not Arena.init(ar, 4096) then Rt.stop("no arena"); end; |
| 10 | - Ints.init(v, ADR(ar.base)); | |
| 11 | + Ints.init(v, SYSTEM.ADR(ar.base)); | |
| 11 | 12 | for i := 1 to 10000 do Ints.push(v, i); end; |
| 12 | 13 | end; |
| 13 | 14 |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | Vec: out of memory |
| 2 | 2 | in Vec(INT).need at lib/Vec.raz:57:9: n = 1 |
| 3 | 3 | in Vec(INT).push at lib/Vec.raz:65:5: x = 257 |
| 4 | - in VecFull.main at test/run/VecFull.raz:11:28: i = 257 | |
| 4 | + in VecFull.main at test/run/VecFull.raz:12:28: i = 257 |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module VecTest; |
| 4 | 4 | import Fmt, Heap, Ints := Vec(INT), Pts := Vec(Point); |
| 5 | 5 | |
| 6 | -type Point = record x, y: INT; name: []U8; end; | |
| 6 | +type Point = record x, y: INT; name: []const U8; end; | |
| 7 | 7 | |
| 8 | 8 | proc main*; |
| 9 | 9 | var v: Ints.Vec; w: Pts.Vec; i, sum, top: INT; ok: BOOL; p: ^Point; s: []INT; |
| @@ -2,12 +2,13 @@ | ||
| 2 | 2 | array as it was, and the program going on. *) |
| 3 | 3 | module VecTry; |
| 4 | 4 | import Arena, Fmt, Rt, Ints := Vec(INT); |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | proc main*; |
| 7 | 8 | var ar: Arena.Arena; v: Ints.Vec; n: INT; p: ^INT; ok: BOOL; |
| 8 | 9 | begin |
| 9 | 10 | if not Arena.init(ar, 4096) then Rt.stop("no arena"); end; |
| 10 | - Ints.init(v, ADR(ar.base)); | |
| 11 | + Ints.init(v, SYSTEM.ADR(ar.base)); | |
| 11 | 12 | n := 0; |
| 12 | 13 | while Ints.tryPush(v, n) do INC(n); end; |
| 13 | 14 | p, ok := Ints.tryAdd(v); |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | parameter of 1, 2, 4 or 8 bytes is read and written as the operand |
| 3 | 3 | [pointer + index * size], where the index comes with no check. *) |
| 4 | 4 | module IndexParamOff; |
| 5 | +import SYSTEM; | |
| 5 | 6 | check off; |
| 6 | 7 | |
| 7 | 8 | const N = 8; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | module Unchecked; |
| 2 | +import SYSTEM; | |
| 2 | 3 | (* A module without index and slice checks *) |
| 3 | 4 | check off; |
| 4 | 5 | |
| @@ -9,7 +10,7 @@ | ||
| 9 | 10 | return p^.a[i]; |
| 10 | 11 | end; |
| 11 | 12 | |
| 12 | -proc width*(s: []U8; lo, hi: INT): INT; | |
| 13 | +proc width*(s: []const U8; lo, hi: INT): INT; | |
| 13 | 14 | begin |
| 14 | 15 | return LEN(s[lo..hi]); |
| 15 | 16 | end; |