Step 5: the system integer INT and UINT (8 bytes here) give LEN of a slice, p - q, ARGC, SYSCALL and pointer conversions, which now take only INT/UINT (or an untyped const). INT widens to I64, UINT to U64, in assignment, args and returns; not in exprs, for, INC/DEC, a, b := f() or return f(x). main and Rt.exit take INT; NEW passes INT sizes; an int const past an extern's params goes as INT. Also from report 2026-10.11: another module's exported var is read-only (no :=, var arg, INC, NEW, ADR, array slice; match on a copy); check off; drops a module's index/slice checks; shifts count mod the operand's width; the lowest of I8/I16/I32 div or mod -1 now faults as I64's did; CAS/XCHG/XADD take INT, UINT, ptrs only. Lib, examples, tools and tests to sec. 11: INT for lengths, counts, fds, pids, statuses; I32 for a char (Str.encode/decode); I64 kept for file size/pos, mtime, clock/now, Str.toInt, Opt.number, Out.int, Fmt.int; size_t as UINT in C. conform/run/Generic's Stack exports a pointer, as the new rule asks. Report 7.7's Head example: its vars are INTs, as Sys now gives. New tests for the above; vim/emacs know INT.
| @@ -139,7 +139,7 @@ | ||
| 139 | 139 | program the entry point stores C's `exit` in `Rt.cExit`, found by |
| 140 | 140 | name like `Rt.exit`, before any module body runs. |
| 141 | 141 | - Past an extern's parameters, a string goes as a C string and an |
| 142 | - integer constant as an `INT` (an `I64` until 2026-10.11 is built). | |
| 142 | + integer constant as an `INT`. | |
| 143 | 143 | - A real constant is held as an F64; one typed `F32` holds a value an |
| 144 | 144 | F32 can hold. An `F32` in a register is its low 32 bits; the upper |
| 145 | 145 | ones are left as they fall. |
| @@ -153,7 +153,16 @@ | ||
| 153 | 153 | threads have none, so a stack overflow in one ends the program by |
| 154 | 154 | the signal with no message. |
| 155 | 155 | - The smallest value of a signed type divided by -1 stops the program |
| 156 | - (SIGFPE), as 6.1 says; until 2026-10.11 is built, only `I64`'s does. | |
| 156 | + (SIGFPE), as 6.1 says, `mod` as `div`; for a type narrower than 64 | |
| 157 | + bits the code makes the division fault, as the machine wouldn't. In | |
| 158 | + a constant it is an error, as dividing by zero is. | |
| 159 | +- `INT` widens to `I64` (and `UINT` to `U64`) wherever a value is | |
| 160 | + assigned, passed or returned, `return a, b` included; not in `a, b := | |
| 161 | + f(x)`, `return f(x)`, a `for` or `INC`/`DEC`. An untyped constant | |
| 162 | + converts to a pointer, as an `INT`. | |
| 163 | +- Another module's exported variable, or a field or array element of | |
| 164 | + it, is read-only: an `extern` one too. A slice in it may be sliced, | |
| 165 | + since that can't change the variable; an array in it may not. | |
| 157 | 166 | - Warnings come only for a module with no errors. A procedure naming |
| 158 | 167 | itself doesn't use it; a type named by a pointer in its own |
| 159 | 168 | declaration does. An enumeration's names are never warned of, nor a |
| @@ -119,7 +119,7 @@ | ||
| 119 | 119 | the IR written down; `doc/ir.md` is removed, and git keeps it. |
| 120 | 120 | - [x] 4. The tests split: a conformance suite any implementation |
| 121 | 121 | passes, apart from this compiler's own messages. |
| 122 | -- [ ] 5. The system integer. | |
| 122 | +- [x] 5. The system integer. | |
| 123 | 123 | - [ ] 6. Optional reals: a target says whether it has them. |
| 124 | 124 | - [ ] 6a. `+` joins string constants (report, section 4). |
| 125 | 125 | - [ ] 6b. Array constants: `const P: [5]I64 = [...]`, in read-only |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module AtomicI64; | |
| 2 | +proc main*; | |
| 3 | +var n: I64; _ok: BOOL; | |
| 4 | +begin | |
| 5 | + _ok := CAS(ADR(n), 0, 1); | |
| 6 | +end; | |
| 7 | +end AtomicI64. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module ExportAdr; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +var _p: ^INT; | |
| 5 | +begin | |
| 6 | + _p := ADR(Owner.n); | |
| 7 | +end; | |
| 8 | +end ExportAdr. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module ExportAsSlice; | |
| 2 | +import Owner; | |
| 3 | +proc sum(_s: []INT): INT; begin return 0; end; | |
| 4 | +proc main*; | |
| 5 | +begin | |
| 6 | + sum(Owner.a); | |
| 7 | +end; | |
| 8 | +end ExportAsSlice. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module ExportAssign; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + Owner.n := 1; | |
| 6 | +end; | |
| 7 | +end ExportAssign. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module ExportElem; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + Owner.a[2] := 1; | |
| 6 | +end; | |
| 7 | +end ExportElem. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module ExportInc; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +begin | |
| 5 | + INC(Owner.n); | |
| 6 | +end; | |
| 7 | +end ExportInc. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module ExportSlice; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +var _s: []INT; | |
| 5 | +begin | |
| 6 | + _s := Owner.a[0..2]; | |
| 7 | +end; | |
| 8 | +end ExportSlice. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module ExportVarParam; | |
| 2 | +import Owner; | |
| 3 | +proc put(var x: INT); begin x := 1; end; | |
| 4 | +proc main*; | |
| 5 | +begin | |
| 6 | + put(Owner.n); | |
| 7 | +end; | |
| 8 | +end ExportVarParam. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntFor; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; s: []U8; | |
| 4 | +begin | |
| 5 | + for i := 0 to LEN(s) - 1 do end; | |
| 6 | +end; | |
| 7 | +end IntFor. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntFromPointer; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; p: ^U8; | |
| 4 | +begin | |
| 5 | + i := I64(p); | |
| 6 | +end; | |
| 7 | +end IntFromPointer. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntInc; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; s: []U8; | |
| 4 | +begin | |
| 5 | + INC(i, LEN(s)); | |
| 6 | +end; | |
| 7 | +end IntInc. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntMix; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; s: []U8; | |
| 4 | +begin | |
| 5 | + if i < LEN(s) then end; | |
| 6 | +end; | |
| 7 | +end IntMix. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntNarrow; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; n: INT; | |
| 4 | +begin | |
| 5 | + n := i; | |
| 6 | +end; | |
| 7 | +end IntNarrow. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module IntPointer; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; p: ^U8; | |
| 4 | +begin | |
| 5 | + p := ^U8(i); | |
| 6 | +end; | |
| 7 | +end IntPointer. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module IntResults; | |
| 2 | +proc two: (INT, INT); begin return 1, 2; end; | |
| 3 | +proc main*; | |
| 4 | +var a, b: I64; | |
| 5 | +begin | |
| 6 | + a, b := two(); | |
| 7 | +end; | |
| 8 | +end IntResults. |
| @@ -0,0 +1,3 @@ | ||
| 1 | +module Owner; | |
| 2 | +var n*: INT; a*: [4]INT; | |
| 3 | +end Owner. |
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | module Args; |
| 2 | 2 | import Out; |
| 3 | 3 | |
| 4 | -proc main*: I64; | |
| 5 | -var i, n: I64; a: ^^U8; s: ^U8; | |
| 4 | +proc main*: INT; | |
| 5 | +var i, n: INT; a: ^^U8; s: ^U8; | |
| 6 | 6 | begin |
| 7 | 7 | a := ARGV(); |
| 8 | 8 | for i := 1 to ARGC() - 1 do |
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | begin |
| 24 | 24 | end; |
| 25 | 25 | |
| 26 | -proc main*: I64; | |
| 26 | +proc main*: INT; | |
| 27 | 27 | var i, full: I64; |
| 28 | 28 | begin |
| 29 | 29 | Rt.atExit(first); |
| @@ -6,12 +6,12 @@ | ||
| 6 | 6 | proc main*; |
| 7 | 7 | var l: Strs.List; v: I64; s: []U8; ok: BOOL; b: Buf.Buf; n: ^Ints.Node; |
| 8 | 8 | begin |
| 9 | - ok := Ints.push(ADR(Stack.s), 7); | |
| 10 | - ok := More.push(ADR(Stack.s), 8); | |
| 11 | - Fmt.print("{} {} {}\n", [Fmt.int(Stack.top()), Fmt.int(Stack.s.len), Fmt.bool(ok)]); | |
| 12 | - n := Stack.s.head; | |
| 13 | - v, ok := Ints.pop(ADR(Stack.s)); | |
| 14 | - Fmt.print("{} {}\n", [Fmt.int(v), Fmt.int(Stack.s.len)]); | |
| 9 | + ok := Ints.push(Stack.p, 7); | |
| 10 | + ok := More.push(Stack.p, 8); | |
| 11 | + Fmt.print("{} {} {}\n", [Fmt.int(Stack.top()), Fmt.int(Stack.p^.len), Fmt.bool(ok)]); | |
| 12 | + n := Stack.p^.head; | |
| 13 | + v, ok := Ints.pop(Stack.p); | |
| 14 | + Fmt.print("{} {}\n", [Fmt.int(v), Fmt.int(Stack.p^.len)]); | |
| 15 | 15 | Strs.init(ADR(l), Heap.heap); |
| 16 | 16 | ok := Strs.push(ADR(l), "b"); |
| 17 | 17 | ok := Strs.push(ADR(l), "a"); |
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | show(Mem.alloc(Heap.heap, 10, 8192)); |
| 20 | 20 | p := Mem.alloc(Heap.heap, 10, 64); |
| 21 | 21 | show(p); |
| 22 | - if I64(p) mod 64 = 0 then Out.str("aligned\n"); end; | |
| 22 | + if INT(p) mod 64 = 0 then Out.str("aligned\n"); end; | |
| 23 | 23 | Mem.free(Heap.heap, p); |
| 24 | 24 | q := Mem.alloc(Heap.heap, 100000, 8); |
| 25 | 25 | show(q); |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | |
| 19 | 19 | proc main*; |
| 20 | 20 | var |
| 21 | - m: Ints.Map; want: [N]I64; i, k, v, n, sum, seed: I64; | |
| 21 | + m: Ints.Map; want: [N]I64; i: INT; k, v, n, sum, seed: I64; | |
| 22 | 22 | found, _ok: BOOL; |
| 23 | 23 | begin |
| 24 | 24 | Ints.init(ADR(m), Heap.heap); |
| @@ -88,7 +88,7 @@ | ||
| 88 | 88 | return a + b; |
| 89 | 89 | end; |
| 90 | 90 | |
| 91 | -proc main*: I64; | |
| 91 | +proc main*: INT; | |
| 92 | 92 | var a, b: I64; p, q: Pair; f: Op; bg: Big; |
| 93 | 93 | begin |
| 94 | 94 | if even(10) and odd(7) and not even(3) then Out.str("parity ok"); Out.ln; end; |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | var buf: [8]U8; |
| 7 | 7 | |
| 8 | 8 | proc count(xs: []I64): I64; |
| 9 | -var i, s: I64; | |
| 9 | +var i: INT; s: I64; | |
| 10 | 10 | begin |
| 11 | 11 | s := 0; |
| 12 | 12 | for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end; |
| @@ -0,0 +1,5 @@ | ||
| 1 | +5 8 3 7 | |
| 2 | +7 28 1 | |
| 3 | +6 -32 6 2 | |
| 4 | +70 | |
| 5 | +6 5 2 11 120 |
| @@ -0,0 +1,74 @@ | ||
| 1 | +module SystemInt; | |
| 2 | +(* INT and UINT: what gives them, where they widen, shifts modulo the | |
| 3 | + width, and another module's variables read but not changed *) | |
| 4 | +import Out, Shared; | |
| 5 | + | |
| 6 | +var cells: [10]I32; | |
| 7 | + | |
| 8 | +proc wide(x: I64): I64; | |
| 9 | +begin | |
| 10 | + return x + 1; | |
| 11 | +end; | |
| 12 | + | |
| 13 | +(* an INT returned as an I64 *) | |
| 14 | +proc len(s: []U8): I64; | |
| 15 | +begin | |
| 16 | + return LEN(s); | |
| 17 | +end; | |
| 18 | + | |
| 19 | +proc main*; | |
| 20 | +var | |
| 21 | + n: INT; i: I64; u: UINT; w: U64; b: U8; h: I32; k: INT; | |
| 22 | + p, q: ^I32; copy: [3]INT; | |
| 23 | +begin | |
| 24 | + n := LEN("four"); (* untyped, so it fits any integer *) | |
| 25 | + b := SIZE(I64); | |
| 26 | + i := n; (* INT into I64 *) | |
| 27 | + i := wide(n); | |
| 28 | + u := 7; | |
| 29 | + w := u; (* UINT into U64 *) | |
| 30 | + Out.int(i); Out.str(" "); Out.int(I64(b)); Out.str(" "); Out.int(len("abc")); | |
| 31 | + Out.str(" "); Out.int(I64(w)); Out.ln; | |
| 32 | + | |
| 33 | + p := ADR(cells[2]); | |
| 34 | + q := ADR(cells[9]); | |
| 35 | + n := q - p; (* an INT *) | |
| 36 | + u := UINT(q) - UINT(p); | |
| 37 | + Out.int(n); Out.str(" "); Out.int(I64(u)); Out.str(" "); | |
| 38 | + Out.int(INT(^I32(INT(p) + 4) - p)); Out.ln; | |
| 39 | + | |
| 40 | + (* a shift counts modulo the width of its operand's type *) | |
| 41 | + b := 3; | |
| 42 | + k := 9; | |
| 43 | + Out.int(I64(b shl k)); Out.str(" "); | |
| 44 | + h := -64; | |
| 45 | + k := 33; | |
| 46 | + Out.int(I64(h shr k)); Out.str(" "); | |
| 47 | + Out.int(I64(U8(3) shl 9)); Out.str(" "); | |
| 48 | + n := 1; | |
| 49 | + k := 65; | |
| 50 | + Out.int(n shl k); Out.ln; | |
| 51 | + | |
| 52 | + (* an index of any integer type, by its value *) | |
| 53 | + cells[U8(3)] := 30; | |
| 54 | + cells[I8(4)] := 40; | |
| 55 | + Out.int(I64(cells[UINT(3)] + cells[U64(4)])); Out.ln; | |
| 56 | + | |
| 57 | + Shared.bump; | |
| 58 | + Shared.bump; | |
| 59 | + copy := Shared.words; | |
| 60 | + copy[0] := 9; (* the importer's own copy *) | |
| 61 | + Shared.bytes[0] := 'x'; (* what the slice points at *) | |
| 62 | + match Shared.shape of | |
| 63 | + | circle(r): r := r + 1; Out.int(r); Out.str(" "); | |
| 64 | + | dot: | |
| 65 | + end; | |
| 66 | + match Shared.shape of | |
| 67 | + | circle(r): Out.int(r); Out.str(" "); | |
| 68 | + | dot: | |
| 69 | + end; | |
| 70 | + Out.int(Shared.count); Out.str(" "); Out.int(copy[0] + copy[1]); Out.str(" "); | |
| 71 | + Out.int(I64(Shared.bytes[0])); Out.ln; | |
| 72 | +end; | |
| 73 | + | |
| 74 | +end SystemInt. |
| @@ -0,0 +1,22 @@ | ||
| 1 | +module Shared; | |
| 2 | +(* Exported variables, which only this module changes *) | |
| 3 | + | |
| 4 | +type Shape* = variant dot; circle(r: INT); end; | |
| 5 | + | |
| 6 | +var | |
| 7 | + count*: INT; | |
| 8 | + words*: [3]INT; | |
| 9 | + bytes*: []U8; | |
| 10 | + shape*: Shape; | |
| 11 | + store: [4]U8; | |
| 12 | + | |
| 13 | +proc bump*; | |
| 14 | +begin | |
| 15 | + INC(count); | |
| 16 | + words[1] := count; | |
| 17 | +end; | |
| 18 | + | |
| 19 | +begin | |
| 20 | + bytes := store; | |
| 21 | + shape := circle(5); | |
| 22 | +end Shared. |
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | module Stack; |
| 2 | 2 | import Ints := List(I64), Heap; |
| 3 | 3 | |
| 4 | -var s*: Ints.List; | |
| 4 | +var | |
| 5 | + s: Ints.List; | |
| 6 | + p*: ^Ints.List; (* s, which only this module could change by its name *) | |
| 5 | 7 | |
| 6 | 8 | proc top*(): I64; |
| 7 | 9 | begin |
| @@ -10,4 +12,5 @@ | ||
| 10 | 12 | |
| 11 | 13 | begin |
| 12 | 14 | Ints.init(ADR(s), Heap.heap); |
| 15 | + p := ADR(s); | |
| 13 | 16 | end Stack. |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | # Reading the raz compiler |
| 2 | 2 | |
| 3 | -The compiler is nine files of Free Pascal, under 6,000 lines of code. | |
| 3 | +The compiler is nine files of Free Pascal, under 6,500 lines of code. | |
| 4 | 4 | This guide walks through them in the order they are best read: from the |
| 5 | 5 | characters of a source file to the bytes of an executable. It assumes |
| 6 | 6 | you know the language from `doc/raz.md`, and enough x86-64 to read a |
| @@ -10,10 +10,10 @@ | ||
| 10 | 10 | |---|---|---|---| |
| 11 | 11 | | `src/diag.pas` | 274 | 198 | Messages: positions, source excerpts, colour, counts | |
| 12 | 12 | | `src/scan.pas` | 851 | 722 | Symbols, literals, comments, positions | |
| 13 | -| `src/sym.pas` | 593 | 494 | Types, objects, scopes, layout | | |
| 13 | +| `src/sym.pas` | 596 | 497 | Types, objects, scopes, layout | | |
| 14 | 14 | | `src/x64.pas` | 693 | 557 | Code buffer, chunks, fixups, places, instruction encoder | |
| 15 | -| `src/gen.pas` | 1,631 | 1,408 | Items: loading, storing, copying, frames, calls | | |
| 16 | -| `src/parse.pas` | 2,444 | 2,203 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 15 | +| `src/gen.pas` | 1,733 | 1,481 | Items: loading, storing, copying, frames, calls | | |
| 16 | +| `src/parse.pas` | 2,464 | 2,221 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 17 | 17 | | `src/link.pas` | 180 | 139 | Tree shaking, layout, patching, the places | |
| 18 | 18 | | `src/elf.pas` | 425 | 352 | Static and dynamic ELF, symbol table, line numbers | |
| 19 | 19 | | `src/raz.pas` | 227 | 179 | The command line, the entry points | |
| @@ -270,14 +270,21 @@ | ||
| 270 | 270 | on the right of `*`, `div` or `mod` becomes shifts (`DivPow2`), since |
| 271 | 271 | `idiv` is slow. Narrow integers are brought back to their width |
| 272 | 272 | after each operation (`Norm`), which is how `U8` arithmetic wraps. |
| 273 | +Since they are computed in 64 bits, a shift's count is cut to their | |
| 274 | +width first, and `DivTrap` makes the smallest value of one divided by | |
| 275 | +-1 fault as an `I64`'s does. | |
| 273 | 276 | `=` and `#` on arrays, slices and strings make a slice of each side |
| 274 | 277 | (`SeqSlice`), compare the lengths, and then the bytes with `repe |
| 275 | 278 | cmpsb`, right where the comparison stands: no call. |
| 276 | 279 | |
| 277 | 280 | Variables: `Deref`, `Field`, `Index` and `Slice` turn an item for a |
| 278 | -variable into an item for part of it, mostly by adding to `off`. | |
| 279 | -`Index` and `Slice` emit the bounds checks, and `Convert` the check of | |
| 280 | -an enumeration's position; `Check` jumps over a call to `Rt.fail` when | |
| 281 | +variable into an item for part of it, mostly by adding to `off`. An | |
| 282 | +item for another module's exported variable, or part of it, is `ro`: | |
| 283 | +it isn't a variable (`isVar`), and `NotReadOnly` says why where one is | |
| 284 | +wanted; what it points at is. | |
| 285 | +`Index` and `Slice` emit the bounds checks, unless the module says | |
| 286 | +`check off;` (`checks`, which `CompileFile` sets for each module), and | |
| 287 | +`Convert` the check of an enumeration's position; `Check` jumps over a call to `Rt.fail` when | |
| 281 | 288 | the check holds. The call passes what failed, the values involved and |
| 282 | 289 | its own address, by which `Rt` finds the place; that code has the |
| 283 | 290 | place of the offending expression (`LineCol` in `scan.pas`), and the |
| @@ -285,7 +292,9 @@ | ||
| 285 | 292 | |
| 286 | 293 | Assignment and conversion: `Coerce` makes a value fit the type it's |
| 287 | 294 | going to, or reports that it can't; it's where a string literal becomes |
| 288 | -a slice, an array a slice, an untyped constant a typed one. `Assign` | |
| 295 | +a slice, an array a slice, an untyped constant a typed one, and an | |
| 296 | +`INT` an `I64` (`Widens`). `CoerceExact` is for where the types must | |
| 297 | +be the same, as in a `for` loop, `INC` and several results. `Assign` | |
| 289 | 298 | stores, copying records and arrays with `rep movsb`. `Convert` is the |
| 290 | 299 | written conversion, `T(x)`. |
| 291 | 300 |
| @@ -931,7 +931,7 @@ | ||
| 931 | 931 | |
| 932 | 932 | (* Prints the first line of the file at path. *) |
| 933 | 933 | proc head(path: []U8): BOOL; |
| 934 | -var fd, n, i: I64; buf: [256]U8; | |
| 934 | +var fd, n, i: INT; buf: [256]U8; | |
| 935 | 935 | begin |
| 936 | 936 | fd := Sys.openRead(path); |
| 937 | 937 | if fd < 0 then return false; end; |
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | "variant" "VOLATILE" "while" "xor")) |
| 29 | 29 | |
| 30 | 30 | (defconst raz-types |
| 31 | - '("I8" "I16" "I32" "I64" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR")) | |
| 31 | + '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR")) | |
| 32 | 32 | |
| 33 | 33 | (defconst raz-builtins |
| 34 | 34 | '("SIZE" "ADR" "LEN" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD" |
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | syntax keyword razKeyword match mod module not of or packed proc record |
| 13 | 13 | syntax keyword razKeyword repeat return set shl shr then to type until var |
| 14 | 14 | syntax keyword razKeyword variant VOLATILE while xor |
| 15 | -syntax keyword razType I8 I16 I32 I64 U8 U16 U32 U64 BOOL F32 F64 ERROR | |
| 15 | +syntax keyword razType I8 I16 I32 I64 INT UINT U8 U16 U32 U64 BOOL F32 F64 ERROR | |
| 16 | 16 | syntax keyword razBuiltin SIZE ADR LEN NEW MSG SYSCALL FENCE CAS XCHG XADD |
| 17 | 17 | syntax keyword razBuiltin ARGC ARGV INC DEC |
| 18 | 18 | syntax keyword razConstant true false nil |
| @@ -3,16 +3,16 @@ | ||
| 3 | 3 | import Out; |
| 4 | 4 | |
| 5 | 5 | (* The length of a C string. *) |
| 6 | -proc len(s: ^U8): I64; | |
| 7 | -var n: I64; | |
| 6 | +proc len(s: ^U8): INT; | |
| 7 | +var n: INT; | |
| 8 | 8 | begin |
| 9 | 9 | n := 0; |
| 10 | 10 | while s[n] # 0 do n := n + 1; end; |
| 11 | 11 | return n; |
| 12 | 12 | end; |
| 13 | 13 | |
| 14 | -proc main*: I64; | |
| 15 | -var i: I64; s: ^U8; | |
| 14 | +proc main*: INT; | |
| 15 | +var i: INT; s: ^U8; | |
| 16 | 16 | begin |
| 17 | 17 | for i := 1 to ARGC() - 1 do |
| 18 | 18 | s := ARGV()[i]; |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | 0C3H; (* ret *) |
| 17 | 17 | |
| 18 | 18 | proc main*; |
| 19 | -var buf: [12]U8; i: I64; ok: BOOL; | |
| 19 | +var buf: [12]U8; i: INT; ok: BOOL; | |
| 20 | 20 | begin |
| 21 | 21 | vendor(ADR(buf[0])); |
| 22 | 22 | ok := true; |
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | Perms = set of Perm; |
| 10 | 10 | Mode = record user, group, other: Perms; end; |
| 11 | 11 | |
| 12 | -proc digit(p: Perms): I64; | |
| 12 | +proc digit(p: Perms): INT; | |
| 13 | 13 | begin |
| 14 | - return I64(U8(p)); | |
| 14 | + return INT(U8(p)); | |
| 15 | 15 | end; |
| 16 | 16 | |
| 17 | 17 | proc show(p: Perms); |
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | import Out, C; |
| 5 | 5 | |
| 6 | 6 | proc main*; |
| 7 | -var i: I64; | |
| 7 | +var i: INT; | |
| 8 | 8 | begin |
| 9 | 9 | for i := 1 to 3 do |
| 10 | 10 | Out.str("raz says "); Out.int(i); Out.ln; |
| @@ -8,13 +8,13 @@ | ||
| 8 | 8 | N = 1000000; |
| 9 | 9 | |
| 10 | 10 | type |
| 11 | - Part = record lo, hi, sum: I64; end; | |
| 12 | - Numbers = [N]I64; | |
| 11 | + Part = record lo, hi, sum: INT; end; | |
| 12 | + Numbers = [N]INT; | |
| 13 | 13 | |
| 14 | 14 | var numbers: ^Numbers; |
| 15 | 15 | |
| 16 | 16 | proc work(arg: ^U8): ^U8; |
| 17 | -var p: ^Part; i: I64; scratch: ^U8; | |
| 17 | +var p: ^Part; i: INT; scratch: ^U8; | |
| 18 | 18 | begin |
| 19 | 19 | p := ^Part(arg); |
| 20 | 20 | for i := p^.lo to p^.hi - 1 do |
| @@ -28,8 +28,8 @@ | ||
| 28 | 28 | return nil; |
| 29 | 29 | end; |
| 30 | 30 | |
| 31 | -proc main*: I64; | |
| 32 | -var t: [Workers]U64; parts: [Workers]Part; i, total: I64; | |
| 31 | +proc main*: INT; | |
| 32 | +var t: [Workers]UINT; parts: [Workers]Part; i, total: INT; | |
| 33 | 33 | begin |
| 34 | 34 | NEW(numbers, Heap.heap); |
| 35 | 35 | for i := 0 to N - 1 do numbers^[i] := i + 1; end; |
| @@ -21,13 +21,13 @@ | ||
| 21 | 21 | type |
| 22 | 22 | Command = record |
| 23 | 23 | args: [maxWords][]U8; |
| 24 | - n: I64; | |
| 24 | + n: INT; | |
| 25 | 25 | input, output, errors: []U8; (* the files of <, > or >>, and 2>; "" for none *) |
| 26 | 26 | append: BOOL; (* output is >> *) |
| 27 | 27 | end; |
| 28 | 28 | Pipeline = record |
| 29 | 29 | cmds: [maxCmds]Command; |
| 30 | - n: I64; | |
| 30 | + n: INT; | |
| 31 | 31 | background: BOOL; |
| 32 | 32 | end; |
| 33 | 33 | (* What the parser reads: a word, |, &, ; or a line's end, <, >, >>, 2>, |
| @@ -35,17 +35,17 @@ | ||
| 35 | 35 | Token = (word, pipe, amp, sep, from, into, onto, errTo, eof); |
| 36 | 36 | |
| 37 | 37 | var |
| 38 | - status: I64; (* of the last pipeline: $? *) | |
| 38 | + status: INT; (* of the last pipeline: $? *) | |
| 39 | 39 | interactive: BOOL; (* commands come from a terminal: job control *) |
| 40 | - group: I64; (* the shell's process group *) | |
| 40 | + group: INT; (* the shell's process group *) | |
| 41 | 41 | arena: Arena.Arena; (* the words of what is being run *) |
| 42 | 42 | s: []U8; (* the script being read *) |
| 43 | - at: I64; (* where in it *) | |
| 43 | + at: INT; (* where in it *) | |
| 44 | 44 | text: []U8; (* the last word read *) |
| 45 | 45 | |
| 46 | 46 | (* "Sh: " and a message on standard error. *) |
| 47 | 47 | proc say(f: []U8; args: []Fmt.Arg); |
| 48 | -var b: Buf.Buf; _n: I64; | |
| 48 | +var b: Buf.Buf; _n: INT; | |
| 49 | 49 | begin |
| 50 | 50 | Buf.init(ADR(b), Heap.heap); |
| 51 | 51 | Fmt.write(ADR(b), "Sh: ", []); |
| @@ -64,7 +64,7 @@ | ||
| 64 | 64 | (* $NAME or $? at s[at], its value added to b; a $ before anything else |
| 65 | 65 | is itself. *) |
| 66 | 66 | proc dollar(b: ^Buf.Buf); |
| 67 | -var start: I64; | |
| 67 | +var start: INT; | |
| 68 | 68 | begin |
| 69 | 69 | INC(at); |
| 70 | 70 | if (at < LEN(s)) and (s[at] = '?') then |
| @@ -172,7 +172,7 @@ | ||
| 172 | 172 | (* The program a command names: the name itself if it has a /, else the |
| 173 | 173 | first executable file of that name in a directory of $PATH. *) |
| 174 | 174 | proc find(name: []U8): ([]U8, BOOL); |
| 175 | -var path, dir: []U8; i, start, err: I64; b: Buf.Buf; info: Sys.Info; | |
| 175 | +var path, dir: []U8; i, start, err: INT; b: Buf.Buf; info: Sys.Info; | |
| 176 | 176 | begin |
| 177 | 177 | if Str.find(name, "/") >= 0 then return name, true; end; |
| 178 | 178 | path := Sys.env("PATH"); |
| @@ -191,8 +191,8 @@ | ||
| 191 | 191 | end; |
| 192 | 192 | |
| 193 | 193 | (* The fd of a redirection's file, or -1 after saying why not. *) |
| 194 | -proc redirect(path: []U8; how: Sys.Accesses): I64; | |
| 195 | -var fd: I64; | |
| 194 | +proc redirect(path: []U8; how: Sys.Accesses): INT; | |
| 195 | +var fd: INT; | |
| 196 | 196 | begin |
| 197 | 197 | fd := Sys.open(path, how); |
| 198 | 198 | if fd < 0 then say("{}: can't open it", [Fmt.str(path)]); return -1; end; |
| @@ -202,7 +202,7 @@ | ||
| 202 | 202 | (* cd, wait and exit, which change the shell itself, so it can't start |
| 203 | 203 | them as programs; true if c is one. *) |
| 204 | 204 | proc builtin(c: ^Command): BOOL; |
| 205 | -var dir: []U8; n, pid, _code: I64; ok: BOOL; _st: Sys.Status; | |
| 205 | +var dir: []U8; n: I64; pid, _code: INT; ok: BOOL; _st: Sys.Status; | |
| 206 | 206 | begin |
| 207 | 207 | if c^.args[0] = "cd" then |
| 208 | 208 | if c^.n > 1 then dir := c^.args[1]; else dir := Sys.env("HOME"); end; |
| @@ -217,7 +217,7 @@ | ||
| 217 | 217 | n, ok := Str.toInt(c^.args[1]); |
| 218 | 218 | if not ok then say("exit: {} isn't a number", [Fmt.str(c^.args[1])]); n := 2; end; |
| 219 | 219 | end; |
| 220 | - Rt.exit(n); | |
| 220 | + Rt.exit(INT(n)); | |
| 221 | 221 | else |
| 222 | 222 | return false; |
| 223 | 223 | end; |
| @@ -238,7 +238,7 @@ | ||
| 238 | 238 | has the terminal until they end. *) |
| 239 | 239 | proc start(p: ^Pipeline); |
| 240 | 240 | var |
| 241 | - pids: [maxCmds]I64; fds: [3]I64; i, j, inNext, r, w, leader, joins, how, _pid: I64; | |
| 241 | + pids: [maxCmds]INT; fds: [3]INT; i, j, inNext, r, w, leader, joins, how, _pid: INT; | |
| 242 | 242 | c: ^Command; path: []U8; found, _ok: BOOL; st: Sys.Status; |
| 243 | 243 | begin |
| 244 | 244 | if (p^.n = 1) and not p^.background and builtin(ADR(p^.cmds[0])) then return; end; |
| @@ -322,7 +322,7 @@ | ||
| 322 | 322 | |
| 323 | 323 | (* Before a prompt: the background programs that have ended. *) |
| 324 | 324 | proc reap; |
| 325 | -var pid, _code: I64; _st: Sys.Status; | |
| 325 | +var pid, _code: INT; _st: Sys.Status; | |
| 326 | 326 | begin |
| 327 | 327 | repeat |
| 328 | 328 | pid, _st, _code := Sys.wait(-1, false); |
| @@ -334,7 +334,7 @@ | ||
| 334 | 334 | shell in a process group of its own, which ignores the keys that |
| 335 | 335 | stop or end the pipeline in front of it. *) |
| 336 | 336 | proc interact; |
| 337 | -var line: Buf.Buf; keys: [5]I64; i: I64; _ok: BOOL; | |
| 337 | +var line: Buf.Buf; keys: [5]INT; i: INT; _ok: BOOL; | |
| 338 | 338 | begin |
| 339 | 339 | interactive := Sys.isTerminal(Sys.stdin); |
| 340 | 340 | if interactive then |
| @@ -353,7 +353,7 @@ | ||
| 353 | 353 | if interactive then show("\n", []); end; |
| 354 | 354 | end; |
| 355 | 355 | |
| 356 | -proc main*: I64; | |
| 356 | +proc main*: INT; | |
| 357 | 357 | var p: Opt.Parser; script, file: []U8; given, found: BOOL; b: Buf.Buf; |
| 358 | 358 | begin |
| 359 | 359 | if not Arena.init(ADR(arena), 1 shl 24) then Rt.stop("Sh: no memory"); end; |
| @@ -4,13 +4,13 @@ | ||
| 4 | 4 | |
| 5 | 5 | type |
| 6 | 6 | Shape = variant |
| 7 | - circle(r: I64); | |
| 8 | - rect(w, h: I64); | |
| 7 | + circle(r: INT); | |
| 8 | + rect(w, h: INT); | |
| 9 | 9 | dot; |
| 10 | 10 | end; |
| 11 | 11 | |
| 12 | 12 | (* Twice the area, rounded down, of a circle taken as pi = 22/7. *) |
| 13 | -proc area(s: Shape): I64; | |
| 13 | +proc area(s: Shape): INT; | |
| 14 | 14 | begin |
| 15 | 15 | match s of |
| 16 | 16 | | circle(r): return 44 * r * r div 7; |
| @@ -19,8 +19,8 @@ | ||
| 19 | 19 | end; |
| 20 | 20 | end; |
| 21 | 21 | |
| 22 | -proc total(shapes: []Shape): I64; | |
| 23 | -var i, sum: I64; | |
| 22 | +proc total(shapes: []Shape): INT; | |
| 23 | +var i, sum: INT; | |
| 24 | 24 | begin |
| 25 | 25 | sum := 0; |
| 26 | 26 | for i := 0 to LEN(shapes) - 1 do sum := sum + area(shapes[i]); end; |
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | var page: [64]U8; |
| 16 | 16 | |
| 17 | 17 | proc main*; |
| 18 | -var dev: ^VOLATILE Uart; i: I64; | |
| 18 | +var dev: ^VOLATILE Uart; i: INT; | |
| 19 | 19 | begin |
| 20 | 20 | dev := ^VOLATILE Uart(ADR(page)); |
| 21 | 21 | dev^.control := 1; |
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | end; |
| 27 | 27 | Out.ln; |
| 28 | 28 | FENCE; |
| 29 | - Out.int(I64(page[8])); Out.str(" "); Out.int(I64(dev^.status)); Out.ln; | |
| 29 | + Out.int(INT(page[8])); Out.str(" "); Out.int(INT(dev^.status)); Out.ln; | |
| 30 | 30 | end; |
| 31 | 31 | |
| 32 | 32 | end Volatile. |
| @@ -34,13 +34,13 @@ | ||
| 34 | 34 | extern proc XCreateSimpleWindow(d: ^U8; parent: U64; x, y: I32; |
| 35 | 35 | width, height, border: U32; borderColor, background: U64): U64; |
| 36 | 36 | extern proc XStoreName(d: ^U8; w: U64; name: ^U8): I32; |
| 37 | -extern proc XSelectInput(d: ^U8; w: U64; mask: I64): I32; | |
| 37 | +extern proc XSelectInput(d: ^U8; w: U64; mask: INT): I32; | |
| 38 | 38 | extern proc XMapWindow(d: ^U8; w: U64): I32; |
| 39 | 39 | extern proc XNextEvent(d: ^U8; ev: ^U8): I32; |
| 40 | 40 | extern proc XDrawString(d: ^U8; w: U64; gc: ^U8; x, y: I32; s: ^U8; n: I32): I32; |
| 41 | 41 | extern proc XCloseDisplay(d: ^U8): I32; |
| 42 | 42 | |
| 43 | -proc main*: I64; | |
| 43 | +proc main*: INT; | |
| 44 | 44 | const text = "hello, world: press a key"; |
| 45 | 45 | var |
| 46 | 46 | d: ^U8; s: I32; w: U64; |
| @@ -62,7 +62,7 @@ | ||
| 62 | 62 | end; |
| 63 | 63 | until I32(ev[0]) = KeyPress; |
| 64 | 64 | key := ^KeyEvent(ADR(ev)); |
| 65 | - Out.str("key "); Out.int(I64(key^.keycode)); Out.ln; | |
| 65 | + Out.str("key "); Out.int(INT(key^.keycode)); Out.ln; | |
| 66 | 66 | XCloseDisplay(d); |
| 67 | 67 | return 0; |
| 68 | 68 | end; |
| @@ -1,15 +1,15 @@ | ||
| 1 | 1 | (* Generic modules: counts the words of a text in a Map from []U8 to |
| 2 | - I64, hashed and compared by Str's procedures, keeps them in order of | |
| 2 | + INT, hashed and compared by Str's procedures, keeps them in order of | |
| 3 | 3 | first sight in a List([]U8), and prints them with Fmt. *) |
| 4 | 4 | module Words; |
| 5 | -import Fmt, Str, Heap, Count := Map([]U8, I64, Str.hash, Str.eq), Names := List([]U8); | |
| 5 | +import Fmt, Str, Heap, Count := Map([]U8, INT, Str.hash, Str.eq), Names := List([]U8); | |
| 6 | 6 | |
| 7 | 7 | const Text = "the cat and the hat and the bat"; |
| 8 | 8 | |
| 9 | 9 | proc main*; |
| 10 | 10 | var |
| 11 | 11 | counts: Count.Map; order: Names.List; n: ^Names.Node; |
| 12 | - i, start, k, total: I64; found, _ok: BOOL; w: []U8; | |
| 12 | + i, start, k, total: INT; found, _ok: BOOL; w: []U8; | |
| 13 | 13 | begin |
| 14 | 14 | Count.init(ADR(counts), Heap.heap); |
| 15 | 15 | Names.init(ADR(order), Heap.heap); |
| @@ -8,13 +8,13 @@ | ||
| 8 | 8 | Jobs = 100; |
| 9 | 9 | |
| 10 | 10 | var |
| 11 | - next: I64; (* the next job, taken with XADD *) | |
| 11 | + next: INT; (* the next job, taken with XADD *) | |
| 12 | 12 | m: Thread.Mutex; |
| 13 | - total: I64; | |
| 13 | + total: INT; | |
| 14 | 14 | |
| 15 | 15 | (* job n: the sum of the squares up to n *) |
| 16 | -proc job(n: I64): I64; | |
| 17 | -var i, s: I64; | |
| 16 | +proc job(n: INT): INT; | |
| 17 | +var i, s: INT; | |
| 18 | 18 | begin |
| 19 | 19 | s := 0; |
| 20 | 20 | for i := 1 to n do s := s + i * i; end; |
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | end; |
| 23 | 23 | |
| 24 | 24 | proc work(_arg: ^U8); |
| 25 | -var n, r: I64; | |
| 25 | +var n, r: INT; | |
| 26 | 26 | begin |
| 27 | 27 | n := XADD(ADR(next), 1); |
| 28 | 28 | while n < Jobs do |
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | end; |
| 36 | 36 | |
| 37 | 37 | proc main*; |
| 38 | -var t: [Workers]^Thread.Thread; i: I64; err: ERROR; | |
| 38 | +var t: [Workers]^Thread.Thread; i: INT; err: ERROR; | |
| 39 | 39 | begin |
| 40 | 40 | for i := 0 to Workers - 1 do |
| 41 | 41 | t[i], err := Thread.spawn(work, nil); |
| @@ -8,11 +8,11 @@ | ||
| 8 | 8 | Arena* = record |
| 9 | 9 | base*: Mem.Allocator; (* first, so that ^Arena(a) finds the rest *) |
| 10 | 10 | buf: ^U8; |
| 11 | - used, cap: I64; | |
| 11 | + used, cap: INT; | |
| 12 | 12 | end; |
| 13 | 13 | |
| 14 | -proc alloc(a: ^Mem.Allocator; size, align: I64): ^U8; | |
| 15 | -var ar: ^Arena; at: I64; | |
| 14 | +proc alloc(a: ^Mem.Allocator; size, align: INT): ^U8; | |
| 15 | +var ar: ^Arena; at: INT; | |
| 16 | 16 | begin |
| 17 | 17 | ar := ^Arena(a); |
| 18 | 18 | at := (ar^.used + align - 1) div align * align; |
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | end; |
| 27 | 27 | |
| 28 | 28 | (* An arena of size bytes; false if the system has none. *) |
| 29 | -proc init*(ar: ^Arena; size: I64): BOOL; | |
| 29 | +proc init*(ar: ^Arena; size: INT): BOOL; | |
| 30 | 30 | begin |
| 31 | 31 | ar^.base := {alloc: alloc, free: free}; |
| 32 | 32 | ar^.buf := Mem.pages(size); |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | Buf* = record |
| 7 | 7 | a: ^Mem.Allocator; |
| 8 | 8 | data: ^U8; |
| 9 | - len*, cap: I64; | |
| 9 | + len*, cap: INT; | |
| 10 | 10 | end; |
| 11 | 11 | |
| 12 | 12 | proc init*(b: ^Buf; a: ^Mem.Allocator); |
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | end; |
| 16 | 16 | |
| 17 | 17 | (* Room for n more bytes; false if the allocator has none. *) |
| 18 | -proc room*(b: ^Buf; n: I64): BOOL; | |
| 19 | -var cap, i: I64; p: ^U8; | |
| 18 | +proc room*(b: ^Buf; n: INT): BOOL; | |
| 19 | +var cap, i: INT; p: ^U8; | |
| 20 | 20 | begin |
| 21 | 21 | if b^.len + n <= b^.cap then return true; end; |
| 22 | 22 | cap := b^.cap * 2; |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | end; |
| 41 | 41 | |
| 42 | 42 | proc str*(b: ^Buf; s: []U8); |
| 43 | -var i: I64; | |
| 43 | +var i: INT; | |
| 44 | 44 | begin |
| 45 | 45 | if room(b, LEN(s)) then |
| 46 | 46 | for i := 0 to LEN(s) - 1 do b^.data[b^.len + i] := s[i]; end; |
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | |
| 71 | 71 | (* The module's test, over an arena. *) |
| 72 | 72 | proc main*; |
| 73 | -var ar: Arena.Arena; b: Buf; i: I64; s: []U8; | |
| 73 | +var ar: Arena.Arena; b: Buf; i: INT; s: []U8; | |
| 74 | 74 | begin |
| 75 | 75 | if not Arena.init(ADR(ar), 1 shl 20) then Rt.stop("Buf: no arena"); end; |
| 76 | 76 | init(ADR(b), ADR(ar.base)); |
| @@ -3,26 +3,26 @@ | ||
| 3 | 3 | linked dynamically and starts through the C library. *) |
| 4 | 4 | module C; |
| 5 | 5 | |
| 6 | -extern proc write*(fd: I32; buf: ^U8; n: U64): I64; | |
| 7 | -extern proc read*(fd: I32; buf: ^U8; n: U64): I64; | |
| 6 | +extern proc write*(fd: I32; buf: ^U8; n: UINT): INT; | |
| 7 | +extern proc read*(fd: I32; buf: ^U8; n: UINT): INT; | |
| 8 | 8 | extern proc open*(path: ^U8; flags: I32; ...): I32; |
| 9 | 9 | extern proc creat*(path: ^U8; mode: U32): I32; |
| 10 | 10 | extern proc close*(fd: I32): I32; |
| 11 | -extern proc mmap*(addr: ^U8; n: U64; prot, flags, fd: I32; off: I64): ^U8; | |
| 12 | -extern proc munmap*(addr: ^U8; n: U64): I32; | |
| 11 | +extern proc mmap*(addr: ^U8; n: UINT; prot, flags, fd: I32; off: I64): ^U8; | |
| 12 | +extern proc munmap*(addr: ^U8; n: UINT): I32; | |
| 13 | 13 | extern proc isatty*(fd: I32): I32; |
| 14 | 14 | extern proc exit*(status: I32); |
| 15 | 15 | extern proc _exit*(status: I32); |
| 16 | 16 | extern proc __errno_location*: ^I32; (* errno is this thread's: through here *) |
| 17 | 17 | extern proc sched_yield*: I32; |
| 18 | -extern proc pthread_create*(t: ^U64; attr: ^U8; start: proc(arg: ^U8): ^U8; arg: ^U8): I32; | |
| 19 | -extern proc pthread_join*(t: U64; result: ^^U8): I32; | |
| 18 | +extern proc pthread_create*(t: ^UINT; attr: ^U8; start: proc(arg: ^U8): ^U8; arg: ^U8): I32; | |
| 19 | +extern proc pthread_join*(t: UINT; result: ^^U8): I32; | |
| 20 | 20 | extern proc rename*(old, new: ^U8): I32; |
| 21 | 21 | extern proc unlink*(path: ^U8): I32; |
| 22 | 22 | extern proc mkdir*(path: ^U8; mode: U32): I32; |
| 23 | 23 | extern proc rmdir*(path: ^U8): I32; |
| 24 | 24 | extern proc chmod*(path: ^U8; mode: U32): I32; |
| 25 | -extern proc readlink*(path, buf: ^U8; n: U64): I64; | |
| 25 | +extern proc readlink*(path, buf: ^U8; n: UINT): INT; | |
| 26 | 26 | extern proc lseek*(fd: I32; off: I64; whence: I32): I64; |
| 27 | 27 | extern proc opendir*(path: ^U8): ^U8; (* DIR * *) |
| 28 | 28 | extern proc readdir*(d: ^U8): ^U8; (* struct dirent * *) |
| @@ -30,11 +30,11 @@ | ||
| 30 | 30 | extern proc tcgetattr*(fd: I32; t: ^U8): I32; |
| 31 | 31 | extern proc tcsetattr*(fd: I32; when: I32; t: ^U8): I32; |
| 32 | 32 | extern proc cfmakeraw*(t: ^U8); |
| 33 | -extern proc ioctl*(fd: I32; request: U64; ...): I32; | |
| 34 | -extern proc poll*(fds: ^U8; n: U64; ms: I32): I32; | |
| 33 | +extern proc ioctl*(fd: I32; request: UINT; ...): I32; | |
| 34 | +extern proc poll*(fds: ^U8; n: UINT; ms: I32): I32; | |
| 35 | 35 | extern proc socket*(domain, kind, protocol: I32): I32; |
| 36 | 36 | extern proc connect*(fd: I32; addr: ^U8; len: U32): I32; |
| 37 | -extern proc send*(fd: I32; buf: ^U8; n: U64; flags: I32): I64; | |
| 37 | +extern proc send*(fd: I32; buf: ^U8; n: UINT; flags: I32): INT; | |
| 38 | 38 | extern proc bind*(fd: I32; addr: ^U8; len: U32): I32; |
| 39 | 39 | extern proc listen*(fd, backlog: I32): I32; |
| 40 | 40 | extern proc accept*(fd: I32; addr: ^U8; len: ^U32): I32; |
| @@ -43,9 +43,9 @@ | ||
| 43 | 43 | extern proc inet_pton*(family: I32; src, dst: ^U8): I32; |
| 44 | 44 | extern proc clock_gettime*(clock: I32; t: ^U8): I32; |
| 45 | 45 | extern proc clock_nanosleep*(clock, flags: I32; t, left: ^U8): I32; |
| 46 | -extern proc getrandom*(buf: ^U8; n: U64; flags: U32): I64; | |
| 46 | +extern proc getrandom*(buf: ^U8; n: UINT; flags: U32): INT; | |
| 47 | 47 | extern proc getenv*(name: ^U8): ^U8; |
| 48 | -extern proc getcwd*(buf: ^U8; n: U64): ^U8; | |
| 48 | +extern proc getcwd*(buf: ^U8; n: UINT): ^U8; | |
| 49 | 49 | extern proc chdir*(path: ^U8): I32; |
| 50 | 50 | extern proc stat*(path, st: ^U8): I32; |
| 51 | 51 | extern proc lstat*(path, st: ^U8): I32; |
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | import Sys, Buf; |
| 5 | 5 | |
| 6 | 6 | (* Argument i, a C string, as a slice. *) |
| 7 | -proc arg*(i: I64): []U8; | |
| 8 | -var s: ^U8; n: I64; | |
| 7 | +proc arg*(i: INT): []U8; | |
| 8 | +var s: ^U8; n: INT; | |
| 9 | 9 | begin |
| 10 | 10 | s := ARGV()[i]; |
| 11 | 11 | n := 0; |
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | (* Adds the file at path to b; false if it can't be read. *) |
| 17 | 17 | proc read*(path: []U8; b: ^Buf.Buf): BOOL; |
| 18 | -var fd, n: I64; chunk: [4096]U8; | |
| 18 | +var fd, n: INT; chunk: [4096]U8; | |
| 19 | 19 | begin |
| 20 | 20 | fd := Sys.openRead(path); |
| 21 | 21 | if fd < 0 then return false; end; |
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | |
| 30 | 30 | (* Makes the file at path hold data; false if it can't be written. *) |
| 31 | 31 | proc write*(path, data: []U8): BOOL; |
| 32 | -var fd, n, at: I64; | |
| 32 | +var fd, n, at: INT; | |
| 33 | 33 | begin |
| 34 | 34 | fd := Sys.create(path); |
| 35 | 35 | if fd < 0 then return false; end; |
| @@ -13,12 +13,12 @@ | ||
| 13 | 13 | str(s: []U8); |
| 14 | 14 | char(c: U8); |
| 15 | 15 | bool(b: BOOL); |
| 16 | - real(r: F64; places: I64); | |
| 16 | + real(r: F64; places: INT); | |
| 17 | 17 | end; |
| 18 | 18 | |
| 19 | 19 | (* The digits of u in base, at the end of the array: it and where they start. *) |
| 20 | -proc digits(u: U64; base: U64): ([24]U8, I64); | |
| 21 | -var d: [24]U8; i: I64; v: U8; | |
| 20 | +proc digits(u: U64; base: U64): ([24]U8, INT); | |
| 21 | +var d: [24]U8; i: INT; v: U8; | |
| 22 | 22 | begin |
| 23 | 23 | i := 24; |
| 24 | 24 | repeat |
| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | nearest; from 1E15 on, with the exponent that makes it less than 10, |
| 41 | 41 | as 1.50e17. The whole part and the fraction are taken apart, so that |
| 42 | 42 | each fits an I64. *) |
| 43 | -proc putReal(b: ^Buf.Buf; x: F64; places: I64); | |
| 43 | +proc putReal(b: ^Buf.Buf; x: F64; places: INT); | |
| 44 | 44 | const zeros = "00000000"; |
| 45 | -var d: [24]U8; at, scale, i, whole, frac, e: I64; | |
| 45 | +var d: [24]U8; at, i, e: INT; scale, whole, frac: I64; | |
| 46 | 46 | begin |
| 47 | 47 | if x # x then put(b, "nan"); return; end; |
| 48 | 48 | if x < 0.0 then put(b, "-"); x := -x; end; |
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | end; |
| 74 | 74 | |
| 75 | 75 | proc arg(b: ^Buf.Buf; a: Arg); |
| 76 | -var d: [24]U8; at: I64; one: [1]U8; | |
| 76 | +var d: [24]U8; at: INT; one: [1]U8; | |
| 77 | 77 | begin |
| 78 | 78 | match a of |
| 79 | 79 | | int(i): |
| @@ -94,7 +94,7 @@ | ||
| 94 | 94 | end; |
| 95 | 95 | |
| 96 | 96 | proc format(b: ^Buf.Buf; f: []U8; args: []Arg); |
| 97 | -var i, start, n: I64; | |
| 97 | +var i, start, n: INT; | |
| 98 | 98 | begin |
| 99 | 99 | i := 0; start := 0; n := 0; |
| 100 | 100 | while i < LEN(f) do |
| @@ -18,30 +18,30 @@ | ||
| 18 | 18 | |
| 19 | 19 | type |
| 20 | 20 | Block = record next: ^Block; end; |
| 21 | - Head = record size, mark: I64; end; | |
| 21 | + Head = record size, mark: INT; end; | |
| 22 | 22 | |
| 23 | 23 | var |
| 24 | 24 | lists: [Classes]^Block; |
| 25 | 25 | cur: ^U8; (* where the next new small block comes from *) |
| 26 | - left: I64; | |
| 26 | + left: INT; | |
| 27 | 27 | lock: Lock.Lock; |
| 28 | 28 | std: Mem.Allocator; |
| 29 | 29 | heap*: ^Mem.Allocator; |
| 30 | 30 | |
| 31 | 31 | (* The block p, with size for its header, given out. *) |
| 32 | -proc give(p: ^U8; size: I64): ^U8; | |
| 32 | +proc give(p: ^U8; size: INT): ^U8; | |
| 33 | 33 | var h: ^Head; |
| 34 | 34 | begin |
| 35 | 35 | h := ^Head(p); |
| 36 | 36 | h^.size := size; |
| 37 | - h^.mark := Out xor I64(h); | |
| 37 | + h^.mark := Out xor INT(h); | |
| 38 | 38 | return p + Header; |
| 39 | 39 | end; |
| 40 | 40 | |
| 41 | 41 | (* size bytes aligned to align, or nil: also for a size below zero or |
| 42 | 42 | too big, and an alignment that isn't a power of two up to a page. *) |
| 43 | -proc alloc(_a: ^Mem.Allocator; size, align: I64): ^U8; | |
| 44 | -var c, n: I64; b: ^Block; p: ^U8; | |
| 43 | +proc alloc(_a: ^Mem.Allocator; size, align: INT): ^U8; | |
| 44 | +var c, n: INT; b: ^Block; p: ^U8; | |
| 45 | 45 | begin |
| 46 | 46 | if (size < 0) or (size > Largest) or (align < 1) or (align > Mem.Page) |
| 47 | 47 | or (align & (align - 1) # 0) then |
| @@ -78,18 +78,18 @@ | ||
| 78 | 78 | end; |
| 79 | 79 | |
| 80 | 80 | proc free(_a: ^Mem.Allocator; p: ^U8); |
| 81 | -var h: ^Head; b: ^Block; c: I64; | |
| 81 | +var h: ^Head; b: ^Block; c: INT; | |
| 82 | 82 | begin |
| 83 | 83 | if p = nil then return; end; |
| 84 | 84 | h := ^Head(p - Header); |
| 85 | 85 | Lock.take(ADR(lock)); |
| 86 | - if h^.mark # Out xor I64(h) then | |
| 86 | + if h^.mark # Out xor INT(h) then | |
| 87 | 87 | Rt.stop("Heap: a block freed twice, or never given out"); |
| 88 | 88 | end; |
| 89 | 89 | h^.mark := 0; |
| 90 | 90 | if h^.size < 0 then |
| 91 | 91 | Lock.give(ADR(lock)); |
| 92 | - Mem.unmap(^U8(I64(h) - I64(h) mod Mem.Page), -h^.size); | |
| 92 | + Mem.unmap(^U8(INT(h) - INT(h) mod Mem.Page), -h^.size); | |
| 93 | 93 | else |
| 94 | 94 | c := h^.size; (* before next, which takes its place, is set *) |
| 95 | 95 | b := ^Block(h); |
| @@ -102,12 +102,12 @@ | ||
| 102 | 102 | (* The module's test: blocks of every class and big ones, written, |
| 103 | 103 | freed and taken again. *) |
| 104 | 104 | proc main*; |
| 105 | -var p: [40]^U8; i, j, n: I64; again: ^U8; | |
| 105 | +var p: [40]^U8; i, j, n: INT; again: ^U8; | |
| 106 | 106 | begin |
| 107 | 107 | for i := 0 to 39 do |
| 108 | 108 | n := (i * i * 37) mod 9000 + 1; |
| 109 | 109 | p[i] := Mem.alloc(heap, n, 8); |
| 110 | - if (p[i] = nil) or (I64(p[i]) mod 8 # 0) then Rt.stop("Heap: alloc"); end; | |
| 110 | + if (p[i] = nil) or (INT(p[i]) mod 8 # 0) then Rt.stop("Heap: alloc"); end; | |
| 111 | 111 | for j := 0 to n - 1 do p[i][j] := U8(i); end; |
| 112 | 112 | end; |
| 113 | 113 | for i := 0 to 39 do |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | end; |
| 10 | 10 | List* = record |
| 11 | 11 | head*: ^Node; |
| 12 | - len*: I64; | |
| 12 | + len*: INT; | |
| 13 | 13 | a: ^Mem.Allocator; |
| 14 | 14 | end; |
| 15 | 15 |
| @@ -5,10 +5,10 @@ | ||
| 5 | 5 | module Lock; |
| 6 | 6 | import Sys, Rt; |
| 7 | 7 | |
| 8 | -type Lock* = record held: I64; end; | |
| 8 | +type Lock* = record held: INT; end; | |
| 9 | 9 | |
| 10 | 10 | proc take*(l: ^Lock); |
| 11 | -var tries: I64; | |
| 11 | +var tries: INT; | |
| 12 | 12 | begin |
| 13 | 13 | tries := 0; |
| 14 | 14 | while not CAS(ADR(l^.held), 0, 1) do |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | (* A hash map from K to V, by open addressing; it hashes and compares |
| 2 | 2 | keys with the procedures it is given: |
| 3 | - import Count := Map([]U8, I64, Str.hash, Str.eq); *) | |
| 3 | + import Count := Map([]U8, INT, Str.hash, Str.eq); *) | |
| 4 | 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL); |
| 5 | 5 | import Mem; |
| 6 | 6 | |
| @@ -13,8 +13,8 @@ | ||
| 13 | 13 | Map* = record |
| 14 | 14 | a: ^Mem.Allocator; |
| 15 | 15 | slots: ^Entry; |
| 16 | - cap: I64; (* a power of two, or 0 *) | |
| 17 | - len*: I64; | |
| 16 | + cap: INT; (* a power of two, or 0 *) | |
| 17 | + len*: INT; | |
| 18 | 18 | end; |
| 19 | 19 | |
| 20 | 20 | proc init*(m: ^Map; a: ^Mem.Allocator); |
| @@ -23,10 +23,10 @@ | ||
| 23 | 23 | end; |
| 24 | 24 | |
| 25 | 25 | (* The slot of k, or of the empty slot where it would go. *) |
| 26 | -proc slot(m: ^Map; k: K): I64; | |
| 27 | -var i: I64; | |
| 26 | +proc slot(m: ^Map; k: K): INT; | |
| 27 | +var i: INT; | |
| 28 | 28 | begin |
| 29 | - i := I64(hash(k) & U64(m^.cap - 1)); | |
| 29 | + i := INT(hash(k) & U64(m^.cap - 1)); | |
| 30 | 30 | while m^.slots[i].used and not eq(m^.slots[i].key, k) do |
| 31 | 31 | i := (i + 1) & (m^.cap - 1); |
| 32 | 32 | end; |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | end; |
| 35 | 35 | |
| 36 | 36 | proc grow(m: ^Map): BOOL; |
| 37 | -var old: ^Entry; n, i, j: I64; | |
| 37 | +var old: ^Entry; n, i, j: INT; | |
| 38 | 38 | begin |
| 39 | 39 | old := m^.slots; |
| 40 | 40 | n := m^.cap; |
| @@ -54,7 +54,7 @@ | ||
| 54 | 54 | |
| 55 | 55 | (* k now maps to v; false if there was no room. *) |
| 56 | 56 | proc put*(m: ^Map; k: K; v: V): BOOL; |
| 57 | -var i: I64; | |
| 57 | +var i: INT; | |
| 58 | 58 | begin |
| 59 | 59 | if (m^.len + 1) * 4 > m^.cap * 3 then |
| 60 | 60 | if not grow(m) then return false; end; |
| @@ -72,7 +72,7 @@ | ||
| 72 | 72 | after it that were pushed on past its slot move back, so that a |
| 73 | 73 | search for each still finds it before an empty slot. *) |
| 74 | 74 | proc remove*(m: ^Map; k: K): BOOL; |
| 75 | -var i, j, home: I64; | |
| 75 | +var i, j, home: INT; | |
| 76 | 76 | begin |
| 77 | 77 | if m^.cap = 0 then return false; end; |
| 78 | 78 | i := slot(m, k); |
| @@ -80,7 +80,7 @@ | ||
| 80 | 80 | j := (i + 1) & (m^.cap - 1); |
| 81 | 81 | while m^.slots[j].used do |
| 82 | 82 | (* the entry at j may fill i if i lies between its home and j *) |
| 83 | - home := I64(hash(m^.slots[j].key) & U64(m^.cap - 1)); | |
| 83 | + home := INT(hash(m^.slots[j].key) & U64(m^.cap - 1)); | |
| 84 | 84 | if (j - home) & (m^.cap - 1) >= (j - i) & (m^.cap - 1) then |
| 85 | 85 | m^.slots[i] := m^.slots[j]; |
| 86 | 86 | i := j; |
| @@ -94,7 +94,7 @@ | ||
| 94 | 94 | |
| 95 | 95 | (* What k maps to, and whether it maps to anything. *) |
| 96 | 96 | proc get*(m: ^Map; k: K): (V, BOOL); |
| 97 | -var i: I64; none: V; | |
| 97 | +var i: INT; none: V; | |
| 98 | 98 | begin |
| 99 | 99 | if m^.cap = 0 then return none, false; end; |
| 100 | 100 | i := slot(m, k); |
| @@ -104,7 +104,7 @@ | ||
| 104 | 104 | |
| 105 | 105 | (* The entry after i, walking from 0: the number to pass for the one |
| 106 | 106 | after it, or -1 if there are no more, then its key and value. *) |
| 107 | -proc next*(m: ^Map; i: I64): (I64, K, V); | |
| 107 | +proc next*(m: ^Map; i: INT): (INT, K, V); | |
| 108 | 108 | var k: K; v: V; |
| 109 | 109 | begin |
| 110 | 110 | while i < m^.cap do |
| @@ -45,14 +45,14 @@ | ||
| 45 | 45 | var t: F64; |
| 46 | 46 | begin |
| 47 | 47 | if not (x > -4503599627370496.0) or not (x < 4503599627370496.0) or (x = 0.0) then return x; end; |
| 48 | - t := F64(I64(x)); | |
| 48 | + t := F64(INT(x)); | |
| 49 | 49 | if t > x then t := t - 1.0; end; |
| 50 | 50 | return t; |
| 51 | 51 | end; |
| 52 | 52 | |
| 53 | 53 | (* x times 2^k, for k from -1075 to 1024: 2^k is made from its bits, |
| 54 | 54 | in two steps where k is past what an F64's exponent holds. *) |
| 55 | -proc scale(x: F64; k: I64): F64; | |
| 55 | +proc scale(x: F64; k: INT): F64; | |
| 56 | 56 | begin |
| 57 | 57 | if k > 1023 then x := x * fromBits(U64(2046) shl 52); DEC(k, 1023); end; |
| 58 | 58 | if k < -1022 then x := x * fromBits(U64(1 + 53) shl 52); INC(k, 1022 - 53); end; |
| @@ -61,13 +61,13 @@ | ||
| 61 | 61 | |
| 62 | 62 | (* e^x = 2^k e^r, with r = x - k ln 2 at most ln 2 / 2 across. *) |
| 63 | 63 | proc exp*(x: F64): F64; |
| 64 | -var k: I64; hi, lo, r, rr, c: F64; | |
| 64 | +var k: INT; hi, lo, r, rr, c: F64; | |
| 65 | 65 | begin |
| 66 | 66 | if x # x then return x; end; |
| 67 | 67 | if x > 709.782712893383973096 then return x * fromBits(U64(2046) shl 52); end; (* too big: inf *) |
| 68 | 68 | if x < -745.13321910194110842 then return 0.0; end; |
| 69 | - if x < 0.0 then k := I64(x * 1.44269504088896338700 - 0.5); | |
| 70 | - else k := I64(x * 1.44269504088896338700 + 0.5); | |
| 69 | + if x < 0.0 then k := INT(x * 1.44269504088896338700 - 0.5); | |
| 70 | + else k := INT(x * 1.44269504088896338700 + 0.5); | |
| 71 | 71 | end; |
| 72 | 72 | hi := x - F64(k) * ln2hi; |
| 73 | 73 | lo := F64(k) * ln2lo; |
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | found through s = f / (2 + f), f = m - 1, whose series converges |
| 84 | 84 | fast. *) |
| 85 | 85 | proc ln*(x: F64): F64; |
| 86 | -var u: U64; k: I64; f, hfsq, s, z, w, r: F64; | |
| 86 | +var u: U64; k: INT; f, hfsq, s, z, w, r: F64; | |
| 87 | 87 | begin |
| 88 | 88 | if x # x then return x; end; |
| 89 | 89 | if x < 0.0 then return (x - x) / 0.0; end; (* NaN *) |
| @@ -95,7 +95,7 @@ | ||
| 95 | 95 | end; |
| 96 | 96 | (* the exponent, counted from m's lower end, and the bits of m *) |
| 97 | 97 | u := bits(x) + (3FF0000000000000H - 3FE6A09E00000000H); |
| 98 | - INC(k, I64(u shr 52) - 3FFH); | |
| 98 | + INC(k, INT(u shr 52) - 3FFH); | |
| 99 | 99 | f := fromBits((u & 0FFFFFFFFFFFFFH) + 3FE6A09E00000000H) - 1.0; |
| 100 | 100 | hfsq := 0.5 * f * f; |
| 101 | 101 | s := f / (2.0 + f); |
| @@ -114,8 +114,8 @@ | ||
| 114 | 114 | 0C3H; (* ret *) |
| 115 | 115 | |
| 116 | 116 | (* 64 bits of t from bit s on, the first bit of t[0] being 0. *) |
| 117 | -proc window(t: []U64; s: I64): U64; | |
| 118 | -var q, r: I64; | |
| 117 | +proc window(t: []U64; s: INT): U64; | |
| 118 | +var q, r: INT; | |
| 119 | 119 | begin |
| 120 | 120 | q := s div 64; |
| 121 | 121 | r := s mod 64; |
| @@ -129,10 +129,10 @@ | ||
| 129 | 129 | turns, which change no sine, and are left out; the 192 after them |
| 130 | 130 | give the two bits of n mod 4 and the fraction past n, exact far |
| 131 | 131 | beyond an F64. *) |
| 132 | -proc reduceLarge(x: F64): (I64, F64, F64); | |
| 132 | +proc reduceLarge(x: F64): (INT, F64, F64); | |
| 133 | 133 | var |
| 134 | 134 | t: [21]U64; (* 2/pi's bits after its point, behind a word of zeros *) |
| 135 | - m, w0, w1, w2, p0, p1, p2, lo: U64; e, s, n, k: I64; y: F64; neg, up: BOOL; | |
| 135 | + m, w0, w1, w2, p0, p1, p2, lo: U64; e, s, n, k: INT; y: F64; neg, up: BOOL; | |
| 136 | 136 | begin |
| 137 | 137 | t := [0, 0A2F9836E4E441529H, 0FC2757D1F534DDC0H, 0DB6295993C439041H, 0FE5163ABDEBBC561H, |
| 138 | 138 | 0B7246E3A424DD2E0H, 06492EEA09D1921CH, 0FE1DEB1CB129A73EH, 0E88235F52EBB4484H, |
| @@ -142,7 +142,7 @@ | ||
| 142 | 142 | neg := x < 0.0; |
| 143 | 143 | if neg then x := -x; end; |
| 144 | 144 | m := bits(x) & 0FFFFFFFFFFFFFH | 10000000000000H; |
| 145 | - e := I64(bits(x) shr 52) - 1075; | |
| 145 | + e := INT(bits(x) shr 52) - 1075; | |
| 146 | 146 | (* W, the 192 bits of 2/pi from the one worth 2^(1 - e), so that |
| 147 | 147 | x 2/pi is m W 2^-190, of which the bits from 2^192 up are left out *) |
| 148 | 148 | s := e + 62; |
| @@ -157,7 +157,7 @@ | ||
| 157 | 157 | (* n is the two bits from 2^190, the fraction those below; from a |
| 158 | 158 | half up, n is the next and the fraction 1 less, taken as 1 less |
| 159 | 159 | the fraction, negated: its bits complemented, one in 2^190 short *) |
| 160 | - n := I64(p2 shr 62); | |
| 160 | + n := INT(p2 shr 62); | |
| 161 | 161 | p2 := p2 & 3FFFFFFFFFFFFFFFH; |
| 162 | 162 | up := p2 shr 61 = 1; |
| 163 | 163 | if up then |
| @@ -182,12 +182,12 @@ | ||
| 182 | 182 | than one F64; and n. pi/2 is taken in three parts of 33 bits, each |
| 183 | 183 | with what is left of it after, so that n times each is exact while |
| 184 | 184 | n is below 2^20, about x = 1.6E6. *) |
| 185 | -proc reduce(x: F64): (I64, F64, F64); | |
| 186 | -var n: I64; fn, r, t, w, y: F64; | |
| 185 | +proc reduce(x: F64): (INT, F64, F64); | |
| 186 | +var n: INT; fn, r, t, w, y: F64; | |
| 187 | 187 | begin |
| 188 | 188 | if (x > 1.6E6) or (x < -1.6E6) then return reduceLarge(x); end; |
| 189 | - if x < 0.0 then n := I64(x * 6.36619772367581382433E-01 - 0.5); | |
| 190 | - else n := I64(x * 6.36619772367581382433E-01 + 0.5); | |
| 189 | + if x < 0.0 then n := INT(x * 6.36619772367581382433E-01 - 0.5); | |
| 190 | + else n := INT(x * 6.36619772367581382433E-01 + 0.5); | |
| 191 | 191 | end; |
| 192 | 192 | fn := F64(n); |
| 193 | 193 | r := x - fn * 1.57079632673412561417E+00; |
| @@ -227,7 +227,7 @@ | ||
| 227 | 227 | end; |
| 228 | 228 | |
| 229 | 229 | proc sin*(x: F64): F64; |
| 230 | -var n: I64; y, yy: F64; | |
| 230 | +var n: INT; y, yy: F64; | |
| 231 | 231 | begin |
| 232 | 232 | if (x = 0.0) or (x # x) then return x; end; |
| 233 | 233 | if (x - x) # 0.0 then return x - x; end; (* an infinity: NaN *) |
| @@ -241,7 +241,7 @@ | ||
| 241 | 241 | end; |
| 242 | 242 | |
| 243 | 243 | proc cos*(x: F64): F64; |
| 244 | -var n: I64; y, yy: F64; | |
| 244 | +var n: INT; y, yy: F64; | |
| 245 | 245 | begin |
| 246 | 246 | if (x - x) # 0.0 then return x - x; end; (* an infinity or NaN: NaN *) |
| 247 | 247 | n, y, yy := reduce(x); |
| @@ -5,24 +5,24 @@ | ||
| 5 | 5 | |
| 6 | 6 | type |
| 7 | 7 | Allocator* = record |
| 8 | - alloc*: proc(a: ^Allocator; size, align: I64): ^U8; (* nil if out of room *) | |
| 8 | + alloc*: proc(a: ^Allocator; size, align: INT): ^U8; (* nil if out of room *) | |
| 9 | 9 | free*: proc(a: ^Allocator; p: ^U8); |
| 10 | 10 | end; |
| 11 | 11 | |
| 12 | 12 | const Page* = 4096; |
| 13 | 13 | |
| 14 | 14 | (* size bytes, rounded up to whole pages, zeroed; or nil. *) |
| 15 | -proc pages*(size: I64): ^U8; | |
| 15 | +proc pages*(size: INT): ^U8; | |
| 16 | 16 | begin |
| 17 | 17 | return Sys.mmap((size + Page - 1) div Page * Page); |
| 18 | 18 | end; |
| 19 | 19 | |
| 20 | -proc unmap*(p: ^U8; size: I64); | |
| 20 | +proc unmap*(p: ^U8; size: INT); | |
| 21 | 21 | begin |
| 22 | 22 | Sys.munmap(p, (size + Page - 1) div Page * Page); |
| 23 | 23 | end; |
| 24 | 24 | |
| 25 | -proc alloc*(a: ^Allocator; size, align: I64): ^U8; | |
| 25 | +proc alloc*(a: ^Allocator; size, align: INT): ^U8; | |
| 26 | 26 | begin |
| 27 | 27 | return a^.alloc(a, size, align); |
| 28 | 28 | end; |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | |
| 35 | 35 | (* The module's test. *) |
| 36 | 36 | proc main*; |
| 37 | -var p: ^U8; i: I64; | |
| 37 | +var p: ^U8; i: INT; | |
| 38 | 38 | begin |
| 39 | 39 | p := pages(10000); |
| 40 | 40 | if p = nil then Rt.stop("Mem.pages"); end; |
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | name: []U8; (* the program's, as the messages begin *) |
| 26 | 26 | table: []Row; |
| 27 | 27 | scope: []U8; |
| 28 | - at: I64; (* the next word *) | |
| 28 | + at: INT; (* the next word *) | |
| 29 | 29 | group: []U8; (* the letters left of a word of them, as -lw *) |
| 30 | 30 | spelt: []U8; (* the option just read as written, without its dashes *) |
| 31 | 31 | ended: BOOL; (* the scope's options have ended *) |
| @@ -36,8 +36,8 @@ | ||
| 36 | 36 | const read1 = 1; readEnd = 0; readSkip = -1; |
| 37 | 37 | |
| 38 | 38 | (* b written whole to fd, then freed. *) |
| 39 | -proc say(fd: I64; b: ^Buf.Buf); | |
| 40 | -var s: []U8; n: I64; | |
| 39 | +proc say(fd: INT; b: ^Buf.Buf); | |
| 40 | +var s: []U8; n: INT; | |
| 41 | 41 | begin |
| 42 | 42 | s := Buf.bytes(b); |
| 43 | 43 | while LEN(s) > 0 do |
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | "usage: " and the first, the others under it; or, for a scope with |
| 62 | 62 | none, "usage: keep start". *) |
| 63 | 63 | proc usageOf(p: ^Parser; b: ^Buf.Buf); |
| 64 | -var i, lines: I64; c: U8; | |
| 64 | +var i, lines: INT; c: U8; | |
| 65 | 65 | begin |
| 66 | 66 | for i := 0 to LEN(p^.table) - 1 do |
| 67 | 67 | match p^.table[i] of |
| @@ -124,8 +124,8 @@ | ||
| 124 | 124 | end; |
| 125 | 125 | end; |
| 126 | 126 | |
| 127 | -proc leftWidth(r: ^Row): I64; | |
| 128 | -var b: Buf.Buf; n: I64; | |
| 127 | +proc leftWidth(r: ^Row): INT; | |
| 128 | +var b: Buf.Buf; n: INT; | |
| 129 | 129 | begin |
| 130 | 130 | Buf.init(ADR(b), Heap.heap); |
| 131 | 131 | left(ADR(b), r); |
| @@ -136,8 +136,8 @@ | ||
| 136 | 136 | |
| 137 | 137 | (* A line of the list: the left column, padded to width and three |
| 138 | 138 | spaces more, and the line of help. *) |
| 139 | -proc item(b: ^Buf.Buf; r: ^Row; width: I64); | |
| 140 | -var i: I64; | |
| 139 | +proc item(b: ^Buf.Buf; r: ^Row; width: INT); | |
| 140 | +var i: INT; | |
| 141 | 141 | begin |
| 142 | 142 | Buf.str(b, " "); |
| 143 | 143 | left(b, r); |
| @@ -153,7 +153,7 @@ | ||
| 153 | 153 | (* The scope's help: its synopsis lines, then its subcommands, its |
| 154 | 154 | options and the help itself, each with its line; and status 0. *) |
| 155 | 155 | proc printHelp(p: ^Parser); |
| 156 | -var b: Buf.Buf; i, width: I64; r: ^Row; | |
| 156 | +var b: Buf.Buf; i, width: INT; r: ^Row; | |
| 157 | 157 | begin |
| 158 | 158 | Buf.init(ADR(b), Heap.heap); |
| 159 | 159 | usageOf(p, ADR(b)); |
| @@ -184,8 +184,8 @@ | ||
| 184 | 184 | |
| 185 | 185 | (* The scope's option with the letter c, or with the long name long: |
| 186 | 186 | its row, or -1, and its letter and the name of its value. *) |
| 187 | -proc find(p: ^Parser; c: U8; long: []U8): (I64, U8, []U8); | |
| 188 | -var i: I64; | |
| 187 | +proc find(p: ^Parser; c: U8; long: []U8): (INT, U8, []U8); | |
| 188 | +var i: INT; | |
| 189 | 189 | begin |
| 190 | 190 | for i := 0 to LEN(p^.table) - 1 do |
| 191 | 191 | match p^.table[i] of |
| @@ -202,8 +202,8 @@ | ||
| 202 | 202 | (* The next option, a word or a letter of one, into p: read1, or |
| 203 | 203 | readEnd at the end of the options. A mistake is refused, or, if |
| 204 | 204 | quiet, passed over, as readSkip. *) |
| 205 | -proc read(p: ^Parser; quiet: BOOL): I64; | |
| 206 | -var w, val: []U8; r, eq: I64; c: U8; | |
| 205 | +proc read(p: ^Parser; quiet: BOOL): INT; | |
| 206 | +var w, val: []U8; r, eq: INT; c: U8; | |
| 207 | 207 | begin |
| 208 | 208 | p^.help := false; |
| 209 | 209 | p^.value := ""; |
| @@ -272,7 +272,7 @@ | ||
| 272 | 272 | program sees one: a copy of the parser reads them, passing over |
| 273 | 273 | mistakes. *) |
| 274 | 274 | proc answerHelp(p: ^Parser); |
| 275 | -var q: Parser; k: I64; | |
| 275 | +var q: Parser; k: INT; | |
| 276 | 276 | begin |
| 277 | 277 | q := p^; |
| 278 | 278 | repeat |
| @@ -282,7 +282,7 @@ | ||
| 282 | 282 | end; |
| 283 | 283 | |
| 284 | 284 | (* A mistake in the table: the program's, with status 1. *) |
| 285 | -proc badTable(p: ^Parser; row: I64; why: []U8); | |
| 285 | +proc badTable(p: ^Parser; row: INT; why: []U8); | |
| 286 | 286 | var b: Buf.Buf; |
| 287 | 287 | begin |
| 288 | 288 | Buf.init(ADR(b), Heap.heap); |
| @@ -292,7 +292,7 @@ | ||
| 292 | 292 | end; |
| 293 | 293 | |
| 294 | 294 | proc check(p: ^Parser); |
| 295 | -var i, j: I64; | |
| 295 | +var i, j: INT; | |
| 296 | 296 | begin |
| 297 | 297 | for i := 0 to LEN(p^.table) - 1 do |
| 298 | 298 | match p^.table[i] of |
| @@ -455,12 +455,12 @@ | ||
| 455 | 455 | mode: []U8; (* OPTTEST=... *) |
| 456 | 456 | args: [][]U8; |
| 457 | 457 | out, err: []U8; |
| 458 | - status: I64; | |
| 458 | + status: INT; | |
| 459 | 459 | end; |
| 460 | 460 | |
| 461 | 461 | (* Everything left to read on fd, into buf: how much. *) |
| 462 | -proc readAll(fd: I64; buf: []U8): I64; | |
| 463 | -var n, k: I64; | |
| 462 | +proc readAll(fd: INT; buf: []U8): INT; | |
| 463 | +var n, k: INT; | |
| 464 | 464 | begin |
| 465 | 465 | repeat |
| 466 | 466 | k := Sys.read(fd, buf[n..LEN(buf)]); |
| @@ -470,8 +470,8 @@ | ||
| 470 | 470 | return n; |
| 471 | 471 | end; |
| 472 | 472 | |
| 473 | -proc run(c: Case; n: I64); | |
| 474 | -var outR, outW, errR, errW, pid, status, no, ne: I64; st: Sys.Status; out, err: [4096]U8; | |
| 473 | +proc run(c: Case; n: INT); | |
| 474 | +var outR, outW, errR, errW, pid, status, no, ne: INT; st: Sys.Status; out, err: [4096]U8; | |
| 475 | 475 | begin |
| 476 | 476 | outR, outW := Sys.pipe(); |
| 477 | 477 | errR, errW := Sys.pipe(); |
| @@ -494,7 +494,7 @@ | ||
| 494 | 494 | keepHelp = "usage: keep [-v] [--wait secs] start ...\n\n start start a job\n -v, --verbose say more\n --wait secs give the job secs to start\n -h, --help print this and exit\n"; |
| 495 | 495 | startHelp = "usage: keep start [-b label] name command [argument ...]\n\n -b, --bar label show the job in the bar as label\n -h, --help print this and exit\n"; |
| 496 | 496 | k = "OPTTEST=keep"; |
| 497 | -var cases: []Case; i: I64; mode: []U8; | |
| 497 | +var cases: []Case; i: INT; mode: []U8; | |
| 498 | 498 | begin |
| 499 | 499 | mode := Sys.env("OPTTEST"); |
| 500 | 500 | if mode = "keep" then keep; return; |
| @@ -9,14 +9,14 @@ | ||
| 9 | 9 | |
| 10 | 10 | var |
| 11 | 11 | buf: [Sys.outSize]U8; |
| 12 | - n: I64; (* bytes in buf *) | |
| 12 | + n: INT; (* bytes in buf *) | |
| 13 | 13 | tty: BOOL; (* standard output is a terminal *) |
| 14 | 14 | lock: Lock.Lock; |
| 15 | 15 | |
| 16 | 16 | (* Writes out the buffer, with the lock held. What can't be written is |
| 17 | 17 | dropped. *) |
| 18 | 18 | proc out; |
| 19 | -var i, k: I64; | |
| 19 | +var i, k: INT; | |
| 20 | 20 | begin |
| 21 | 21 | i := 0; |
| 22 | 22 | while i < n do |
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | end; |
| 37 | 37 | |
| 38 | 38 | proc str*(s: []U8); |
| 39 | -var i: I64; | |
| 39 | +var i: INT; | |
| 40 | 40 | begin |
| 41 | 41 | Lock.take(ADR(lock)); |
| 42 | 42 | for i := 0 to LEN(s) - 1 do |
| @@ -62,7 +62,7 @@ | ||
| 62 | 62 | |
| 63 | 63 | (* n in decimal *) |
| 64 | 64 | proc int*(n: I64); |
| 65 | -var buf: [20]U8; i: I64; u: U64; | |
| 65 | +var buf: [20]U8; i: INT; u: U64; | |
| 66 | 66 | begin |
| 67 | 67 | u := U64(n); |
| 68 | 68 | if n < 0 then u := 0 - u; end; |
| @@ -80,8 +80,8 @@ | ||
| 80 | 80 | end; |
| 81 | 81 | |
| 82 | 82 | (* n in hexadecimal, digits digits at least *) |
| 83 | -proc hex*(n: U64; digits: I64); | |
| 84 | -var buf: [16]U8; i: I64; d: U8; | |
| 83 | +proc hex*(n: U64; digits: INT); | |
| 84 | +var buf: [16]U8; i: INT; d: U8; | |
| 85 | 85 | begin |
| 86 | 86 | i := 16; |
| 87 | 87 | repeat |
| @@ -23,23 +23,23 @@ | ||
| 23 | 23 | Place = record at, line, col, path: U32; end; |
| 24 | 24 | (* What rt_sigaction and sigaltstack take *) |
| 25 | 25 | Action = record |
| 26 | - handler: proc(sig: I64; info, ctx: ^U8); | |
| 26 | + handler: proc(sig: INT; info, ctx: ^U8); | |
| 27 | 27 | flags: U64; |
| 28 | 28 | restorer: proc; |
| 29 | 29 | mask: U64; |
| 30 | 30 | end; |
| 31 | - Stack = record sp: ^U8; flags, size: I64; end; | |
| 31 | + Stack = record sp: ^U8; flags, size: INT; end; | |
| 32 | 32 | |
| 33 | 33 | var |
| 34 | 34 | atExits: [MaxAtExit]proc; |
| 35 | - numAtExit: I64; | |
| 35 | + numAtExit: INT; | |
| 36 | 36 | cExit: proc(status: I32); (* C's exit, set first thing in a program that uses C *) |
| 37 | 37 | (* Set first thing too: the number of places, where the program's |
| 38 | 38 | code starts and stops, the places, and the paths. The linker |
| 39 | 39 | makes them. *) |
| 40 | - places: ^I64; | |
| 40 | + places: ^INT; | |
| 41 | 41 | line: [256]U8; (* the message being made *) |
| 42 | - lineLen: I64; | |
| 42 | + lineLen: INT; | |
| 43 | 43 | act: Action; |
| 44 | 44 | alt: Stack; |
| 45 | 45 | altStack: [16384]U8; (* where the handlers run, even when the stack is full *) |
| @@ -58,7 +58,7 @@ | ||
| 58 | 58 | uses C, so that C flushes its buffers too. Each procedure is taken |
| 59 | 59 | off the list before it runs, so it runs once even if it fails or |
| 60 | 60 | calls exit itself. *) |
| 61 | -proc exit*(status: I64); | |
| 61 | +proc exit*(status: INT); | |
| 62 | 62 | var p: proc; |
| 63 | 63 | begin |
| 64 | 64 | while numAtExit > 0 do |
| @@ -82,7 +82,7 @@ | ||
| 82 | 82 | (* Messages, made in line, one byte kept for the line feed, and |
| 83 | 83 | written by say in one piece *) |
| 84 | 84 | proc put(s: []U8); |
| 85 | -var i: I64; | |
| 85 | +var i: INT; | |
| 86 | 86 | begin |
| 87 | 87 | for i := 0 to LEN(s) - 1 do |
| 88 | 88 | if lineLen < LEN(line) - 1 then |
| @@ -93,9 +93,9 @@ | ||
| 93 | 93 | end; |
| 94 | 94 | |
| 95 | 95 | (* The digits are made from the last, those of a negative n from its |
| 96 | - negative remainders, so that the lowest I64 comes out too. *) | |
| 97 | -proc putInt(n: I64); | |
| 98 | -var buf: [20]U8; i: I64; neg: BOOL; | |
| 96 | + negative remainders, so that the lowest INT comes out too. *) | |
| 97 | +proc putInt(n: INT); | |
| 98 | +var buf: [20]U8; i: INT; neg: BOOL; | |
| 99 | 99 | begin |
| 100 | 100 | neg := n < 0; |
| 101 | 101 | i := 20; |
| @@ -109,7 +109,7 @@ | ||
| 109 | 109 | end; |
| 110 | 110 | |
| 111 | 111 | proc putStr(s: ^U8); |
| 112 | -var n: I64; | |
| 112 | +var n: INT; | |
| 113 | 113 | begin |
| 114 | 114 | n := 0; |
| 115 | 115 | while s[n] # 0 do INC(n); end; |
| @@ -126,22 +126,22 @@ | ||
| 126 | 126 | (* Puts where the code at address a comes from, as file:line:col: and |
| 127 | 127 | a space, if a is in the program's code: the place with the highest |
| 128 | 128 | address up to a. *) |
| 129 | -proc where(a: U64); | |
| 130 | -var p, best: ^Place; i, n: I64; | |
| 129 | +proc where(a: UINT); | |
| 130 | +var p, best: ^Place; i, n: INT; | |
| 131 | 131 | begin |
| 132 | - if (places = nil) or (a < U64(places[1])) or (a >= U64(places[2])) then return; end; | |
| 132 | + if (places = nil) or (a < UINT(places[1])) or (a >= UINT(places[2])) then return; end; | |
| 133 | 133 | n := places[0]; |
| 134 | 134 | p := ^Place(places + 3); |
| 135 | 135 | best := nil; |
| 136 | 136 | for i := 0 to n - 1 do |
| 137 | - if (U64(p[i].at) <= a) and ((best = nil) or (p[i].at > best^.at)) then best := p + i; end; | |
| 137 | + if (UINT(p[i].at) <= a) and ((best = nil) or (p[i].at > best^.at)) then best := p + i; end; | |
| 138 | 138 | end; |
| 139 | 139 | if best = nil then return; end; |
| 140 | - putStr(^U8(p + n) + I64(best^.path)); | |
| 140 | + putStr(^U8(p + n) + INT(best^.path)); | |
| 141 | 141 | put(":"); |
| 142 | - putInt(I64(best^.line)); | |
| 142 | + putInt(INT(best^.line)); | |
| 143 | 143 | put(":"); |
| 144 | - putInt(I64(best^.col)); | |
| 144 | + putInt(INT(best^.col)); | |
| 145 | 145 | put(": "); |
| 146 | 146 | end; |
| 147 | 147 | |
| @@ -151,7 +151,7 @@ | ||
| 151 | 151 | something whose length is len; 2 for a, which is no position of |
| 152 | 152 | the enumeration called name; 3 for a slice a..b of a pointer, which |
| 153 | 153 | runs backwards. *) |
| 154 | -proc fail*(what, a, b, len: I64; at: U64; name: ^U8); | |
| 154 | +proc fail*(what, a, b, len: INT; at: UINT; name: ^U8); | |
| 155 | 155 | begin |
| 156 | 156 | where(at); |
| 157 | 157 | if what = 0 then |
| @@ -186,18 +186,18 @@ | ||
| 186 | 186 | reset as it was called, so the instruction faults again and the |
| 187 | 187 | signal ends the program. info and ctx are the kernel's siginfo and |
| 188 | 188 | ucontext. *) |
| 189 | -proc onSignal(sig: I64; info, ctx: ^U8); | |
| 190 | -var adr, sp, ip: U64; q: ^U64; why: []U8; | |
| 189 | +proc onSignal(sig: INT; info, ctx: ^U8); | |
| 190 | +var adr, sp, ip: UINT; q: ^UINT; why: []U8; | |
| 191 | 191 | begin |
| 192 | - q := ^U64(info + 16); (* si_addr *) | |
| 192 | + q := ^UINT(info + 16); (* si_addr *) | |
| 193 | 193 | adr := q^; |
| 194 | - q := ^U64(ctx + 160); (* uc_mcontext's rsp, then rip *) | |
| 194 | + q := ^UINT(ctx + 160); (* uc_mcontext's rsp, then rip *) | |
| 195 | 195 | sp := q[0]; |
| 196 | 196 | ip := q[1]; |
| 197 | 197 | if sig = SigFpe then why := "a division fault"; |
| 198 | 198 | elsif ip < Low then |
| 199 | 199 | why := "a nil procedure"; |
| 200 | - q := ^U64(sp); | |
| 200 | + q := ^UINT(sp); | |
| 201 | 201 | ip := q^ - 1; (* the call, by its return address *) |
| 202 | 202 | elsif adr < Low then why := "a nil pointer"; |
| 203 | 203 | elsif adr - sp + 100000H < 200000H then why := "a stack overflow"; (* within a megabyte of rsp *) |
| @@ -8,8 +8,8 @@ | ||
| 8 | 8 | (* The element at i sinks through s[0..n], a heap with the largest at |
| 9 | 9 | its root, to where it is no smaller than its children, 2i+1 and |
| 10 | 10 | 2i+2. *) |
| 11 | -proc sink(s: []T; i, n: I64); | |
| 12 | -var c: I64; t: T; | |
| 11 | +proc sink(s: []T; i, n: INT); | |
| 12 | +var c: INT; t: T; | |
| 13 | 13 | begin |
| 14 | 14 | c := 2 * i + 1; |
| 15 | 15 | while c < n do |
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | (* s made a heap, then its largest taken, in turn, to the end. *) |
| 25 | 25 | proc sort*(s: []T); |
| 26 | -var i: I64; t: T; | |
| 26 | +var i: INT; t: T; | |
| 27 | 27 | begin |
| 28 | 28 | for i := LEN(s) div 2 - 1 to 0 by -1 do sink(s, i, LEN(s)); end; |
| 29 | 29 | for i := LEN(s) - 1 to 1 by -1 do |
| @@ -7,8 +7,8 @@ | ||
| 7 | 7 | const least = -9223372036854775807 - 1; (* the smallest I64 *) |
| 8 | 8 | |
| 9 | 9 | (* -1, 0 or 1 as a sorts before, with or after b, byte by byte. *) |
| 10 | -proc cmp*(a, b: []U8): I64; | |
| 11 | -var i, n: I64; | |
| 10 | +proc cmp*(a, b: []U8): INT; | |
| 11 | +var i, n: INT; | |
| 12 | 12 | begin |
| 13 | 13 | n := LEN(a); |
| 14 | 14 | if LEN(b) < n then n := LEN(b); end; |
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | |
| 31 | 31 | (* FNV-1a, 64 bits. *) |
| 32 | 32 | proc hash*(s: []U8): U64; |
| 33 | -var h: U64; i: I64; | |
| 33 | +var h: U64; i: INT; | |
| 34 | 34 | begin |
| 35 | 35 | h := 0CBF29CE484222325H; |
| 36 | 36 | for i := 0 to LEN(s) - 1 do |
| @@ -40,8 +40,8 @@ | ||
| 40 | 40 | end; |
| 41 | 41 | |
| 42 | 42 | (* Where sub first starts in s, or -1. *) |
| 43 | -proc find*(s, sub: []U8): I64; | |
| 44 | -var i: I64; | |
| 43 | +proc find*(s, sub: []U8): INT; | |
| 44 | +var i: INT; | |
| 45 | 45 | begin |
| 46 | 46 | for i := 0 to LEN(s) - LEN(sub) do |
| 47 | 47 | if s[i..i + LEN(sub)] = sub then return i; end; |
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | (* c in UTF-8: its bytes, and how many. A number that isn't a |
| 58 | 58 | character, a surrogate or one past 10FFFFH, becomes FFFDH, the |
| 59 | 59 | character that stands for a wrong one. *) |
| 60 | -proc encode*(c: I64): ([4]U8, I64); | |
| 60 | +proc encode*(c: I32): ([4]U8, INT); | |
| 61 | 61 | var b: [4]U8; |
| 62 | 62 | begin |
| 63 | 63 | if (c < 0) or (c > 10FFFFH) or (c >= 0D800H) and (c <= 0DFFFH) then c := 0FFFDH; end; |
| @@ -85,11 +85,11 @@ | ||
| 85 | 85 | if its first byte doesn't start one rightly, being a continuation, |
| 86 | 86 | or followed by too few continuations, or spelling a surrogate or a |
| 87 | 87 | character in more bytes than it needs; 0 and 0 if s is empty. *) |
| 88 | -proc decode*(s: []U8): (I64, I64); | |
| 89 | -var c, n, least, i: I64; | |
| 88 | +proc decode*(s: []U8): (I32, INT); | |
| 89 | +var c, least: I32; n, i: INT; | |
| 90 | 90 | begin |
| 91 | 91 | if LEN(s) = 0 then return 0, 0; end; |
| 92 | - c := I64(s[0]); | |
| 92 | + c := I32(s[0]); | |
| 93 | 93 | if c < 80H then return c, 1; |
| 94 | 94 | elsif c < 0C0H then return 0FFFDH, 1; |
| 95 | 95 | elsif c < 0E0H then n := 2; c := c & 1FH; least := 80H; |
| @@ -100,7 +100,7 @@ | ||
| 100 | 100 | if LEN(s) < n then return 0FFFDH, 1; end; |
| 101 | 101 | for i := 1 to n - 1 do |
| 102 | 102 | if s[i] & 0C0H # 80H then return 0FFFDH, 1; end; |
| 103 | - c := c shl 6 + I64(s[i] & 3FH); | |
| 103 | + c := c shl 6 + I32(s[i] & 3FH); | |
| 104 | 104 | end; |
| 105 | 105 | if (c < least) or (c > 10FFFFH) or (c >= 0D800H) and (c <= 0DFFFH) then return 0FFFDH, 1; end; |
| 106 | 106 | return c, n; |
| @@ -109,7 +109,7 @@ | ||
| 109 | 109 | (* s as a decimal number, with a - or + before it if any, and nothing |
| 110 | 110 | else; false if it isn't one, or an I64 can't hold it. *) |
| 111 | 111 | proc toInt*(s: []U8): (I64, BOOL); |
| 112 | -var n, i, d: I64; neg: BOOL; | |
| 112 | +var n, d: I64; i: INT; neg: BOOL; | |
| 113 | 113 | begin |
| 114 | 114 | neg := (LEN(s) > 0) and (s[0] = '-'); |
| 115 | 115 | if (LEN(s) > 0) and ((s[0] = '-') or (s[0] = '+')) then i := 1; end; |
| @@ -133,7 +133,7 @@ | ||
| 133 | 133 | the lowest: how a file or a message in little-endian order is read, |
| 134 | 134 | whatever the machine's own order. *) |
| 135 | 135 | proc le*(s: []U8): U64; |
| 136 | -var v: U64; i: I64; | |
| 136 | +var v: U64; i: INT; | |
| 137 | 137 | begin |
| 138 | 138 | if LEN(s) > 8 then Rt.stop("Str.le: more than 8 bytes"); end; |
| 139 | 139 | for i := LEN(s) - 1 to 0 by -1 do v := v shl 8 | U64(s[i]); end; |
| @@ -142,7 +142,7 @@ | ||
| 142 | 142 | |
| 143 | 143 | (* As le, the first byte the highest: big-endian, network order. *) |
| 144 | 144 | proc be*(s: []U8): U64; |
| 145 | -var v: U64; i: I64; | |
| 145 | +var v: U64; i: INT; | |
| 146 | 146 | begin |
| 147 | 147 | if LEN(s) > 8 then Rt.stop("Str.be: more than 8 bytes"); end; |
| 148 | 148 | for i := 0 to LEN(s) - 1 do v := v shl 8 | U64(s[i]); end; |
| @@ -152,7 +152,7 @@ | ||
| 152 | 152 | (* v into the bytes of s, at most 8, the lowest first; what doesn't |
| 153 | 153 | fit is left out. *) |
| 154 | 154 | proc putLE*(s: []U8; v: U64); |
| 155 | -var i: I64; | |
| 155 | +var i: INT; | |
| 156 | 156 | begin |
| 157 | 157 | if LEN(s) > 8 then Rt.stop("Str.putLE: more than 8 bytes"); end; |
| 158 | 158 | for i := 0 to LEN(s) - 1 do s[i] := U8(v); v := v shr 8; end; |
| @@ -160,7 +160,7 @@ | ||
| 160 | 160 | |
| 161 | 161 | (* As putLE, the highest first. *) |
| 162 | 162 | proc putBE*(s: []U8; v: U64); |
| 163 | -var i: I64; | |
| 163 | +var i: INT; | |
| 164 | 164 | begin |
| 165 | 165 | if LEN(s) > 8 then Rt.stop("Str.putBE: more than 8 bytes"); end; |
| 166 | 166 | for i := LEN(s) - 1 to 0 by -1 do s[i] := U8(v); v := v shr 8; end; |
| @@ -182,7 +182,7 @@ | ||
| 182 | 182 | end; |
| 183 | 183 | |
| 184 | 184 | proc testUtf8; |
| 185 | -var b: [4]U8; n, c, i: I64; | |
| 185 | +var b: [4]U8; n: INT; c, i: I32; | |
| 186 | 186 | begin |
| 187 | 187 | b, n := encode('a'); |
| 188 | 188 | if (n # 1) or (b[0] # 'a') then Rt.stop("Str.encode: a"); end; |
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | Info* = record |
| 25 | 25 | size*: I64; (* in bytes *) |
| 26 | 26 | mtime*: I64; (* when its contents last changed, in nanoseconds since 1970 *) |
| 27 | - mode*: I64; (* its permission bits, rwxrwxrwx *) | |
| 27 | + mode*: INT; (* its permission bits, rwxrwxrwx *) | |
| 28 | 28 | dir*: BOOL; (* a directory *) |
| 29 | 29 | file*: BOOL; (* a regular file: not a directory, device, pipe or socket *) |
| 30 | 30 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| @@ -32,7 +32,7 @@ | ||
| 32 | 32 | |
| 33 | 33 | (* An open directory: getdents64's records, read a block at a time. *) |
| 34 | 34 | Dir* = record |
| 35 | - fd, pos, len: I64; | |
| 35 | + fd, pos, len: INT; | |
| 36 | 36 | buf: [8192]U8; |
| 37 | 37 | end; |
| 38 | 38 | |
| @@ -43,10 +43,10 @@ | ||
| 43 | 43 | env*: [][]U8; (* NAME=value, each added to this program's environment *) |
| 44 | 44 | onlyEnv*: BOOL; (* env is its whole environment *) |
| 45 | 45 | dir*: []U8; (* its working directory; "" for this program's *) |
| 46 | - fds*: [3]I64; (* its standard input, output and error; 0 for this program's own *) | |
| 47 | - group*: I64; (* the process group it joins: 0 for this program's, -1 a new one it leads *) | |
| 46 | + fds*: [3]INT; (* its standard input, output and error; 0 for this program's own *) | |
| 47 | + group*: INT; (* the process group it joins: 0 for this program's, -1 a new one it leads *) | |
| 48 | 48 | foreground*: BOOL; (* its group takes the terminal on standard input *) |
| 49 | - tty*: I64; (* a pseudo-terminal's fd, to start a session on; 0 for none *) | |
| 49 | + tty*: INT; (* a pseudo-terminal's fd, to start a session on; 0 for none *) | |
| 50 | 50 | end; |
| 51 | 51 | (* How a program that wait waited for changed. *) |
| 52 | 52 | Status* = (running, exited, killed, stopped); |
| @@ -79,11 +79,11 @@ | ||
| 79 | 79 | linked: [4096]U8; (* what readLink gives *) |
| 80 | 80 | saved: Termios; (* the terminal as rawMode found it *) |
| 81 | 81 | caughtSigs: U64; (* the signals catch has blocked, bit n - 1 for signal n *) |
| 82 | - sigFd: I64; (* the signalfd that gives them, once caughtSigs isn't empty *) | |
| 82 | + sigFd: INT; (* the signalfd that gives them, once caughtSigs isn't empty *) | |
| 83 | 83 | |
| 84 | 84 | (* Writes s to the file descriptor fd; the number of bytes written, or |
| 85 | 85 | minus an errno. *) |
| 86 | -proc write*(fd: I64; s: []U8): I64; | |
| 86 | +proc write*(fd: INT; s: []U8): INT; | |
| 87 | 87 | begin |
| 88 | 88 | if LEN(s) = 0 then return 0; end; |
| 89 | 89 | return SYSCALL(1, fd, ADR(s[0]), LEN(s)); |
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | |
| 92 | 92 | (* Reads into buf from fd; the number of bytes read, 0 at the end, or |
| 93 | 93 | minus an errno. *) |
| 94 | -proc read*(fd: I64; buf: []U8): I64; | |
| 94 | +proc read*(fd: INT; buf: []U8): INT; | |
| 95 | 95 | begin |
| 96 | 96 | if LEN(buf) = 0 then return 0; end; |
| 97 | 97 | return SYSCALL(0, fd, ADR(buf[0]), LEN(buf)); |
| @@ -99,7 +99,7 @@ | ||
| 99 | 99 | |
| 100 | 100 | (* path, a C string in buf, or false if it doesn't fit. *) |
| 101 | 101 | proc cstr(path, buf: []U8): BOOL; |
| 102 | -var i: I64; | |
| 102 | +var i: INT; | |
| 103 | 103 | begin |
| 104 | 104 | if LEN(path) >= LEN(buf) then return false; end; |
| 105 | 105 | for i := 0 to LEN(path) - 1 do buf[i] := path[i]; end; |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | (* The file at path, opened as how asks: its file descriptor, or minus |
| 127 | 127 | an errno. A file it creates is readable by all, writable by its |
| 128 | 128 | owner. *) |
| 129 | -proc open*(path: []U8; how: Accesses): I64; | |
| 129 | +proc open*(path: []U8; how: Accesses): INT; | |
| 130 | 130 | var buf: [4096]U8; |
| 131 | 131 | begin |
| 132 | 132 | if not cstr(path, buf) then return -36; end; (* ENAMETOOLONG *) |
| @@ -134,55 +134,55 @@ | ||
| 134 | 134 | end; |
| 135 | 135 | |
| 136 | 136 | (* The file at path, opened for reading. *) |
| 137 | -proc openRead*(path: []U8): I64; | |
| 137 | +proc openRead*(path: []U8): INT; | |
| 138 | 138 | begin |
| 139 | 139 | return open(path, {reading}); |
| 140 | 140 | end; |
| 141 | 141 | |
| 142 | 142 | (* The file at path, made empty or new, opened for writing. *) |
| 143 | -proc create*(path: []U8): I64; | |
| 143 | +proc create*(path: []U8): INT; | |
| 144 | 144 | begin |
| 145 | 145 | return open(path, {writing, creating, truncating}); |
| 146 | 146 | end; |
| 147 | 147 | |
| 148 | 148 | (* Moves fd to pos from the start of its file, or from the end if |
| 149 | 149 | fromEnd: the new position, or minus an errno. *) |
| 150 | -proc seek*(fd, pos: I64; fromEnd: BOOL): I64; | |
| 150 | +proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; | |
| 151 | 151 | begin |
| 152 | 152 | if fromEnd then return SYSCALL(8, fd, pos, 2); end; (* lseek, SEEK_END *) |
| 153 | 153 | return SYSCALL(8, fd, pos, 0); (* SEEK_SET *) |
| 154 | 154 | end; |
| 155 | 155 | |
| 156 | -proc close*(fd: I64); | |
| 156 | +proc close*(fd: INT); | |
| 157 | 157 | begin |
| 158 | 158 | SYSCALL(3, fd); |
| 159 | 159 | end; |
| 160 | 160 | |
| 161 | 161 | (* size bytes of fresh, zeroed memory from the system, a multiple of |
| 162 | 162 | pages, or nil. *) |
| 163 | -proc mmap*(size: I64): ^U8; | |
| 164 | -var p: I64; | |
| 163 | +proc mmap*(size: INT): ^U8; | |
| 164 | +var p: INT; | |
| 165 | 165 | begin |
| 166 | 166 | p := SYSCALL(9, 0, size, 3, 22H, -1, 0); (* read, write; private, anonymous *) |
| 167 | 167 | if p < 0 then return nil; end; |
| 168 | 168 | return ^U8(p); |
| 169 | 169 | end; |
| 170 | 170 | |
| 171 | -proc munmap*(p: ^U8; size: I64); | |
| 171 | +proc munmap*(p: ^U8; size: INT); | |
| 172 | 172 | begin |
| 173 | 173 | SYSCALL(11, p, size); |
| 174 | 174 | end; |
| 175 | 175 | |
| 176 | 176 | (* Whether the file descriptor fd is a terminal: whether it has a |
| 177 | 177 | terminal's settings to read (ioctl TCGETS). *) |
| 178 | -proc isTerminal*(fd: I64): BOOL; | |
| 179 | -var t: [8]I64; (* struct termios: 60 bytes *) | |
| 178 | +proc isTerminal*(fd: INT): BOOL; | |
| 179 | +var t: [8]INT; (* struct termios: 60 bytes *) | |
| 180 | 180 | begin |
| 181 | 181 | return SYSCALL(16, fd, 5401H, ADR(t)) = 0; |
| 182 | 182 | end; |
| 183 | 183 | |
| 184 | 184 | (* Renames old to new, replacing what new names: 0, or minus an errno. *) |
| 185 | -proc rename*(old, new: []U8): I64; | |
| 185 | +proc rename*(old, new: []U8): INT; | |
| 186 | 186 | var a, b: [4096]U8; |
| 187 | 187 | begin |
| 188 | 188 | if not cstr(old, a) or not cstr(new, b) then return -36; end; |
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | end; |
| 191 | 191 | |
| 192 | 192 | (* Removes the file at path; not a directory. *) |
| 193 | -proc remove*(path: []U8): I64; | |
| 193 | +proc remove*(path: []U8): INT; | |
| 194 | 194 | var a: [4096]U8; |
| 195 | 195 | begin |
| 196 | 196 | if not cstr(path, a) then return -36; end; |
| @@ -198,7 +198,7 @@ | ||
| 198 | 198 | end; |
| 199 | 199 | |
| 200 | 200 | (* Makes a directory at path, readable by all, writable by its owner. *) |
| 201 | -proc makeDir*(path: []U8): I64; | |
| 201 | +proc makeDir*(path: []U8): INT; | |
| 202 | 202 | var a: [4096]U8; |
| 203 | 203 | begin |
| 204 | 204 | if not cstr(path, a) then return -36; end; |
| @@ -206,7 +206,7 @@ | ||
| 206 | 206 | end; |
| 207 | 207 | |
| 208 | 208 | (* Removes the directory at path, which must be empty. *) |
| 209 | -proc removeDir*(path: []U8): I64; | |
| 209 | +proc removeDir*(path: []U8): INT; | |
| 210 | 210 | var a: [4096]U8; |
| 211 | 211 | begin |
| 212 | 212 | if not cstr(path, a) then return -36; end; |
| @@ -214,7 +214,7 @@ | ||
| 214 | 214 | end; |
| 215 | 215 | |
| 216 | 216 | (* Sets the permission bits of what path names. *) |
| 217 | -proc chmod*(path: []U8; mode: I64): I64; | |
| 217 | +proc chmod*(path: []U8; mode: INT): INT; | |
| 218 | 218 | var a: [4096]U8; |
| 219 | 219 | begin |
| 220 | 220 | if not cstr(path, a) then return -36; end; |
| @@ -222,7 +222,7 @@ | ||
| 222 | 222 | end; |
| 223 | 223 | |
| 224 | 224 | (* Makes path a symbolic link to target. *) |
| 225 | -proc symlink*(target, path: []U8): I64; | |
| 225 | +proc symlink*(target, path: []U8): INT; | |
| 226 | 226 | var a, b: [4096]U8; |
| 227 | 227 | begin |
| 228 | 228 | if not cstr(target, a) or not cstr(path, b) then return -36; end; |
| @@ -231,8 +231,8 @@ | ||
| 231 | 231 | |
| 232 | 232 | (* What the symbolic link at path names, good until the next call; and |
| 233 | 233 | 0, or minus an errno. *) |
| 234 | -proc readLink*(path: []U8): ([]U8, I64); | |
| 235 | -var a: [4096]U8; n: I64; | |
| 234 | +proc readLink*(path: []U8): ([]U8, INT); | |
| 235 | +var a: [4096]U8; n: INT; | |
| 236 | 236 | begin |
| 237 | 237 | if not cstr(path, a) then return "", -36; end; |
| 238 | 238 | n := SYSCALL(89, ADR(a), ADR(linked), LEN(linked)); (* readlink *) |
| @@ -244,8 +244,8 @@ | ||
| 244 | 244 | (* The size of what path names, whether it is a directory or a regular |
| 245 | 245 | file, following a symbolic link, and whether path is one; and 0, or |
| 246 | 246 | minus an errno. *) |
| 247 | -proc info*(path: []U8): (Info, I64); | |
| 248 | -var a: [4096]U8; st: [18]I64; i: Info; r: I64; (* struct stat: 144 bytes *) | |
| 247 | +proc info*(path: []U8): (Info, INT); | |
| 248 | +var a: [4096]U8; st: [18]INT; i: Info; r: INT; (* struct stat: 144 bytes *) | |
| 249 | 249 | begin |
| 250 | 250 | if not cstr(path, a) then return i, -36; end; |
| 251 | 251 | r := SYSCALL(6, ADR(a), ADR(st)); (* lstat *) |
| @@ -262,7 +262,7 @@ | ||
| 262 | 262 | end; |
| 263 | 263 | |
| 264 | 264 | (* Opens the directory at path, for nextEntry. *) |
| 265 | -proc openDir*(d: ^Dir; path: []U8): I64; | |
| 265 | +proc openDir*(d: ^Dir; path: []U8): INT; | |
| 266 | 266 | var a: [4096]U8; |
| 267 | 267 | begin |
| 268 | 268 | d^.pos := 0; |
| @@ -276,7 +276,7 @@ | ||
| 276 | 276 | (* The next name in the directory, good until the next call, but . and |
| 277 | 277 | .., in no order; false at the end. *) |
| 278 | 278 | proc nextEntry*(d: ^Dir): ([]U8, BOOL); |
| 279 | -var n, at: I64; | |
| 279 | +var n, at: INT; | |
| 280 | 280 | begin |
| 281 | 281 | while true do |
| 282 | 282 | if d^.pos >= d^.len then |
| @@ -289,7 +289,7 @@ | ||
| 289 | 289 | at := d^.pos + 19; |
| 290 | 290 | n := 0; |
| 291 | 291 | while d^.buf[at + n] # 0 do INC(n); end; |
| 292 | - INC(d^.pos, I64(d^.buf[d^.pos + 16]) + I64(d^.buf[d^.pos + 17]) * 256); | |
| 292 | + INC(d^.pos, INT(d^.buf[d^.pos + 16]) + INT(d^.buf[d^.pos + 17]) * 256); | |
| 293 | 293 | if (d^.buf[at..at + n] # ".") and (d^.buf[at..at + n] # "..") then |
| 294 | 294 | return d^.buf[at..at + n], true; |
| 295 | 295 | end; |
| @@ -305,7 +305,7 @@ | ||
| 305 | 305 | (* Puts the terminal on fd into raw mode: no echo, no lines, no signals, |
| 306 | 306 | no flow control, no CR to NL, no NL to CR NL; false if fd isn't a |
| 307 | 307 | terminal. *) |
| 308 | -proc rawMode*(fd: I64): BOOL; | |
| 308 | +proc rawMode*(fd: INT): BOOL; | |
| 309 | 309 | var t: Termios; |
| 310 | 310 | begin |
| 311 | 311 | if SYSCALL(16, fd, 5401H, ADR(saved)) # 0 then return false; end; (* TCGETS *) |
| @@ -320,25 +320,25 @@ | ||
| 320 | 320 | end; |
| 321 | 321 | |
| 322 | 322 | (* The terminal on fd as rawMode found it. *) |
| 323 | -proc restoreMode*(fd: I64); | |
| 323 | +proc restoreMode*(fd: INT); | |
| 324 | 324 | begin |
| 325 | 325 | SYSCALL(16, fd, 5402H, ADR(saved)); |
| 326 | 326 | end; |
| 327 | 327 | |
| 328 | 328 | (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't |
| 329 | 329 | say. *) |
| 330 | -proc termSize*(fd: I64): (I64, I64); | |
| 330 | +proc termSize*(fd: INT): (INT, INT); | |
| 331 | 331 | var w: Winsize; |
| 332 | 332 | begin |
| 333 | 333 | if (SYSCALL(16, fd, 5413H, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then (* TIOCGWINSZ *) |
| 334 | 334 | return 80, 24; |
| 335 | 335 | end; |
| 336 | - return I64(w.cols), I64(w.rows); | |
| 336 | + return INT(w.cols), INT(w.rows); | |
| 337 | 337 | end; |
| 338 | 338 | |
| 339 | 339 | (* Whether fd has something to read within ms milliseconds; ms < 0 |
| 340 | 340 | waits as long as it takes. *) |
| 341 | -proc ready*(fd, ms: I64): BOOL; | |
| 341 | +proc ready*(fd, ms: INT): BOOL; | |
| 342 | 342 | var p: Pollfd; |
| 343 | 343 | begin |
| 344 | 344 | p := {fd: I32(fd), events: 1}; (* POLLIN *) |
| @@ -363,17 +363,17 @@ | ||
| 363 | 363 | end; |
| 364 | 364 | |
| 365 | 365 | (* Waits ms milliseconds. *) |
| 366 | -proc sleep*(ms: I64); | |
| 366 | +proc sleep*(ms: INT); | |
| 367 | 367 | var t: Timespec; at: I64; |
| 368 | 368 | begin |
| 369 | - at := clock() + ms * 1000000; | |
| 369 | + at := clock() + I64(ms) * 1000000; | |
| 370 | 370 | t := {sec: at div 1000000000, nsec: at mod 1000000000}; |
| 371 | 371 | repeat until SYSCALL(230, 1, 1, ADR(t), 0) # -4; (* clock_nanosleep until t, again after EINTR *) |
| 372 | 372 | end; |
| 373 | 373 | |
| 374 | 374 | (* Fills b with random bytes, from the kernel. *) |
| 375 | 375 | proc random*(b: []U8); |
| 376 | -var n, r: I64; | |
| 376 | +var n, r: INT; | |
| 377 | 377 | begin |
| 378 | 378 | n := 0; |
| 379 | 379 | while n < LEN(b) do (* a signal may cut it short *) |
| @@ -386,8 +386,8 @@ | ||
| 386 | 386 | bytes, or, if serving, bound to it and taking connections: its file |
| 387 | 387 | descriptor, or minus an errno. It is closed in a program exec |
| 388 | 388 | starts. *) |
| 389 | -proc socket(family, kind: I64; a: ^U8; size: I64; serving: BOOL): I64; | |
| 390 | -var fd, r, one: I64; | |
| 389 | +proc socket(family, kind: INT; a: ^U8; size: INT; serving: BOOL): INT; | |
| 390 | +var fd, r, one: INT; | |
| 391 | 391 | begin |
| 392 | 392 | fd := SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *) |
| 393 | 393 | if fd < 0 then return fd; end; |
| @@ -405,7 +405,7 @@ | ||
| 405 | 405 | |
| 406 | 406 | (* path as a Unix socket's address in a, or false if it is too long. *) |
| 407 | 407 | proc unixAddr(path: []U8; a: ^SockaddrUn): BOOL; |
| 408 | -var i: I64; | |
| 408 | +var i: INT; | |
| 409 | 409 | begin |
| 410 | 410 | if LEN(path) >= LEN(a^.path) then return false; end; |
| 411 | 411 | a^.family := 1; (* AF_UNIX *) |
| @@ -414,7 +414,7 @@ | ||
| 414 | 414 | end; |
| 415 | 415 | |
| 416 | 416 | (* A stream socket connected to the Unix socket at path. *) |
| 417 | -proc connect*(path: []U8): I64; | |
| 417 | +proc connect*(path: []U8): INT; | |
| 418 | 418 | var a: SockaddrUn; |
| 419 | 419 | begin |
| 420 | 420 | if not unixAddr(path, ADR(a)) then return -36; end; (* ENAMETOOLONG *) |
| @@ -423,7 +423,7 @@ | ||
| 423 | 423 | |
| 424 | 424 | (* A stream socket made at path, which must not be there yet, taking |
| 425 | 425 | connections. *) |
| 426 | -proc listen*(path: []U8): I64; | |
| 426 | +proc listen*(path: []U8): INT; | |
| 427 | 427 | var a: SockaddrUn; |
| 428 | 428 | begin |
| 429 | 429 | if not unixAddr(path, ADR(a)) then return -36; end; |
| @@ -431,18 +431,18 @@ | ||
| 431 | 431 | end; |
| 432 | 432 | |
| 433 | 433 | (* The value of the hexadecimal digit c, or -1 if it isn't one. *) |
| 434 | -proc hexDigit(c: U8): I64; | |
| 434 | +proc hexDigit(c: U8): INT; | |
| 435 | 435 | begin |
| 436 | - if (c >= '0') and (c <= '9') then return I64(c - '0'); end; | |
| 437 | - if (c >= 'a') and (c <= 'f') then return I64(c - 'a') + 10; end; | |
| 438 | - if (c >= 'A') and (c <= 'F') then return I64(c - 'A') + 10; end; | |
| 436 | + if (c >= '0') and (c <= '9') then return INT(c - '0'); end; | |
| 437 | + if (c >= 'a') and (c <= 'f') then return INT(c - 'a') + 10; end; | |
| 438 | + if (c >= 'A') and (c <= 'F') then return INT(c - 'A') + 10; end; | |
| 439 | 439 | return -1; |
| 440 | 440 | end; |
| 441 | 441 | |
| 442 | 442 | (* The IPv4 address s, four numbers and dots, in out's 4 bytes, or false |
| 443 | 443 | if it isn't one. *) |
| 444 | 444 | proc ipv4(s, out: []U8): BOOL; |
| 445 | -var b: [4]U8; n, i, v, d: I64; | |
| 445 | +var b: [4]U8; n, i, v, d: INT; | |
| 446 | 446 | begin |
| 447 | 447 | i := 0; |
| 448 | 448 | for n := 0 to 3 do |
| @@ -453,7 +453,7 @@ | ||
| 453 | 453 | v := 0; |
| 454 | 454 | d := 0; |
| 455 | 455 | while (i < LEN(s)) and (d < 3) and (s[i] >= '0') and (s[i] <= '9') do |
| 456 | - v := v * 10 + I64(s[i] - '0'); | |
| 456 | + v := v * 10 + INT(s[i] - '0'); | |
| 457 | 457 | INC(i); |
| 458 | 458 | INC(d); |
| 459 | 459 | end; |
| @@ -469,7 +469,7 @@ | ||
| 469 | 469 | standing for groups of zeros, in out's 16 bytes, or false if it isn't |
| 470 | 470 | one. *) |
| 471 | 471 | proc ipv6(s, out: []U8): BOOL; |
| 472 | -var g: [8]I64; n, gap, i, v, d, k: I64; | |
| 472 | +var g: [8]INT; n, gap, i, v, d, k: INT; | |
| 473 | 473 | begin |
| 474 | 474 | n := 0; |
| 475 | 475 | gap := -1; (* the group the :: is before *) |
| @@ -512,7 +512,7 @@ | ||
| 512 | 512 | (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size |
| 513 | 513 | of its struct sockaddr_in or sockaddr_in6, or 0 if either is |
| 514 | 514 | wrong. *) |
| 515 | -proc inetAddr(addr: []U8; port: I64; a: ^Sockaddr): I64; | |
| 515 | +proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT; | |
| 516 | 516 | begin |
| 517 | 517 | if (port < 0) or (port > 65535) then return 0; end; |
| 518 | 518 | a^.port[0] := U8(port shr 8); (* in the network's order, the high byte first *) |
| @@ -524,37 +524,37 @@ | ||
| 524 | 524 | |
| 525 | 525 | (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL) |
| 526 | 526 | if they are wrong. *) |
| 527 | -proc inet(addr: []U8; port, kind: I64; serving: BOOL): I64; | |
| 528 | -var a: Sockaddr; size: I64; | |
| 527 | +proc inet(addr: []U8; port, kind: INT; serving: BOOL): INT; | |
| 528 | +var a: Sockaddr; size: INT; | |
| 529 | 529 | begin |
| 530 | 530 | size := inetAddr(addr, port, ADR(a)); |
| 531 | 531 | if size = 0 then return -22; end; |
| 532 | - return socket(I64(a.family), kind, ^U8(ADR(a)), size, serving); | |
| 532 | + return socket(INT(a.family), kind, ^U8(ADR(a)), size, serving); | |
| 533 | 533 | end; |
| 534 | 534 | |
| 535 | 535 | (* A stream socket connected to port at addr, an IPv4 or IPv6 address |
| 536 | 536 | as numbers. *) |
| 537 | -proc connectTcp*(addr: []U8; port: I64): I64; | |
| 537 | +proc connectTcp*(addr: []U8; port: INT): INT; | |
| 538 | 538 | begin |
| 539 | 539 | return inet(addr, port, 1, false); (* SOCK_STREAM *) |
| 540 | 540 | end; |
| 541 | 541 | |
| 542 | 542 | (* A socket of datagrams to and from port at addr. *) |
| 543 | -proc connectUdp*(addr: []U8; port: I64): I64; | |
| 543 | +proc connectUdp*(addr: []U8; port: INT): INT; | |
| 544 | 544 | begin |
| 545 | 545 | return inet(addr, port, 2, false); (* SOCK_DGRAM *) |
| 546 | 546 | end; |
| 547 | 547 | |
| 548 | 548 | (* A stream socket taking connections on port at addr; "0.0.0.0" or |
| 549 | 549 | "::" is every address the machine has. *) |
| 550 | -proc listenTcp*(addr: []U8; port: I64): I64; | |
| 550 | +proc listenTcp*(addr: []U8; port: INT): INT; | |
| 551 | 551 | begin |
| 552 | 552 | return inet(addr, port, 1, true); |
| 553 | 553 | end; |
| 554 | 554 | |
| 555 | 555 | (* The next connection to the socket fd, waiting for one: a socket of |
| 556 | 556 | its own, closed in a program exec starts; or minus an errno. *) |
| 557 | -proc accept*(fd: I64): I64; | |
| 557 | +proc accept*(fd: INT): INT; | |
| 558 | 558 | begin |
| 559 | 559 | return SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *) |
| 560 | 560 | end; |
| @@ -562,7 +562,7 @@ | ||
| 562 | 562 | (* Writes s to the socket fd, as write does, but returns -32 (EPIPE) |
| 563 | 563 | where write would stop the program with SIGPIPE: when the other end |
| 564 | 564 | has closed it. *) |
| 565 | -proc send*(fd: I64; s: []U8): I64; | |
| 565 | +proc send*(fd: INT; s: []U8): INT; | |
| 566 | 566 | begin |
| 567 | 567 | if LEN(s) = 0 then return 0; end; |
| 568 | 568 | return SYSCALL(44, fd, ADR(s[0]), LEN(s), 4000H, 0, 0); (* sendto, MSG_NOSIGNAL, no address *) |
| @@ -571,8 +571,8 @@ | ||
| 571 | 571 | (* The first of fds that has something to read within ms milliseconds, |
| 572 | 572 | or that has reached its end or failed, so that a read won't wait; -1 |
| 573 | 573 | if none has. ms < 0 waits as long as it takes. At most 64 fds. *) |
| 574 | -proc readyOf*(fds: []I64; ms: I64): I64; | |
| 575 | -var p: [64]Pollfd; n, i: I64; | |
| 574 | +proc readyOf*(fds: []INT; ms: INT): INT; | |
| 575 | +var p: [64]Pollfd; n, i: INT; | |
| 576 | 576 | begin |
| 577 | 577 | n := LEN(fds); |
| 578 | 578 | if n > LEN(p) then n := LEN(p); end; |
| @@ -587,7 +587,7 @@ | ||
| 587 | 587 | (* The value of the environment variable name; "" if it isn't set. The |
| 588 | 588 | environment follows the arguments and their nil. *) |
| 589 | 589 | proc env*(name: []U8): []U8; |
| 590 | -var e: ^^U8; s: ^U8; i, n, m: I64; | |
| 590 | +var e: ^^U8; s: ^U8; i, n, m: INT; | |
| 591 | 591 | begin |
| 592 | 592 | e := ARGV() + (ARGC() + 1); |
| 593 | 593 | i := 0; |
| @@ -607,8 +607,8 @@ | ||
| 607 | 607 | |
| 608 | 608 | (* The working directory, good until the next call; and 0, or minus an |
| 609 | 609 | errno. *) |
| 610 | -proc workDir*: ([]U8, I64); | |
| 611 | -var r: I64; | |
| 610 | +proc workDir*: ([]U8, INT); | |
| 611 | +var r: INT; | |
| 612 | 612 | begin |
| 613 | 613 | r := SYSCALL(79, ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *) |
| 614 | 614 | if r < 0 then return "", r; end; |
| @@ -616,7 +616,7 @@ | ||
| 616 | 616 | end; |
| 617 | 617 | |
| 618 | 618 | (* Makes path the working directory. *) |
| 619 | -proc setWorkDir*(path: []U8): I64; | |
| 619 | +proc setWorkDir*(path: []U8): INT; | |
| 620 | 620 | var a: [4096]U8; |
| 621 | 621 | begin |
| 622 | 622 | if not cstr(path, a) then return -36; end; |
| @@ -626,8 +626,8 @@ | ||
| 626 | 626 | (* A pseudo-terminal: the file descriptor of its controlling side, or |
| 627 | 627 | minus an errno. Its other side, the terminal its programs run on, is |
| 628 | 628 | unlocked, for spawn to open. *) |
| 629 | -proc openPty*: I64; | |
| 630 | -var a: [4096]U8; fd, unlock: I64; | |
| 629 | +proc openPty*: INT; | |
| 630 | +var a: [4096]U8; fd, unlock: INT; | |
| 631 | 631 | begin |
| 632 | 632 | cstr("/dev/ptmx", a); |
| 633 | 633 | fd := SYSCALL(2, ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *) |
| @@ -642,7 +642,7 @@ | ||
| 642 | 642 | |
| 643 | 643 | (* Tells the terminal of the pseudo-terminal fd that it has cols |
| 644 | 644 | columns and rows rows: 0, or minus an errno. *) |
| 645 | -proc setTermSize*(fd, cols, rows: I64): I64; | |
| 645 | +proc setTermSize*(fd, cols, rows: INT): INT; | |
| 646 | 646 | var w: Winsize; |
| 647 | 647 | begin |
| 648 | 648 | w := {rows: U16(rows), cols: U16(cols)}; |
| @@ -651,7 +651,7 @@ | ||
| 651 | 651 | |
| 652 | 652 | (* Copies s and a zero to at: the byte after them. *) |
| 653 | 653 | proc put(s: []U8; at: ^U8): ^U8; |
| 654 | -var i: I64; | |
| 654 | +var i: INT; | |
| 655 | 655 | begin |
| 656 | 656 | for i := 0 to LEN(s) - 1 do at[i] := s[i]; end; |
| 657 | 657 | at[LEN(s)] := 0; |
| @@ -661,7 +661,7 @@ | ||
| 661 | 661 | (* Whether the NAME=value s, a C string, names a variable that one of |
| 662 | 662 | env gives. *) |
| 663 | 663 | proc replaced(s: ^U8; env: [][]U8): BOOL; |
| 664 | -var i, n: I64; | |
| 664 | +var i, n: INT; | |
| 665 | 665 | begin |
| 666 | 666 | for i := 0 to LEN(env) - 1 do |
| 667 | 667 | n := 0; |
| @@ -675,8 +675,8 @@ | ||
| 675 | 675 | strings and a nil, then the environment old with each NAME=value of |
| 676 | 676 | env in place of its variable or added, and a nil; or nil. The |
| 677 | 677 | environment follows the arguments. *) |
| 678 | -proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, I64); | |
| 679 | -var p: ^^U8; s: ^U8; size, n, i, k: I64; | |
| 678 | +proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, INT); | |
| 679 | +var p: ^^U8; s: ^U8; size, n, i, k: INT; | |
| 680 | 680 | begin |
| 681 | 681 | n := 0; |
| 682 | 682 | while old[n] # nil do INC(n); end; |
| @@ -700,30 +700,30 @@ | ||
| 700 | 700 | |
| 701 | 701 | (* A pipe: the fd to read and the fd to write, both closed in a program |
| 702 | 702 | exec starts; or minus an errno and -1. *) |
| 703 | -proc pipe*: (I64, I64); | |
| 704 | -var fds: [2]I32; r: I64; | |
| 703 | +proc pipe*: (INT, INT); | |
| 704 | +var fds: [2]I32; r: INT; | |
| 705 | 705 | begin |
| 706 | 706 | r := SYSCALL(293, ADR(fds), 80000H); (* pipe2, O_CLOEXEC *) |
| 707 | 707 | if r < 0 then return r, -1; end; |
| 708 | - return I64(fds[0]), I64(fds[1]); | |
| 708 | + return INT(fds[0]), INT(fds[1]); | |
| 709 | 709 | end; |
| 710 | 710 | |
| 711 | 711 | (* This program's process id. *) |
| 712 | -proc pid*: I64; | |
| 712 | +proc pid*: INT; | |
| 713 | 713 | begin |
| 714 | 714 | return SYSCALL(39); (* getpid *) |
| 715 | 715 | end; |
| 716 | 716 | |
| 717 | 717 | (* Moves the program pid, or this one if pid is 0, to the process group |
| 718 | 718 | group, or to a new one it leads if group is 0. *) |
| 719 | -proc setGroup*(pid, group: I64): I64; | |
| 719 | +proc setGroup*(pid, group: INT): INT; | |
| 720 | 720 | begin |
| 721 | 721 | return SYSCALL(109, pid, group); (* setpgid *) |
| 722 | 722 | end; |
| 723 | 723 | |
| 724 | 724 | (* Gives the keys of the terminal on fd, and its signals, to the process |
| 725 | 725 | group group. *) |
| 726 | -proc foreground*(fd, group: I64): I64; | |
| 726 | +proc foreground*(fd, group: INT): INT; | |
| 727 | 727 | var g: I32; |
| 728 | 728 | begin |
| 729 | 729 | g := I32(group); |
| @@ -732,22 +732,22 @@ | ||
| 732 | 732 | |
| 733 | 733 | (* The process group the terminal on fd gives its keys to, or minus an |
| 734 | 734 | errno. *) |
| 735 | -proc foregroundOf*(fd: I64): I64; | |
| 736 | -var g: I32; r: I64; | |
| 735 | +proc foregroundOf*(fd: INT): INT; | |
| 736 | +var g: I32; r: INT; | |
| 737 | 737 | begin |
| 738 | 738 | r := SYSCALL(16, fd, 540FH, ADR(g)); (* TIOCGPGRP *) |
| 739 | 739 | if r < 0 then return r; end; |
| 740 | - return I64(g); | |
| 740 | + return INT(g); | |
| 741 | 741 | end; |
| 742 | 742 | |
| 743 | 743 | (* Starts the program p describes: its process id, or minus an errno. |
| 744 | 744 | A program that can't be started ends with status 127. Every signal |
| 745 | 745 | is blocked from the fork until the program has its own: its group, |
| 746 | 746 | its terminal's foreground, and signals as they are at first. *) |
| 747 | -proc spawn*(p: Program): I64; | |
| 747 | +proc spawn*(p: Program): INT; | |
| 748 | 748 | var |
| 749 | 749 | a, dir: [4096]U8; name: [32]U8; dfl: [4]U64; (* struct sigaction: SIG_DFL *) |
| 750 | - argv: ^^U8; none: ^U8; all, old, empty: U64; size, pid, n, i, fd, g: I64; | |
| 750 | + argv: ^^U8; none: ^U8; all, old, empty: U64; size, pid, n, i, fd, g: INT; | |
| 751 | 751 | begin |
| 752 | 752 | if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| 753 | 753 | if p.tty # 0 then |
| @@ -808,21 +808,21 @@ | ||
| 808 | 808 | its exit status; killed or stopped, with the signal's number. Without |
| 809 | 809 | block it doesn't wait: 0 and running if none has changed. Minus an |
| 810 | 810 | errno, and running, if there is none to wait for. *) |
| 811 | -proc wait*(pid: I64; block: BOOL): (I64, Status, I64); | |
| 812 | -var status: I32; r, options: I64; | |
| 811 | +proc wait*(pid: INT; block: BOOL): (INT, Status, INT); | |
| 812 | +var status: I32; r, options: INT; | |
| 813 | 813 | begin |
| 814 | 814 | options := 3; (* WNOHANG, WUNTRACED *) |
| 815 | 815 | if block then options := 2; end; |
| 816 | 816 | r := SYSCALL(61, pid, ADR(status), options, 0); (* wait4 *) |
| 817 | 817 | if r <= 0 then return r, running, 0; end; |
| 818 | - if status & 7FH = 0 then return r, exited, I64(status) shr 8 & 0FFH; end; | |
| 819 | - if status & 0FFH = 7FH then return r, stopped, I64(status) shr 8 & 0FFH; end; | |
| 820 | - return r, killed, I64(status) & 7FH; | |
| 818 | + if status & 7FH = 0 then return r, exited, INT(status) shr 8 & 0FFH; end; | |
| 819 | + if status & 0FFH = 7FH then return r, stopped, INT(status) shr 8 & 0FFH; end; | |
| 820 | + return r, killed, INT(status) & 7FH; | |
| 821 | 821 | end; |
| 822 | 822 | |
| 823 | 823 | (* Sends the program pid, or the group -pid, the signal: 0, or minus an |
| 824 | 824 | errno. *) |
| 825 | -proc kill*(pid, signal: I64): I64; | |
| 825 | +proc kill*(pid, signal: INT): INT; | |
| 826 | 826 | begin |
| 827 | 827 | return SYSCALL(62, pid, signal); |
| 828 | 828 | end; |
| @@ -831,8 +831,8 @@ | ||
| 831 | 831 | they would, and gives them on an fd, which a later catch adds to and |
| 832 | 832 | gives again; or minus an errno. Only the thread that catches them |
| 833 | 833 | blocks them, and threads it starts later. *) |
| 834 | -proc catch*(sigs: []I64): I64; | |
| 835 | -var m: U64; i, fd: I64; | |
| 834 | +proc catch*(sigs: []INT): INT; | |
| 835 | +var m: U64; i, fd: INT; | |
| 836 | 836 | begin |
| 837 | 837 | m := caughtSigs; |
| 838 | 838 | for i := 0 to LEN(sigs) - 1 do |
| @@ -853,16 +853,16 @@ | ||
| 853 | 853 | end; |
| 854 | 854 | |
| 855 | 855 | (* The next signal catch's fd has, or 0 if none is waiting. *) |
| 856 | -proc caught*(fd: I64): I64; | |
| 856 | +proc caught*(fd: INT): INT; | |
| 857 | 857 | var info: [128]U8; (* struct signalfd_siginfo: the number first, little-endian, below 65 *) |
| 858 | 858 | begin |
| 859 | 859 | if read(fd, info) # 128 then return 0; end; |
| 860 | - return I64(info[0]); | |
| 860 | + return INT(info[0]); | |
| 861 | 861 | end; |
| 862 | 862 | |
| 863 | 863 | (* Makes the signal sig do nothing, or, if not yes, what it does at |
| 864 | 864 | first: 0, or minus an errno. *) |
| 865 | -proc ignore*(sig: I64; yes: BOOL): I64; | |
| 865 | +proc ignore*(sig: INT; yes: BOOL): INT; | |
| 866 | 866 | var act: [4]U64; (* struct sigaction: its handler, SIG_IGN or SIG_DFL, first *) |
| 867 | 867 | begin |
| 868 | 868 | if yes then act[0] := 1; end; |
| @@ -876,7 +876,7 @@ | ||
| 876 | 876 | end; |
| 877 | 877 | |
| 878 | 878 | (* Ends the program, at once, with status. *) |
| 879 | -proc exit*(status: I64); | |
| 879 | +proc exit*(status: INT); | |
| 880 | 880 | begin |
| 881 | 881 | SYSCALL(231, status); |
| 882 | 882 | end; |
| @@ -890,7 +890,7 @@ | ||
| 890 | 890 | one is sent; and a program starts with them neither caught nor |
| 891 | 891 | ignored. *) |
| 892 | 892 | proc testPrograms; |
| 893 | -var pty, child, n, m, r, w, sigs, c: I64; st: Status; buf: [64]U8; | |
| 893 | +var pty, child, n, m, r, w, sigs, c: INT; st: Status; buf: [64]U8; | |
| 894 | 894 | begin |
| 895 | 895 | pty := openPty(); |
| 896 | 896 | if (pty < 0) or (setTermSize(pty, 100, 30) # 0) then exit(2); end; |
| @@ -960,7 +960,7 @@ | ||
| 960 | 960 | sees; addresses read and refused; a TCP connection on the loopback; |
| 961 | 961 | and a datagram to a port where no one listens, refused. *) |
| 962 | 962 | proc testNet; |
| 963 | -var t, l, c, a, u: I64; x, y: [16]U8; s, s6: Sockaddr; | |
| 963 | +var t: I64; l, c, a, u: INT; x, y: [16]U8; s, s6: Sockaddr; | |
| 964 | 964 | begin |
| 965 | 965 | t := clock(); |
| 966 | 966 | sleep(20); |
| @@ -1001,7 +1001,7 @@ | ||
| 1001 | 1001 | directory made, listed and emptied; no terminal; a socket, sent to |
| 1002 | 1002 | after its end; programs; time and the network. *) |
| 1003 | 1003 | proc main*; |
| 1004 | -var fd, n, err, w, h, l, c, a: I64; buf: [16]U8; p: ^U8; i: Info; d: Dir; name: []U8; ok: BOOL; | |
| 1004 | +var fd, n, err, w, h, l, c, a: INT; buf: [16]U8; p: ^U8; i: Info; d: Dir; name: []U8; ok: BOOL; | |
| 1005 | 1005 | begin |
| 1006 | 1006 | fd := create("/tmp/raz-sys-test"); |
| 1007 | 1007 | if fd < 0 then exit(2); end; |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | Info* = record |
| 38 | 38 | size*: I64; (* in bytes *) |
| 39 | 39 | mtime*: I64; (* when its contents last changed, in nanoseconds since 1970 *) |
| 40 | - mode*: I64; (* its permission bits, rwxrwxrwx *) | |
| 40 | + mode*: INT; (* its permission bits, rwxrwxrwx *) | |
| 41 | 41 | dir*: BOOL; (* a directory *) |
| 42 | 42 | file*: BOOL; (* a regular file: not a directory, device, pipe or socket *) |
| 43 | 43 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| @@ -55,10 +55,10 @@ | ||
| 55 | 55 | env*: [][]U8; (* NAME=value, each added to this program's environment *) |
| 56 | 56 | onlyEnv*: BOOL; (* env is its whole environment *) |
| 57 | 57 | dir*: []U8; (* its working directory; "" for this program's *) |
| 58 | - fds*: [3]I64; (* its standard input, output and error; 0 for this program's own *) | |
| 59 | - group*: I64; (* the process group it joins: 0 for this program's, -1 a new one it leads *) | |
| 58 | + fds*: [3]INT; (* its standard input, output and error; 0 for this program's own *) | |
| 59 | + group*: INT; (* the process group it joins: 0 for this program's, -1 a new one it leads *) | |
| 60 | 60 | foreground*: BOOL; (* its group takes the terminal on standard input *) |
| 61 | - tty*: I64; (* a pseudo-terminal's fd, to start a session on; 0 for none *) | |
| 61 | + tty*: INT; (* a pseudo-terminal's fd, to start a session on; 0 for none *) | |
| 62 | 62 | end; |
| 63 | 63 | (* How a program that wait waited for changed. *) |
| 64 | 64 | Status* = (running, exited, killed, stopped); |
| @@ -96,38 +96,38 @@ | ||
| 96 | 96 | sigRead, sigWrite: I32; (* the pipe the handler of caught signals writes their numbers to, once open *) |
| 97 | 97 | |
| 98 | 98 | (* minus errno, as a system call returns it *) |
| 99 | -proc failed: I64; | |
| 99 | +proc failed: INT; | |
| 100 | 100 | var e: ^I32; |
| 101 | 101 | begin |
| 102 | 102 | e := C.__errno_location(); |
| 103 | - return -I64(e^); | |
| 103 | + return -INT(e^); | |
| 104 | 104 | end; |
| 105 | 105 | |
| 106 | 106 | (* Writes s to the file descriptor fd; the number of bytes written, or |
| 107 | 107 | minus an errno. *) |
| 108 | -proc write*(fd: I64; s: []U8): I64; | |
| 109 | -var r: I64; | |
| 108 | +proc write*(fd: INT; s: []U8): INT; | |
| 109 | +var r: INT; | |
| 110 | 110 | begin |
| 111 | 111 | if LEN(s) = 0 then return 0; end; |
| 112 | - r := C.write(I32(fd), ADR(s[0]), U64(LEN(s))); | |
| 112 | + r := C.write(I32(fd), ADR(s[0]), UINT(LEN(s))); | |
| 113 | 113 | if r < 0 then return failed(); end; |
| 114 | 114 | return r; |
| 115 | 115 | end; |
| 116 | 116 | |
| 117 | 117 | (* Reads into buf from fd; the number of bytes read, 0 at the end, or |
| 118 | 118 | minus an errno. *) |
| 119 | -proc read*(fd: I64; buf: []U8): I64; | |
| 120 | -var r: I64; | |
| 119 | +proc read*(fd: INT; buf: []U8): INT; | |
| 120 | +var r: INT; | |
| 121 | 121 | begin |
| 122 | 122 | if LEN(buf) = 0 then return 0; end; |
| 123 | - r := C.read(I32(fd), ADR(buf[0]), U64(LEN(buf))); | |
| 123 | + r := C.read(I32(fd), ADR(buf[0]), UINT(LEN(buf))); | |
| 124 | 124 | if r < 0 then return failed(); end; |
| 125 | 125 | return r; |
| 126 | 126 | end; |
| 127 | 127 | |
| 128 | 128 | (* path, a C string in buf, or false if it doesn't fit. *) |
| 129 | 129 | proc cstr(path, buf: []U8): BOOL; |
| 130 | -var i: I64; | |
| 130 | +var i: INT; | |
| 131 | 131 | begin |
| 132 | 132 | if LEN(path) >= LEN(buf) then return false; end; |
| 133 | 133 | for i := 0 to LEN(path) - 1 do buf[i] := path[i]; end; |
| @@ -154,30 +154,30 @@ | ||
| 154 | 154 | (* The file at path, opened as how asks: its file descriptor, or minus |
| 155 | 155 | an errno. A file it creates is readable by all, writable by its |
| 156 | 156 | owner. *) |
| 157 | -proc open*(path: []U8; how: Accesses): I64; | |
| 158 | -var buf: [4096]U8; r: I64; | |
| 157 | +proc open*(path: []U8; how: Accesses): INT; | |
| 158 | +var buf: [4096]U8; r: INT; | |
| 159 | 159 | begin |
| 160 | 160 | if not cstr(path, buf) then return -36; end; |
| 161 | - r := I64(C.open(ADR(buf[0]), flags(how), 1A4H)); (* mode 644 *) | |
| 161 | + r := INT(C.open(ADR(buf[0]), flags(how), 1A4H)); (* mode 644 *) | |
| 162 | 162 | if r < 0 then return failed(); end; |
| 163 | 163 | return r; |
| 164 | 164 | end; |
| 165 | 165 | |
| 166 | 166 | (* The file at path, opened for reading. *) |
| 167 | -proc openRead*(path: []U8): I64; | |
| 167 | +proc openRead*(path: []U8): INT; | |
| 168 | 168 | begin |
| 169 | 169 | return open(path, {reading}); |
| 170 | 170 | end; |
| 171 | 171 | |
| 172 | 172 | (* The file at path, made empty or new, opened for writing. *) |
| 173 | -proc create*(path: []U8): I64; | |
| 173 | +proc create*(path: []U8): INT; | |
| 174 | 174 | begin |
| 175 | 175 | return open(path, {writing, creating, truncating}); |
| 176 | 176 | end; |
| 177 | 177 | |
| 178 | 178 | (* Moves fd to pos from the start of its file, or from the end if |
| 179 | 179 | fromEnd: the new position, or minus an errno. *) |
| 180 | -proc seek*(fd, pos: I64; fromEnd: BOOL): I64; | |
| 180 | +proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; | |
| 181 | 181 | var r: I64; |
| 182 | 182 | begin |
| 183 | 183 | if fromEnd then r := C.lseek(I32(fd), pos, 2); (* SEEK_END *) |
| @@ -186,28 +186,28 @@ | ||
| 186 | 186 | return r; |
| 187 | 187 | end; |
| 188 | 188 | |
| 189 | -proc close*(fd: I64); | |
| 189 | +proc close*(fd: INT); | |
| 190 | 190 | begin |
| 191 | 191 | C.close(I32(fd)); |
| 192 | 192 | end; |
| 193 | 193 | |
| 194 | 194 | (* size bytes of fresh, zeroed memory from the system, a multiple of |
| 195 | 195 | pages, or nil. *) |
| 196 | -proc mmap*(size: I64): ^U8; | |
| 196 | +proc mmap*(size: INT): ^U8; | |
| 197 | 197 | var p: ^U8; |
| 198 | 198 | begin |
| 199 | - p := C.mmap(nil, U64(size), 3, 22H, -1, 0); (* read, write; private, anonymous *) | |
| 200 | - if I64(p) = -1 then return nil; end; | |
| 199 | + p := C.mmap(nil, UINT(size), 3, 22H, -1, 0); (* read, write; private, anonymous *) | |
| 200 | + if INT(p) = -1 then return nil; end; | |
| 201 | 201 | return p; |
| 202 | 202 | end; |
| 203 | 203 | |
| 204 | -proc munmap*(p: ^U8; size: I64); | |
| 204 | +proc munmap*(p: ^U8; size: INT); | |
| 205 | 205 | begin |
| 206 | - C.munmap(p, U64(size)); | |
| 206 | + C.munmap(p, UINT(size)); | |
| 207 | 207 | end; |
| 208 | 208 | |
| 209 | 209 | (* Renames old to new, replacing what new names: 0, or minus an errno. *) |
| 210 | -proc rename*(old, new: []U8): I64; | |
| 210 | +proc rename*(old, new: []U8): INT; | |
| 211 | 211 | var a, b: [4096]U8; |
| 212 | 212 | begin |
| 213 | 213 | if not cstr(old, a) or not cstr(new, b) then return -36; end; |
| @@ -216,7 +216,7 @@ | ||
| 216 | 216 | end; |
| 217 | 217 | |
| 218 | 218 | (* Removes the file at path; not a directory. *) |
| 219 | -proc remove*(path: []U8): I64; | |
| 219 | +proc remove*(path: []U8): INT; | |
| 220 | 220 | var a: [4096]U8; |
| 221 | 221 | begin |
| 222 | 222 | if not cstr(path, a) then return -36; end; |
| @@ -225,7 +225,7 @@ | ||
| 225 | 225 | end; |
| 226 | 226 | |
| 227 | 227 | (* Makes a directory at path, readable by all, writable by its owner. *) |
| 228 | -proc makeDir*(path: []U8): I64; | |
| 228 | +proc makeDir*(path: []U8): INT; | |
| 229 | 229 | var a: [4096]U8; |
| 230 | 230 | begin |
| 231 | 231 | if not cstr(path, a) then return -36; end; |
| @@ -234,7 +234,7 @@ | ||
| 234 | 234 | end; |
| 235 | 235 | |
| 236 | 236 | (* Removes the directory at path, which must be empty. *) |
| 237 | -proc removeDir*(path: []U8): I64; | |
| 237 | +proc removeDir*(path: []U8): INT; | |
| 238 | 238 | var a: [4096]U8; |
| 239 | 239 | begin |
| 240 | 240 | if not cstr(path, a) then return -36; end; |
| @@ -243,7 +243,7 @@ | ||
| 243 | 243 | end; |
| 244 | 244 | |
| 245 | 245 | (* Sets the permission bits of what path names. *) |
| 246 | -proc chmod*(path: []U8; mode: I64): I64; | |
| 246 | +proc chmod*(path: []U8; mode: INT): INT; | |
| 247 | 247 | var a: [4096]U8; |
| 248 | 248 | begin |
| 249 | 249 | if not cstr(path, a) then return -36; end; |
| @@ -252,7 +252,7 @@ | ||
| 252 | 252 | end; |
| 253 | 253 | |
| 254 | 254 | (* Makes path a symbolic link to target. *) |
| 255 | -proc symlink*(target, path: []U8): I64; | |
| 255 | +proc symlink*(target, path: []U8): INT; | |
| 256 | 256 | var a, b: [4096]U8; |
| 257 | 257 | begin |
| 258 | 258 | if not cstr(target, a) or not cstr(path, b) then return -36; end; |
| @@ -262,11 +262,11 @@ | ||
| 262 | 262 | |
| 263 | 263 | (* What the symbolic link at path names, good until the next call; and |
| 264 | 264 | 0, or minus an errno. *) |
| 265 | -proc readLink*(path: []U8): ([]U8, I64); | |
| 266 | -var a: [4096]U8; n: I64; | |
| 265 | +proc readLink*(path: []U8): ([]U8, INT); | |
| 266 | +var a: [4096]U8; n: INT; | |
| 267 | 267 | begin |
| 268 | 268 | if not cstr(path, a) then return "", -36; end; |
| 269 | - n := C.readlink(ADR(a[0]), ADR(linked[0]), U64(LEN(linked))); | |
| 269 | + n := C.readlink(ADR(a[0]), ADR(linked[0]), UINT(LEN(linked))); | |
| 270 | 270 | if n < 0 then return "", failed(); end; |
| 271 | 271 | if n = LEN(linked) then return "", -36; end; (* it may be cut short *) |
| 272 | 272 | return linked[0..n], 0; |
| @@ -275,8 +275,8 @@ | ||
| 275 | 275 | (* The size of what path names, whether it is a directory or a regular |
| 276 | 276 | file, following a symbolic link, and whether path is one; and 0, or |
| 277 | 277 | minus an errno. *) |
| 278 | -proc info*(path: []U8): (Info, I64); | |
| 279 | -var a: [4096]U8; st: [18]I64; i: Info; (* glibc's struct stat: 144 bytes *) | |
| 278 | +proc info*(path: []U8): (Info, INT); | |
| 279 | +var a: [4096]U8; st: [18]INT; i: Info; (* glibc's struct stat: 144 bytes *) | |
| 280 | 280 | begin |
| 281 | 281 | if not cstr(path, a) then return i, -36; end; |
| 282 | 282 | if C.lstat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end; |
| @@ -291,7 +291,7 @@ | ||
| 291 | 291 | end; |
| 292 | 292 | |
| 293 | 293 | (* Opens the directory at path, for nextEntry. *) |
| 294 | -proc openDir*(d: ^Dir; path: []U8): I64; | |
| 294 | +proc openDir*(d: ^Dir; path: []U8): INT; | |
| 295 | 295 | var a: [4096]U8; |
| 296 | 296 | begin |
| 297 | 297 | if not cstr(path, a) then return -36; end; |
| @@ -303,7 +303,7 @@ | ||
| 303 | 303 | (* The next name in the directory, good until the next call, but . and |
| 304 | 304 | .., in no order; false at the end. *) |
| 305 | 305 | proc nextEntry*(d: ^Dir): ([]U8, BOOL); |
| 306 | -var e: ^U8; n: I64; | |
| 306 | +var e: ^U8; n: INT; | |
| 307 | 307 | begin |
| 308 | 308 | while true do |
| 309 | 309 | e := C.readdir(d^.d); |
| @@ -324,7 +324,7 @@ | ||
| 324 | 324 | (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no |
| 325 | 325 | echo, no lines, no signals, no flow control, no CR to NL, no NL to |
| 326 | 326 | CR NL; false if fd isn't a terminal. *) |
| 327 | -proc rawMode*(fd: I64): BOOL; | |
| 327 | +proc rawMode*(fd: INT): BOOL; | |
| 328 | 328 | var t: [256]U8; |
| 329 | 329 | begin |
| 330 | 330 | if C.tcgetattr(I32(fd), ADR(saved[0])) # 0 then return false; end; |
| @@ -334,25 +334,25 @@ | ||
| 334 | 334 | end; |
| 335 | 335 | |
| 336 | 336 | (* The terminal on fd as rawMode found it. *) |
| 337 | -proc restoreMode*(fd: I64); | |
| 337 | +proc restoreMode*(fd: INT); | |
| 338 | 338 | begin |
| 339 | 339 | C.tcsetattr(I32(fd), 0, ADR(saved[0])); |
| 340 | 340 | end; |
| 341 | 341 | |
| 342 | 342 | (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't |
| 343 | 343 | say. *) |
| 344 | -proc termSize*(fd: I64): (I64, I64); | |
| 344 | +proc termSize*(fd: INT): (INT, INT); | |
| 345 | 345 | var w: Winsize; |
| 346 | 346 | begin |
| 347 | 347 | if (C.ioctl(I32(fd), TIOCGWINSZ, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then |
| 348 | 348 | return 80, 24; |
| 349 | 349 | end; |
| 350 | - return I64(w.cols), I64(w.rows); | |
| 350 | + return INT(w.cols), INT(w.rows); | |
| 351 | 351 | end; |
| 352 | 352 | |
| 353 | 353 | (* Whether fd has something to read within ms milliseconds; ms < 0 |
| 354 | 354 | waits as long as it takes. *) |
| 355 | -proc ready*(fd, ms: I64): BOOL; | |
| 355 | +proc ready*(fd, ms: INT): BOOL; | |
| 356 | 356 | var p: Pollfd; r: I32; |
| 357 | 357 | begin |
| 358 | 358 | p := {fd: I32(fd), events: 1}; (* POLLIN *) |
| @@ -382,21 +382,21 @@ | ||
| 382 | 382 | end; |
| 383 | 383 | |
| 384 | 384 | (* Waits ms milliseconds. *) |
| 385 | -proc sleep*(ms: I64); | |
| 385 | +proc sleep*(ms: INT); | |
| 386 | 386 | var t: Timespec; at: I64; |
| 387 | 387 | begin |
| 388 | - at := clock() + ms * 1000000; | |
| 388 | + at := clock() + I64(ms) * 1000000; | |
| 389 | 389 | t := {sec: at div 1000000000, nsec: at mod 1000000000}; |
| 390 | 390 | repeat until C.clock_nanosleep(1, 1, ^U8(ADR(t)), nil) # 4; (* until t, again after EINTR *) |
| 391 | 391 | end; |
| 392 | 392 | |
| 393 | 393 | (* Fills b with random bytes, from the kernel. *) |
| 394 | 394 | proc random*(b: []U8); |
| 395 | -var n, r: I64; | |
| 395 | +var n, r: INT; | |
| 396 | 396 | begin |
| 397 | 397 | n := 0; |
| 398 | 398 | while n < LEN(b) do (* a signal may cut it short *) |
| 399 | - r := C.getrandom(ADR(b[n]), U64(LEN(b) - n), 0); | |
| 399 | + r := C.getrandom(ADR(b[n]), UINT(LEN(b) - n), 0); | |
| 400 | 400 | if r > 0 then INC(n, r); end; |
| 401 | 401 | end; |
| 402 | 402 | end; |
| @@ -405,8 +405,8 @@ | ||
| 405 | 405 | bytes, or, if serving, bound to it and taking connections: its file |
| 406 | 406 | descriptor, or minus an errno. It is closed in a program exec |
| 407 | 407 | starts. *) |
| 408 | -proc socket(family, kind: I64; a: ^U8; size: I64; serving: BOOL): I64; | |
| 409 | -var fd, r, one: I32; err: I64; | |
| 408 | +proc socket(family, kind: INT; a: ^U8; size: INT; serving: BOOL): INT; | |
| 409 | +var fd, r, one: I32; err: INT; | |
| 410 | 410 | begin |
| 411 | 411 | fd := C.socket(I32(family), I32(kind) | 80000H, 0); (* SOCK_CLOEXEC *) |
| 412 | 412 | if fd < 0 then return failed(); end; |
| @@ -423,12 +423,12 @@ | ||
| 423 | 423 | C.close(fd); |
| 424 | 424 | return err; |
| 425 | 425 | end; |
| 426 | - return I64(fd); | |
| 426 | + return INT(fd); | |
| 427 | 427 | end; |
| 428 | 428 | |
| 429 | 429 | (* path as a Unix socket's address in a, or false if it is too long. *) |
| 430 | 430 | proc unixAddr(path: []U8; a: ^SockaddrUn): BOOL; |
| 431 | -var i: I64; | |
| 431 | +var i: INT; | |
| 432 | 432 | begin |
| 433 | 433 | if LEN(path) >= LEN(a^.path) then return false; end; |
| 434 | 434 | a^.family := 1; (* AF_UNIX *) |
| @@ -437,7 +437,7 @@ | ||
| 437 | 437 | end; |
| 438 | 438 | |
| 439 | 439 | (* A stream socket connected to the Unix socket at path. *) |
| 440 | -proc connect*(path: []U8): I64; | |
| 440 | +proc connect*(path: []U8): INT; | |
| 441 | 441 | var a: SockaddrUn; |
| 442 | 442 | begin |
| 443 | 443 | if not unixAddr(path, ADR(a)) then return -36; end; (* ENAMETOOLONG *) |
| @@ -446,7 +446,7 @@ | ||
| 446 | 446 | |
| 447 | 447 | (* A stream socket made at path, which must not be there yet, taking |
| 448 | 448 | connections. *) |
| 449 | -proc listen*(path: []U8): I64; | |
| 449 | +proc listen*(path: []U8): INT; | |
| 450 | 450 | var a: SockaddrUn; |
| 451 | 451 | begin |
| 452 | 452 | if not unixAddr(path, ADR(a)) then return -36; end; |
| @@ -456,7 +456,7 @@ | ||
| 456 | 456 | (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size |
| 457 | 457 | of its struct sockaddr_in or sockaddr_in6, or 0 if either is |
| 458 | 458 | wrong. *) |
| 459 | -proc inetAddr(addr: []U8; port: I64; a: ^Sockaddr): I64; | |
| 459 | +proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT; | |
| 460 | 460 | var s: [64]U8; |
| 461 | 461 | begin |
| 462 | 462 | if (port < 0) or (port > 65535) or not cstr(addr, s) then return 0; end; |
| @@ -469,52 +469,52 @@ | ||
| 469 | 469 | |
| 470 | 470 | (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL) |
| 471 | 471 | if they are wrong. *) |
| 472 | -proc inet(addr: []U8; port, kind: I64; serving: BOOL): I64; | |
| 473 | -var a: Sockaddr; size: I64; | |
| 472 | +proc inet(addr: []U8; port, kind: INT; serving: BOOL): INT; | |
| 473 | +var a: Sockaddr; size: INT; | |
| 474 | 474 | begin |
| 475 | 475 | size := inetAddr(addr, port, ADR(a)); |
| 476 | 476 | if size = 0 then return -22; end; |
| 477 | - return socket(I64(a.family), kind, ^U8(ADR(a)), size, serving); | |
| 477 | + return socket(INT(a.family), kind, ^U8(ADR(a)), size, serving); | |
| 478 | 478 | end; |
| 479 | 479 | |
| 480 | 480 | (* A stream socket connected to port at addr, an IPv4 or IPv6 address |
| 481 | 481 | as numbers. *) |
| 482 | -proc connectTcp*(addr: []U8; port: I64): I64; | |
| 482 | +proc connectTcp*(addr: []U8; port: INT): INT; | |
| 483 | 483 | begin |
| 484 | 484 | return inet(addr, port, 1, false); (* SOCK_STREAM *) |
| 485 | 485 | end; |
| 486 | 486 | |
| 487 | 487 | (* A socket of datagrams to and from port at addr. *) |
| 488 | -proc connectUdp*(addr: []U8; port: I64): I64; | |
| 488 | +proc connectUdp*(addr: []U8; port: INT): INT; | |
| 489 | 489 | begin |
| 490 | 490 | return inet(addr, port, 2, false); (* SOCK_DGRAM *) |
| 491 | 491 | end; |
| 492 | 492 | |
| 493 | 493 | (* A stream socket taking connections on port at addr; "0.0.0.0" or |
| 494 | 494 | "::" is every address the machine has. *) |
| 495 | -proc listenTcp*(addr: []U8; port: I64): I64; | |
| 495 | +proc listenTcp*(addr: []U8; port: INT): INT; | |
| 496 | 496 | begin |
| 497 | 497 | return inet(addr, port, 1, true); |
| 498 | 498 | end; |
| 499 | 499 | |
| 500 | 500 | (* The next connection to the socket fd, waiting for one: a socket of |
| 501 | 501 | its own, closed in a program exec starts; or minus an errno. *) |
| 502 | -proc accept*(fd: I64): I64; | |
| 502 | +proc accept*(fd: INT): INT; | |
| 503 | 503 | var r: I32; |
| 504 | 504 | begin |
| 505 | 505 | r := C.accept4(I32(fd), nil, nil, 80000H); (* SOCK_CLOEXEC *) |
| 506 | 506 | if r < 0 then return failed(); end; |
| 507 | - return I64(r); | |
| 507 | + return INT(r); | |
| 508 | 508 | end; |
| 509 | 509 | |
| 510 | 510 | (* Writes s to the socket fd, as write does, but returns -32 (EPIPE) |
| 511 | 511 | where write would stop the program with SIGPIPE: when the other end |
| 512 | 512 | has closed it. *) |
| 513 | -proc send*(fd: I64; s: []U8): I64; | |
| 514 | -var r: I64; | |
| 513 | +proc send*(fd: INT; s: []U8): INT; | |
| 514 | +var r: INT; | |
| 515 | 515 | begin |
| 516 | 516 | if LEN(s) = 0 then return 0; end; |
| 517 | - r := C.send(I32(fd), ADR(s[0]), U64(LEN(s)), 4000H); (* MSG_NOSIGNAL, glibc's *) | |
| 517 | + r := C.send(I32(fd), ADR(s[0]), UINT(LEN(s)), 4000H); (* MSG_NOSIGNAL, glibc's *) | |
| 518 | 518 | if r < 0 then return failed(); end; |
| 519 | 519 | return r; |
| 520 | 520 | end; |
| @@ -522,13 +522,13 @@ | ||
| 522 | 522 | (* The first of fds that has something to read within ms milliseconds, |
| 523 | 523 | or that has reached its end or failed, so that a read won't wait; -1 |
| 524 | 524 | if none has. ms < 0 waits as long as it takes. At most 64 fds. *) |
| 525 | -proc readyOf*(fds: []I64; ms: I64): I64; | |
| 526 | -var p: [64]Pollfd; n, i: I64; r: I32; | |
| 525 | +proc readyOf*(fds: []INT; ms: INT): INT; | |
| 526 | +var p: [64]Pollfd; n, i: INT; r: I32; | |
| 527 | 527 | begin |
| 528 | 528 | n := LEN(fds); |
| 529 | 529 | if n > LEN(p) then n := LEN(p); end; |
| 530 | 530 | for i := 0 to n - 1 do p[i] := {fd: I32(fds[i]), events: 1}; end; (* POLLIN *) |
| 531 | - repeat r := C.poll(^U8(ADR(p)), U64(n), I32(ms)); until (r >= 0) or (failed() # -4); (* EINTR *) | |
| 531 | + repeat r := C.poll(^U8(ADR(p)), UINT(n), I32(ms)); until (r >= 0) or (failed() # -4); (* EINTR *) | |
| 532 | 532 | if r <= 0 then return -1; end; |
| 533 | 533 | for i := 0 to n - 1 do |
| 534 | 534 | if p[i].revents # 0 then return fds[i]; end; |
| @@ -538,7 +538,7 @@ | ||
| 538 | 538 | |
| 539 | 539 | (* The value of the environment variable name; "" if it isn't set. *) |
| 540 | 540 | proc env*(name: []U8): []U8; |
| 541 | -var a: [4096]U8; s: ^U8; n: I64; | |
| 541 | +var a: [4096]U8; s: ^U8; n: INT; | |
| 542 | 542 | begin |
| 543 | 543 | if not cstr(name, a) then return ""; end; |
| 544 | 544 | s := C.getenv(ADR(a[0])); |
| @@ -550,8 +550,8 @@ | ||
| 550 | 550 | |
| 551 | 551 | (* The working directory, good until the next call; and 0, or minus an |
| 552 | 552 | errno. *) |
| 553 | -proc workDir*: ([]U8, I64); | |
| 554 | -var n: I64; | |
| 553 | +proc workDir*: ([]U8, INT); | |
| 554 | +var n: INT; | |
| 555 | 555 | begin |
| 556 | 556 | if C.getcwd(ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end; |
| 557 | 557 | n := 0; |
| @@ -560,7 +560,7 @@ | ||
| 560 | 560 | end; |
| 561 | 561 | |
| 562 | 562 | (* Makes path the working directory. *) |
| 563 | -proc setWorkDir*(path: []U8): I64; | |
| 563 | +proc setWorkDir*(path: []U8): INT; | |
| 564 | 564 | var a: [4096]U8; |
| 565 | 565 | begin |
| 566 | 566 | if not cstr(path, a) then return -36; end; |
| @@ -571,8 +571,8 @@ | ||
| 571 | 571 | (* A pseudo-terminal: the file descriptor of its controlling side, or |
| 572 | 572 | minus an errno. Its other side, the terminal its programs run on, is |
| 573 | 573 | unlocked, for spawn to open. *) |
| 574 | -proc openPty*: I64; | |
| 575 | -var fd: I32; err: I64; | |
| 574 | +proc openPty*: INT; | |
| 575 | +var fd: I32; err: INT; | |
| 576 | 576 | begin |
| 577 | 577 | fd := C.posix_openpt(102H); (* O_RDWR, O_NOCTTY: glibc's *) |
| 578 | 578 | if fd < 0 then return failed(); end; |
| @@ -581,12 +581,12 @@ | ||
| 581 | 581 | C.close(fd); |
| 582 | 582 | return err; |
| 583 | 583 | end; |
| 584 | - return I64(fd); | |
| 584 | + return INT(fd); | |
| 585 | 585 | end; |
| 586 | 586 | |
| 587 | 587 | (* Tells the terminal of the pseudo-terminal fd that it has cols |
| 588 | 588 | columns and rows rows: 0, or minus an errno. *) |
| 589 | -proc setTermSize*(fd, cols, rows: I64): I64; | |
| 589 | +proc setTermSize*(fd, cols, rows: INT): INT; | |
| 590 | 590 | var w: Winsize; |
| 591 | 591 | begin |
| 592 | 592 | w := {rows: U16(rows), cols: U16(cols)}; |
| @@ -596,7 +596,7 @@ | ||
| 596 | 596 | |
| 597 | 597 | (* Copies s and a zero to at: the byte after them. *) |
| 598 | 598 | proc put(s: []U8; at: ^U8): ^U8; |
| 599 | -var i: I64; | |
| 599 | +var i: INT; | |
| 600 | 600 | begin |
| 601 | 601 | for i := 0 to LEN(s) - 1 do at[i] := s[i]; end; |
| 602 | 602 | at[LEN(s)] := 0; |
| @@ -606,7 +606,7 @@ | ||
| 606 | 606 | (* Whether the NAME=value s, a C string, names a variable that one of |
| 607 | 607 | env gives. *) |
| 608 | 608 | proc replaced(s: ^U8; env: [][]U8): BOOL; |
| 609 | -var i, n: I64; | |
| 609 | +var i, n: INT; | |
| 610 | 610 | begin |
| 611 | 611 | for i := 0 to LEN(env) - 1 do |
| 612 | 612 | n := 0; |
| @@ -620,8 +620,8 @@ | ||
| 620 | 620 | strings and a nil, then the environment old with each NAME=value of |
| 621 | 621 | env in place of its variable or added, and a nil; or nil. The |
| 622 | 622 | environment follows the arguments. *) |
| 623 | -proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, I64); | |
| 624 | -var p: ^^U8; s: ^U8; size, n, i, k: I64; | |
| 623 | +proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, INT); | |
| 624 | +var p: ^^U8; s: ^U8; size, n, i, k: INT; | |
| 625 | 625 | begin |
| 626 | 626 | n := 0; |
| 627 | 627 | while old[n] # nil do INC(n); end; |
| @@ -645,22 +645,22 @@ | ||
| 645 | 645 | |
| 646 | 646 | (* A pipe: the fd to read and the fd to write, both closed in a program |
| 647 | 647 | exec starts; or minus an errno and -1. *) |
| 648 | -proc pipe*: (I64, I64); | |
| 648 | +proc pipe*: (INT, INT); | |
| 649 | 649 | var fds: [2]I32; |
| 650 | 650 | begin |
| 651 | 651 | if C.pipe2(ADR(fds[0]), 80000H) # 0 then return failed(), -1; end; (* O_CLOEXEC, glibc's *) |
| 652 | - return I64(fds[0]), I64(fds[1]); | |
| 652 | + return INT(fds[0]), INT(fds[1]); | |
| 653 | 653 | end; |
| 654 | 654 | |
| 655 | 655 | (* This program's process id. *) |
| 656 | -proc pid*: I64; | |
| 656 | +proc pid*: INT; | |
| 657 | 657 | begin |
| 658 | - return I64(C.getpid()); | |
| 658 | + return INT(C.getpid()); | |
| 659 | 659 | end; |
| 660 | 660 | |
| 661 | 661 | (* Moves the program pid, or this one if pid is 0, to the process group |
| 662 | 662 | group, or to a new one it leads if group is 0. *) |
| 663 | -proc setGroup*(pid, group: I64): I64; | |
| 663 | +proc setGroup*(pid, group: INT): INT; | |
| 664 | 664 | begin |
| 665 | 665 | if C.setpgid(I32(pid), I32(group)) # 0 then return failed(); end; |
| 666 | 666 | return 0; |
| @@ -668,7 +668,7 @@ | ||
| 668 | 668 | |
| 669 | 669 | (* Gives the keys of the terminal on fd, and its signals, to the process |
| 670 | 670 | group group. *) |
| 671 | -proc foreground*(fd, group: I64): I64; | |
| 671 | +proc foreground*(fd, group: INT): INT; | |
| 672 | 672 | begin |
| 673 | 673 | if C.tcsetpgrp(I32(fd), I32(group)) # 0 then return failed(); end; |
| 674 | 674 | return 0; |
| @@ -676,21 +676,21 @@ | ||
| 676 | 676 | |
| 677 | 677 | (* The process group the terminal on fd gives its keys to, or minus an |
| 678 | 678 | errno. *) |
| 679 | -proc foregroundOf*(fd: I64): I64; | |
| 679 | +proc foregroundOf*(fd: INT): INT; | |
| 680 | 680 | var g: I32; |
| 681 | 681 | begin |
| 682 | 682 | g := C.tcgetpgrp(I32(fd)); |
| 683 | 683 | if g < 0 then return failed(); end; |
| 684 | - return I64(g); | |
| 684 | + return INT(g); | |
| 685 | 685 | end; |
| 686 | 686 | |
| 687 | 687 | (* Starts the program p describes: its process id, or minus an errno. |
| 688 | 688 | A program that can't be started ends with status 127. Every signal |
| 689 | 689 | is blocked from the fork until the program has its own: its group, |
| 690 | 690 | its terminal's foreground, and signals as they are at first. *) |
| 691 | -proc spawn*(p: Program): I64; | |
| 691 | +proc spawn*(p: Program): INT; | |
| 692 | 692 | var |
| 693 | - a, dir, name: [4096]U8; argv: ^^U8; none, s: ^U8; size, n, err, i, g: I64; | |
| 693 | + a, dir, name: [4096]U8; argv: ^^U8; none, s: ^U8; size, n, err, i, g: INT; | |
| 694 | 694 | all, old, empty: [16]U64; dfl: Sigaction; pid, fd: I32; (* sigset_t: 128 bytes *) |
| 695 | 695 | begin |
| 696 | 696 | if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| @@ -737,14 +737,14 @@ | ||
| 737 | 737 | if (pid > 0) and (p.tty = 0) then |
| 738 | 738 | (* as the program does, for whichever of the two runs first *) |
| 739 | 739 | g := p.group; |
| 740 | - if g = -1 then g := I64(pid); elsif g = 0 then g := I64(C.getpgrp()); end; | |
| 740 | + if g = -1 then g := INT(pid); elsif g = 0 then g := INT(C.getpgrp()); end; | |
| 741 | 741 | if p.group # 0 then C.setpgid(pid, I32(g)); end; |
| 742 | 742 | if p.foreground then C.tcsetpgrp(0, I32(g)); end; |
| 743 | 743 | end; |
| 744 | 744 | C.sigprocmask(2, ^U8(ADR(old)), nil); |
| 745 | 745 | munmap(^U8(argv), size); |
| 746 | 746 | if pid < 0 then return err; end; |
| 747 | - return I64(pid); | |
| 747 | + return INT(pid); | |
| 748 | 748 | end; |
| 749 | 749 | |
| 750 | 750 | (* Waits for the program pid, or any of this program's if pid is -1, to |
| @@ -753,7 +753,7 @@ | ||
| 753 | 753 | block it doesn't wait: 0 and running if none has changed. Minus an |
| 754 | 754 | errno, and running, if there is none to wait for. The status is read |
| 755 | 755 | as glibc's macros read it. *) |
| 756 | -proc wait*(pid: I64; block: BOOL): (I64, Status, I64); | |
| 756 | +proc wait*(pid: INT; block: BOOL): (INT, Status, INT); | |
| 757 | 757 | var status, options, r: I32; |
| 758 | 758 | begin |
| 759 | 759 | options := 3; (* WNOHANG, WUNTRACED *) |
| @@ -761,14 +761,14 @@ | ||
| 761 | 761 | r := C.waitpid(I32(pid), ADR(status), options); |
| 762 | 762 | if r < 0 then return failed(), running, 0; end; |
| 763 | 763 | if r = 0 then return 0, running, 0; end; |
| 764 | - if status & 7FH = 0 then return I64(r), exited, I64(status) shr 8 & 0FFH; end; | |
| 765 | - if status & 0FFH = 7FH then return I64(r), stopped, I64(status) shr 8 & 0FFH; end; | |
| 766 | - return I64(r), killed, I64(status) & 7FH; | |
| 764 | + if status & 7FH = 0 then return INT(r), exited, INT(status) shr 8 & 0FFH; end; | |
| 765 | + if status & 0FFH = 7FH then return INT(r), stopped, INT(status) shr 8 & 0FFH; end; | |
| 766 | + return INT(r), killed, INT(status) & 7FH; | |
| 767 | 767 | end; |
| 768 | 768 | |
| 769 | 769 | (* Sends the program pid, or the group -pid, the signal: 0, or minus an |
| 770 | 770 | errno. *) |
| 771 | -proc kill*(pid, signal: I64): I64; | |
| 771 | +proc kill*(pid, signal: INT): INT; | |
| 772 | 772 | begin |
| 773 | 773 | if C.kill(I32(pid), I32(signal)) # 0 then return failed(); end; |
| 774 | 774 | return 0; |
| @@ -789,8 +789,8 @@ | ||
| 789 | 789 | (* Catches the signals sigs: they don't do what they would, but give |
| 790 | 790 | their numbers on an fd, which a later catch adds to and gives again; |
| 791 | 791 | or minus an errno. *) |
| 792 | -proc catch*(sigs: []I64): I64; | |
| 793 | -var fds: [2]I32; act: Sigaction; i: I64; | |
| 792 | +proc catch*(sigs: []INT): INT; | |
| 793 | +var fds: [2]I32; act: Sigaction; i: INT; | |
| 794 | 794 | begin |
| 795 | 795 | for i := 0 to LEN(sigs) - 1 do |
| 796 | 796 | if (sigs[i] < 1) or (sigs[i] > 64) or (sigs[i] = sigKill) or (sigs[i] = sigStop) |
| @@ -807,20 +807,20 @@ | ||
| 807 | 807 | for i := 0 to LEN(sigs) - 1 do |
| 808 | 808 | if C.sigaction(I32(sigs[i]), ^U8(ADR(act)), nil) # 0 then return failed(); end; |
| 809 | 809 | end; |
| 810 | - return I64(sigRead); | |
| 810 | + return INT(sigRead); | |
| 811 | 811 | end; |
| 812 | 812 | |
| 813 | 813 | (* The next signal catch's fd has, or 0 if none is waiting. *) |
| 814 | -proc caught*(fd: I64): I64; | |
| 814 | +proc caught*(fd: INT): INT; | |
| 815 | 815 | var b: [1]U8; |
| 816 | 816 | begin |
| 817 | 817 | if read(fd, b) # 1 then return 0; end; |
| 818 | - return I64(b[0]); | |
| 818 | + return INT(b[0]); | |
| 819 | 819 | end; |
| 820 | 820 | |
| 821 | 821 | (* Makes the signal sig do nothing, or, if not yes, what it does at |
| 822 | 822 | first: 0, or minus an errno. *) |
| 823 | -proc ignore*(sig: I64; yes: BOOL): I64; | |
| 823 | +proc ignore*(sig: INT; yes: BOOL): INT; | |
| 824 | 824 | var act: Sigaction; |
| 825 | 825 | begin |
| 826 | 826 | if yes then act.handler := Handler(1); end; (* SIG_IGN *) |
| @@ -828,7 +828,7 @@ | ||
| 828 | 828 | return 0; |
| 829 | 829 | end; |
| 830 | 830 | |
| 831 | -proc isTerminal*(fd: I64): BOOL; | |
| 831 | +proc isTerminal*(fd: INT): BOOL; | |
| 832 | 832 | begin |
| 833 | 833 | return C.isatty(I32(fd)) = 1; |
| 834 | 834 | end; |
| @@ -839,7 +839,7 @@ | ||
| 839 | 839 | end; |
| 840 | 840 | |
| 841 | 841 | (* Ends the program, at once, with status. *) |
| 842 | -proc exit*(status: I64); | |
| 842 | +proc exit*(status: INT); | |
| 843 | 843 | begin |
| 844 | 844 | C._exit(I32(status)); |
| 845 | 845 | end; |
| @@ -853,7 +853,7 @@ | ||
| 853 | 853 | one is sent; and a program starts with them neither caught nor |
| 854 | 854 | ignored. *) |
| 855 | 855 | proc testPrograms; |
| 856 | -var pty, child, n, m, r, w, sigs, c: I64; st: Status; buf: [64]U8; | |
| 856 | +var pty, child, n, m, r, w, sigs, c: INT; st: Status; buf: [64]U8; | |
| 857 | 857 | begin |
| 858 | 858 | pty := openPty(); |
| 859 | 859 | if (pty < 0) or (setTermSize(pty, 100, 30) # 0) then exit(2); end; |
| @@ -923,7 +923,7 @@ | ||
| 923 | 923 | sees; addresses read and refused; a TCP connection on the loopback; |
| 924 | 924 | and a datagram to a port where no one listens, refused. *) |
| 925 | 925 | proc testNet; |
| 926 | -var t, l, c, a, u: I64; x, y: [16]U8; s, s6: Sockaddr; | |
| 926 | +var t: I64; l, c, a, u: INT; x, y: [16]U8; s, s6: Sockaddr; | |
| 927 | 927 | begin |
| 928 | 928 | t := clock(); |
| 929 | 929 | sleep(20); |
| @@ -964,7 +964,7 @@ | ||
| 964 | 964 | and closed; a directory made, listed and emptied; no terminal; a |
| 965 | 965 | socket, sent to after its end; programs; time and the network. *) |
| 966 | 966 | proc main*; |
| 967 | -var fd, n, err, w, h, l, c, a: I64; buf: [16]U8; p: ^U8; i: Info; d: Dir; name: []U8; ok: BOOL; | |
| 967 | +var fd, n, err, w, h, l, c, a: INT; buf: [16]U8; p: ^U8; i: Info; d: Dir; name: []U8; ok: BOOL; | |
| 968 | 968 | begin |
| 969 | 969 | fd := create("/tmp/raz-sys-test"); |
| 970 | 970 | if fd < 0 then exit(2); end; |
| @@ -24,23 +24,23 @@ | ||
| 24 | 24 | |
| 25 | 25 | type |
| 26 | 26 | Thread* = record |
| 27 | - tid: I64; (* the kernel's id, until the thread ends *) | |
| 27 | + tid: INT; (* the kernel's id, until the thread ends *) | |
| 28 | 28 | base: ^U8; (* its stack's mapping, the guard page first *) |
| 29 | - size: I64; | |
| 29 | + size: INT; | |
| 30 | 30 | fn: proc(arg: ^U8); (* what it runs, and with what *) |
| 31 | 31 | arg: ^U8; |
| 32 | 32 | end; |
| 33 | 33 | (* What sigaltstack takes *) |
| 34 | - AltStack = record sp: ^U8; flags, size: I64; end; | |
| 34 | + AltStack = record sp: ^U8; flags, size: INT; end; | |
| 35 | 35 | (* 0 free, 1 taken, 2 taken with a thread waiting *) |
| 36 | - Mutex* = record state: I64; end; | |
| 36 | + Mutex* = record state: INT; end; | |
| 37 | 37 | |
| 38 | 38 | (* clone(flags, stack, tid, tid), the new thread starting with fn(arg) |
| 39 | 39 | on stack and ending, when fn returns, with the exit system call. |
| 40 | 40 | fn and arg go on the new stack first, since the new thread has no |
| 41 | 41 | registers but rsp of its own to find them by. Returns the new |
| 42 | 42 | thread's id, or minus an errno. *) |
| 43 | -proc start(flags: I64; stack: ^U8; ptid, ctid: ^I64; fn: proc(arg: ^U8); arg: ^U8): I64; | |
| 43 | +proc start(flags: INT; stack: ^U8; ptid, ctid: ^INT; fn: proc(arg: ^U8); arg: ^U8): INT; | |
| 44 | 44 | code 48H, 83H, 0EEH, 10H, (* sub rsi, 16 *) |
| 45 | 45 | 4CH, 89H, 06H, (* mov [rsi], r8 *) |
| 46 | 46 | 4CH, 89H, 4EH, 08H, (* mov [rsi + 8], r9 *) |
| @@ -58,7 +58,7 @@ | ||
| 58 | 58 | 0FH, 05H, (* syscall *) |
| 59 | 59 | 0C3H; (* parent: ret *) |
| 60 | 60 | |
| 61 | -proc futex(word: ^I64; op, val: I64): I64; | |
| 61 | +proc futex(word: ^INT; op, val: INT): INT; | |
| 62 | 62 | begin |
| 63 | 63 | return SYSCALL(202, word, op, val, 0); |
| 64 | 64 | end; |
| @@ -76,7 +76,7 @@ | ||
| 76 | 76 | |
| 77 | 77 | (* Starts p(arg) in a new thread. *) |
| 78 | 78 | proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR); |
| 79 | -var base: ^U8; t: ^Thread; size: I64; | |
| 79 | +var base: ^U8; t: ^Thread; size: INT; | |
| 80 | 80 | begin |
| 81 | 81 | size := Page + Stack + Alt + Page; |
| 82 | 82 | base := Sys.mmap(size); |
| @@ -103,7 +103,7 @@ | ||
| 103 | 103 | |
| 104 | 104 | (* Waits for t to end, then frees its stack. *) |
| 105 | 105 | proc join*(t: ^Thread); |
| 106 | -var tid: ^VOLATILE I64; v: I64; base: ^U8; size: I64; | |
| 106 | +var tid: ^VOLATILE INT; v: INT; base: ^U8; size: INT; | |
| 107 | 107 | begin |
| 108 | 108 | tid := ADR(t^.tid); |
| 109 | 109 | v := tid^; |
| @@ -117,7 +117,7 @@ | ||
| 117 | 117 | end; |
| 118 | 118 | |
| 119 | 119 | proc lock*(m: ^Mutex); |
| 120 | -var c: I64; | |
| 120 | +var c: INT; | |
| 121 | 121 | begin |
| 122 | 122 | if CAS(ADR(m^.state), 0, 1) then return; end; |
| 123 | 123 | c := XCHG(ADR(m^.state), 2); |
| @@ -145,7 +145,7 @@ | ||
| 145 | 145 | Thread [n alive], Thread fail *) |
| 146 | 146 | var |
| 147 | 147 | testLock: Mutex; |
| 148 | - testCount: I64; | |
| 148 | + testCount: INT; | |
| 149 | 149 | wave: [1000]^Thread; |
| 150 | 150 | |
| 151 | 151 | proc testWork(_arg: ^U8); |
| @@ -155,18 +155,18 @@ | ||
| 155 | 155 | unlock(ADR(testLock)); |
| 156 | 156 | end; |
| 157 | 157 | |
| 158 | -proc testArg(i: I64): I64; | |
| 159 | -var s: ^U8; n, v: I64; | |
| 158 | +proc testArg(i: INT): INT; | |
| 159 | +var s: ^U8; n, v: INT; | |
| 160 | 160 | begin |
| 161 | 161 | s := ARGV()[i]; |
| 162 | 162 | v := 0; |
| 163 | 163 | n := 0; |
| 164 | - while s[n] # 0 do v := v * 10 + I64(s[n]) - '0'; INC(n); end; | |
| 164 | + while s[n] # 0 do v := v * 10 + INT(s[n]) - '0'; INC(n); end; | |
| 165 | 165 | return v; |
| 166 | 166 | end; |
| 167 | 167 | |
| 168 | 168 | proc main*; |
| 169 | -var n, alive, started, k, i: I64; t: ^Thread; err: ERROR; fail: BOOL; | |
| 169 | +var n, alive, started, k, i: INT; t: ^Thread; err: ERROR; fail: BOOL; | |
| 170 | 170 | begin |
| 171 | 171 | n := 2000; alive := 50; |
| 172 | 172 | fail := (ARGC() = 2) and (ARGV()[1][0] = 'f'); |
| @@ -44,6 +44,8 @@ | ||
| 44 | 44 | vol: boolean; { mVar: reached through ^VOLATILE } |
| 45 | 45 | isVar: boolean; { mVar: a variable of the program, not a temporary } |
| 46 | 46 | odd: boolean; { mVar: in a packed record, so maybe misaligned } |
| 47 | + ro: boolean; { mVar: another module's exported variable, or part | |
| 48 | + of one, which only that module changes } | |
| 47 | 49 | obj: PObj; { mProc, mBuiltin, mCase } |
| 48 | 50 | pos: TPos; { where it is in the source, for messages } |
| 49 | 51 | end; |
| @@ -64,6 +66,8 @@ | ||
| 64 | 66 | var |
| 65 | 67 | rtFail, argcChunk, argvChunk: longint; |
| 66 | 68 | depth: longint; { values pushed and not yet popped } |
| 69 | + checks: boolean; { the module's index and slice checks are made: it | |
| 70 | + doesn't say check off } | |
| 67 | 71 | |
| 68 | 72 | procedure MakeConst(var x: TItem; t: PType; v: int64); |
| 69 | 73 | function What(const x: TItem): shortstring; |
| @@ -76,6 +80,8 @@ | ||
| 76 | 80 | procedure Address(var x: TItem; r: longint); |
| 77 | 81 | procedure Save(var x: TItem); |
| 78 | 82 | procedure Coerce(var x: TItem; t: PType); |
| 83 | +procedure CoerceExact(var x: TItem; t: PType; const help: shortstring); | |
| 84 | +procedure NotReadOnly(const x: TItem); | |
| 79 | 85 | procedure Assign(var dst, src: TItem); |
| 80 | 86 | procedure CopyToTemp(var x: TItem); |
| 81 | 87 | function ToSlot(var x: TItem): int64; |
| @@ -92,6 +98,7 @@ | ||
| 92 | 98 | procedure Complement(var x: TItem); |
| 93 | 99 | procedure Op1(op: TSym; var x: TItem; var L: longint); |
| 94 | 100 | procedure Op2(op: TSym; var x, y: TItem; L: longint); |
| 101 | +function IsWord(t: PType): boolean; | |
| 95 | 102 | procedure Convert(var x: TItem; t: PType); |
| 96 | 103 | |
| 97 | 104 | procedure BeginCall(var c: TCall; var x: TItem); |
| @@ -251,7 +258,8 @@ | ||
| 251 | 258 | end; |
| 252 | 259 | oVar: begin |
| 253 | 260 | x.mode := mVar; |
| 254 | - x.isVar := true; | |
| 261 | + x.ro := (o^.lev = 0) and (o^.module <> curModule); | |
| 262 | + x.isVar := not x.ro; | |
| 255 | 263 | if o^.ext then begin |
| 256 | 264 | Load(RAX, MemRip(o^.chunk, 0), 8, false); |
| 257 | 265 | x.base := bReg; x.reg := RAX; |
| @@ -497,6 +505,20 @@ | ||
| 497 | 505 | TempItem(x, t, s); |
| 498 | 506 | end; |
| 499 | 507 | |
| 508 | +{ An INT goes silently into an I64, and a UINT into a U64, losing | |
| 509 | + nothing on any target (report section 5.10). } | |
| 510 | +function Widens(s, t: PType): boolean; | |
| 511 | +begin | |
| 512 | + Widens := ((s = tInt) and Same(t, tI64)) or ((s = tUInt) and Same(t, tU64)); | |
| 513 | +end; | |
| 514 | + | |
| 515 | +{ Another module's exported variable can be read, not changed, nor | |
| 516 | + handed to anything that could change it (report section 3). } | |
| 517 | +procedure NotReadOnly(const x: TItem); | |
| 518 | +begin | |
| 519 | + if x.ro then MarkAt(x.pos, Source(x.pos) + ' is ' + NameOf(x.obj^.module^.name) + '''s, and can''t be changed outside it'); | |
| 520 | +end; | |
| 521 | + | |
| 500 | 522 | procedure Coerce(var x: TItem; t: PType); |
| 501 | 523 | var s: PType; tmp: int64; |
| 502 | 524 | begin |
| @@ -521,7 +543,8 @@ | ||
| 521 | 543 | end; |
| 522 | 544 | if x.mode in [mType, mBuiltin, mNone, mCase] then NotValue(x); |
| 523 | 545 | if Same(s, t) then exit; |
| 524 | - if (s = tRConst) and (t^.form = fReal) then RealTo(x, t) | |
| 546 | + if Widens(s, t) then x.typ := t { the same bits, on a 64-bit target } | |
| 547 | + else if (s = tRConst) and (t^.form = fReal) then RealTo(x, t) | |
| 525 | 548 | else if (s^.form = fConst) and (t^.form = fInt) then begin |
| 526 | 549 | if (x.mode = mConst) and not Fits(x.val, t) then MarkAt(x.pos, IntStr(x.val) + ' doesn''t fit ' + TypeName(t)); |
| 527 | 550 | x.typ := t; |
| @@ -531,6 +554,7 @@ | ||
| 531 | 554 | and Same(s^.base, t^.base) then |
| 532 | 555 | x.typ := t |
| 533 | 556 | else if (s^.form = fArray) and (t^.form = fSlice) and Same(s^.base, t^.base) then begin |
| 557 | + NotReadOnly(x); | |
| 534 | 558 | if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); |
| 535 | 559 | if x.odd then MarkAt(x.pos, 'can''t make a slice of a field of a packed record'); |
| 536 | 560 | Address(x, RAX); |
| @@ -539,6 +563,20 @@ | ||
| 539 | 563 | MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t)); |
| 540 | 564 | end; |
| 541 | 565 | |
| 566 | +{ Coerce where the types must be the same, as in a for loop, INC and | |
| 567 | + several results, which don't widen an INT to an I64 (report sections | |
| 568 | + 5.10, 6.1 and 7.2); help, if not empty, says why. } | |
| 569 | +procedure CoerceExact(var x: TItem; t: PType; const help: shortstring); | |
| 570 | +var h: shortstring; | |
| 571 | +begin | |
| 572 | + if Widens(x.typ, t) then begin | |
| 573 | + h := help; | |
| 574 | + if h = '' then h := 'they don''t mix here: write ' + TypeName(t) + '(' + Source(x.pos) + ')'; | |
| 575 | + MarkHelp(x.pos, 'expected ' + TypeName(t) + ', found ' + What(x), h); | |
| 576 | + end; | |
| 577 | + Coerce(x, t); | |
| 578 | +end; | |
| 579 | + | |
| 542 | 580 | procedure Assign(var dst, src: TItem); |
| 543 | 581 | var m: TMem; |
| 544 | 582 | begin |
| @@ -613,7 +651,7 @@ | ||
| 613 | 651 | if t^.base = nil then MarkAt(x.pos, TypeName(t) + ' points to a type never declared'); |
| 614 | 652 | Value(x); |
| 615 | 653 | x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; |
| 616 | - x.typ := t^.base; x.vol := t^.vol; x.isVar := true; x.odd := false; | |
| 654 | + x.typ := t^.base; x.vol := t^.vol; x.isVar := true; x.odd := false; x.ro := false; | |
| 617 | 655 | end; |
| 618 | 656 | |
| 619 | 657 | { A field of a packed record, of more than one byte's alignment, may |
| @@ -654,7 +692,7 @@ | ||
| 654 | 692 | PopR(RCX); |
| 655 | 693 | Alu(aluAdd, RAX, RCX); |
| 656 | 694 | x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; |
| 657 | - x.vol := t^.vol; x.isVar := true; x.odd := false; | |
| 695 | + x.vol := t^.vol; x.isVar := true; x.odd := false; x.ro := false; | |
| 658 | 696 | end else if (t^.form = fArray) and (y.mode = mConst) then begin |
| 659 | 697 | if (y.val < 0) or (y.val >= t^.len) then MarkAt(y.pos, 'index ' + IntStr(y.val) + ' is out of range for a length of ' + IntStr(t^.len)); |
| 660 | 698 | x.off := x.off + y.val * s; |
| @@ -663,8 +701,10 @@ | ||
| 663 | 701 | end; |
| 664 | 702 | end else if t^.form = fArray then begin |
| 665 | 703 | Value(y); |
| 666 | - CmpI(RAX, t^.len); | |
| 667 | - Check(ccB, 0, y.pos, RAX, NoMem, t^.len, -1); | |
| 704 | + if checks then begin | |
| 705 | + CmpI(RAX, t^.len); | |
| 706 | + Check(ccB, 0, y.pos, RAX, NoMem, t^.len, -1); | |
| 707 | + end; | |
| 668 | 708 | if s <> 1 then ImulI(RAX, s); |
| 669 | 709 | if x.base = bStack then PopR(RCX) else Lea(RCX, MemOf(x, RCX)); |
| 670 | 710 | Alu(aluAdd, RAX, RCX); |
| @@ -674,11 +714,13 @@ | ||
| 674 | 714 | Value(y); |
| 675 | 715 | m := MemOf(x, RCX); |
| 676 | 716 | ml := m; ml.disp := ml.disp + 8; |
| 677 | - AluM(aluCmp, RAX, ml); | |
| 678 | - Check(ccB, 0, y.pos, RAX, ml, 0, -1); | |
| 717 | + if checks then begin | |
| 718 | + AluM(aluCmp, RAX, ml); | |
| 719 | + Check(ccB, 0, y.pos, RAX, ml, 0, -1); | |
| 720 | + end; | |
| 679 | 721 | if s <> 1 then ImulI(RAX, s); |
| 680 | 722 | AluM(aluAdd, RAX, m); |
| 681 | - x.base := bReg; x.reg := RAX; x.off := 0; x.isVar := true; x.vol := false; | |
| 723 | + x.base := bReg; x.reg := RAX; x.off := 0; x.isVar := true; x.vol := false; x.ro := false; | |
| 682 | 724 | end; |
| 683 | 725 | x.typ := t^.base; |
| 684 | 726 | end; |
| @@ -698,22 +740,27 @@ | ||
| 698 | 740 | if not IsInt(hi.typ) then MarkAt(hi.pos, 'an index is an integer, found ' + What(hi)); |
| 699 | 741 | if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); |
| 700 | 742 | if x.odd then MarkAt(x.pos, 'can''t make a slice of a field of a packed record'); |
| 743 | + if t^.form = fArray then NotReadOnly(x); | |
| 701 | 744 | Value(hi); |
| 702 | 745 | MovRR(RDX, RAX); |
| 703 | 746 | PopR(RCX); |
| 704 | 747 | if t^.form = fPtr then begin |
| 705 | 748 | { the bounds can't be known, but a slice can't run backwards } |
| 706 | 749 | PopR(R8); |
| 707 | - Alu(aluCmp, RCX, RDX); | |
| 708 | - Check(ccLE, 3, lo.pos, RCX, NoMem, 0, -1); | |
| 750 | + if checks then begin | |
| 751 | + Alu(aluCmp, RCX, RDX); | |
| 752 | + Check(ccLE, 3, lo.pos, RCX, NoMem, 0, -1); | |
| 753 | + end; | |
| 709 | 754 | end else begin |
| 710 | 755 | m := MemOf(x, R8); |
| 711 | 756 | ml := m; ml.disp := ml.disp + 8; |
| 712 | - if t^.form = fArray then begin CmpI(RDX, t^.len); ml := NoMem end | |
| 713 | - else AluM(aluCmp, RDX, ml); | |
| 714 | - Check(ccBE, 1, lo.pos, RCX, ml, t^.len, -1); | |
| 715 | - Alu(aluCmp, RCX, RDX); | |
| 716 | - Check(ccBE, 1, lo.pos, RCX, ml, t^.len, -1); | |
| 757 | + if checks then begin | |
| 758 | + if t^.form = fArray then begin CmpI(RDX, t^.len); ml := NoMem end | |
| 759 | + else AluM(aluCmp, RDX, ml); | |
| 760 | + Check(ccBE, 1, lo.pos, RCX, ml, t^.len, -1); | |
| 761 | + Alu(aluCmp, RCX, RDX); | |
| 762 | + Check(ccBE, 1, lo.pos, RCX, ml, t^.len, -1); | |
| 763 | + end; | |
| 717 | 764 | end; |
| 718 | 765 | tmp := AllocTemp(16, 8); |
| 719 | 766 | MovRR(RAX, RDX); |
| @@ -853,6 +900,12 @@ | ||
| 853 | 900 | end; |
| 854 | 901 | end; |
| 855 | 902 | |
| 903 | +{ A type's width in bits; an untyped constant's is an I64's } | |
| 904 | +function Bits(t: PType): longint; | |
| 905 | +begin | |
| 906 | + Bits := t^.size * 8; | |
| 907 | +end; | |
| 908 | + | |
| 856 | 909 | function FoldInt(op: TSym; a, b: int64; t: PType; const p: TPos): int64; |
| 857 | 910 | var u: boolean; |
| 858 | 911 | begin |
| @@ -867,16 +920,16 @@ | ||
| 867 | 920 | if u then begin |
| 868 | 921 | if op = sDiv then FoldInt := int64(qword(a) div qword(b)) |
| 869 | 922 | else FoldInt := int64(qword(a) mod qword(b)); |
| 870 | - end else if (b = -1) and (a = low(int64)) then MarkAt(p, 'division overflows') | |
| 923 | + end else if (b = -1) and (a = int64(-1) shl (Bits(t) - 1)) then MarkAt(p, 'division overflows') | |
| 871 | 924 | else if op = sDiv then FoldInt := a div b |
| 872 | 925 | else FoldInt := a mod b; |
| 873 | 926 | end; |
| 874 | 927 | sAmp: FoldInt := a and b; |
| 875 | 928 | sBar: FoldInt := a or b; |
| 876 | 929 | sXor: FoldInt := a xor b; |
| 877 | - sShl: FoldInt := a shl (b and 63); | |
| 878 | - sShr: if u then FoldInt := int64(qword(a) shr (b and 63)) | |
| 879 | - else FoldInt := SarInt64(a, b and 63); | |
| 930 | + sShl: FoldInt := a shl (b and (Bits(t) - 1)); | |
| 931 | + sShr: if u then FoldInt := int64(qword(a) shr (b and (Bits(t) - 1))) | |
| 932 | + else FoldInt := SarInt64(a, b and (Bits(t) - 1)); | |
| 880 | 933 | sEql: FoldInt := ord(a = b); |
| 881 | 934 | sNeq: FoldInt := ord(a <> b); |
| 882 | 935 | sLss: if u then FoldInt := ord(qword(a) < qword(b)) else FoldInt := ord(a < b); |
| @@ -913,6 +966,22 @@ | ||
| 913 | 966 | { and, or and not are for BOOLs; &, |, xor and ~ for the bits of |
| 914 | 967 | integers: x is the wrong kind for op, and the message names the |
| 915 | 968 | operator it may have meant } |
| 969 | +{ Before rax div rcx, of a signed type narrower than 64 bits: its | |
| 970 | + smallest value divided by -1 overflows it, which must stop the program | |
| 971 | + as it does for an I64 (report section 6.1). idiv on the 64-bit values | |
| 972 | + wouldn't fault, so then rax is made the smallest I64, and it does. } | |
| 973 | +procedure DivTrap(t: PType); | |
| 974 | +var L: longint; | |
| 975 | +begin | |
| 976 | + L := NoLabel; | |
| 977 | + CmpI(RCX, -1); | |
| 978 | + Jcc(ccNE, L); | |
| 979 | + CmpI(RAX, int64(-1) shl (Bits(t) - 1)); | |
| 980 | + Jcc(ccNE, L); | |
| 981 | + ShiftI(shShl, RAX, 64 - Bits(t)); | |
| 982 | + FixLink(L); | |
| 983 | +end; | |
| 984 | + | |
| 916 | 985 | procedure WrongLogic(op: TSym; var x: TItem); |
| 917 | 986 | const Bits = 'the bits of integers take '; |
| 918 | 987 | begin |
| @@ -1013,10 +1082,10 @@ | ||
| 1013 | 1082 | t := tBool; |
| 1014 | 1083 | end else if (xt^.form = fPtr) and IsInt(yt) and (op in [sPlus, sMinus]) then begin |
| 1015 | 1084 | t := xt; scale := xt^.base^.size; isPtr := true; |
| 1016 | - if y.mode = mConst then y.typ := tI64; | |
| 1085 | + if y.mode = mConst then y.typ := tInt; | |
| 1017 | 1086 | end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin |
| 1018 | 1087 | if not Same(xt, yt) then Mismatch(x, y, xt, yt); |
| 1019 | - t := tI64; scale := xt^.base^.size; isPtr := true; | |
| 1088 | + t := tInt; scale := xt^.base^.size; isPtr := true; | |
| 1020 | 1089 | end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin |
| 1021 | 1090 | if not (op in Rel) then MarkAt(Join(x.pos, y.pos), SymText(op) + ' doesn''t apply to ' + TypeName(xt)); |
| 1022 | 1091 | if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then |
| @@ -1122,9 +1191,9 @@ | ||
| 1122 | 1191 | case op of |
| 1123 | 1192 | sPlus: begin if scale <> 1 then ImulI(RCX, scale); Alu(aluAdd, RAX, RCX) end; |
| 1124 | 1193 | sMinus: begin |
| 1125 | - if (scale <> 1) and (t <> tI64) then ImulI(RCX, scale); | |
| 1194 | + if (scale <> 1) and (t <> tInt) then ImulI(RCX, scale); | |
| 1126 | 1195 | Alu(aluSub, RAX, RCX); |
| 1127 | - if (t = tI64) and isPtr and (scale <> 1) then begin | |
| 1196 | + if (t = tInt) and isPtr and (scale <> 1) then begin | |
| 1128 | 1197 | sh := Log2(scale); |
| 1129 | 1198 | if sh >= 0 then ShiftI(shSar, RAX, sh) |
| 1130 | 1199 | else begin MovRI(RCX, scale); Cqo; Unary(7, RCX) end; |
| @@ -1133,14 +1202,21 @@ | ||
| 1133 | 1202 | sTimes: if k >= 1 then ShiftI(shShl, RAX, k) else Imul(RAX, RCX); |
| 1134 | 1203 | sDiv, sMod: if k >= 1 then DivPow2(op, k, unsign) else begin |
| 1135 | 1204 | if unsign then begin MovRI(RDX, 0); Unary(6, RCX) end |
| 1136 | - else begin Cqo; Unary(7, RCX) end; | |
| 1205 | + else begin | |
| 1206 | + if (t^.size < 8) and ((y.mode <> mConst) or (y.val = -1)) then DivTrap(t); | |
| 1207 | + Cqo; Unary(7, RCX) | |
| 1208 | + end; | |
| 1137 | 1209 | if op = sMod then MovRR(RAX, RDX); |
| 1138 | 1210 | end; |
| 1139 | 1211 | sAmp: Alu(aluAnd, RAX, RCX); |
| 1140 | 1212 | sBar: Alu(aluOr, RAX, RCX); |
| 1141 | 1213 | sXor: Alu(aluXor, RAX, RCX); |
| 1142 | - sShl: Shift(shShl, RAX); | |
| 1143 | - sShr: if unsign then Shift(shShr, RAX) else Shift(shSar, RAX); | |
| 1214 | + sShl, sShr: begin | |
| 1215 | + { the count modulo the width: the machine takes it modulo 64 } | |
| 1216 | + if Bits(t) < 64 then AluI(aluAnd, RCX, Bits(t) - 1); | |
| 1217 | + if op = sShl then Shift(shShl, RAX) | |
| 1218 | + else if unsign then Shift(shShr, RAX) else Shift(shSar, RAX); | |
| 1219 | + end; | |
| 1144 | 1220 | else MarkAt(Join(x.pos, y.pos), SymText(op) + ' doesn''t apply to ' + TypeName(t)); |
| 1145 | 1221 | end; |
| 1146 | 1222 | Norm(t); |
| @@ -1149,6 +1225,13 @@ | ||
| 1149 | 1225 | if op in Rel + [sIn] then x.typ := tBool else x.typ := t; |
| 1150 | 1226 | end; |
| 1151 | 1227 | |
| 1228 | +{ INT and UINT, the integers as big as an address, through which | |
| 1229 | + integers and pointers convert (report section 6.7) } | |
| 1230 | +function IsWord(t: PType): boolean; | |
| 1231 | +begin | |
| 1232 | + IsWord := Same(t, tInt) or Same(t, tUInt); | |
| 1233 | +end; | |
| 1234 | + | |
| 1152 | 1235 | procedure Convert(var x: TItem; t: PType); |
| 1153 | 1236 | var s: PType; r: double; L1, L2: longint; f: boolean; |
| 1154 | 1237 | begin |
| @@ -1213,11 +1296,11 @@ | ||
| 1213 | 1296 | end else begin |
| 1214 | 1297 | Value(x); MovqXR(0, RAX); Cvtts2si(RAX, 0, IsF32(s)); Norm(t) |
| 1215 | 1298 | end; |
| 1216 | - end else if (IsInt(s) or (s^.form in [fPtr, fProc, fNil])) and (t^.form in [fPtr, fProc]) then begin | |
| 1299 | + end else if (IsWord(s) or (s^.form in [fConst, fPtr, fProc, fNil])) and (t^.form in [fPtr, fProc]) then begin | |
| 1217 | 1300 | if x.mode <> mConst then Value(x); |
| 1218 | - end else if (s^.form in [fPtr, fProc]) and (t^.form = fInt) then begin | |
| 1219 | - Value(x); Norm(t) | |
| 1220 | - end else | |
| 1301 | + end else if (s^.form in [fPtr, fProc]) and IsWord(t) then | |
| 1302 | + Value(x) | |
| 1303 | + else | |
| 1221 | 1304 | MarkAt(x.pos, 'can''t convert ' + TypeName(s) + ' to ' + TypeName(t)); |
| 1222 | 1305 | x.typ := t; |
| 1223 | 1306 | end; |
| @@ -1255,11 +1338,11 @@ | ||
| 1255 | 1338 | if c.n > High(c.slots) then MarkAt(a.pos, 'too many arguments'); |
| 1256 | 1339 | if p = nil then begin |
| 1257 | 1340 | { past the parameters of a C procedure that ends in ...: a string |
| 1258 | - goes as a C string, an integer constant as an I64, a real | |
| 1341 | + goes as a C string, an integer constant as an INT, a real | |
| 1259 | 1342 | constant as an F64; C takes no F32 there } |
| 1260 | 1343 | if not c.sig^.variadic then WrongCount(c, a.pos, 'too many arguments'); |
| 1261 | 1344 | if a.mode = mStr then Coerce(a, tPtrU8) |
| 1262 | - else if a.typ^.form = fConst then Coerce(a, tI64) | |
| 1345 | + else if a.typ^.form = fConst then Coerce(a, tInt) | |
| 1263 | 1346 | else if a.typ = tRConst then Coerce(a, tReal) |
| 1264 | 1347 | else if IsF32(a.typ) then MarkAt(a.pos, 'an F32 goes to ... as F64(x)') |
| 1265 | 1348 | else if not IsScalar(a.typ) then MarkAt(a.pos, 'only a single value goes to ...'); |
| @@ -1270,6 +1353,7 @@ | ||
| 1270 | 1353 | end; |
| 1271 | 1354 | c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar; |
| 1272 | 1355 | if p^.isVar then begin |
| 1356 | + NotReadOnly(a); | |
| 1273 | 1357 | if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable'); |
| 1274 | 1358 | if a.odd then MarkAt(a.pos, 'a field of a packed record can''t be a var parameter'); |
| 1275 | 1359 | if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ) + ', found ' + What(a)); |
| @@ -1393,6 +1477,7 @@ | ||
| 1393 | 1477 | begin |
| 1394 | 1478 | if x.typ^.form = fEnum then exit(ToSlot(x)); |
| 1395 | 1479 | if (x.mode <> mVar) or (x.typ^.form <> fVariant) then MarkAt(x.pos, 'match needs a variant or an enumeration, found ' + What(x)); |
| 1480 | + if x.ro then CopyToTemp(x); { its arms' names stand for a copy's fields } | |
| 1396 | 1481 | Address(x, RAX); |
| 1397 | 1482 | p := AllocTemp(8, 8); |
| 1398 | 1483 | Store(Mem(RBP, p), RAX, 8); |
| @@ -1571,7 +1656,7 @@ | ||
| 1571 | 1656 | procedure IncDec(var v, k: TItem; dec: boolean); |
| 1572 | 1657 | var n: longint; |
| 1573 | 1658 | begin |
| 1574 | - Coerce(k, v.typ); | |
| 1659 | + CoerceExact(k, v.typ, ''); | |
| 1575 | 1660 | Value(k); |
| 1576 | 1661 | MovRR(RCX, RAX); |
| 1577 | 1662 | Address(v, RDX); |
| @@ -76,7 +76,7 @@ | ||
| 76 | 76 | curResult: PType; { the result type of the procedure being compiled } |
| 77 | 77 | inExtern: boolean; { reading an extern's signature: ... allowed } |
| 78 | 78 | tArgv, tBodySig: PType; |
| 79 | - nameRt, nameFail, nameMain, nameBody, nameStatic: longint; | |
| 79 | + nameRt, nameFail, nameMain, nameBody, nameStatic, nameCheck, nameOff: longint; | |
| 80 | 80 | declaring: array[0..63] of longint; { the names the declaration being read declares } |
| 81 | 81 | numDeclaring: longint; |
| 82 | 82 | skipped: boolean; { the last statement had an error and was skipped } |
| @@ -667,7 +667,7 @@ | ||
| 667 | 667 | if i > 0 then Expect(sComma); |
| 668 | 668 | Expression(a, nil); |
| 669 | 669 | if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then MarkAt(a.pos, 'expected an integer or a pointer, found ' + What(a)); |
| 670 | - if a.typ^.form = fConst then Coerce(a, tI64); | |
| 670 | + if a.typ^.form = fConst then Coerce(a, tInt); | |
| 671 | 671 | slots[i] := ToSlot(a); |
| 672 | 672 | end; |
| 673 | 673 | end; |
| @@ -678,8 +678,9 @@ | ||
| 678 | 678 | Expression(p, nil); |
| 679 | 679 | if p.typ^.form <> fPtr then MarkAt(p.pos, 'expected a pointer, found ' + What(p)); |
| 680 | 680 | t := p.typ^.base; |
| 681 | - if not (((t^.form = fInt) or ((t^.form = fPtr) and (which <> bXadd))) and (t^.size = 8)) then | |
| 682 | - MarkAt(p.pos, 'expected an 8-byte integer or a pointer, found ' + TypeName(t)); | |
| 681 | + if not (IsWord(t) or ((t^.form = fPtr) and (which <> bXadd))) then | |
| 682 | + if which = bXadd then MarkAt(p.pos, 'expected a pointer to an INT or a UINT, found ' + TypeName(p.typ)) | |
| 683 | + else MarkAt(p.pos, 'expected a pointer to an INT, a UINT or a pointer, found ' + TypeName(p.typ)); | |
| 683 | 684 | s[0] := ToSlot(p); |
| 684 | 685 | if which = bCas then n := 2 else n := 1; |
| 685 | 686 | for i := 1 to n do begin |
| @@ -710,6 +711,7 @@ | ||
| 710 | 711 | var y, z: TItem; t: PType; f: PObj; s: int64; c: TCall; L: longint; |
| 711 | 712 | begin |
| 712 | 713 | Expression(x, nil); |
| 714 | + NotReadOnly(x); | |
| 713 | 715 | if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then MarkAt(x.pos, 'NEW needs a pointer variable'); |
| 714 | 716 | t := x.typ^.base; |
| 715 | 717 | Save(x); |
| @@ -728,9 +730,9 @@ | ||
| 728 | 730 | MakeConst(z, y.typ, 0); |
| 729 | 731 | z.mode := mReg; |
| 730 | 732 | PassArg(c, z); |
| 731 | - MakeConst(z, tI64, t^.size); | |
| 733 | + MakeConst(z, tInt, t^.size); | |
| 732 | 734 | PassArg(c, z); |
| 733 | - MakeConst(z, tI64, t^.align); | |
| 735 | + MakeConst(z, tInt, t^.align); | |
| 734 | 736 | PassArg(c, z); |
| 735 | 737 | EndCall(c, z); |
| 736 | 738 | L := NoLabel; |
| @@ -764,7 +766,7 @@ | ||
| 764 | 766 | MakeConst(x, tNone, 0); |
| 765 | 767 | case which of |
| 766 | 768 | bFence: begin Mfence; x.mode := mNone end; |
| 767 | - bArgc: begin Load(RAX, MemRip(argcChunk, 0), 8, false); x.typ := tI64; x.mode := mReg end; | |
| 769 | + bArgc: begin Load(RAX, MemRip(argcChunk, 0), 8, false); x.typ := tInt; x.mode := mReg end; | |
| 768 | 770 | bArgv: begin Load(RAX, MemRip(argvChunk, 0), 8, false); x.typ := tArgv; x.mode := mReg end; |
| 769 | 771 | end; |
| 770 | 772 | exit; |
| @@ -777,6 +779,7 @@ | ||
| 777 | 779 | end; |
| 778 | 780 | bAdr: begin |
| 779 | 781 | Expression(y, nil); |
| 782 | + NotReadOnly(y); | |
| 780 | 783 | if (y.mode <> mVar) or not y.isVar then MarkAt(y.pos, 'ADR needs a variable'); |
| 781 | 784 | if y.odd then MarkAt(y.pos, 'a field of a packed record has no address'); |
| 782 | 785 | t := NewPtr(y.typ, y.vol); |
| @@ -791,7 +794,7 @@ | ||
| 791 | 794 | else if (y.typ^.form = fSlice) and (y.mode = mVar) then begin |
| 792 | 795 | Address(y, RAX); |
| 793 | 796 | Load(RAX, Mem(RAX, 8), 8, false); |
| 794 | - MakeConst(x, tI64, 0); | |
| 797 | + MakeConst(x, tInt, 0); | |
| 795 | 798 | x.mode := mReg; |
| 796 | 799 | end else MarkAt(y.pos, 'LEN needs an array or a slice, found ' + What(y)); |
| 797 | 800 | end; |
| @@ -802,19 +805,20 @@ | ||
| 802 | 805 | Next; |
| 803 | 806 | Expression(y, nil); |
| 804 | 807 | if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then MarkAt(y.pos, 'expected an integer or a pointer, found ' + What(y)); |
| 805 | - if y.typ^.form = fConst then Coerce(y, tI64); | |
| 808 | + if y.typ^.form = fConst then Coerce(y, tInt); | |
| 806 | 809 | slots[n] := ToSlot(y); |
| 807 | 810 | inc(n); |
| 808 | 811 | end; |
| 809 | 812 | for i := 0 to n - 1 do Load(SysRegs[i], Mem(RBP, slots[i]), 8, false); |
| 810 | 813 | Syscall; |
| 811 | - MakeConst(x, tI64, 0); | |
| 814 | + MakeConst(x, tInt, 0); | |
| 812 | 815 | x.mode := mReg; |
| 813 | 816 | end; |
| 814 | 817 | bCas, bXchg, bXadd: Atomic(x, which); |
| 815 | 818 | bMsg: begin Expression(x, tError); Msg(x) end; |
| 816 | 819 | bInc, bDec: begin |
| 817 | 820 | Expression(x, nil); |
| 821 | + NotReadOnly(x); | |
| 818 | 822 | if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then |
| 819 | 823 | MarkAt(x.pos, IncOrDec(which) + ' needs an integer variable'); |
| 820 | 824 | Save(x); |
| @@ -1261,10 +1265,11 @@ | ||
| 1261 | 1265 | MakeItem(v, o); |
| 1262 | 1266 | Save(v); |
| 1263 | 1267 | Expression(a, o^.typ); |
| 1268 | + CoerceExact(a, o^.typ, ''); | |
| 1264 | 1269 | Assign(v, a); |
| 1265 | 1270 | Expect(sTo); |
| 1266 | 1271 | Expression(b, o^.typ); |
| 1267 | - Coerce(b, o^.typ); | |
| 1272 | + CoerceExact(b, o^.typ, ''); | |
| 1268 | 1273 | bslot := ToSlot(b); |
| 1269 | 1274 | step := 1; |
| 1270 | 1275 | if tok = sBy then begin |
| @@ -1397,6 +1402,7 @@ | ||
| 1397 | 1402 | d[0] := x; |
| 1398 | 1403 | dn[0] := first; |
| 1399 | 1404 | repeat |
| 1405 | + NotReadOnly(d[n]); | |
| 1400 | 1406 | if (d[n].mode <> mVar) or not d[n].isVar then MarkAt(d[n].pos, 'can''t assign to ' + Subject(d[n], dn[n])); |
| 1401 | 1407 | Pin(d[n]); |
| 1402 | 1408 | inc(n); |
| @@ -1414,6 +1420,7 @@ | ||
| 1414 | 1420 | for i := 0 to n - 1 do begin |
| 1415 | 1421 | z := y; |
| 1416 | 1422 | Field(z, f); |
| 1423 | + CoerceExact(z, d[i].typ, 'several results go to variables of just their types'); | |
| 1417 | 1424 | Assign(d[i], z); |
| 1418 | 1425 | f := f^.next; |
| 1419 | 1426 | end; |
| @@ -1477,6 +1484,7 @@ | ||
| 1477 | 1484 | sIdent: begin |
| 1478 | 1485 | LeftSide(x, called); |
| 1479 | 1486 | if tok = sBecomes then begin |
| 1487 | + NotReadOnly(x); | |
| 1480 | 1488 | if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, first)); |
| 1481 | 1489 | Save(x); |
| 1482 | 1490 | Next; |
| @@ -2078,13 +2086,14 @@ | ||
| 2078 | 2086 | function CompileFile(const path: shortstring; n: longint; const args: TArgs; checkOnly: boolean): PModule; |
| 2079 | 2087 | var |
| 2080 | 2088 | st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint; |
| 2081 | - oldMod: PModule; oldCheck: boolean; m: PModule; | |
| 2089 | + oldMod: PModule; oldCheck, oldChecks: boolean; m: PModule; | |
| 2082 | 2090 | lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; |
| 2083 | 2091 | generic: boolean; argsAt: TScanState; |
| 2084 | 2092 | begin |
| 2085 | 2093 | SaveScan(st); |
| 2086 | 2094 | SaveScopes(d, saved); |
| 2087 | - oldMod := curModule; oldCheck := checkMode; oldPath := curFile; | |
| 2095 | + oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks; | |
| 2096 | + checks := true; | |
| 2088 | 2097 | curFile := Name(path); |
| 2089 | 2098 | if not Open(path) then Fatal('can''t read ' + path); |
| 2090 | 2099 | New(m); |
| @@ -2167,6 +2176,15 @@ | ||
| 2167 | 2176 | Next; |
| 2168 | 2177 | Expect(sSemicolon); |
| 2169 | 2178 | end; |
| 2179 | + { check off;: the module's index and slice checks left out; neither | |
| 2180 | + word is reserved } | |
| 2181 | + if (tok = sIdent) and (id = nameCheck) then begin | |
| 2182 | + Next; | |
| 2183 | + if (tok <> sIdent) or (id <> nameOff) then Expected('"off"'); | |
| 2184 | + Next; | |
| 2185 | + Expect(sSemicolon); | |
| 2186 | + checks := false; | |
| 2187 | + end; | |
| 2170 | 2188 | Declarations(true); |
| 2171 | 2189 | if tok = sBegin then begin |
| 2172 | 2190 | if checkMode then SkipBody |
| @@ -2203,7 +2221,7 @@ | ||
| 2203 | 2221 | if lastModule = nil then firstModule := m else lastModule^.next := m; |
| 2204 | 2222 | lastModule := m; |
| 2205 | 2223 | end; |
| 2206 | - curModule := oldMod; checkMode := oldCheck; curFile := oldPath; | |
| 2224 | + curModule := oldMod; checkMode := oldCheck; curFile := oldPath; checks := oldChecks; | |
| 2207 | 2225 | RestoreScopes(d, saved); |
| 2208 | 2226 | RestoreScan(st); |
| 2209 | 2227 | CompileFile := m; |
| @@ -2430,6 +2448,8 @@ | ||
| 2430 | 2448 | nameMain := Name('main'); |
| 2431 | 2449 | nameBody := Name('body'); |
| 2432 | 2450 | nameStatic := Name('static'); |
| 2451 | + nameCheck := Name('check'); | |
| 2452 | + nameOff := Name('off'); | |
| 2433 | 2453 | rtFail := NewChunk(secText, nameRt, nameFail); |
| 2434 | 2454 | argcChunk := NewChunk(secBss, -1, Name('argc')); |
| 2435 | 2455 | SetBss(argcChunk, 8, 8); |
| @@ -153,8 +153,8 @@ | ||
| 153 | 153 | hasResult := false; |
| 154 | 154 | if main <> nil then begin |
| 155 | 155 | if (main^.cls <> oProc) or not main^.exported then Error(main^.pos, 'main must be an exported procedure') |
| 156 | - else if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tI64)) then | |
| 157 | - Error(main^.pos, 'main must be proc main* or proc main*: I64'); | |
| 156 | + else if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tInt)) then | |
| 157 | + Error(main^.pos, 'main must be proc main* or proc main*: INT'); | |
| 158 | 158 | if errors > 0 then Finish; |
| 159 | 159 | hasResult := main^.typ^.base <> nil; |
| 160 | 160 | end; |
| @@ -129,6 +129,7 @@ | ||
| 129 | 129 | |
| 130 | 130 | var |
| 131 | 131 | tI8, tI16, tI32, tI64, tU8, tU16, tU32, tU64: PType; |
| 132 | + tInt, tUInt: PType; { INT and UINT, as big as an address: 8 bytes here } | |
| 132 | 133 | tBool, tF32, tReal, tRConst, tError, tConst, tNil, tStr, tNone, tPtrU8, tBytes: PType; |
| 133 | 134 | tPoison: PType; { of a name reported as not declared } |
| 134 | 135 | curModule: PModule; |
| @@ -557,6 +558,8 @@ | ||
| 557 | 558 | tU16 := Basic('U16', fInt, 2, false); |
| 558 | 559 | tU32 := Basic('U32', fInt, 4, false); |
| 559 | 560 | tU64 := Basic('U64', fInt, 8, false); |
| 561 | + tInt := Basic('INT', fInt, 8, true); | |
| 562 | + tUInt := Basic('UINT', fInt, 8, false); | |
| 560 | 563 | tBool := Basic('BOOL', fBool, 1, false); |
| 561 | 564 | tF32 := Basic('F32', fReal, 4, false); |
| 562 | 565 | tReal := Basic('F64', fReal, 8, false); |
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | name: []U8; (* the program's, as the messages begin *) |
| 25 | 25 | table: []Row; |
| 26 | 26 | scope: []U8; |
| 27 | - at: I64; (* the next word *) | |
| 27 | + at: INT; (* the next word *) | |
| 28 | 28 | group: []U8; (* the letters left of a word of them, as -lw *) |
| 29 | 29 | spelt: []U8; (* the option just read as written, without its dashes *) |
| 30 | 30 | ended: BOOL; (* the scope's options have ended *) |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module orders, searches and hashes them, reads and writes their |
| 4 | 4 | UTF-8, and reads a number from one. |
| 5 | 5 | |
| 6 | -proc cmp*(a, b: []U8): I64; | |
| 6 | +proc cmp*(a, b: []U8): INT; | |
| 7 | 7 | -1, 0 or 1 as a sorts before, with or after b, byte by byte. |
| 8 | 8 | |
| 9 | 9 | proc eq*(a, b: []U8): BOOL; |
| @@ -11,17 +11,17 @@ | ||
| 11 | 11 | proc hash*(s: []U8): U64; |
| 12 | 12 | FNV-1a, 64 bits. |
| 13 | 13 | |
| 14 | -proc find*(s, sub: []U8): I64; | |
| 14 | +proc find*(s, sub: []U8): INT; | |
| 15 | 15 | Where sub first starts in s, or -1. |
| 16 | 16 | |
| 17 | 17 | proc hasPrefix*(s, p: []U8): BOOL; |
| 18 | 18 | |
| 19 | -proc encode*(c: I64): ([4]U8, I64); | |
| 19 | +proc encode*(c: I32): ([4]U8, INT); | |
| 20 | 20 | c in UTF-8: its bytes, and how many. A number that isn't a |
| 21 | 21 | character, a surrogate or one past 10FFFFH, becomes FFFDH, the |
| 22 | 22 | character that stands for a wrong one. |
| 23 | 23 | |
| 24 | -proc decode*(s: []U8): (I64, I64); | |
| 24 | +proc decode*(s: []U8): (I32, INT); | |
| 25 | 25 | The character s starts with, and its length in bytes: FFFDH and 1 |
| 26 | 26 | if its first byte doesn't start one rightly, being a continuation, |
| 27 | 27 | or followed by too few continuations, or spelling a surrogate or a |
| @@ -11,14 +11,14 @@ | ||
| 11 | 11 | const Failed*: ERROR = "can't start a thread"; |
| 12 | 12 | |
| 13 | 13 | type Thread* = record |
| 14 | - tid: I64; (* the kernel's id, until the thread ends *) | |
| 14 | + tid: INT; (* the kernel's id, until the thread ends *) | |
| 15 | 15 | base: ^U8; (* its stack's mapping, the guard page first *) |
| 16 | - size: I64; | |
| 16 | + size: INT; | |
| 17 | 17 | fn: proc(arg: ^U8); (* what it runs, and with what *) |
| 18 | 18 | arg: ^U8; |
| 19 | 19 | end; |
| 20 | 20 | |
| 21 | -type Mutex* = record state: I64; end; | |
| 21 | +type Mutex* = record state: INT; end; | |
| 22 | 22 | 0 free, 1 taken, 2 taken with a thread waiting |
| 23 | 23 | |
| 24 | 24 | proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR); |
| @@ -1,4 +1,4 @@ | ||
| 1 | -test/err/DeclAtomicSize.raz:8:15: error: expected an 8-byte integer or a pointer, found U8 | |
| 1 | +test/err/DeclAtomicSize.raz:8:15: error: expected a pointer to an INT or a UINT, found ^U8 | |
| 2 | 2 | 8 | n := XADD(p, 1); |
| 3 | 3 | | ^ |
| 4 | 4 | raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/DivLowestConst.raz:5:11: error: division overflows | |
| 2 | + 5 | _x := I8(-128) div (-1); | |
| 3 | + | ^^^^^^^^^^^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module DivLowestConst; | |
| 2 | +proc main*; | |
| 3 | +var _x: I8; | |
| 4 | +begin | |
| 5 | + _x := I8(-128) div (-1); | |
| 6 | +end; | |
| 7 | +end DivLowestConst. |
| @@ -8,22 +8,22 @@ | ||
| 8 | 8 | import Out; |
| 9 | 9 | |
| 10 | 10 | type |
| 11 | - Pair = record x, y: I64; end; | |
| 12 | - Shape = variant circle(r: I64); rect(w, h: I64); dot; end; | |
| 11 | + Pair = record x, y: INT; end; | |
| 12 | + Shape = variant circle(r: INT); rect(w, h: INT); dot; end; | |
| 13 | 13 | |
| 14 | 14 | var |
| 15 | - g: [16]I64; | |
| 16 | - data: [64]I64; | |
| 15 | + g: [16]INT; | |
| 16 | + data: [64]INT; | |
| 17 | 17 | """) |
| 18 | -print("""proc p0(a, b: I64; _s: []I64): I64; | |
| 18 | +print("""proc p0(a, b: INT; _s: []INT): INT; | |
| 19 | 19 | begin |
| 20 | 20 | return a + b; |
| 21 | 21 | end; |
| 22 | 22 | """) |
| 23 | 23 | for i in range(1, n + 1): |
| 24 | 24 | print(f"""(* procedure {i} *) |
| 25 | -proc p{i}(a, b: I64; s: []I64): I64; | |
| 26 | -var i, t: I64; r: Pair; sh: Shape; | |
| 25 | +proc p{i}(a, b: INT; s: []INT): INT; | |
| 26 | +var i, t: INT; r: Pair; sh: Shape; | |
| 27 | 27 | begin |
| 28 | 28 | t := 0; |
| 29 | 29 | for i := 0 to LEN(s) - 1 do |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | end; |
| 52 | 52 | """) |
| 53 | 53 | print(f"""proc main*; |
| 54 | -var i: I64; | |
| 54 | +var i: INT; | |
| 55 | 55 | begin |
| 56 | 56 | for i := 0 to 63 do data[i] := i; end; |
| 57 | 57 | Out.int(p{n}(1, 2, data[0..4])); |
| @@ -0,0 +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 | + | ^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +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 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportAsSlice.raz:6:9: error: Owner.a is Owner's, and can't be changed outside it | |
| 2 | + 6 | sum(Owner.a); | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportAssign.raz:5:5: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | + 5 | Owner.n := 1; | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportElem.raz:5:5: error: Owner.a[2] is Owner's, and can't be changed outside it | |
| 2 | + 5 | Owner.a[2] := 1; | |
| 3 | + | ^^^^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportInc.raz:5:9: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | + 5 | INC(Owner.n); | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportSlice.raz:6:11: error: Owner.a is Owner's, and can't be changed outside it | |
| 2 | + 6 | _s := Owner.a[0..2]; | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/ExportVarParam.raz:6:9: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | + 6 | put(Owner.n); | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/IntFor.raz:5:19: error: expected I64, found INT | |
| 2 | + 5 | for i := 0 to LEN(s) - 1 do end; | |
| 3 | + | ^^^^^^^^^^ | |
| 4 | +help: they don't mix here: write I64(LEN(s) - 1) | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/IntFromPointer.raz:5:14: error: can't convert ^U8 to I64 | |
| 2 | + 5 | i := I64(p); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/IntInc.raz:5:12: error: expected I64, found INT | |
| 2 | + 5 | INC(i, LEN(s)); | |
| 3 | + | ^^^^^^ | |
| 4 | +help: they don't mix here: write I64(LEN(s)) | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/IntMix.raz:5:8: error: I64 and INT are different types | |
| 2 | + 5 | if i < LEN(s) then end; | |
| 3 | + | ^^^^^^^^^^ | |
| 4 | +help: convert one to the other's type, as in I64(LEN(s)) | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/IntNarrow.raz:5:10: error: can't use I64 as INT | |
| 2 | + 5 | n := i; | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/IntPointer.raz:5:14: error: can't convert I64 to ^U8 | |
| 2 | + 5 | p := ^U8(i); | |
| 3 | + | ^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/IntResults.raz:6:13: error: expected I64, found INT | |
| 2 | + 6 | a, b := two(); | |
| 3 | + | ^^^^^ | |
| 4 | +help: several results go to variables of just their types | |
| 5 | +raz: 1 error |
| @@ -1,4 +1,4 @@ | ||
| 1 | -conform/err/ScanMain.raz:2:6: error: main must be proc main* or proc main*: I64 | |
| 1 | +conform/err/ScanMain.raz:2:6: error: main must be proc main* or proc main*: INT | |
| 2 | 2 | 2 | proc main*(_n: I64); |
| 3 | 3 | | ^^^^ |
| 4 | 4 | raz: 1 error |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | module Atomic; |
| 2 | 2 | import Out; |
| 3 | 3 | |
| 4 | -var counter: I64; flag: U64; p: ^I64; | |
| 4 | +var counter: INT; flag: UINT; p: ^INT; | |
| 5 | 5 | |
| 6 | 6 | proc add3*(a, b, c: I64): I64; |
| 7 | 7 | code 48H, 8DH, 04H, 37H, (* lea rax, [rdi+rsi] *) |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | 0C3H; (* ret *) |
| 10 | 10 | |
| 11 | 11 | proc main*; |
| 12 | -var old: I64; ok: BOOL; v: ^VOLATILE I64; x: I64; | |
| 12 | +var old: INT; ok: BOOL; v: ^VOLATILE INT; x: INT; | |
| 13 | 13 | begin |
| 14 | 14 | old := XADD(ADR(counter), 5); |
| 15 | 15 | old := XADD(ADR(counter), 2); |
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | v^ := 5; |
| 29 | 29 | v^ := v^ + 1; |
| 30 | 30 | Out.int(x); Out.ln; |
| 31 | - v := ^VOLATILE I64(ADR(counter)); | |
| 31 | + v := ^VOLATILE INT(ADR(counter)); | |
| 32 | 32 | Out.int(v^); Out.ln; |
| 33 | 33 | end; |
| 34 | 34 |
| @@ -0,0 +1 @@ | ||
| 1 | +42 4 |
| @@ -0,0 +1,18 @@ | ||
| 1 | +module CheckOff; | |
| 2 | +(* check off leaves out the checks of its own module only: here | |
| 3 | + Unchecked reads past an array, into the field after it, and makes a | |
| 4 | + slice past its string's end; then this module's own index fails *) | |
| 5 | +import Out, Unchecked; | |
| 6 | + | |
| 7 | +proc main*; | |
| 8 | +var p: Unchecked.Pair; i: INT; | |
| 9 | +begin | |
| 10 | + p.b := 42; | |
| 11 | + Out.int(Unchecked.get(ADR(p), 2)); Out.str(" "); | |
| 12 | + Out.int(Unchecked.width("abc", 1, 5)); Out.ln; | |
| 13 | + Out.flush; | |
| 14 | + i := 2; | |
| 15 | + Out.int(p.a[i]); | |
| 16 | +end; | |
| 17 | + | |
| 18 | +end CheckOff. |
| @@ -0,0 +1 @@ | ||
| 1 | +2 |
| @@ -0,0 +1 @@ | ||
| 1 | +test/run/CheckOff.raz:15:17: index 2 is out of range for a length of 2 |
| @@ -66,7 +66,7 @@ | ||
| 66 | 66 | m.a := 1; m.b := -2; m.c := 65535; |
| 67 | 67 | Out.int(m.b); Out.str(" "); Out.int(I64(m.c)); Out.ln; |
| 68 | 68 | bp := ^U8(ADR(m)); |
| 69 | - Out.int(I64(ADR(m.c)) - I64(bp)); Out.ln; | |
| 69 | + Out.int(INT(ADR(m.c)) - INT(bp)); Out.ln; | |
| 70 | 70 | end; |
| 71 | 71 | |
| 72 | 72 | end Data. |
| @@ -0,0 +1 @@ | ||
| 1 | +-2 | |
| \ No newline at end of file |
| @@ -0,0 +1,15 @@ | ||
| 1 | +module DivLowestI16; | |
| 2 | +(* mod too: the lowest I16 mod -1 overflows the division as div does *) | |
| 3 | +import Out; | |
| 4 | + | |
| 5 | +proc main*; | |
| 6 | +var a, b: I16; | |
| 7 | +begin | |
| 8 | + a := -32768; | |
| 9 | + b := I16(ARGC() - 2); | |
| 10 | + Out.int(I64(a mod 3)); | |
| 11 | + Out.flush; | |
| 12 | + Out.int(I64(a mod b)); | |
| 13 | +end; | |
| 14 | + | |
| 15 | +end DivLowestI16. |
| @@ -0,0 +1 @@ | ||
| 1 | +136 |
| @@ -0,0 +1 @@ | ||
| 1 | +test/run/DivLowestI16.raz:12:5: stopped by a division fault |
| @@ -0,0 +1 @@ | ||
| 1 | +-1073741824 | |
| \ No newline at end of file |
| @@ -0,0 +1,14 @@ | ||
| 1 | +module DivLowestI32; | |
| 2 | +(* The lowest I32 divided by the constant -1 *) | |
| 3 | +import Out; | |
| 4 | + | |
| 5 | +proc main*; | |
| 6 | +var a: I32; | |
| 7 | +begin | |
| 8 | + a := I32(ARGC()) - 2147483647 - 2; | |
| 9 | + Out.int(I64(a div 2)); | |
| 10 | + Out.flush; | |
| 11 | + Out.int(I64(a div (-1))); | |
| 12 | +end; | |
| 13 | + | |
| 14 | +end DivLowestI32. |
| @@ -0,0 +1 @@ | ||
| 1 | +136 |
| @@ -0,0 +1 @@ | ||
| 1 | +test/run/DivLowestI32.raz:11:5: stopped by a division fault |
| @@ -0,0 +1 @@ | ||
| 1 | +64 | |
| \ No newline at end of file |
| @@ -0,0 +1,16 @@ | ||
| 1 | +module DivLowestI8; | |
| 2 | +(* The lowest of every signed type divided by -1 stops the program, not | |
| 3 | + only the lowest I64's: here an I8's, by a divisor not known *) | |
| 4 | +import Out; | |
| 5 | + | |
| 6 | +proc main*; | |
| 7 | +var a, b: I8; | |
| 8 | +begin | |
| 9 | + a := -128; | |
| 10 | + b := I8(ARGC() - 2); | |
| 11 | + Out.int(I64(a div (-2))); | |
| 12 | + Out.flush; | |
| 13 | + Out.int(I64(a div b)); | |
| 14 | +end; | |
| 15 | + | |
| 16 | +end DivLowestI8. |
| @@ -0,0 +1 @@ | ||
| 1 | +136 |
| @@ -0,0 +1 @@ | ||
| 1 | +test/run/DivLowestI8.raz:13:5: stopped by a division fault |
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | module DivZero; |
| 2 | 2 | (* Dividing by zero stops the program with SIGFPE, after saying where *) |
| 3 | 3 | |
| 4 | -proc main*: I64; | |
| 5 | -var a, b: I64; | |
| 4 | +proc main*: INT; | |
| 5 | +var a, b: INT; | |
| 6 | 6 | begin |
| 7 | 7 | a := 7; |
| 8 | 8 | b := ARGC() - 1; |
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | end; |
| 32 | 32 | |
| 33 | 33 | proc sumInner(xs: []Inner): I64; |
| 34 | -var i, j, s: I64; | |
| 34 | +var i, j: INT; s: I64; | |
| 35 | 35 | begin |
| 36 | 36 | s := 0; |
| 37 | 37 | for i := 0 to LEN(xs) - 1 do |
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | module NilProc; |
| 2 | 2 | (* Calling a nil procedure: the place is the call's *) |
| 3 | 3 | |
| 4 | -var f: proc(n: I64): I64; | |
| 4 | +var f: proc(n: INT): INT; | |
| 5 | 5 | |
| 6 | -proc main*: I64; | |
| 6 | +proc main*: INT; | |
| 7 | 7 | begin |
| 8 | 8 | return f(1) |
| 9 | 9 | + 1; |
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | var |
| 13 | 13 | m: Thread.Mutex; |
| 14 | - count, atomic: I64; | |
| 14 | + count: I64; atomic: INT; | |
| 15 | 15 | |
| 16 | 16 | proc work(arg: ^U8); |
| 17 | 17 | var i: I64; p, list: ^Node; |
| @@ -4,14 +4,14 @@ | ||
| 4 | 4 | zeroes it from the bottom: with a small one, where the stack starts |
| 5 | 5 | could put the guard page under the body's pushes instead. *) |
| 6 | 6 | |
| 7 | -proc down(n: I64): I64; | |
| 8 | -var pad: [65536]I64; | |
| 7 | +proc down(n: INT): INT; | |
| 8 | +var pad: [65536]INT; | |
| 9 | 9 | begin |
| 10 | 10 | pad[n mod 65536] := n; |
| 11 | 11 | return down(n + 1) + pad[0]; |
| 12 | 12 | end; |
| 13 | 13 | |
| 14 | -proc main*: I64; | |
| 14 | +proc main*: INT; | |
| 15 | 15 | begin |
| 16 | 16 | return down(0); |
| 17 | 17 | end; |
| @@ -0,0 +1,17 @@ | ||
| 1 | +module Unchecked; | |
| 2 | +(* A module without index and slice checks *) | |
| 3 | +check off; | |
| 4 | + | |
| 5 | +type Pair* = record a*: [2]INT; b*: INT; end; | |
| 6 | + | |
| 7 | +proc get*(p: ^Pair; i: INT): INT; | |
| 8 | +begin | |
| 9 | + return p^.a[i]; | |
| 10 | +end; | |
| 11 | + | |
| 12 | +proc width*(s: []U8; lo, hi: INT): INT; | |
| 13 | +begin | |
| 14 | + return LEN(s[lo..hi]); | |
| 15 | +end; | |
| 16 | + | |
| 17 | +end Unchecked. |
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | var |
| 16 | 16 | sc: Scan.Scanner; (* the text being read, at the current symbol *) |
| 17 | 17 | src: []U8; |
| 18 | - docStart, docEnd: I64; (* the comment just before it, or -1 *) | |
| 18 | + docStart, docEnd: INT; (* the comment just before it, or -1 *) | |
| 19 | 19 | |
| 20 | 20 | (* On to the next symbol that isn't a comment, keeping where the last |
| 21 | 21 | comment that starts a line was: one after code on its line belongs |
| @@ -53,8 +53,8 @@ | ||
| 53 | 53 | |
| 54 | 54 | (* On to the ; that ends what starts here, past anything bracketed and |
| 55 | 55 | any record or variant; returns where it ends. *) |
| 56 | -proc toSemicolon: I64; | |
| 57 | -var depth: I64; | |
| 56 | +proc toSemicolon: INT; | |
| 57 | +var depth: INT; | |
| 58 | 58 | begin |
| 59 | 59 | depth := 0; |
| 60 | 60 | while sc.kind # Scan.eof do |
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | end; |
| 69 | 69 | |
| 70 | 70 | (* stop, or the end of a comment that follows it on its line. *) |
| 71 | -proc trailing(stop: I64): I64; | |
| 71 | +proc trailing(stop: INT): INT; | |
| 72 | 72 | var t: Scan.Scanner; |
| 73 | 73 | begin |
| 74 | 74 | while (stop < LEN(src)) and ((src[stop] = ' ') or (src[stop] = 9)) do INC(stop); end; |
| @@ -80,7 +80,7 @@ | ||
| 80 | 80 | end; |
| 81 | 81 | |
| 82 | 82 | (* Where the line holding p starts. *) |
| 83 | -proc lineStart(p: I64): I64; | |
| 83 | +proc lineStart(p: INT): INT; | |
| 84 | 84 | begin |
| 85 | 85 | while (p > 0) and (src[p - 1] # 10) do DEC(p); end; |
| 86 | 86 | return p; |
| @@ -88,8 +88,8 @@ | ||
| 88 | 88 | |
| 89 | 89 | (* src[start..stop] as written, each line after the first moved left as |
| 90 | 90 | far as the first one's column. *) |
| 91 | -proc block(start, stop: I64); | |
| 92 | -var col, i, n: I64; | |
| 91 | +proc block(start, stop: INT); | |
| 92 | +var col, i, n: INT; | |
| 93 | 93 | begin |
| 94 | 94 | col := start - lineStart(start); |
| 95 | 95 | i := start; |
| @@ -106,8 +106,8 @@ | ||
| 106 | 106 | |
| 107 | 107 | (* The comment from start to stop, without its brackets, each line |
| 108 | 108 | indented by four. *) |
| 109 | -proc comment(start, stop: I64); | |
| 110 | -var i, j: I64; atLine: BOOL; | |
| 109 | +proc comment(start, stop: INT); | |
| 110 | +var i, j: INT; atLine: BOOL; | |
| 111 | 111 | begin |
| 112 | 112 | if start < 0 then return; end; |
| 113 | 113 | i := start + 2; |
| @@ -128,7 +128,7 @@ | ||
| 128 | 128 | end; |
| 129 | 129 | |
| 130 | 130 | (* One declaration, from its first token, the comment before it kept. *) |
| 131 | -proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: I64); | |
| 131 | +proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: INT); | |
| 132 | 132 | begin |
| 133 | 133 | if not exported then return; end; |
| 134 | 134 | Out.ln; |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | (* A procedure's body: to the end that closes its begin, the procedure |
| 150 | 150 | name after it and its ;. *) |
| 151 | 151 | proc skipBody; |
| 152 | -var depth: I64; sawBegin: BOOL; | |
| 152 | +var depth: INT; sawBegin: BOOL; | |
| 153 | 153 | begin |
| 154 | 154 | depth := 0; |
| 155 | 155 | sawBegin := false; |
| @@ -172,7 +172,7 @@ | ||
| 172 | 172 | end; |
| 173 | 173 | |
| 174 | 174 | proc procedure; |
| 175 | -var start, ds, de, stop: I64; exp: BOOL; | |
| 175 | +var start, ds, de, stop: INT; exp: BOOL; | |
| 176 | 176 | begin |
| 177 | 177 | start := sc.start; ds := docStart; de := docEnd; |
| 178 | 178 | exp := name(); |
| @@ -186,7 +186,7 @@ | ||
| 186 | 186 | end; |
| 187 | 187 | |
| 188 | 188 | proc section; |
| 189 | -var word: []U8; start, ds, de, stop: I64; exp: BOOL; | |
| 189 | +var word: []U8; start, ds, de, stop: INT; exp: BOOL; | |
| 190 | 190 | begin |
| 191 | 191 | word := text(); |
| 192 | 192 | next; |
| @@ -206,7 +206,7 @@ | ||
| 206 | 206 | end; |
| 207 | 207 | |
| 208 | 208 | proc external; |
| 209 | -var start, ds, de, stop: I64; exp: BOOL; | |
| 209 | +var start, ds, de, stop: INT; exp: BOOL; | |
| 210 | 210 | begin |
| 211 | 211 | start := sc.start; ds := docStart; de := docEnd; |
| 212 | 212 | next; |
| @@ -217,7 +217,7 @@ | ||
| 217 | 217 | end; |
| 218 | 218 | |
| 219 | 219 | proc document(path: []U8); |
| 220 | -var b: Buf.Buf; start, ds, de: I64; | |
| 220 | +var b: Buf.Buf; start, ds, de: INT; | |
| 221 | 221 | begin |
| 222 | 222 | Buf.init(ADR(b), Heap.heap); |
| 223 | 223 | if not Files.read(path, ADR(b)) then Rt.stop("Doc: can't read the file"); end; |
| @@ -243,7 +243,7 @@ | ||
| 243 | 243 | |
| 244 | 244 | (* line, without the spaces at its ends *) |
| 245 | 245 | proc trim(line: []U8): []U8; |
| 246 | -var i, j: I64; | |
| 246 | +var i, j: INT; | |
| 247 | 247 | begin |
| 248 | 248 | i := 0; |
| 249 | 249 | j := LEN(line); |
| @@ -255,7 +255,7 @@ | ||
| 255 | 255 | (* The report's examples that are whole modules, each to dir. *) |
| 256 | 256 | proc examples(path, dir: []U8); |
| 257 | 257 | var |
| 258 | - b, out: Buf.Buf; s, line, first, last, name: []U8; i, start, k, n: I64; | |
| 258 | + b, out: Buf.Buf; s, line, first, last, name: []U8; i, start, k, n: INT; | |
| 259 | 259 | inBlock, whole: BOOL; |
| 260 | 260 | begin |
| 261 | 261 | Buf.init(ADR(b), Heap.heap); |
| @@ -14,17 +14,17 @@ | ||
| 14 | 14 | state: U64; (* the generator: xorshift64 *) |
| 15 | 15 | |
| 16 | 16 | (* A number from the generator, below n. *) |
| 17 | -proc random(n: I64): I64; | |
| 17 | +proc random(n: INT): INT; | |
| 18 | 18 | begin |
| 19 | 19 | state := state xor (state shl 13); |
| 20 | 20 | state := state xor (state shr 7); |
| 21 | 21 | state := state xor (state shl 17); |
| 22 | - return I64(state mod U64(n)); | |
| 22 | + return INT(state mod U64(n)); | |
| 23 | 23 | end; |
| 24 | 24 | |
| 25 | 25 | (* The seed, as a nonzero state. *) |
| 26 | 26 | proc seed(s: []U8); |
| 27 | -var i: I64; | |
| 27 | +var i: INT; | |
| 28 | 28 | begin |
| 29 | 29 | state := 88172645463325252; |
| 30 | 30 | for i := 0 to LEN(s) - 1 do state := state * 31 + U64(s[i]); end; |
| @@ -33,8 +33,8 @@ | ||
| 33 | 33 | end; |
| 34 | 34 | |
| 35 | 35 | (* The symbols that aren't comments. *) |
| 36 | -proc count(): I64; | |
| 37 | -var sc: Scan.Scanner; n: I64; | |
| 36 | +proc count(): INT; | |
| 37 | +var sc: Scan.Scanner; n: INT; | |
| 38 | 38 | begin |
| 39 | 39 | Scan.init(ADR(sc), src); |
| 40 | 40 | Scan.next(ADR(sc)); |
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | end; |
| 48 | 48 | |
| 49 | 49 | (* Symbol k, counting from 0 and leaving out comments. *) |
| 50 | -proc symbol(k: I64): Scan.Scanner; | |
| 50 | +proc symbol(k: INT): Scan.Scanner; | |
| 51 | 51 | var sc: Scan.Scanner; |
| 52 | 52 | begin |
| 53 | 53 | Scan.init(ADR(sc), src); |
| @@ -59,7 +59,7 @@ | ||
| 59 | 59 | end; |
| 60 | 60 | |
| 61 | 61 | proc main*; |
| 62 | -var buf: Buf.Buf; n, op, i: I64; a, b, c: Scan.Scanner; | |
| 62 | +var buf: Buf.Buf; n, op, i: INT; a, b, c: Scan.Scanner; | |
| 63 | 63 | begin |
| 64 | 64 | if ARGC() # 3 then Rt.stop("usage: Mutate File.raz seed"); end; |
| 65 | 65 | Buf.init(ADR(buf), Heap.heap); |
| @@ -34,25 +34,25 @@ | ||
| 34 | 34 | sc: Scan.Scanner; (* the source, at the symbol being written *) |
| 35 | 35 | src: []U8; |
| 36 | 36 | out: Buf.Buf; |
| 37 | - lineAt: I64; (* where the line being written starts in out *) | |
| 38 | - lineDelta: I64; (* how far this line's indent moved *) | |
| 37 | + lineAt: INT; (* where the line being written starts in out *) | |
| 38 | + lineDelta: INT; (* how far this line's indent moved *) | |
| 39 | 39 | |
| 40 | 40 | (* the blocks open, each with the indent of the statement that |
| 41 | 41 | opened it *) |
| 42 | - bases: [100]I64; | |
| 43 | - depth: I64; | |
| 44 | - brackets: I64; (* brackets open *) | |
| 42 | + bases: [100]INT; | |
| 43 | + depth: INT; | |
| 44 | + brackets: INT; (* brackets open *) | |
| 45 | 45 | inSection: BOOL; (* among the declarations of const, type or var *) |
| 46 | - stmtIndent: I64; (* the indent of the current statement's first line *) | |
| 47 | - stmtDelta: I64; (* and how far that moved *) | |
| 46 | + stmtIndent: INT; (* the indent of the current statement's first line *) | |
| 47 | + stmtDelta: INT; (* and how far that moved *) | |
| 48 | 48 | |
| 49 | 49 | (* the last symbol that wasn't a comment, and the one before it *) |
| 50 | 50 | prev, prev2: Scan.Scanner; |
| 51 | 51 | prevBinary, prevUnary: BOOL; |
| 52 | 52 | afterComment: BOOL; (* the last symbol written was a comment *) |
| 53 | - last: I64; (* where the last symbol written ends in src *) | |
| 53 | + last: INT; (* where the last symbol written ends in src *) | |
| 54 | 54 | |
| 55 | -proc spaces(n: I64); | |
| 55 | +proc spaces(n: INT); | |
| 56 | 56 | begin |
| 57 | 57 | while n > 0 do Buf.add(ADR(out), ' '); DEC(n); end; |
| 58 | 58 | end; |
| @@ -75,15 +75,15 @@ | ||
| 75 | 75 | end; |
| 76 | 76 | |
| 77 | 77 | (* Where the line holding p starts in src. *) |
| 78 | -proc lineStart(p: I64): I64; | |
| 78 | +proc lineStart(p: INT): INT; | |
| 79 | 79 | begin |
| 80 | 80 | while (p > 0) and (src[p - 1] # '\n') do DEC(p); end; |
| 81 | 81 | return p; |
| 82 | 82 | end; |
| 83 | 83 | |
| 84 | 84 | (* The column src[p] is at, a tab going on to the next multiple of 8. *) |
| 85 | -proc column(p: I64): I64; | |
| 86 | -var i, col: I64; | |
| 85 | +proc column(p: INT): INT; | |
| 86 | +var i, col: INT; | |
| 87 | 87 | begin |
| 88 | 88 | col := 0; |
| 89 | 89 | for i := lineStart(p) to p - 1 do |
| @@ -153,21 +153,21 @@ | ||
| 153 | 153 | end; |
| 154 | 154 | |
| 155 | 155 | (* The indent of the block's own lines, or of its end. *) |
| 156 | -proc inner: I64; | |
| 156 | +proc inner: INT; | |
| 157 | 157 | begin |
| 158 | 158 | if depth > 0 then return bases[depth - 1] + width; end; |
| 159 | 159 | if inSection then return width; end; |
| 160 | 160 | return 0; |
| 161 | 161 | end; |
| 162 | 162 | |
| 163 | -proc outer: I64; | |
| 163 | +proc outer: INT; | |
| 164 | 164 | begin |
| 165 | 165 | if depth > 0 then return bases[depth - 1]; end; |
| 166 | 166 | return 0; |
| 167 | 167 | end; |
| 168 | 168 | |
| 169 | 169 | (* The indent of the line the current symbol starts, which was at old. *) |
| 170 | -proc indent(old: I64): I64; | |
| 170 | +proc indent(old: INT): INT; | |
| 171 | 171 | var n: Scan.Scanner; |
| 172 | 172 | begin |
| 173 | 173 | if continues() then |
| @@ -192,7 +192,7 @@ | ||
| 192 | 192 | |
| 193 | 193 | (* Starts the line of the current symbol, at its indent. *) |
| 194 | 194 | proc startLine; |
| 195 | -var old, new: I64; | |
| 195 | +var old, new: INT; | |
| 196 | 196 | begin |
| 197 | 197 | old := column(sc.start); |
| 198 | 198 | new := indent(old); |
| @@ -207,7 +207,7 @@ | ||
| 207 | 207 | (* The spaces between the last symbol written and the current one, on |
| 208 | 208 | the same line. *) |
| 209 | 209 | proc gap(binaryNow: BOOL); |
| 210 | -var n: I64; | |
| 210 | +var n: INT; | |
| 211 | 211 | begin |
| 212 | 212 | if sc.kind = Scan.comment then |
| 213 | 213 | n := column(sc.start) + lineDelta - (out.len - lineAt); |
| @@ -226,7 +226,7 @@ | ||
| 226 | 226 | (* The current symbol as written; each line of a comment after its |
| 227 | 227 | first is moved as far as the line the comment starts on. *) |
| 228 | 228 | proc write; |
| 229 | -var i, k: I64; | |
| 229 | +var i, k: INT; | |
| 230 | 230 | begin |
| 231 | 231 | i := sc.start; |
| 232 | 232 | while i < sc.stop do |
| @@ -270,8 +270,8 @@ | ||
| 270 | 270 | end; |
| 271 | 271 | |
| 272 | 272 | (* The line breaks in src[from..upto]. *) |
| 273 | -proc lineBreaks(from, upto: I64); | |
| 274 | -var i: I64; | |
| 273 | +proc lineBreaks(from, upto: INT); | |
| 274 | +var i: INT; | |
| 275 | 275 | begin |
| 276 | 276 | for i := from to upto - 1 do |
| 277 | 277 | if src[i] = '\n' then newLine; end; |
| @@ -317,7 +317,7 @@ | ||
| 317 | 317 | end; |
| 318 | 318 | |
| 319 | 319 | proc main*; |
| 320 | -var b: Buf.Buf; i: I64; path: []U8; | |
| 320 | +var b: Buf.Buf; i: INT; path: []U8; | |
| 321 | 321 | begin |
| 322 | 322 | Buf.init(ADR(b), Heap.heap); |
| 323 | 323 | Buf.init(ADR(out), Heap.heap); |
| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | character; symbol an operator or delimiter. *) |
| 14 | 14 | Scanner* = record |
| 15 | 15 | src*: []U8; |
| 16 | - pos*: I64; (* where the next symbol is looked for *) | |
| 16 | + pos*: INT; (* where the next symbol is looked for *) | |
| 17 | 17 | kind*: Kind; (* the current symbol *) |
| 18 | - start*, stop*: I64; (* its text: src[start..stop] *) | |
| 18 | + start*, stop*: INT; (* its text: src[start..stop] *) | |
| 19 | 19 | lineBreak*: BOOL; (* a line break comes before it, or it is the first *) |
| 20 | 20 | end; |
| 21 | 21 | |
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | (* Whether w is one of the words of list, which are separated by |
| 42 | 42 | single spaces. *) |
| 43 | 43 | proc among*(w, list: []U8): BOOL; |
| 44 | -var i, j: I64; | |
| 44 | +var i, j: INT; | |
| 45 | 45 | begin |
| 46 | 46 | i := 0; |
| 47 | 47 | while i < LEN(list) do |
| @@ -66,8 +66,8 @@ | ||
| 66 | 66 | end; |
| 67 | 67 | |
| 68 | 68 | (* Past the comment that starts at p, its nested comments with it. *) |
| 69 | -proc pastComment(src: []U8; p: I64): I64; | |
| 70 | -var depth: I64; | |
| 69 | +proc pastComment(src: []U8; p: INT): INT; | |
| 70 | +var depth: INT; | |
| 71 | 71 | begin |
| 72 | 72 | depth := 0; |
| 73 | 73 | repeat |
| @@ -84,7 +84,7 @@ | ||
| 84 | 84 | |
| 85 | 85 | (* Past the number that starts at p: digits and letters, then a real's |
| 86 | 86 | point, digits and exponent, as in 0FFH and 2.0E-3. *) |
| 87 | -proc pastNumber(src: []U8; p: I64): I64; | |
| 87 | +proc pastNumber(src: []U8; p: INT): INT; | |
| 88 | 88 | begin |
| 89 | 89 | while (p < LEN(src)) and isWord(src[p]) do INC(p); end; |
| 90 | 90 | if (p + 1 < LEN(src)) and (src[p] = '.') and isDigit(src[p + 1]) then |
| @@ -99,7 +99,7 @@ | ||
| 99 | 99 | end; |
| 100 | 100 | |
| 101 | 101 | (* Past the string or character that starts at p, or to its line's end. *) |
| 102 | -proc pastLiteral(src: []U8; p: I64): I64; | |
| 102 | +proc pastLiteral(src: []U8; p: INT): INT; | |
| 103 | 103 | var q: U8; |
| 104 | 104 | begin |
| 105 | 105 | q := src[p]; |
| @@ -113,14 +113,14 @@ | ||
| 113 | 113 | end; |
| 114 | 114 | |
| 115 | 115 | (* Whether src[p..] starts with the symbol t. *) |
| 116 | -proc at(src: []U8; p: I64; t: []U8): BOOL; | |
| 116 | +proc at(src: []U8; p: INT; t: []U8): BOOL; | |
| 117 | 117 | begin |
| 118 | 118 | return (p + LEN(t) <= LEN(src)) and (src[p..p + LEN(t)] = t); |
| 119 | 119 | end; |
| 120 | 120 | |
| 121 | 121 | (* On to the next symbol. *) |
| 122 | 122 | proc next*(s: ^Scanner); |
| 123 | -var src: []U8; p: I64; c: U8; | |
| 123 | +var src: []U8; p: INT; c: U8; | |
| 124 | 124 | begin |
| 125 | 125 | src := s^.src; |
| 126 | 126 | p := s^.pos; |