raz / commit 2411fde8

commit
2411fde85f3a9ff9bd48baa74bcebaac2839efc6
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
31f6696c
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.

patch · log

118 files changed, +1096 -586

CLAUDE.md modified +11 -2

@@ -139,7 +139,7 @@
139139 program the entry point stores C's `exit` in `Rt.cExit`, found by
140140 name like `Rt.exit`, before any module body runs.
141141 - 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`.
143143 - A real constant is held as an F64; one typed `F32` holds a value an
144144 F32 can hold. An `F32` in a register is its low 32 bits; the upper
145145 ones are left as they fall.
@@ -153,7 +153,16 @@
153153 threads have none, so a stack overflow in one ends the program by
154154 the signal with no message.
155155 - 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.
157166 - Warnings come only for a module with no errors. A procedure naming
158167 itself doesn't use it; a type named by a pointer in its own
159168 declaration does. An enumeration's names are never warned of, nor a

PLAN.md (history) modified +1 -1

@@ -119,7 +119,7 @@
119119 the IR written down; `doc/ir.md` is removed, and git keeps it.
120120 - [x] 4. The tests split: a conformance suite any implementation
121121 passes, apart from this compiler's own messages.
122-- [ ] 5. The system integer.
122+- [x] 5. The system integer.
123123 - [ ] 6. Optional reals: a target says whether it has them.
124124 - [ ] 6a. `+` joins string constants (report, section 4).
125125 - [ ] 6b. Array constants: `const P: [5]I64 = [...]`, in read-only

conform/err/AtomicI64.raz (history) added +7 -0

@@ -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.

conform/err/ExportAdr.raz (history) added +8 -0

@@ -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.

conform/err/ExportAsSlice.raz (history) added +8 -0

@@ -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.

conform/err/ExportAssign.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module ExportAssign;
2+import Owner;
3+proc main*;
4+begin
5+ Owner.n := 1;
6+end;
7+end ExportAssign.

conform/err/ExportElem.raz (history) added +7 -0

@@ -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.

conform/err/ExportInc.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module ExportInc;
2+import Owner;
3+proc main*;
4+begin
5+ INC(Owner.n);
6+end;
7+end ExportInc.

conform/err/ExportSlice.raz (history) added +8 -0

@@ -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.

conform/err/ExportVarParam.raz (history) added +8 -0

@@ -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.

conform/err/IntFor.raz added +7 -0

@@ -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.

conform/err/IntFromPointer.raz (history) added +7 -0

@@ -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.

conform/err/IntInc.raz added +7 -0

@@ -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.

conform/err/IntMix.raz added +7 -0

@@ -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.

conform/err/IntNarrow.raz (history) added +7 -0

@@ -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.

conform/err/IntPointer.raz (history) added +7 -0

@@ -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.

conform/err/IntResults.raz added +8 -0

@@ -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.

conform/err/mods/Owner.raz (history) added +3 -0

@@ -0,0 +1,3 @@
1+module Owner;
2+var n*: INT; a*: [4]INT;
3+end Owner.

conform/run/Args.raz (history) modified +2 -2

@@ -1,8 +1,8 @@
11 module Args;
22 import Out;
33
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;
66 begin
77 a := ARGV();
88 for i := 1 to ARGC() - 1 do

conform/run/AtExit.raz (history) modified +1 -1

@@ -23,7 +23,7 @@
2323 begin
2424 end;
2525
26-proc main*: I64;
26+proc main*: INT;
2727 var i, full: I64;
2828 begin
2929 Rt.atExit(first);

conform/run/Generic.raz (history) modified +6 -6

@@ -6,12 +6,12 @@
66 proc main*;
77 var l: Strs.List; v: I64; s: []U8; ok: BOOL; b: Buf.Buf; n: ^Ints.Node;
88 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)]);
1515 Strs.init(ADR(l), Heap.heap);
1616 ok := Strs.push(ADR(l), "b");
1717 ok := Strs.push(ADR(l), "a");

conform/run/HeapCheck.raz modified +1 -1

@@ -19,7 +19,7 @@
1919 show(Mem.alloc(Heap.heap, 10, 8192));
2020 p := Mem.alloc(Heap.heap, 10, 64);
2121 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;
2323 Mem.free(Heap.heap, p);
2424 q := Mem.alloc(Heap.heap, 100000, 8);
2525 show(q);

conform/run/MapRemove.raz modified +1 -1

@@ -18,7 +18,7 @@
1818
1919 proc main*;
2020 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;
2222 found, _ok: BOOL;
2323 begin
2424 Ints.init(ADR(m), Heap.heap);

conform/run/Procs.raz (history) modified +1 -1

@@ -88,7 +88,7 @@
8888 return a + b;
8989 end;
9090
91-proc main*: I64;
91+proc main*: INT;
9292 var a, b: I64; p, q: Pair; f: Op; bg: Big;
9393 begin
9494 if even(10) and odd(7) and not even(3) then Out.str("parity ok"); Out.ln; end;

conform/run/Strings.raz (history) modified +1 -1

@@ -6,7 +6,7 @@
66 var buf: [8]U8;
77
88 proc count(xs: []I64): I64;
9-var i, s: I64;
9+var i: INT; s: I64;
1010 begin
1111 s := 0;
1212 for i := 0 to LEN(xs) - 1 do s := s + xs[i]; end;

conform/run/SystemInt.expect (history) added +5 -0

@@ -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

conform/run/SystemInt.raz (history) added +74 -0

@@ -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.

conform/run/mods/Shared.raz (history) added +22 -0

@@ -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.

conform/run/mods/Stack.raz (history) modified +4 -1

@@ -1,7 +1,9 @@
11 module Stack;
22 import Ints := List(I64), Heap;
33
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 *)
57
68 proc top*(): I64;
79 begin
@@ -10,4 +12,5 @@
1012
1113 begin
1214 Ints.init(ADR(s), Heap.heap);
15+ p := ADR(s);
1316 end Stack.

doc/compiler.md (history) modified +17 -8

@@ -1,6 +1,6 @@
11 # Reading the raz compiler
22
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.
44 This guide walks through them in the order they are best read: from the
55 characters of a source file to the bytes of an executable. It assumes
66 you know the language from `doc/raz.md`, and enough x86-64 to read a
@@ -10,10 +10,10 @@
1010 |---|---|---|---|
1111 | `src/diag.pas` | 274 | 198 | Messages: positions, source excerpts, colour, counts |
1212 | `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 |
1414 | `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 |
1717 | `src/link.pas` | 180 | 139 | Tree shaking, layout, patching, the places |
1818 | `src/elf.pas` | 425 | 352 | Static and dynamic ELF, symbol table, line numbers |
1919 | `src/raz.pas` | 227 | 179 | The command line, the entry points |
@@ -270,14 +270,21 @@
270270 on the right of `*`, `div` or `mod` becomes shifts (`DivPow2`), since
271271 `idiv` is slow. Narrow integers are brought back to their width
272272 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.
273276 `=` and `#` on arrays, slices and strings make a slice of each side
274277 (`SeqSlice`), compare the lengths, and then the bytes with `repe
275278 cmpsb`, right where the comparison stands: no call.
276279
277280 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
281288 the check holds. The call passes what failed, the values involved and
282289 its own address, by which `Rt` finds the place; that code has the
283290 place of the offending expression (`LineCol` in `scan.pas`), and the
@@ -285,7 +292,9 @@
285292
286293 Assignment and conversion: `Coerce` makes a value fit the type it's
287294 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`
289298 stores, copying records and arrays with `rep movsb`. `Convert` is the
290299 written conversion, `T(x)`.
291300

doc/raz.md (history) modified +1 -1

@@ -931,7 +931,7 @@
931931
932932 (* Prints the first line of the file at path. *)
933933 proc head(path: []U8): BOOL;
934-var fd, n, i: I64; buf: [256]U8;
934+var fd, n, i: INT; buf: [256]U8;
935935 begin
936936 fd := Sys.openRead(path);
937937 if fd < 0 then return false; end;

editor/emacs/raz-mode.el (history) modified +1 -1

@@ -28,7 +28,7 @@
2828 "variant" "VOLATILE" "while" "xor"))
2929
3030 (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"))
3232
3333 (defconst raz-builtins
3434 '("SIZE" "ADR" "LEN" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD"

editor/vim/syntax/raz.vim (history) modified +1 -1

@@ -12,7 +12,7 @@
1212 syntax keyword razKeyword match mod module not of or packed proc record
1313 syntax keyword razKeyword repeat return set shl shr then to type until var
1414 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
1616 syntax keyword razBuiltin SIZE ADR LEN NEW MSG SYSCALL FENCE CAS XCHG XADD
1717 syntax keyword razBuiltin ARGC ARGV INC DEC
1818 syntax keyword razConstant true false nil

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

@@ -3,16 +3,16 @@
33 import Out;
44
55 (* 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;
88 begin
99 n := 0;
1010 while s[n] # 0 do n := n + 1; end;
1111 return n;
1212 end;
1313
14-proc main*: I64;
15-var i: I64; s: ^U8;
14+proc main*: INT;
15+var i: INT; s: ^U8;
1616 begin
1717 for i := 1 to ARGC() - 1 do
1818 s := ARGV()[i];

examples/Cpu.raz (history) modified +1 -1

@@ -16,7 +16,7 @@
1616 0C3H; (* ret *)
1717
1818 proc main*;
19-var buf: [12]U8; i: I64; ok: BOOL;
19+var buf: [12]U8; i: INT; ok: BOOL;
2020 begin
2121 vendor(ADR(buf[0]));
2222 ok := true;

examples/Flags.raz (history) modified +2 -2

@@ -9,9 +9,9 @@
99 Perms = set of Perm;
1010 Mode = record user, group, other: Perms; end;
1111
12-proc digit(p: Perms): I64;
12+proc digit(p: Perms): INT;
1313 begin
14- return I64(U8(p));
14+ return INT(U8(p));
1515 end;
1616
1717 proc show(p: Perms);

examples/Printf.raz (history) modified +1 -1

@@ -4,7 +4,7 @@
44 import Out, C;
55
66 proc main*;
7-var i: I64;
7+var i: INT;
88 begin
99 for i := 1 to 3 do
1010 Out.str("raz says "); Out.int(i); Out.ln;

examples/Pthreads.raz (history) modified +5 -5

@@ -8,13 +8,13 @@
88 N = 1000000;
99
1010 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;
1313
1414 var numbers: ^Numbers;
1515
1616 proc work(arg: ^U8): ^U8;
17-var p: ^Part; i: I64; scratch: ^U8;
17+var p: ^Part; i: INT; scratch: ^U8;
1818 begin
1919 p := ^Part(arg);
2020 for i := p^.lo to p^.hi - 1 do
@@ -28,8 +28,8 @@
2828 return nil;
2929 end;
3030
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;
3333 begin
3434 NEW(numbers, Heap.heap);
3535 for i := 0 to N - 1 do numbers^[i] := i + 1; end;

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

@@ -21,13 +21,13 @@
2121 type
2222 Command = record
2323 args: [maxWords][]U8;
24- n: I64;
24+ n: INT;
2525 input, output, errors: []U8; (* the files of <, > or >>, and 2>; "" for none *)
2626 append: BOOL; (* output is >> *)
2727 end;
2828 Pipeline = record
2929 cmds: [maxCmds]Command;
30- n: I64;
30+ n: INT;
3131 background: BOOL;
3232 end;
3333 (* What the parser reads: a word, |, &, ; or a line's end, <, >, >>, 2>,
@@ -35,17 +35,17 @@
3535 Token = (word, pipe, amp, sep, from, into, onto, errTo, eof);
3636
3737 var
38- status: I64; (* of the last pipeline: $? *)
38+ status: INT; (* of the last pipeline: $? *)
3939 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 *)
4141 arena: Arena.Arena; (* the words of what is being run *)
4242 s: []U8; (* the script being read *)
43- at: I64; (* where in it *)
43+ at: INT; (* where in it *)
4444 text: []U8; (* the last word read *)
4545
4646 (* "Sh: " and a message on standard error. *)
4747 proc say(f: []U8; args: []Fmt.Arg);
48-var b: Buf.Buf; _n: I64;
48+var b: Buf.Buf; _n: INT;
4949 begin
5050 Buf.init(ADR(b), Heap.heap);
5151 Fmt.write(ADR(b), "Sh: ", []);
@@ -64,7 +64,7 @@
6464 (* $NAME or $? at s[at], its value added to b; a $ before anything else
6565 is itself. *)
6666 proc dollar(b: ^Buf.Buf);
67-var start: I64;
67+var start: INT;
6868 begin
6969 INC(at);
7070 if (at < LEN(s)) and (s[at] = '?') then
@@ -172,7 +172,7 @@
172172 (* The program a command names: the name itself if it has a /, else the
173173 first executable file of that name in a directory of $PATH. *)
174174 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;
176176 begin
177177 if Str.find(name, "/") >= 0 then return name, true; end;
178178 path := Sys.env("PATH");
@@ -191,8 +191,8 @@
191191 end;
192192
193193 (* 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;
196196 begin
197197 fd := Sys.open(path, how);
198198 if fd < 0 then say("{}: can't open it", [Fmt.str(path)]); return -1; end;
@@ -202,7 +202,7 @@
202202 (* cd, wait and exit, which change the shell itself, so it can't start
203203 them as programs; true if c is one. *)
204204 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;
206206 begin
207207 if c^.args[0] = "cd" then
208208 if c^.n > 1 then dir := c^.args[1]; else dir := Sys.env("HOME"); end;
@@ -217,7 +217,7 @@
217217 n, ok := Str.toInt(c^.args[1]);
218218 if not ok then say("exit: {} isn't a number", [Fmt.str(c^.args[1])]); n := 2; end;
219219 end;
220- Rt.exit(n);
220+ Rt.exit(INT(n));
221221 else
222222 return false;
223223 end;
@@ -238,7 +238,7 @@
238238 has the terminal until they end. *)
239239 proc start(p: ^Pipeline);
240240 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;
242242 c: ^Command; path: []U8; found, _ok: BOOL; st: Sys.Status;
243243 begin
244244 if (p^.n = 1) and not p^.background and builtin(ADR(p^.cmds[0])) then return; end;
@@ -322,7 +322,7 @@
322322
323323 (* Before a prompt: the background programs that have ended. *)
324324 proc reap;
325-var pid, _code: I64; _st: Sys.Status;
325+var pid, _code: INT; _st: Sys.Status;
326326 begin
327327 repeat
328328 pid, _st, _code := Sys.wait(-1, false);
@@ -334,7 +334,7 @@
334334 shell in a process group of its own, which ignores the keys that
335335 stop or end the pipeline in front of it. *)
336336 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;
338338 begin
339339 interactive := Sys.isTerminal(Sys.stdin);
340340 if interactive then
@@ -353,7 +353,7 @@
353353 if interactive then show("\n", []); end;
354354 end;
355355
356-proc main*: I64;
356+proc main*: INT;
357357 var p: Opt.Parser; script, file: []U8; given, found: BOOL; b: Buf.Buf;
358358 begin
359359 if not Arena.init(ADR(arena), 1 shl 24) then Rt.stop("Sh: no memory"); end;

examples/Shapes.raz (history) modified +5 -5

@@ -4,13 +4,13 @@
44
55 type
66 Shape = variant
7- circle(r: I64);
8- rect(w, h: I64);
7+ circle(r: INT);
8+ rect(w, h: INT);
99 dot;
1010 end;
1111
1212 (* 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;
1414 begin
1515 match s of
1616 | circle(r): return 44 * r * r div 7;
@@ -19,8 +19,8 @@
1919 end;
2020 end;
2121
22-proc total(shapes: []Shape): I64;
23-var i, sum: I64;
22+proc total(shapes: []Shape): INT;
23+var i, sum: INT;
2424 begin
2525 sum := 0;
2626 for i := 0 to LEN(shapes) - 1 do sum := sum + area(shapes[i]); end;

examples/Volatile.raz (history) modified +2 -2

@@ -15,7 +15,7 @@
1515 var page: [64]U8;
1616
1717 proc main*;
18-var dev: ^VOLATILE Uart; i: I64;
18+var dev: ^VOLATILE Uart; i: INT;
1919 begin
2020 dev := ^VOLATILE Uart(ADR(page));
2121 dev^.control := 1;
@@ -26,7 +26,7 @@
2626 end;
2727 Out.ln;
2828 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;
3030 end;
3131
3232 end Volatile.

examples/Window.raz (history) modified +3 -3

@@ -34,13 +34,13 @@
3434 extern proc XCreateSimpleWindow(d: ^U8; parent: U64; x, y: I32;
3535 width, height, border: U32; borderColor, background: U64): U64;
3636 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;
3838 extern proc XMapWindow(d: ^U8; w: U64): I32;
3939 extern proc XNextEvent(d: ^U8; ev: ^U8): I32;
4040 extern proc XDrawString(d: ^U8; w: U64; gc: ^U8; x, y: I32; s: ^U8; n: I32): I32;
4141 extern proc XCloseDisplay(d: ^U8): I32;
4242
43-proc main*: I64;
43+proc main*: INT;
4444 const text = "hello, world: press a key";
4545 var
4646 d: ^U8; s: I32; w: U64;
@@ -62,7 +62,7 @@
6262 end;
6363 until I32(ev[0]) = KeyPress;
6464 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;
6666 XCloseDisplay(d);
6767 return 0;
6868 end;

examples/Words.raz (history) modified +3 -3

@@ -1,15 +1,15 @@
11 (* 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
33 first sight in a List([]U8), and prints them with Fmt. *)
44 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);
66
77 const Text = "the cat and the hat and the bat";
88
99 proc main*;
1010 var
1111 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;
1313 begin
1414 Count.init(ADR(counts), Heap.heap);
1515 Names.init(ADR(order), Heap.heap);

examples/Workers.raz (history) modified +6 -6

@@ -8,13 +8,13 @@
88 Jobs = 100;
99
1010 var
11- next: I64; (* the next job, taken with XADD *)
11+ next: INT; (* the next job, taken with XADD *)
1212 m: Thread.Mutex;
13- total: I64;
13+ total: INT;
1414
1515 (* 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;
1818 begin
1919 s := 0;
2020 for i := 1 to n do s := s + i * i; end;
@@ -22,7 +22,7 @@
2222 end;
2323
2424 proc work(_arg: ^U8);
25-var n, r: I64;
25+var n, r: INT;
2626 begin
2727 n := XADD(ADR(next), 1);
2828 while n < Jobs do
@@ -35,7 +35,7 @@
3535 end;
3636
3737 proc main*;
38-var t: [Workers]^Thread.Thread; i: I64; err: ERROR;
38+var t: [Workers]^Thread.Thread; i: INT; err: ERROR;
3939 begin
4040 for i := 0 to Workers - 1 do
4141 t[i], err := Thread.spawn(work, nil);

lib/Arena.raz (history) modified +4 -4

@@ -8,11 +8,11 @@
88 Arena* = record
99 base*: Mem.Allocator; (* first, so that ^Arena(a) finds the rest *)
1010 buf: ^U8;
11- used, cap: I64;
11+ used, cap: INT;
1212 end;
1313
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;
1616 begin
1717 ar := ^Arena(a);
1818 at := (ar^.used + align - 1) div align * align;
@@ -26,7 +26,7 @@
2626 end;
2727
2828 (* 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;
3030 begin
3131 ar^.base := {alloc: alloc, free: free};
3232 ar^.buf := Mem.pages(size);

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

@@ -6,7 +6,7 @@
66 Buf* = record
77 a: ^Mem.Allocator;
88 data: ^U8;
9- len*, cap: I64;
9+ len*, cap: INT;
1010 end;
1111
1212 proc init*(b: ^Buf; a: ^Mem.Allocator);
@@ -15,8 +15,8 @@
1515 end;
1616
1717 (* 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;
2020 begin
2121 if b^.len + n <= b^.cap then return true; end;
2222 cap := b^.cap * 2;
@@ -40,7 +40,7 @@
4040 end;
4141
4242 proc str*(b: ^Buf; s: []U8);
43-var i: I64;
43+var i: INT;
4444 begin
4545 if room(b, LEN(s)) then
4646 for i := 0 to LEN(s) - 1 do b^.data[b^.len + i] := s[i]; end;
@@ -70,7 +70,7 @@
7070
7171 (* The module's test, over an arena. *)
7272 proc main*;
73-var ar: Arena.Arena; b: Buf; i: I64; s: []U8;
73+var ar: Arena.Arena; b: Buf; i: INT; s: []U8;
7474 begin
7575 if not Arena.init(ADR(ar), 1 shl 20) then Rt.stop("Buf: no arena"); end;
7676 init(ADR(b), ADR(ar.base));

lib/C.raz (history) modified +12 -12

@@ -3,26 +3,26 @@
33 linked dynamically and starts through the C library. *)
44 module C;
55
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;
88 extern proc open*(path: ^U8; flags: I32; ...): I32;
99 extern proc creat*(path: ^U8; mode: U32): I32;
1010 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;
1313 extern proc isatty*(fd: I32): I32;
1414 extern proc exit*(status: I32);
1515 extern proc _exit*(status: I32);
1616 extern proc __errno_location*: ^I32; (* errno is this thread's: through here *)
1717 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;
2020 extern proc rename*(old, new: ^U8): I32;
2121 extern proc unlink*(path: ^U8): I32;
2222 extern proc mkdir*(path: ^U8; mode: U32): I32;
2323 extern proc rmdir*(path: ^U8): I32;
2424 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;
2626 extern proc lseek*(fd: I32; off: I64; whence: I32): I64;
2727 extern proc opendir*(path: ^U8): ^U8; (* DIR * *)
2828 extern proc readdir*(d: ^U8): ^U8; (* struct dirent * *)
@@ -30,11 +30,11 @@
3030 extern proc tcgetattr*(fd: I32; t: ^U8): I32;
3131 extern proc tcsetattr*(fd: I32; when: I32; t: ^U8): I32;
3232 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;
3535 extern proc socket*(domain, kind, protocol: I32): I32;
3636 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;
3838 extern proc bind*(fd: I32; addr: ^U8; len: U32): I32;
3939 extern proc listen*(fd, backlog: I32): I32;
4040 extern proc accept*(fd: I32; addr: ^U8; len: ^U32): I32;
@@ -43,9 +43,9 @@
4343 extern proc inet_pton*(family: I32; src, dst: ^U8): I32;
4444 extern proc clock_gettime*(clock: I32; t: ^U8): I32;
4545 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;
4747 extern proc getenv*(name: ^U8): ^U8;
48-extern proc getcwd*(buf: ^U8; n: U64): ^U8;
48+extern proc getcwd*(buf: ^U8; n: UINT): ^U8;
4949 extern proc chdir*(path: ^U8): I32;
5050 extern proc stat*(path, st: ^U8): I32;
5151 extern proc lstat*(path, st: ^U8): I32;

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

@@ -4,8 +4,8 @@
44 import Sys, Buf;
55
66 (* 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;
99 begin
1010 s := ARGV()[i];
1111 n := 0;
@@ -15,7 +15,7 @@
1515
1616 (* Adds the file at path to b; false if it can't be read. *)
1717 proc read*(path: []U8; b: ^Buf.Buf): BOOL;
18-var fd, n: I64; chunk: [4096]U8;
18+var fd, n: INT; chunk: [4096]U8;
1919 begin
2020 fd := Sys.openRead(path);
2121 if fd < 0 then return false; end;
@@ -29,7 +29,7 @@
2929
3030 (* Makes the file at path hold data; false if it can't be written. *)
3131 proc write*(path, data: []U8): BOOL;
32-var fd, n, at: I64;
32+var fd, n, at: INT;
3333 begin
3434 fd := Sys.create(path);
3535 if fd < 0 then return false; end;

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

@@ -13,12 +13,12 @@
1313 str(s: []U8);
1414 char(c: U8);
1515 bool(b: BOOL);
16- real(r: F64; places: I64);
16+ real(r: F64; places: INT);
1717 end;
1818
1919 (* 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;
2222 begin
2323 i := 24;
2424 repeat
@@ -40,9 +40,9 @@
4040 nearest; from 1E15 on, with the exponent that makes it less than 10,
4141 as 1.50e17. The whole part and the fraction are taken apart, so that
4242 each fits an I64. *)
43-proc putReal(b: ^Buf.Buf; x: F64; places: I64);
43+proc putReal(b: ^Buf.Buf; x: F64; places: INT);
4444 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;
4646 begin
4747 if x # x then put(b, "nan"); return; end;
4848 if x < 0.0 then put(b, "-"); x := -x; end;
@@ -73,7 +73,7 @@
7373 end;
7474
7575 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;
7777 begin
7878 match a of
7979 | int(i):
@@ -94,7 +94,7 @@
9494 end;
9595
9696 proc format(b: ^Buf.Buf; f: []U8; args: []Arg);
97-var i, start, n: I64;
97+var i, start, n: INT;
9898 begin
9999 i := 0; start := 0; n := 0;
100100 while i < LEN(f) do

lib/Heap.raz (history) modified +11 -11

@@ -18,30 +18,30 @@
1818
1919 type
2020 Block = record next: ^Block; end;
21- Head = record size, mark: I64; end;
21+ Head = record size, mark: INT; end;
2222
2323 var
2424 lists: [Classes]^Block;
2525 cur: ^U8; (* where the next new small block comes from *)
26- left: I64;
26+ left: INT;
2727 lock: Lock.Lock;
2828 std: Mem.Allocator;
2929 heap*: ^Mem.Allocator;
3030
3131 (* 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;
3333 var h: ^Head;
3434 begin
3535 h := ^Head(p);
3636 h^.size := size;
37- h^.mark := Out xor I64(h);
37+ h^.mark := Out xor INT(h);
3838 return p + Header;
3939 end;
4040
4141 (* size bytes aligned to align, or nil: also for a size below zero or
4242 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;
4545 begin
4646 if (size < 0) or (size > Largest) or (align < 1) or (align > Mem.Page)
4747 or (align & (align - 1) # 0) then
@@ -78,18 +78,18 @@
7878 end;
7979
8080 proc free(_a: ^Mem.Allocator; p: ^U8);
81-var h: ^Head; b: ^Block; c: I64;
81+var h: ^Head; b: ^Block; c: INT;
8282 begin
8383 if p = nil then return; end;
8484 h := ^Head(p - Header);
8585 Lock.take(ADR(lock));
86- if h^.mark # Out xor I64(h) then
86+ if h^.mark # Out xor INT(h) then
8787 Rt.stop("Heap: a block freed twice, or never given out");
8888 end;
8989 h^.mark := 0;
9090 if h^.size < 0 then
9191 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);
9393 else
9494 c := h^.size; (* before next, which takes its place, is set *)
9595 b := ^Block(h);
@@ -102,12 +102,12 @@
102102 (* The module's test: blocks of every class and big ones, written,
103103 freed and taken again. *)
104104 proc main*;
105-var p: [40]^U8; i, j, n: I64; again: ^U8;
105+var p: [40]^U8; i, j, n: INT; again: ^U8;
106106 begin
107107 for i := 0 to 39 do
108108 n := (i * i * 37) mod 9000 + 1;
109109 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;
111111 for j := 0 to n - 1 do p[i][j] := U8(i); end;
112112 end;
113113 for i := 0 to 39 do

lib/List.raz (history) modified +1 -1

@@ -9,7 +9,7 @@
99 end;
1010 List* = record
1111 head*: ^Node;
12- len*: I64;
12+ len*: INT;
1313 a: ^Mem.Allocator;
1414 end;
1515

lib/Lock.raz (history) modified +2 -2

@@ -5,10 +5,10 @@
55 module Lock;
66 import Sys, Rt;
77
8-type Lock* = record held: I64; end;
8+type Lock* = record held: INT; end;
99
1010 proc take*(l: ^Lock);
11-var tries: I64;
11+var tries: INT;
1212 begin
1313 tries := 0;
1414 while not CAS(ADR(l^.held), 0, 1) do

lib/Map.raz (history) modified +12 -12

@@ -1,6 +1,6 @@
11 (* A hash map from K to V, by open addressing; it hashes and compares
22 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); *)
44 module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
55 import Mem;
66
@@ -13,8 +13,8 @@
1313 Map* = record
1414 a: ^Mem.Allocator;
1515 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;
1818 end;
1919
2020 proc init*(m: ^Map; a: ^Mem.Allocator);
@@ -23,10 +23,10 @@
2323 end;
2424
2525 (* 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;
2828 begin
29- i := I64(hash(k) & U64(m^.cap - 1));
29+ i := INT(hash(k) & U64(m^.cap - 1));
3030 while m^.slots[i].used and not eq(m^.slots[i].key, k) do
3131 i := (i + 1) & (m^.cap - 1);
3232 end;
@@ -34,7 +34,7 @@
3434 end;
3535
3636 proc grow(m: ^Map): BOOL;
37-var old: ^Entry; n, i, j: I64;
37+var old: ^Entry; n, i, j: INT;
3838 begin
3939 old := m^.slots;
4040 n := m^.cap;
@@ -54,7 +54,7 @@
5454
5555 (* k now maps to v; false if there was no room. *)
5656 proc put*(m: ^Map; k: K; v: V): BOOL;
57-var i: I64;
57+var i: INT;
5858 begin
5959 if (m^.len + 1) * 4 > m^.cap * 3 then
6060 if not grow(m) then return false; end;
@@ -72,7 +72,7 @@
7272 after it that were pushed on past its slot move back, so that a
7373 search for each still finds it before an empty slot. *)
7474 proc remove*(m: ^Map; k: K): BOOL;
75-var i, j, home: I64;
75+var i, j, home: INT;
7676 begin
7777 if m^.cap = 0 then return false; end;
7878 i := slot(m, k);
@@ -80,7 +80,7 @@
8080 j := (i + 1) & (m^.cap - 1);
8181 while m^.slots[j].used do
8282 (* 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));
8484 if (j - home) & (m^.cap - 1) >= (j - i) & (m^.cap - 1) then
8585 m^.slots[i] := m^.slots[j];
8686 i := j;
@@ -94,7 +94,7 @@
9494
9595 (* What k maps to, and whether it maps to anything. *)
9696 proc get*(m: ^Map; k: K): (V, BOOL);
97-var i: I64; none: V;
97+var i: INT; none: V;
9898 begin
9999 if m^.cap = 0 then return none, false; end;
100100 i := slot(m, k);
@@ -104,7 +104,7 @@
104104
105105 (* The entry after i, walking from 0: the number to pass for the one
106106 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);
108108 var k: K; v: V;
109109 begin
110110 while i < m^.cap do

lib/Math.raz (history) modified +19 -19

@@ -45,14 +45,14 @@
4545 var t: F64;
4646 begin
4747 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));
4949 if t > x then t := t - 1.0; end;
5050 return t;
5151 end;
5252
5353 (* x times 2^k, for k from -1075 to 1024: 2^k is made from its bits,
5454 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;
5656 begin
5757 if k > 1023 then x := x * fromBits(U64(2046) shl 52); DEC(k, 1023); end;
5858 if k < -1022 then x := x * fromBits(U64(1 + 53) shl 52); INC(k, 1022 - 53); end;
@@ -61,13 +61,13 @@
6161
6262 (* e^x = 2^k e^r, with r = x - k ln 2 at most ln 2 / 2 across. *)
6363 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;
6565 begin
6666 if x # x then return x; end;
6767 if x > 709.782712893383973096 then return x * fromBits(U64(2046) shl 52); end; (* too big: inf *)
6868 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);
7171 end;
7272 hi := x - F64(k) * ln2hi;
7373 lo := F64(k) * ln2lo;
@@ -83,7 +83,7 @@
8383 found through s = f / (2 + f), f = m - 1, whose series converges
8484 fast. *)
8585 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;
8787 begin
8888 if x # x then return x; end;
8989 if x < 0.0 then return (x - x) / 0.0; end; (* NaN *)
@@ -95,7 +95,7 @@
9595 end;
9696 (* the exponent, counted from m's lower end, and the bits of m *)
9797 u := bits(x) + (3FF0000000000000H - 3FE6A09E00000000H);
98- INC(k, I64(u shr 52) - 3FFH);
98+ INC(k, INT(u shr 52) - 3FFH);
9999 f := fromBits((u & 0FFFFFFFFFFFFFH) + 3FE6A09E00000000H) - 1.0;
100100 hfsq := 0.5 * f * f;
101101 s := f / (2.0 + f);
@@ -114,8 +114,8 @@
114114 0C3H; (* ret *)
115115
116116 (* 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;
119119 begin
120120 q := s div 64;
121121 r := s mod 64;
@@ -129,10 +129,10 @@
129129 turns, which change no sine, and are left out; the 192 after them
130130 give the two bits of n mod 4 and the fraction past n, exact far
131131 beyond an F64. *)
132-proc reduceLarge(x: F64): (I64, F64, F64);
132+proc reduceLarge(x: F64): (INT, F64, F64);
133133 var
134134 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;
136136 begin
137137 t := [0, 0A2F9836E4E441529H, 0FC2757D1F534DDC0H, 0DB6295993C439041H, 0FE5163ABDEBBC561H,
138138 0B7246E3A424DD2E0H, 06492EEA09D1921CH, 0FE1DEB1CB129A73EH, 0E88235F52EBB4484H,
@@ -142,7 +142,7 @@
142142 neg := x < 0.0;
143143 if neg then x := -x; end;
144144 m := bits(x) & 0FFFFFFFFFFFFFH | 10000000000000H;
145- e := I64(bits(x) shr 52) - 1075;
145+ e := INT(bits(x) shr 52) - 1075;
146146 (* W, the 192 bits of 2/pi from the one worth 2^(1 - e), so that
147147 x 2/pi is m W 2^-190, of which the bits from 2^192 up are left out *)
148148 s := e + 62;
@@ -157,7 +157,7 @@
157157 (* n is the two bits from 2^190, the fraction those below; from a
158158 half up, n is the next and the fraction 1 less, taken as 1 less
159159 the fraction, negated: its bits complemented, one in 2^190 short *)
160- n := I64(p2 shr 62);
160+ n := INT(p2 shr 62);
161161 p2 := p2 & 3FFFFFFFFFFFFFFFH;
162162 up := p2 shr 61 = 1;
163163 if up then
@@ -182,12 +182,12 @@
182182 than one F64; and n. pi/2 is taken in three parts of 33 bits, each
183183 with what is left of it after, so that n times each is exact while
184184 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;
187187 begin
188188 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);
191191 end;
192192 fn := F64(n);
193193 r := x - fn * 1.57079632673412561417E+00;
@@ -227,7 +227,7 @@
227227 end;
228228
229229 proc sin*(x: F64): F64;
230-var n: I64; y, yy: F64;
230+var n: INT; y, yy: F64;
231231 begin
232232 if (x = 0.0) or (x # x) then return x; end;
233233 if (x - x) # 0.0 then return x - x; end; (* an infinity: NaN *)
@@ -241,7 +241,7 @@
241241 end;
242242
243243 proc cos*(x: F64): F64;
244-var n: I64; y, yy: F64;
244+var n: INT; y, yy: F64;
245245 begin
246246 if (x - x) # 0.0 then return x - x; end; (* an infinity or NaN: NaN *)
247247 n, y, yy := reduce(x);

lib/Mem.raz (history) modified +5 -5

@@ -5,24 +5,24 @@
55
66 type
77 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 *)
99 free*: proc(a: ^Allocator; p: ^U8);
1010 end;
1111
1212 const Page* = 4096;
1313
1414 (* size bytes, rounded up to whole pages, zeroed; or nil. *)
15-proc pages*(size: I64): ^U8;
15+proc pages*(size: INT): ^U8;
1616 begin
1717 return Sys.mmap((size + Page - 1) div Page * Page);
1818 end;
1919
20-proc unmap*(p: ^U8; size: I64);
20+proc unmap*(p: ^U8; size: INT);
2121 begin
2222 Sys.munmap(p, (size + Page - 1) div Page * Page);
2323 end;
2424
25-proc alloc*(a: ^Allocator; size, align: I64): ^U8;
25+proc alloc*(a: ^Allocator; size, align: INT): ^U8;
2626 begin
2727 return a^.alloc(a, size, align);
2828 end;
@@ -34,7 +34,7 @@
3434
3535 (* The module's test. *)
3636 proc main*;
37-var p: ^U8; i: I64;
37+var p: ^U8; i: INT;
3838 begin
3939 p := pages(10000);
4040 if p = nil then Rt.stop("Mem.pages"); end;

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

@@ -25,7 +25,7 @@
2525 name: []U8; (* the program's, as the messages begin *)
2626 table: []Row;
2727 scope: []U8;
28- at: I64; (* the next word *)
28+ at: INT; (* the next word *)
2929 group: []U8; (* the letters left of a word of them, as -lw *)
3030 spelt: []U8; (* the option just read as written, without its dashes *)
3131 ended: BOOL; (* the scope's options have ended *)
@@ -36,8 +36,8 @@
3636 const read1 = 1; readEnd = 0; readSkip = -1;
3737
3838 (* 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;
4141 begin
4242 s := Buf.bytes(b);
4343 while LEN(s) > 0 do
@@ -61,7 +61,7 @@
6161 "usage: " and the first, the others under it; or, for a scope with
6262 none, "usage: keep start". *)
6363 proc usageOf(p: ^Parser; b: ^Buf.Buf);
64-var i, lines: I64; c: U8;
64+var i, lines: INT; c: U8;
6565 begin
6666 for i := 0 to LEN(p^.table) - 1 do
6767 match p^.table[i] of
@@ -124,8 +124,8 @@
124124 end;
125125 end;
126126
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;
129129 begin
130130 Buf.init(ADR(b), Heap.heap);
131131 left(ADR(b), r);
@@ -136,8 +136,8 @@
136136
137137 (* A line of the list: the left column, padded to width and three
138138 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;
141141 begin
142142 Buf.str(b, " ");
143143 left(b, r);
@@ -153,7 +153,7 @@
153153 (* The scope's help: its synopsis lines, then its subcommands, its
154154 options and the help itself, each with its line; and status 0. *)
155155 proc printHelp(p: ^Parser);
156-var b: Buf.Buf; i, width: I64; r: ^Row;
156+var b: Buf.Buf; i, width: INT; r: ^Row;
157157 begin
158158 Buf.init(ADR(b), Heap.heap);
159159 usageOf(p, ADR(b));
@@ -184,8 +184,8 @@
184184
185185 (* The scope's option with the letter c, or with the long name long:
186186 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;
189189 begin
190190 for i := 0 to LEN(p^.table) - 1 do
191191 match p^.table[i] of
@@ -202,8 +202,8 @@
202202 (* The next option, a word or a letter of one, into p: read1, or
203203 readEnd at the end of the options. A mistake is refused, or, if
204204 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;
207207 begin
208208 p^.help := false;
209209 p^.value := "";
@@ -272,7 +272,7 @@
272272 program sees one: a copy of the parser reads them, passing over
273273 mistakes. *)
274274 proc answerHelp(p: ^Parser);
275-var q: Parser; k: I64;
275+var q: Parser; k: INT;
276276 begin
277277 q := p^;
278278 repeat
@@ -282,7 +282,7 @@
282282 end;
283283
284284 (* 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);
286286 var b: Buf.Buf;
287287 begin
288288 Buf.init(ADR(b), Heap.heap);
@@ -292,7 +292,7 @@
292292 end;
293293
294294 proc check(p: ^Parser);
295-var i, j: I64;
295+var i, j: INT;
296296 begin
297297 for i := 0 to LEN(p^.table) - 1 do
298298 match p^.table[i] of
@@ -455,12 +455,12 @@
455455 mode: []U8; (* OPTTEST=... *)
456456 args: [][]U8;
457457 out, err: []U8;
458- status: I64;
458+ status: INT;
459459 end;
460460
461461 (* 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;
464464 begin
465465 repeat
466466 k := Sys.read(fd, buf[n..LEN(buf)]);
@@ -470,8 +470,8 @@
470470 return n;
471471 end;
472472
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;
475475 begin
476476 outR, outW := Sys.pipe();
477477 errR, errW := Sys.pipe();
@@ -494,7 +494,7 @@
494494 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";
495495 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";
496496 k = "OPTTEST=keep";
497-var cases: []Case; i: I64; mode: []U8;
497+var cases: []Case; i: INT; mode: []U8;
498498 begin
499499 mode := Sys.env("OPTTEST");
500500 if mode = "keep" then keep; return;

lib/Out.raz (history) modified +6 -6

@@ -9,14 +9,14 @@
99
1010 var
1111 buf: [Sys.outSize]U8;
12- n: I64; (* bytes in buf *)
12+ n: INT; (* bytes in buf *)
1313 tty: BOOL; (* standard output is a terminal *)
1414 lock: Lock.Lock;
1515
1616 (* Writes out the buffer, with the lock held. What can't be written is
1717 dropped. *)
1818 proc out;
19-var i, k: I64;
19+var i, k: INT;
2020 begin
2121 i := 0;
2222 while i < n do
@@ -36,7 +36,7 @@
3636 end;
3737
3838 proc str*(s: []U8);
39-var i: I64;
39+var i: INT;
4040 begin
4141 Lock.take(ADR(lock));
4242 for i := 0 to LEN(s) - 1 do
@@ -62,7 +62,7 @@
6262
6363 (* n in decimal *)
6464 proc int*(n: I64);
65-var buf: [20]U8; i: I64; u: U64;
65+var buf: [20]U8; i: INT; u: U64;
6666 begin
6767 u := U64(n);
6868 if n < 0 then u := 0 - u; end;
@@ -80,8 +80,8 @@
8080 end;
8181
8282 (* 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;
8585 begin
8686 i := 16;
8787 repeat

lib/Rt.raz (history) modified +24 -24

@@ -23,23 +23,23 @@
2323 Place = record at, line, col, path: U32; end;
2424 (* What rt_sigaction and sigaltstack take *)
2525 Action = record
26- handler: proc(sig: I64; info, ctx: ^U8);
26+ handler: proc(sig: INT; info, ctx: ^U8);
2727 flags: U64;
2828 restorer: proc;
2929 mask: U64;
3030 end;
31- Stack = record sp: ^U8; flags, size: I64; end;
31+ Stack = record sp: ^U8; flags, size: INT; end;
3232
3333 var
3434 atExits: [MaxAtExit]proc;
35- numAtExit: I64;
35+ numAtExit: INT;
3636 cExit: proc(status: I32); (* C's exit, set first thing in a program that uses C *)
3737 (* Set first thing too: the number of places, where the program's
3838 code starts and stops, the places, and the paths. The linker
3939 makes them. *)
40- places: ^I64;
40+ places: ^INT;
4141 line: [256]U8; (* the message being made *)
42- lineLen: I64;
42+ lineLen: INT;
4343 act: Action;
4444 alt: Stack;
4545 altStack: [16384]U8; (* where the handlers run, even when the stack is full *)
@@ -58,7 +58,7 @@
5858 uses C, so that C flushes its buffers too. Each procedure is taken
5959 off the list before it runs, so it runs once even if it fails or
6060 calls exit itself. *)
61-proc exit*(status: I64);
61+proc exit*(status: INT);
6262 var p: proc;
6363 begin
6464 while numAtExit > 0 do
@@ -82,7 +82,7 @@
8282 (* Messages, made in line, one byte kept for the line feed, and
8383 written by say in one piece *)
8484 proc put(s: []U8);
85-var i: I64;
85+var i: INT;
8686 begin
8787 for i := 0 to LEN(s) - 1 do
8888 if lineLen < LEN(line) - 1 then
@@ -93,9 +93,9 @@
9393 end;
9494
9595 (* 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;
9999 begin
100100 neg := n < 0;
101101 i := 20;
@@ -109,7 +109,7 @@
109109 end;
110110
111111 proc putStr(s: ^U8);
112-var n: I64;
112+var n: INT;
113113 begin
114114 n := 0;
115115 while s[n] # 0 do INC(n); end;
@@ -126,22 +126,22 @@
126126 (* Puts where the code at address a comes from, as file:line:col: and
127127 a space, if a is in the program's code: the place with the highest
128128 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;
131131 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;
133133 n := places[0];
134134 p := ^Place(places + 3);
135135 best := nil;
136136 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;
138138 end;
139139 if best = nil then return; end;
140- putStr(^U8(p + n) + I64(best^.path));
140+ putStr(^U8(p + n) + INT(best^.path));
141141 put(":");
142- putInt(I64(best^.line));
142+ putInt(INT(best^.line));
143143 put(":");
144- putInt(I64(best^.col));
144+ putInt(INT(best^.col));
145145 put(": ");
146146 end;
147147
@@ -151,7 +151,7 @@
151151 something whose length is len; 2 for a, which is no position of
152152 the enumeration called name; 3 for a slice a..b of a pointer, which
153153 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);
155155 begin
156156 where(at);
157157 if what = 0 then
@@ -186,18 +186,18 @@
186186 reset as it was called, so the instruction faults again and the
187187 signal ends the program. info and ctx are the kernel's siginfo and
188188 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;
191191 begin
192- q := ^U64(info + 16); (* si_addr *)
192+ q := ^UINT(info + 16); (* si_addr *)
193193 adr := q^;
194- q := ^U64(ctx + 160); (* uc_mcontext's rsp, then rip *)
194+ q := ^UINT(ctx + 160); (* uc_mcontext's rsp, then rip *)
195195 sp := q[0];
196196 ip := q[1];
197197 if sig = SigFpe then why := "a division fault";
198198 elsif ip < Low then
199199 why := "a nil procedure";
200- q := ^U64(sp);
200+ q := ^UINT(sp);
201201 ip := q^ - 1; (* the call, by its return address *)
202202 elsif adr < Low then why := "a nil pointer";
203203 elsif adr - sp + 100000H < 200000H then why := "a stack overflow"; (* within a megabyte of rsp *)

lib/Sort.raz (history) modified +3 -3

@@ -8,8 +8,8 @@
88 (* The element at i sinks through s[0..n], a heap with the largest at
99 its root, to where it is no smaller than its children, 2i+1 and
1010 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;
1313 begin
1414 c := 2 * i + 1;
1515 while c < n do
@@ -23,7 +23,7 @@
2323
2424 (* s made a heap, then its largest taken, in turn, to the end. *)
2525 proc sort*(s: []T);
26-var i: I64; t: T;
26+var i: INT; t: T;
2727 begin
2828 for i := LEN(s) div 2 - 1 to 0 by -1 do sink(s, i, LEN(s)); end;
2929 for i := LEN(s) - 1 to 1 by -1 do

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

@@ -7,8 +7,8 @@
77 const least = -9223372036854775807 - 1; (* the smallest I64 *)
88
99 (* -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;
1212 begin
1313 n := LEN(a);
1414 if LEN(b) < n then n := LEN(b); end;
@@ -30,7 +30,7 @@
3030
3131 (* FNV-1a, 64 bits. *)
3232 proc hash*(s: []U8): U64;
33-var h: U64; i: I64;
33+var h: U64; i: INT;
3434 begin
3535 h := 0CBF29CE484222325H;
3636 for i := 0 to LEN(s) - 1 do
@@ -40,8 +40,8 @@
4040 end;
4141
4242 (* 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;
4545 begin
4646 for i := 0 to LEN(s) - LEN(sub) do
4747 if s[i..i + LEN(sub)] = sub then return i; end;
@@ -57,7 +57,7 @@
5757 (* c in UTF-8: its bytes, and how many. A number that isn't a
5858 character, a surrogate or one past 10FFFFH, becomes FFFDH, the
5959 character that stands for a wrong one. *)
60-proc encode*(c: I64): ([4]U8, I64);
60+proc encode*(c: I32): ([4]U8, INT);
6161 var b: [4]U8;
6262 begin
6363 if (c < 0) or (c > 10FFFFH) or (c >= 0D800H) and (c <= 0DFFFH) then c := 0FFFDH; end;
@@ -85,11 +85,11 @@
8585 if its first byte doesn't start one rightly, being a continuation,
8686 or followed by too few continuations, or spelling a surrogate or a
8787 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;
9090 begin
9191 if LEN(s) = 0 then return 0, 0; end;
92- c := I64(s[0]);
92+ c := I32(s[0]);
9393 if c < 80H then return c, 1;
9494 elsif c < 0C0H then return 0FFFDH, 1;
9595 elsif c < 0E0H then n := 2; c := c & 1FH; least := 80H;
@@ -100,7 +100,7 @@
100100 if LEN(s) < n then return 0FFFDH, 1; end;
101101 for i := 1 to n - 1 do
102102 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);
104104 end;
105105 if (c < least) or (c > 10FFFFH) or (c >= 0D800H) and (c <= 0DFFFH) then return 0FFFDH, 1; end;
106106 return c, n;
@@ -109,7 +109,7 @@
109109 (* s as a decimal number, with a - or + before it if any, and nothing
110110 else; false if it isn't one, or an I64 can't hold it. *)
111111 proc toInt*(s: []U8): (I64, BOOL);
112-var n, i, d: I64; neg: BOOL;
112+var n, d: I64; i: INT; neg: BOOL;
113113 begin
114114 neg := (LEN(s) > 0) and (s[0] = '-');
115115 if (LEN(s) > 0) and ((s[0] = '-') or (s[0] = '+')) then i := 1; end;
@@ -133,7 +133,7 @@
133133 the lowest: how a file or a message in little-endian order is read,
134134 whatever the machine's own order. *)
135135 proc le*(s: []U8): U64;
136-var v: U64; i: I64;
136+var v: U64; i: INT;
137137 begin
138138 if LEN(s) > 8 then Rt.stop("Str.le: more than 8 bytes"); end;
139139 for i := LEN(s) - 1 to 0 by -1 do v := v shl 8 | U64(s[i]); end;
@@ -142,7 +142,7 @@
142142
143143 (* As le, the first byte the highest: big-endian, network order. *)
144144 proc be*(s: []U8): U64;
145-var v: U64; i: I64;
145+var v: U64; i: INT;
146146 begin
147147 if LEN(s) > 8 then Rt.stop("Str.be: more than 8 bytes"); end;
148148 for i := 0 to LEN(s) - 1 do v := v shl 8 | U64(s[i]); end;
@@ -152,7 +152,7 @@
152152 (* v into the bytes of s, at most 8, the lowest first; what doesn't
153153 fit is left out. *)
154154 proc putLE*(s: []U8; v: U64);
155-var i: I64;
155+var i: INT;
156156 begin
157157 if LEN(s) > 8 then Rt.stop("Str.putLE: more than 8 bytes"); end;
158158 for i := 0 to LEN(s) - 1 do s[i] := U8(v); v := v shr 8; end;
@@ -160,7 +160,7 @@
160160
161161 (* As putLE, the highest first. *)
162162 proc putBE*(s: []U8; v: U64);
163-var i: I64;
163+var i: INT;
164164 begin
165165 if LEN(s) > 8 then Rt.stop("Str.putBE: more than 8 bytes"); end;
166166 for i := LEN(s) - 1 to 0 by -1 do s[i] := U8(v); v := v shr 8; end;
@@ -182,7 +182,7 @@
182182 end;
183183
184184 proc testUtf8;
185-var b: [4]U8; n, c, i: I64;
185+var b: [4]U8; n: INT; c, i: I32;
186186 begin
187187 b, n := encode('a');
188188 if (n # 1) or (b[0] # 'a') then Rt.stop("Str.encode: a"); end;

lib/Sys.linux-x86_64.raz (history) modified +100 -100

@@ -24,7 +24,7 @@
2424 Info* = record
2525 size*: I64; (* in bytes *)
2626 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 *)
2828 dir*: BOOL; (* a directory *)
2929 file*: BOOL; (* a regular file: not a directory, device, pipe or socket *)
3030 symlink*: BOOL; (* the path itself is a symbolic link *)
@@ -32,7 +32,7 @@
3232
3333 (* An open directory: getdents64's records, read a block at a time. *)
3434 Dir* = record
35- fd, pos, len: I64;
35+ fd, pos, len: INT;
3636 buf: [8192]U8;
3737 end;
3838
@@ -43,10 +43,10 @@
4343 env*: [][]U8; (* NAME=value, each added to this program's environment *)
4444 onlyEnv*: BOOL; (* env is its whole environment *)
4545 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 *)
4848 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 *)
5050 end;
5151 (* How a program that wait waited for changed. *)
5252 Status* = (running, exited, killed, stopped);
@@ -79,11 +79,11 @@
7979 linked: [4096]U8; (* what readLink gives *)
8080 saved: Termios; (* the terminal as rawMode found it *)
8181 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 *)
8383
8484 (* Writes s to the file descriptor fd; the number of bytes written, or
8585 minus an errno. *)
86-proc write*(fd: I64; s: []U8): I64;
86+proc write*(fd: INT; s: []U8): INT;
8787 begin
8888 if LEN(s) = 0 then return 0; end;
8989 return SYSCALL(1, fd, ADR(s[0]), LEN(s));
@@ -91,7 +91,7 @@
9191
9292 (* Reads into buf from fd; the number of bytes read, 0 at the end, or
9393 minus an errno. *)
94-proc read*(fd: I64; buf: []U8): I64;
94+proc read*(fd: INT; buf: []U8): INT;
9595 begin
9696 if LEN(buf) = 0 then return 0; end;
9797 return SYSCALL(0, fd, ADR(buf[0]), LEN(buf));
@@ -99,7 +99,7 @@
9999
100100 (* path, a C string in buf, or false if it doesn't fit. *)
101101 proc cstr(path, buf: []U8): BOOL;
102-var i: I64;
102+var i: INT;
103103 begin
104104 if LEN(path) >= LEN(buf) then return false; end;
105105 for i := 0 to LEN(path) - 1 do buf[i] := path[i]; end;
@@ -126,7 +126,7 @@
126126 (* The file at path, opened as how asks: its file descriptor, or minus
127127 an errno. A file it creates is readable by all, writable by its
128128 owner. *)
129-proc open*(path: []U8; how: Accesses): I64;
129+proc open*(path: []U8; how: Accesses): INT;
130130 var buf: [4096]U8;
131131 begin
132132 if not cstr(path, buf) then return -36; end; (* ENAMETOOLONG *)
@@ -134,55 +134,55 @@
134134 end;
135135
136136 (* The file at path, opened for reading. *)
137-proc openRead*(path: []U8): I64;
137+proc openRead*(path: []U8): INT;
138138 begin
139139 return open(path, {reading});
140140 end;
141141
142142 (* The file at path, made empty or new, opened for writing. *)
143-proc create*(path: []U8): I64;
143+proc create*(path: []U8): INT;
144144 begin
145145 return open(path, {writing, creating, truncating});
146146 end;
147147
148148 (* Moves fd to pos from the start of its file, or from the end if
149149 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;
151151 begin
152152 if fromEnd then return SYSCALL(8, fd, pos, 2); end; (* lseek, SEEK_END *)
153153 return SYSCALL(8, fd, pos, 0); (* SEEK_SET *)
154154 end;
155155
156-proc close*(fd: I64);
156+proc close*(fd: INT);
157157 begin
158158 SYSCALL(3, fd);
159159 end;
160160
161161 (* size bytes of fresh, zeroed memory from the system, a multiple of
162162 pages, or nil. *)
163-proc mmap*(size: I64): ^U8;
164-var p: I64;
163+proc mmap*(size: INT): ^U8;
164+var p: INT;
165165 begin
166166 p := SYSCALL(9, 0, size, 3, 22H, -1, 0); (* read, write; private, anonymous *)
167167 if p < 0 then return nil; end;
168168 return ^U8(p);
169169 end;
170170
171-proc munmap*(p: ^U8; size: I64);
171+proc munmap*(p: ^U8; size: INT);
172172 begin
173173 SYSCALL(11, p, size);
174174 end;
175175
176176 (* Whether the file descriptor fd is a terminal: whether it has a
177177 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 *)
180180 begin
181181 return SYSCALL(16, fd, 5401H, ADR(t)) = 0;
182182 end;
183183
184184 (* 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;
186186 var a, b: [4096]U8;
187187 begin
188188 if not cstr(old, a) or not cstr(new, b) then return -36; end;
@@ -190,7 +190,7 @@
190190 end;
191191
192192 (* Removes the file at path; not a directory. *)
193-proc remove*(path: []U8): I64;
193+proc remove*(path: []U8): INT;
194194 var a: [4096]U8;
195195 begin
196196 if not cstr(path, a) then return -36; end;
@@ -198,7 +198,7 @@
198198 end;
199199
200200 (* Makes a directory at path, readable by all, writable by its owner. *)
201-proc makeDir*(path: []U8): I64;
201+proc makeDir*(path: []U8): INT;
202202 var a: [4096]U8;
203203 begin
204204 if not cstr(path, a) then return -36; end;
@@ -206,7 +206,7 @@
206206 end;
207207
208208 (* Removes the directory at path, which must be empty. *)
209-proc removeDir*(path: []U8): I64;
209+proc removeDir*(path: []U8): INT;
210210 var a: [4096]U8;
211211 begin
212212 if not cstr(path, a) then return -36; end;
@@ -214,7 +214,7 @@
214214 end;
215215
216216 (* Sets the permission bits of what path names. *)
217-proc chmod*(path: []U8; mode: I64): I64;
217+proc chmod*(path: []U8; mode: INT): INT;
218218 var a: [4096]U8;
219219 begin
220220 if not cstr(path, a) then return -36; end;
@@ -222,7 +222,7 @@
222222 end;
223223
224224 (* Makes path a symbolic link to target. *)
225-proc symlink*(target, path: []U8): I64;
225+proc symlink*(target, path: []U8): INT;
226226 var a, b: [4096]U8;
227227 begin
228228 if not cstr(target, a) or not cstr(path, b) then return -36; end;
@@ -231,8 +231,8 @@
231231
232232 (* What the symbolic link at path names, good until the next call; and
233233 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;
236236 begin
237237 if not cstr(path, a) then return "", -36; end;
238238 n := SYSCALL(89, ADR(a), ADR(linked), LEN(linked)); (* readlink *)
@@ -244,8 +244,8 @@
244244 (* The size of what path names, whether it is a directory or a regular
245245 file, following a symbolic link, and whether path is one; and 0, or
246246 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 *)
249249 begin
250250 if not cstr(path, a) then return i, -36; end;
251251 r := SYSCALL(6, ADR(a), ADR(st)); (* lstat *)
@@ -262,7 +262,7 @@
262262 end;
263263
264264 (* Opens the directory at path, for nextEntry. *)
265-proc openDir*(d: ^Dir; path: []U8): I64;
265+proc openDir*(d: ^Dir; path: []U8): INT;
266266 var a: [4096]U8;
267267 begin
268268 d^.pos := 0;
@@ -276,7 +276,7 @@
276276 (* The next name in the directory, good until the next call, but . and
277277 .., in no order; false at the end. *)
278278 proc nextEntry*(d: ^Dir): ([]U8, BOOL);
279-var n, at: I64;
279+var n, at: INT;
280280 begin
281281 while true do
282282 if d^.pos >= d^.len then
@@ -289,7 +289,7 @@
289289 at := d^.pos + 19;
290290 n := 0;
291291 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);
293293 if (d^.buf[at..at + n] # ".") and (d^.buf[at..at + n] # "..") then
294294 return d^.buf[at..at + n], true;
295295 end;
@@ -305,7 +305,7 @@
305305 (* Puts the terminal on fd into raw mode: no echo, no lines, no signals,
306306 no flow control, no CR to NL, no NL to CR NL; false if fd isn't a
307307 terminal. *)
308-proc rawMode*(fd: I64): BOOL;
308+proc rawMode*(fd: INT): BOOL;
309309 var t: Termios;
310310 begin
311311 if SYSCALL(16, fd, 5401H, ADR(saved)) # 0 then return false; end; (* TCGETS *)
@@ -320,25 +320,25 @@
320320 end;
321321
322322 (* The terminal on fd as rawMode found it. *)
323-proc restoreMode*(fd: I64);
323+proc restoreMode*(fd: INT);
324324 begin
325325 SYSCALL(16, fd, 5402H, ADR(saved));
326326 end;
327327
328328 (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't
329329 say. *)
330-proc termSize*(fd: I64): (I64, I64);
330+proc termSize*(fd: INT): (INT, INT);
331331 var w: Winsize;
332332 begin
333333 if (SYSCALL(16, fd, 5413H, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then (* TIOCGWINSZ *)
334334 return 80, 24;
335335 end;
336- return I64(w.cols), I64(w.rows);
336+ return INT(w.cols), INT(w.rows);
337337 end;
338338
339339 (* Whether fd has something to read within ms milliseconds; ms < 0
340340 waits as long as it takes. *)
341-proc ready*(fd, ms: I64): BOOL;
341+proc ready*(fd, ms: INT): BOOL;
342342 var p: Pollfd;
343343 begin
344344 p := {fd: I32(fd), events: 1}; (* POLLIN *)
@@ -363,17 +363,17 @@
363363 end;
364364
365365 (* Waits ms milliseconds. *)
366-proc sleep*(ms: I64);
366+proc sleep*(ms: INT);
367367 var t: Timespec; at: I64;
368368 begin
369- at := clock() + ms * 1000000;
369+ at := clock() + I64(ms) * 1000000;
370370 t := {sec: at div 1000000000, nsec: at mod 1000000000};
371371 repeat until SYSCALL(230, 1, 1, ADR(t), 0) # -4; (* clock_nanosleep until t, again after EINTR *)
372372 end;
373373
374374 (* Fills b with random bytes, from the kernel. *)
375375 proc random*(b: []U8);
376-var n, r: I64;
376+var n, r: INT;
377377 begin
378378 n := 0;
379379 while n < LEN(b) do (* a signal may cut it short *)
@@ -386,8 +386,8 @@
386386 bytes, or, if serving, bound to it and taking connections: its file
387387 descriptor, or minus an errno. It is closed in a program exec
388388 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;
391391 begin
392392 fd := SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *)
393393 if fd < 0 then return fd; end;
@@ -405,7 +405,7 @@
405405
406406 (* path as a Unix socket's address in a, or false if it is too long. *)
407407 proc unixAddr(path: []U8; a: ^SockaddrUn): BOOL;
408-var i: I64;
408+var i: INT;
409409 begin
410410 if LEN(path) >= LEN(a^.path) then return false; end;
411411 a^.family := 1; (* AF_UNIX *)
@@ -414,7 +414,7 @@
414414 end;
415415
416416 (* A stream socket connected to the Unix socket at path. *)
417-proc connect*(path: []U8): I64;
417+proc connect*(path: []U8): INT;
418418 var a: SockaddrUn;
419419 begin
420420 if not unixAddr(path, ADR(a)) then return -36; end; (* ENAMETOOLONG *)
@@ -423,7 +423,7 @@
423423
424424 (* A stream socket made at path, which must not be there yet, taking
425425 connections. *)
426-proc listen*(path: []U8): I64;
426+proc listen*(path: []U8): INT;
427427 var a: SockaddrUn;
428428 begin
429429 if not unixAddr(path, ADR(a)) then return -36; end;
@@ -431,18 +431,18 @@
431431 end;
432432
433433 (* 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;
435435 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;
439439 return -1;
440440 end;
441441
442442 (* The IPv4 address s, four numbers and dots, in out's 4 bytes, or false
443443 if it isn't one. *)
444444 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;
446446 begin
447447 i := 0;
448448 for n := 0 to 3 do
@@ -453,7 +453,7 @@
453453 v := 0;
454454 d := 0;
455455 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');
457457 INC(i);
458458 INC(d);
459459 end;
@@ -469,7 +469,7 @@
469469 standing for groups of zeros, in out's 16 bytes, or false if it isn't
470470 one. *)
471471 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;
473473 begin
474474 n := 0;
475475 gap := -1; (* the group the :: is before *)
@@ -512,7 +512,7 @@
512512 (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size
513513 of its struct sockaddr_in or sockaddr_in6, or 0 if either is
514514 wrong. *)
515-proc inetAddr(addr: []U8; port: I64; a: ^Sockaddr): I64;
515+proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT;
516516 begin
517517 if (port < 0) or (port > 65535) then return 0; end;
518518 a^.port[0] := U8(port shr 8); (* in the network's order, the high byte first *)
@@ -524,37 +524,37 @@
524524
525525 (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL)
526526 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;
529529 begin
530530 size := inetAddr(addr, port, ADR(a));
531531 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);
533533 end;
534534
535535 (* A stream socket connected to port at addr, an IPv4 or IPv6 address
536536 as numbers. *)
537-proc connectTcp*(addr: []U8; port: I64): I64;
537+proc connectTcp*(addr: []U8; port: INT): INT;
538538 begin
539539 return inet(addr, port, 1, false); (* SOCK_STREAM *)
540540 end;
541541
542542 (* 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;
544544 begin
545545 return inet(addr, port, 2, false); (* SOCK_DGRAM *)
546546 end;
547547
548548 (* A stream socket taking connections on port at addr; "0.0.0.0" or
549549 "::" is every address the machine has. *)
550-proc listenTcp*(addr: []U8; port: I64): I64;
550+proc listenTcp*(addr: []U8; port: INT): INT;
551551 begin
552552 return inet(addr, port, 1, true);
553553 end;
554554
555555 (* The next connection to the socket fd, waiting for one: a socket of
556556 its own, closed in a program exec starts; or minus an errno. *)
557-proc accept*(fd: I64): I64;
557+proc accept*(fd: INT): INT;
558558 begin
559559 return SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *)
560560 end;
@@ -562,7 +562,7 @@
562562 (* Writes s to the socket fd, as write does, but returns -32 (EPIPE)
563563 where write would stop the program with SIGPIPE: when the other end
564564 has closed it. *)
565-proc send*(fd: I64; s: []U8): I64;
565+proc send*(fd: INT; s: []U8): INT;
566566 begin
567567 if LEN(s) = 0 then return 0; end;
568568 return SYSCALL(44, fd, ADR(s[0]), LEN(s), 4000H, 0, 0); (* sendto, MSG_NOSIGNAL, no address *)
@@ -571,8 +571,8 @@
571571 (* The first of fds that has something to read within ms milliseconds,
572572 or that has reached its end or failed, so that a read won't wait; -1
573573 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;
576576 begin
577577 n := LEN(fds);
578578 if n > LEN(p) then n := LEN(p); end;
@@ -587,7 +587,7 @@
587587 (* The value of the environment variable name; "" if it isn't set. The
588588 environment follows the arguments and their nil. *)
589589 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;
591591 begin
592592 e := ARGV() + (ARGC() + 1);
593593 i := 0;
@@ -607,8 +607,8 @@
607607
608608 (* The working directory, good until the next call; and 0, or minus an
609609 errno. *)
610-proc workDir*: ([]U8, I64);
611-var r: I64;
610+proc workDir*: ([]U8, INT);
611+var r: INT;
612612 begin
613613 r := SYSCALL(79, ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *)
614614 if r < 0 then return "", r; end;
@@ -616,7 +616,7 @@
616616 end;
617617
618618 (* Makes path the working directory. *)
619-proc setWorkDir*(path: []U8): I64;
619+proc setWorkDir*(path: []U8): INT;
620620 var a: [4096]U8;
621621 begin
622622 if not cstr(path, a) then return -36; end;
@@ -626,8 +626,8 @@
626626 (* A pseudo-terminal: the file descriptor of its controlling side, or
627627 minus an errno. Its other side, the terminal its programs run on, is
628628 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;
631631 begin
632632 cstr("/dev/ptmx", a);
633633 fd := SYSCALL(2, ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *)
@@ -642,7 +642,7 @@
642642
643643 (* Tells the terminal of the pseudo-terminal fd that it has cols
644644 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;
646646 var w: Winsize;
647647 begin
648648 w := {rows: U16(rows), cols: U16(cols)};
@@ -651,7 +651,7 @@
651651
652652 (* Copies s and a zero to at: the byte after them. *)
653653 proc put(s: []U8; at: ^U8): ^U8;
654-var i: I64;
654+var i: INT;
655655 begin
656656 for i := 0 to LEN(s) - 1 do at[i] := s[i]; end;
657657 at[LEN(s)] := 0;
@@ -661,7 +661,7 @@
661661 (* Whether the NAME=value s, a C string, names a variable that one of
662662 env gives. *)
663663 proc replaced(s: ^U8; env: [][]U8): BOOL;
664-var i, n: I64;
664+var i, n: INT;
665665 begin
666666 for i := 0 to LEN(env) - 1 do
667667 n := 0;
@@ -675,8 +675,8 @@
675675 strings and a nil, then the environment old with each NAME=value of
676676 env in place of its variable or added, and a nil; or nil. The
677677 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;
680680 begin
681681 n := 0;
682682 while old[n] # nil do INC(n); end;
@@ -700,30 +700,30 @@
700700
701701 (* A pipe: the fd to read and the fd to write, both closed in a program
702702 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;
705705 begin
706706 r := SYSCALL(293, ADR(fds), 80000H); (* pipe2, O_CLOEXEC *)
707707 if r < 0 then return r, -1; end;
708- return I64(fds[0]), I64(fds[1]);
708+ return INT(fds[0]), INT(fds[1]);
709709 end;
710710
711711 (* This program's process id. *)
712-proc pid*: I64;
712+proc pid*: INT;
713713 begin
714714 return SYSCALL(39); (* getpid *)
715715 end;
716716
717717 (* Moves the program pid, or this one if pid is 0, to the process group
718718 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;
720720 begin
721721 return SYSCALL(109, pid, group); (* setpgid *)
722722 end;
723723
724724 (* Gives the keys of the terminal on fd, and its signals, to the process
725725 group group. *)
726-proc foreground*(fd, group: I64): I64;
726+proc foreground*(fd, group: INT): INT;
727727 var g: I32;
728728 begin
729729 g := I32(group);
@@ -732,22 +732,22 @@
732732
733733 (* The process group the terminal on fd gives its keys to, or minus an
734734 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;
737737 begin
738738 r := SYSCALL(16, fd, 540FH, ADR(g)); (* TIOCGPGRP *)
739739 if r < 0 then return r; end;
740- return I64(g);
740+ return INT(g);
741741 end;
742742
743743 (* Starts the program p describes: its process id, or minus an errno.
744744 A program that can't be started ends with status 127. Every signal
745745 is blocked from the fork until the program has its own: its group,
746746 its terminal's foreground, and signals as they are at first. *)
747-proc spawn*(p: Program): I64;
747+proc spawn*(p: Program): INT;
748748 var
749749 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;
751751 begin
752752 if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
753753 if p.tty # 0 then
@@ -808,21 +808,21 @@
808808 its exit status; killed or stopped, with the signal's number. Without
809809 block it doesn't wait: 0 and running if none has changed. Minus an
810810 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;
813813 begin
814814 options := 3; (* WNOHANG, WUNTRACED *)
815815 if block then options := 2; end;
816816 r := SYSCALL(61, pid, ADR(status), options, 0); (* wait4 *)
817817 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;
821821 end;
822822
823823 (* Sends the program pid, or the group -pid, the signal: 0, or minus an
824824 errno. *)
825-proc kill*(pid, signal: I64): I64;
825+proc kill*(pid, signal: INT): INT;
826826 begin
827827 return SYSCALL(62, pid, signal);
828828 end;
@@ -831,8 +831,8 @@
831831 they would, and gives them on an fd, which a later catch adds to and
832832 gives again; or minus an errno. Only the thread that catches them
833833 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;
836836 begin
837837 m := caughtSigs;
838838 for i := 0 to LEN(sigs) - 1 do
@@ -853,16 +853,16 @@
853853 end;
854854
855855 (* 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;
857857 var info: [128]U8; (* struct signalfd_siginfo: the number first, little-endian, below 65 *)
858858 begin
859859 if read(fd, info) # 128 then return 0; end;
860- return I64(info[0]);
860+ return INT(info[0]);
861861 end;
862862
863863 (* Makes the signal sig do nothing, or, if not yes, what it does at
864864 first: 0, or minus an errno. *)
865-proc ignore*(sig: I64; yes: BOOL): I64;
865+proc ignore*(sig: INT; yes: BOOL): INT;
866866 var act: [4]U64; (* struct sigaction: its handler, SIG_IGN or SIG_DFL, first *)
867867 begin
868868 if yes then act[0] := 1; end;
@@ -876,7 +876,7 @@
876876 end;
877877
878878 (* Ends the program, at once, with status. *)
879-proc exit*(status: I64);
879+proc exit*(status: INT);
880880 begin
881881 SYSCALL(231, status);
882882 end;
@@ -890,7 +890,7 @@
890890 one is sent; and a program starts with them neither caught nor
891891 ignored. *)
892892 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;
894894 begin
895895 pty := openPty();
896896 if (pty < 0) or (setTermSize(pty, 100, 30) # 0) then exit(2); end;
@@ -960,7 +960,7 @@
960960 sees; addresses read and refused; a TCP connection on the loopback;
961961 and a datagram to a port where no one listens, refused. *)
962962 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;
964964 begin
965965 t := clock();
966966 sleep(20);
@@ -1001,7 +1001,7 @@
10011001 directory made, listed and emptied; no terminal; a socket, sent to
10021002 after its end; programs; time and the network. *)
10031003 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;
10051005 begin
10061006 fd := create("/tmp/raz-sys-test");
10071007 if fd < 0 then exit(2); end;

lib/Sys.raz (history) modified +108 -108

@@ -37,7 +37,7 @@
3737 Info* = record
3838 size*: I64; (* in bytes *)
3939 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 *)
4141 dir*: BOOL; (* a directory *)
4242 file*: BOOL; (* a regular file: not a directory, device, pipe or socket *)
4343 symlink*: BOOL; (* the path itself is a symbolic link *)
@@ -55,10 +55,10 @@
5555 env*: [][]U8; (* NAME=value, each added to this program's environment *)
5656 onlyEnv*: BOOL; (* env is its whole environment *)
5757 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 *)
6060 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 *)
6262 end;
6363 (* How a program that wait waited for changed. *)
6464 Status* = (running, exited, killed, stopped);
@@ -96,38 +96,38 @@
9696 sigRead, sigWrite: I32; (* the pipe the handler of caught signals writes their numbers to, once open *)
9797
9898 (* minus errno, as a system call returns it *)
99-proc failed: I64;
99+proc failed: INT;
100100 var e: ^I32;
101101 begin
102102 e := C.__errno_location();
103- return -I64(e^);
103+ return -INT(e^);
104104 end;
105105
106106 (* Writes s to the file descriptor fd; the number of bytes written, or
107107 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;
110110 begin
111111 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)));
113113 if r < 0 then return failed(); end;
114114 return r;
115115 end;
116116
117117 (* Reads into buf from fd; the number of bytes read, 0 at the end, or
118118 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;
121121 begin
122122 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)));
124124 if r < 0 then return failed(); end;
125125 return r;
126126 end;
127127
128128 (* path, a C string in buf, or false if it doesn't fit. *)
129129 proc cstr(path, buf: []U8): BOOL;
130-var i: I64;
130+var i: INT;
131131 begin
132132 if LEN(path) >= LEN(buf) then return false; end;
133133 for i := 0 to LEN(path) - 1 do buf[i] := path[i]; end;
@@ -154,30 +154,30 @@
154154 (* The file at path, opened as how asks: its file descriptor, or minus
155155 an errno. A file it creates is readable by all, writable by its
156156 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;
159159 begin
160160 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 *)
162162 if r < 0 then return failed(); end;
163163 return r;
164164 end;
165165
166166 (* The file at path, opened for reading. *)
167-proc openRead*(path: []U8): I64;
167+proc openRead*(path: []U8): INT;
168168 begin
169169 return open(path, {reading});
170170 end;
171171
172172 (* The file at path, made empty or new, opened for writing. *)
173-proc create*(path: []U8): I64;
173+proc create*(path: []U8): INT;
174174 begin
175175 return open(path, {writing, creating, truncating});
176176 end;
177177
178178 (* Moves fd to pos from the start of its file, or from the end if
179179 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;
181181 var r: I64;
182182 begin
183183 if fromEnd then r := C.lseek(I32(fd), pos, 2); (* SEEK_END *)
@@ -186,28 +186,28 @@
186186 return r;
187187 end;
188188
189-proc close*(fd: I64);
189+proc close*(fd: INT);
190190 begin
191191 C.close(I32(fd));
192192 end;
193193
194194 (* size bytes of fresh, zeroed memory from the system, a multiple of
195195 pages, or nil. *)
196-proc mmap*(size: I64): ^U8;
196+proc mmap*(size: INT): ^U8;
197197 var p: ^U8;
198198 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;
201201 return p;
202202 end;
203203
204-proc munmap*(p: ^U8; size: I64);
204+proc munmap*(p: ^U8; size: INT);
205205 begin
206- C.munmap(p, U64(size));
206+ C.munmap(p, UINT(size));
207207 end;
208208
209209 (* 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;
211211 var a, b: [4096]U8;
212212 begin
213213 if not cstr(old, a) or not cstr(new, b) then return -36; end;
@@ -216,7 +216,7 @@
216216 end;
217217
218218 (* Removes the file at path; not a directory. *)
219-proc remove*(path: []U8): I64;
219+proc remove*(path: []U8): INT;
220220 var a: [4096]U8;
221221 begin
222222 if not cstr(path, a) then return -36; end;
@@ -225,7 +225,7 @@
225225 end;
226226
227227 (* Makes a directory at path, readable by all, writable by its owner. *)
228-proc makeDir*(path: []U8): I64;
228+proc makeDir*(path: []U8): INT;
229229 var a: [4096]U8;
230230 begin
231231 if not cstr(path, a) then return -36; end;
@@ -234,7 +234,7 @@
234234 end;
235235
236236 (* Removes the directory at path, which must be empty. *)
237-proc removeDir*(path: []U8): I64;
237+proc removeDir*(path: []U8): INT;
238238 var a: [4096]U8;
239239 begin
240240 if not cstr(path, a) then return -36; end;
@@ -243,7 +243,7 @@
243243 end;
244244
245245 (* Sets the permission bits of what path names. *)
246-proc chmod*(path: []U8; mode: I64): I64;
246+proc chmod*(path: []U8; mode: INT): INT;
247247 var a: [4096]U8;
248248 begin
249249 if not cstr(path, a) then return -36; end;
@@ -252,7 +252,7 @@
252252 end;
253253
254254 (* Makes path a symbolic link to target. *)
255-proc symlink*(target, path: []U8): I64;
255+proc symlink*(target, path: []U8): INT;
256256 var a, b: [4096]U8;
257257 begin
258258 if not cstr(target, a) or not cstr(path, b) then return -36; end;
@@ -262,11 +262,11 @@
262262
263263 (* What the symbolic link at path names, good until the next call; and
264264 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;
267267 begin
268268 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)));
270270 if n < 0 then return "", failed(); end;
271271 if n = LEN(linked) then return "", -36; end; (* it may be cut short *)
272272 return linked[0..n], 0;
@@ -275,8 +275,8 @@
275275 (* The size of what path names, whether it is a directory or a regular
276276 file, following a symbolic link, and whether path is one; and 0, or
277277 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 *)
280280 begin
281281 if not cstr(path, a) then return i, -36; end;
282282 if C.lstat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end;
@@ -291,7 +291,7 @@
291291 end;
292292
293293 (* Opens the directory at path, for nextEntry. *)
294-proc openDir*(d: ^Dir; path: []U8): I64;
294+proc openDir*(d: ^Dir; path: []U8): INT;
295295 var a: [4096]U8;
296296 begin
297297 if not cstr(path, a) then return -36; end;
@@ -303,7 +303,7 @@
303303 (* The next name in the directory, good until the next call, but . and
304304 .., in no order; false at the end. *)
305305 proc nextEntry*(d: ^Dir): ([]U8, BOOL);
306-var e: ^U8; n: I64;
306+var e: ^U8; n: INT;
307307 begin
308308 while true do
309309 e := C.readdir(d^.d);
@@ -324,7 +324,7 @@
324324 (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no
325325 echo, no lines, no signals, no flow control, no CR to NL, no NL to
326326 CR NL; false if fd isn't a terminal. *)
327-proc rawMode*(fd: I64): BOOL;
327+proc rawMode*(fd: INT): BOOL;
328328 var t: [256]U8;
329329 begin
330330 if C.tcgetattr(I32(fd), ADR(saved[0])) # 0 then return false; end;
@@ -334,25 +334,25 @@
334334 end;
335335
336336 (* The terminal on fd as rawMode found it. *)
337-proc restoreMode*(fd: I64);
337+proc restoreMode*(fd: INT);
338338 begin
339339 C.tcsetattr(I32(fd), 0, ADR(saved[0]));
340340 end;
341341
342342 (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't
343343 say. *)
344-proc termSize*(fd: I64): (I64, I64);
344+proc termSize*(fd: INT): (INT, INT);
345345 var w: Winsize;
346346 begin
347347 if (C.ioctl(I32(fd), TIOCGWINSZ, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then
348348 return 80, 24;
349349 end;
350- return I64(w.cols), I64(w.rows);
350+ return INT(w.cols), INT(w.rows);
351351 end;
352352
353353 (* Whether fd has something to read within ms milliseconds; ms < 0
354354 waits as long as it takes. *)
355-proc ready*(fd, ms: I64): BOOL;
355+proc ready*(fd, ms: INT): BOOL;
356356 var p: Pollfd; r: I32;
357357 begin
358358 p := {fd: I32(fd), events: 1}; (* POLLIN *)
@@ -382,21 +382,21 @@
382382 end;
383383
384384 (* Waits ms milliseconds. *)
385-proc sleep*(ms: I64);
385+proc sleep*(ms: INT);
386386 var t: Timespec; at: I64;
387387 begin
388- at := clock() + ms * 1000000;
388+ at := clock() + I64(ms) * 1000000;
389389 t := {sec: at div 1000000000, nsec: at mod 1000000000};
390390 repeat until C.clock_nanosleep(1, 1, ^U8(ADR(t)), nil) # 4; (* until t, again after EINTR *)
391391 end;
392392
393393 (* Fills b with random bytes, from the kernel. *)
394394 proc random*(b: []U8);
395-var n, r: I64;
395+var n, r: INT;
396396 begin
397397 n := 0;
398398 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);
400400 if r > 0 then INC(n, r); end;
401401 end;
402402 end;
@@ -405,8 +405,8 @@
405405 bytes, or, if serving, bound to it and taking connections: its file
406406 descriptor, or minus an errno. It is closed in a program exec
407407 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;
410410 begin
411411 fd := C.socket(I32(family), I32(kind) | 80000H, 0); (* SOCK_CLOEXEC *)
412412 if fd < 0 then return failed(); end;
@@ -423,12 +423,12 @@
423423 C.close(fd);
424424 return err;
425425 end;
426- return I64(fd);
426+ return INT(fd);
427427 end;
428428
429429 (* path as a Unix socket's address in a, or false if it is too long. *)
430430 proc unixAddr(path: []U8; a: ^SockaddrUn): BOOL;
431-var i: I64;
431+var i: INT;
432432 begin
433433 if LEN(path) >= LEN(a^.path) then return false; end;
434434 a^.family := 1; (* AF_UNIX *)
@@ -437,7 +437,7 @@
437437 end;
438438
439439 (* A stream socket connected to the Unix socket at path. *)
440-proc connect*(path: []U8): I64;
440+proc connect*(path: []U8): INT;
441441 var a: SockaddrUn;
442442 begin
443443 if not unixAddr(path, ADR(a)) then return -36; end; (* ENAMETOOLONG *)
@@ -446,7 +446,7 @@
446446
447447 (* A stream socket made at path, which must not be there yet, taking
448448 connections. *)
449-proc listen*(path: []U8): I64;
449+proc listen*(path: []U8): INT;
450450 var a: SockaddrUn;
451451 begin
452452 if not unixAddr(path, ADR(a)) then return -36; end;
@@ -456,7 +456,7 @@
456456 (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size
457457 of its struct sockaddr_in or sockaddr_in6, or 0 if either is
458458 wrong. *)
459-proc inetAddr(addr: []U8; port: I64; a: ^Sockaddr): I64;
459+proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT;
460460 var s: [64]U8;
461461 begin
462462 if (port < 0) or (port > 65535) or not cstr(addr, s) then return 0; end;
@@ -469,52 +469,52 @@
469469
470470 (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL)
471471 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;
474474 begin
475475 size := inetAddr(addr, port, ADR(a));
476476 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);
478478 end;
479479
480480 (* A stream socket connected to port at addr, an IPv4 or IPv6 address
481481 as numbers. *)
482-proc connectTcp*(addr: []U8; port: I64): I64;
482+proc connectTcp*(addr: []U8; port: INT): INT;
483483 begin
484484 return inet(addr, port, 1, false); (* SOCK_STREAM *)
485485 end;
486486
487487 (* 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;
489489 begin
490490 return inet(addr, port, 2, false); (* SOCK_DGRAM *)
491491 end;
492492
493493 (* A stream socket taking connections on port at addr; "0.0.0.0" or
494494 "::" is every address the machine has. *)
495-proc listenTcp*(addr: []U8; port: I64): I64;
495+proc listenTcp*(addr: []U8; port: INT): INT;
496496 begin
497497 return inet(addr, port, 1, true);
498498 end;
499499
500500 (* The next connection to the socket fd, waiting for one: a socket of
501501 its own, closed in a program exec starts; or minus an errno. *)
502-proc accept*(fd: I64): I64;
502+proc accept*(fd: INT): INT;
503503 var r: I32;
504504 begin
505505 r := C.accept4(I32(fd), nil, nil, 80000H); (* SOCK_CLOEXEC *)
506506 if r < 0 then return failed(); end;
507- return I64(r);
507+ return INT(r);
508508 end;
509509
510510 (* Writes s to the socket fd, as write does, but returns -32 (EPIPE)
511511 where write would stop the program with SIGPIPE: when the other end
512512 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;
515515 begin
516516 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 *)
518518 if r < 0 then return failed(); end;
519519 return r;
520520 end;
@@ -522,13 +522,13 @@
522522 (* The first of fds that has something to read within ms milliseconds,
523523 or that has reached its end or failed, so that a read won't wait; -1
524524 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;
527527 begin
528528 n := LEN(fds);
529529 if n > LEN(p) then n := LEN(p); end;
530530 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 *)
532532 if r <= 0 then return -1; end;
533533 for i := 0 to n - 1 do
534534 if p[i].revents # 0 then return fds[i]; end;
@@ -538,7 +538,7 @@
538538
539539 (* The value of the environment variable name; "" if it isn't set. *)
540540 proc env*(name: []U8): []U8;
541-var a: [4096]U8; s: ^U8; n: I64;
541+var a: [4096]U8; s: ^U8; n: INT;
542542 begin
543543 if not cstr(name, a) then return ""; end;
544544 s := C.getenv(ADR(a[0]));
@@ -550,8 +550,8 @@
550550
551551 (* The working directory, good until the next call; and 0, or minus an
552552 errno. *)
553-proc workDir*: ([]U8, I64);
554-var n: I64;
553+proc workDir*: ([]U8, INT);
554+var n: INT;
555555 begin
556556 if C.getcwd(ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end;
557557 n := 0;
@@ -560,7 +560,7 @@
560560 end;
561561
562562 (* Makes path the working directory. *)
563-proc setWorkDir*(path: []U8): I64;
563+proc setWorkDir*(path: []U8): INT;
564564 var a: [4096]U8;
565565 begin
566566 if not cstr(path, a) then return -36; end;
@@ -571,8 +571,8 @@
571571 (* A pseudo-terminal: the file descriptor of its controlling side, or
572572 minus an errno. Its other side, the terminal its programs run on, is
573573 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;
576576 begin
577577 fd := C.posix_openpt(102H); (* O_RDWR, O_NOCTTY: glibc's *)
578578 if fd < 0 then return failed(); end;
@@ -581,12 +581,12 @@
581581 C.close(fd);
582582 return err;
583583 end;
584- return I64(fd);
584+ return INT(fd);
585585 end;
586586
587587 (* Tells the terminal of the pseudo-terminal fd that it has cols
588588 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;
590590 var w: Winsize;
591591 begin
592592 w := {rows: U16(rows), cols: U16(cols)};
@@ -596,7 +596,7 @@
596596
597597 (* Copies s and a zero to at: the byte after them. *)
598598 proc put(s: []U8; at: ^U8): ^U8;
599-var i: I64;
599+var i: INT;
600600 begin
601601 for i := 0 to LEN(s) - 1 do at[i] := s[i]; end;
602602 at[LEN(s)] := 0;
@@ -606,7 +606,7 @@
606606 (* Whether the NAME=value s, a C string, names a variable that one of
607607 env gives. *)
608608 proc replaced(s: ^U8; env: [][]U8): BOOL;
609-var i, n: I64;
609+var i, n: INT;
610610 begin
611611 for i := 0 to LEN(env) - 1 do
612612 n := 0;
@@ -620,8 +620,8 @@
620620 strings and a nil, then the environment old with each NAME=value of
621621 env in place of its variable or added, and a nil; or nil. The
622622 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;
625625 begin
626626 n := 0;
627627 while old[n] # nil do INC(n); end;
@@ -645,22 +645,22 @@
645645
646646 (* A pipe: the fd to read and the fd to write, both closed in a program
647647 exec starts; or minus an errno and -1. *)
648-proc pipe*: (I64, I64);
648+proc pipe*: (INT, INT);
649649 var fds: [2]I32;
650650 begin
651651 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]);
653653 end;
654654
655655 (* This program's process id. *)
656-proc pid*: I64;
656+proc pid*: INT;
657657 begin
658- return I64(C.getpid());
658+ return INT(C.getpid());
659659 end;
660660
661661 (* Moves the program pid, or this one if pid is 0, to the process group
662662 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;
664664 begin
665665 if C.setpgid(I32(pid), I32(group)) # 0 then return failed(); end;
666666 return 0;
@@ -668,7 +668,7 @@
668668
669669 (* Gives the keys of the terminal on fd, and its signals, to the process
670670 group group. *)
671-proc foreground*(fd, group: I64): I64;
671+proc foreground*(fd, group: INT): INT;
672672 begin
673673 if C.tcsetpgrp(I32(fd), I32(group)) # 0 then return failed(); end;
674674 return 0;
@@ -676,21 +676,21 @@
676676
677677 (* The process group the terminal on fd gives its keys to, or minus an
678678 errno. *)
679-proc foregroundOf*(fd: I64): I64;
679+proc foregroundOf*(fd: INT): INT;
680680 var g: I32;
681681 begin
682682 g := C.tcgetpgrp(I32(fd));
683683 if g < 0 then return failed(); end;
684- return I64(g);
684+ return INT(g);
685685 end;
686686
687687 (* Starts the program p describes: its process id, or minus an errno.
688688 A program that can't be started ends with status 127. Every signal
689689 is blocked from the fork until the program has its own: its group,
690690 its terminal's foreground, and signals as they are at first. *)
691-proc spawn*(p: Program): I64;
691+proc spawn*(p: Program): INT;
692692 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;
694694 all, old, empty: [16]U64; dfl: Sigaction; pid, fd: I32; (* sigset_t: 128 bytes *)
695695 begin
696696 if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
@@ -737,14 +737,14 @@
737737 if (pid > 0) and (p.tty = 0) then
738738 (* as the program does, for whichever of the two runs first *)
739739 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;
741741 if p.group # 0 then C.setpgid(pid, I32(g)); end;
742742 if p.foreground then C.tcsetpgrp(0, I32(g)); end;
743743 end;
744744 C.sigprocmask(2, ^U8(ADR(old)), nil);
745745 munmap(^U8(argv), size);
746746 if pid < 0 then return err; end;
747- return I64(pid);
747+ return INT(pid);
748748 end;
749749
750750 (* Waits for the program pid, or any of this program's if pid is -1, to
@@ -753,7 +753,7 @@
753753 block it doesn't wait: 0 and running if none has changed. Minus an
754754 errno, and running, if there is none to wait for. The status is read
755755 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);
757757 var status, options, r: I32;
758758 begin
759759 options := 3; (* WNOHANG, WUNTRACED *)
@@ -761,14 +761,14 @@
761761 r := C.waitpid(I32(pid), ADR(status), options);
762762 if r < 0 then return failed(), running, 0; end;
763763 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;
767767 end;
768768
769769 (* Sends the program pid, or the group -pid, the signal: 0, or minus an
770770 errno. *)
771-proc kill*(pid, signal: I64): I64;
771+proc kill*(pid, signal: INT): INT;
772772 begin
773773 if C.kill(I32(pid), I32(signal)) # 0 then return failed(); end;
774774 return 0;
@@ -789,8 +789,8 @@
789789 (* Catches the signals sigs: they don't do what they would, but give
790790 their numbers on an fd, which a later catch adds to and gives again;
791791 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;
794794 begin
795795 for i := 0 to LEN(sigs) - 1 do
796796 if (sigs[i] < 1) or (sigs[i] > 64) or (sigs[i] = sigKill) or (sigs[i] = sigStop)
@@ -807,20 +807,20 @@
807807 for i := 0 to LEN(sigs) - 1 do
808808 if C.sigaction(I32(sigs[i]), ^U8(ADR(act)), nil) # 0 then return failed(); end;
809809 end;
810- return I64(sigRead);
810+ return INT(sigRead);
811811 end;
812812
813813 (* 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;
815815 var b: [1]U8;
816816 begin
817817 if read(fd, b) # 1 then return 0; end;
818- return I64(b[0]);
818+ return INT(b[0]);
819819 end;
820820
821821 (* Makes the signal sig do nothing, or, if not yes, what it does at
822822 first: 0, or minus an errno. *)
823-proc ignore*(sig: I64; yes: BOOL): I64;
823+proc ignore*(sig: INT; yes: BOOL): INT;
824824 var act: Sigaction;
825825 begin
826826 if yes then act.handler := Handler(1); end; (* SIG_IGN *)
@@ -828,7 +828,7 @@
828828 return 0;
829829 end;
830830
831-proc isTerminal*(fd: I64): BOOL;
831+proc isTerminal*(fd: INT): BOOL;
832832 begin
833833 return C.isatty(I32(fd)) = 1;
834834 end;
@@ -839,7 +839,7 @@
839839 end;
840840
841841 (* Ends the program, at once, with status. *)
842-proc exit*(status: I64);
842+proc exit*(status: INT);
843843 begin
844844 C._exit(I32(status));
845845 end;
@@ -853,7 +853,7 @@
853853 one is sent; and a program starts with them neither caught nor
854854 ignored. *)
855855 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;
857857 begin
858858 pty := openPty();
859859 if (pty < 0) or (setTermSize(pty, 100, 30) # 0) then exit(2); end;
@@ -923,7 +923,7 @@
923923 sees; addresses read and refused; a TCP connection on the loopback;
924924 and a datagram to a port where no one listens, refused. *)
925925 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;
927927 begin
928928 t := clock();
929929 sleep(20);
@@ -964,7 +964,7 @@
964964 and closed; a directory made, listed and emptied; no terminal; a
965965 socket, sent to after its end; programs; time and the network. *)
966966 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;
968968 begin
969969 fd := create("/tmp/raz-sys-test");
970970 if fd < 0 then exit(2); end;

lib/Thread.linux-x86_64.raz (history) modified +14 -14

@@ -24,23 +24,23 @@
2424
2525 type
2626 Thread* = record
27- tid: I64; (* the kernel's id, until the thread ends *)
27+ tid: INT; (* the kernel's id, until the thread ends *)
2828 base: ^U8; (* its stack's mapping, the guard page first *)
29- size: I64;
29+ size: INT;
3030 fn: proc(arg: ^U8); (* what it runs, and with what *)
3131 arg: ^U8;
3232 end;
3333 (* What sigaltstack takes *)
34- AltStack = record sp: ^U8; flags, size: I64; end;
34+ AltStack = record sp: ^U8; flags, size: INT; end;
3535 (* 0 free, 1 taken, 2 taken with a thread waiting *)
36- Mutex* = record state: I64; end;
36+ Mutex* = record state: INT; end;
3737
3838 (* clone(flags, stack, tid, tid), the new thread starting with fn(arg)
3939 on stack and ending, when fn returns, with the exit system call.
4040 fn and arg go on the new stack first, since the new thread has no
4141 registers but rsp of its own to find them by. Returns the new
4242 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;
4444 code 48H, 83H, 0EEH, 10H, (* sub rsi, 16 *)
4545 4CH, 89H, 06H, (* mov [rsi], r8 *)
4646 4CH, 89H, 4EH, 08H, (* mov [rsi + 8], r9 *)
@@ -58,7 +58,7 @@
5858 0FH, 05H, (* syscall *)
5959 0C3H; (* parent: ret *)
6060
61-proc futex(word: ^I64; op, val: I64): I64;
61+proc futex(word: ^INT; op, val: INT): INT;
6262 begin
6363 return SYSCALL(202, word, op, val, 0);
6464 end;
@@ -76,7 +76,7 @@
7676
7777 (* Starts p(arg) in a new thread. *)
7878 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;
8080 begin
8181 size := Page + Stack + Alt + Page;
8282 base := Sys.mmap(size);
@@ -103,7 +103,7 @@
103103
104104 (* Waits for t to end, then frees its stack. *)
105105 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;
107107 begin
108108 tid := ADR(t^.tid);
109109 v := tid^;
@@ -117,7 +117,7 @@
117117 end;
118118
119119 proc lock*(m: ^Mutex);
120-var c: I64;
120+var c: INT;
121121 begin
122122 if CAS(ADR(m^.state), 0, 1) then return; end;
123123 c := XCHG(ADR(m^.state), 2);
@@ -145,7 +145,7 @@
145145 Thread [n alive], Thread fail *)
146146 var
147147 testLock: Mutex;
148- testCount: I64;
148+ testCount: INT;
149149 wave: [1000]^Thread;
150150
151151 proc testWork(_arg: ^U8);
@@ -155,18 +155,18 @@
155155 unlock(ADR(testLock));
156156 end;
157157
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;
160160 begin
161161 s := ARGV()[i];
162162 v := 0;
163163 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;
165165 return v;
166166 end;
167167
168168 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;
170170 begin
171171 n := 2000; alive := 50;
172172 fail := (ARGC() = 2) and (ARGV()[1][0] = 'f');

src/gen.pas modified +119 -34

@@ -44,6 +44,8 @@
4444 vol: boolean; { mVar: reached through ^VOLATILE }
4545 isVar: boolean; { mVar: a variable of the program, not a temporary }
4646 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 }
4749 obj: PObj; { mProc, mBuiltin, mCase }
4850 pos: TPos; { where it is in the source, for messages }
4951 end;
@@ -64,6 +66,8 @@
6466 var
6567 rtFail, argcChunk, argvChunk: longint;
6668 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 }
6771
6872 procedure MakeConst(var x: TItem; t: PType; v: int64);
6973 function What(const x: TItem): shortstring;
@@ -76,6 +80,8 @@
7680 procedure Address(var x: TItem; r: longint);
7781 procedure Save(var x: TItem);
7882 procedure Coerce(var x: TItem; t: PType);
83+procedure CoerceExact(var x: TItem; t: PType; const help: shortstring);
84+procedure NotReadOnly(const x: TItem);
7985 procedure Assign(var dst, src: TItem);
8086 procedure CopyToTemp(var x: TItem);
8187 function ToSlot(var x: TItem): int64;
@@ -92,6 +98,7 @@
9298 procedure Complement(var x: TItem);
9399 procedure Op1(op: TSym; var x: TItem; var L: longint);
94100 procedure Op2(op: TSym; var x, y: TItem; L: longint);
101+function IsWord(t: PType): boolean;
95102 procedure Convert(var x: TItem; t: PType);
96103
97104 procedure BeginCall(var c: TCall; var x: TItem);
@@ -251,7 +258,8 @@
251258 end;
252259 oVar: begin
253260 x.mode := mVar;
254- x.isVar := true;
261+ x.ro := (o^.lev = 0) and (o^.module <> curModule);
262+ x.isVar := not x.ro;
255263 if o^.ext then begin
256264 Load(RAX, MemRip(o^.chunk, 0), 8, false);
257265 x.base := bReg; x.reg := RAX;
@@ -497,6 +505,20 @@
497505 TempItem(x, t, s);
498506 end;
499507
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+
500522 procedure Coerce(var x: TItem; t: PType);
501523 var s: PType; tmp: int64;
502524 begin
@@ -521,7 +543,8 @@
521543 end;
522544 if x.mode in [mType, mBuiltin, mNone, mCase] then NotValue(x);
523545 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)
525548 else if (s^.form = fConst) and (t^.form = fInt) then begin
526549 if (x.mode = mConst) and not Fits(x.val, t) then MarkAt(x.pos, IntStr(x.val) + ' doesn''t fit ' + TypeName(t));
527550 x.typ := t;
@@ -531,6 +554,7 @@
531554 and Same(s^.base, t^.base) then
532555 x.typ := t
533556 else if (s^.form = fArray) and (t^.form = fSlice) and Same(s^.base, t^.base) then begin
557+ NotReadOnly(x);
534558 if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer');
535559 if x.odd then MarkAt(x.pos, 'can''t make a slice of a field of a packed record');
536560 Address(x, RAX);
@@ -539,6 +563,20 @@
539563 MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t));
540564 end;
541565
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+
542580 procedure Assign(var dst, src: TItem);
543581 var m: TMem;
544582 begin
@@ -613,7 +651,7 @@
613651 if t^.base = nil then MarkAt(x.pos, TypeName(t) + ' points to a type never declared');
614652 Value(x);
615653 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;
617655 end;
618656
619657 { A field of a packed record, of more than one byte's alignment, may
@@ -654,7 +692,7 @@
654692 PopR(RCX);
655693 Alu(aluAdd, RAX, RCX);
656694 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;
658696 end else if (t^.form = fArray) and (y.mode = mConst) then begin
659697 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));
660698 x.off := x.off + y.val * s;
@@ -663,8 +701,10 @@
663701 end;
664702 end else if t^.form = fArray then begin
665703 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;
668708 if s <> 1 then ImulI(RAX, s);
669709 if x.base = bStack then PopR(RCX) else Lea(RCX, MemOf(x, RCX));
670710 Alu(aluAdd, RAX, RCX);
@@ -674,11 +714,13 @@
674714 Value(y);
675715 m := MemOf(x, RCX);
676716 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;
679721 if s <> 1 then ImulI(RAX, s);
680722 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;
682724 end;
683725 x.typ := t^.base;
684726 end;
@@ -698,22 +740,27 @@
698740 if not IsInt(hi.typ) then MarkAt(hi.pos, 'an index is an integer, found ' + What(hi));
699741 if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer');
700742 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);
701744 Value(hi);
702745 MovRR(RDX, RAX);
703746 PopR(RCX);
704747 if t^.form = fPtr then begin
705748 { the bounds can't be known, but a slice can't run backwards }
706749 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;
709754 end else begin
710755 m := MemOf(x, R8);
711756 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;
717764 end;
718765 tmp := AllocTemp(16, 8);
719766 MovRR(RAX, RDX);
@@ -853,6 +900,12 @@
853900 end;
854901 end;
855902
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+
856909 function FoldInt(op: TSym; a, b: int64; t: PType; const p: TPos): int64;
857910 var u: boolean;
858911 begin
@@ -867,16 +920,16 @@
867920 if u then begin
868921 if op = sDiv then FoldInt := int64(qword(a) div qword(b))
869922 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')
871924 else if op = sDiv then FoldInt := a div b
872925 else FoldInt := a mod b;
873926 end;
874927 sAmp: FoldInt := a and b;
875928 sBar: FoldInt := a or b;
876929 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));
880933 sEql: FoldInt := ord(a = b);
881934 sNeq: FoldInt := ord(a <> b);
882935 sLss: if u then FoldInt := ord(qword(a) < qword(b)) else FoldInt := ord(a < b);
@@ -913,6 +966,22 @@
913966 { and, or and not are for BOOLs; &, |, xor and ~ for the bits of
914967 integers: x is the wrong kind for op, and the message names the
915968 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+
916985 procedure WrongLogic(op: TSym; var x: TItem);
917986 const Bits = 'the bits of integers take ';
918987 begin
@@ -1013,10 +1082,10 @@
10131082 t := tBool;
10141083 end else if (xt^.form = fPtr) and IsInt(yt) and (op in [sPlus, sMinus]) then begin
10151084 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;
10171086 end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin
10181087 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;
10201089 end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin
10211090 if not (op in Rel) then MarkAt(Join(x.pos, y.pos), SymText(op) + ' doesn''t apply to ' + TypeName(xt));
10221091 if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then
@@ -1122,9 +1191,9 @@
11221191 case op of
11231192 sPlus: begin if scale <> 1 then ImulI(RCX, scale); Alu(aluAdd, RAX, RCX) end;
11241193 sMinus: begin
1125- if (scale <> 1) and (t <> tI64) then ImulI(RCX, scale);
1194+ if (scale <> 1) and (t <> tInt) then ImulI(RCX, scale);
11261195 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
11281197 sh := Log2(scale);
11291198 if sh >= 0 then ShiftI(shSar, RAX, sh)
11301199 else begin MovRI(RCX, scale); Cqo; Unary(7, RCX) end;
@@ -1133,14 +1202,21 @@
11331202 sTimes: if k >= 1 then ShiftI(shShl, RAX, k) else Imul(RAX, RCX);
11341203 sDiv, sMod: if k >= 1 then DivPow2(op, k, unsign) else begin
11351204 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;
11371209 if op = sMod then MovRR(RAX, RDX);
11381210 end;
11391211 sAmp: Alu(aluAnd, RAX, RCX);
11401212 sBar: Alu(aluOr, RAX, RCX);
11411213 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;
11441220 else MarkAt(Join(x.pos, y.pos), SymText(op) + ' doesn''t apply to ' + TypeName(t));
11451221 end;
11461222 Norm(t);
@@ -1149,6 +1225,13 @@
11491225 if op in Rel + [sIn] then x.typ := tBool else x.typ := t;
11501226 end;
11511227
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+
11521235 procedure Convert(var x: TItem; t: PType);
11531236 var s: PType; r: double; L1, L2: longint; f: boolean;
11541237 begin
@@ -1213,11 +1296,11 @@
12131296 end else begin
12141297 Value(x); MovqXR(0, RAX); Cvtts2si(RAX, 0, IsF32(s)); Norm(t)
12151298 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
12171300 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
12211304 MarkAt(x.pos, 'can''t convert ' + TypeName(s) + ' to ' + TypeName(t));
12221305 x.typ := t;
12231306 end;
@@ -1255,11 +1338,11 @@
12551338 if c.n > High(c.slots) then MarkAt(a.pos, 'too many arguments');
12561339 if p = nil then begin
12571340 { 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
12591342 constant as an F64; C takes no F32 there }
12601343 if not c.sig^.variadic then WrongCount(c, a.pos, 'too many arguments');
12611344 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)
12631346 else if a.typ = tRConst then Coerce(a, tReal)
12641347 else if IsF32(a.typ) then MarkAt(a.pos, 'an F32 goes to ... as F64(x)')
12651348 else if not IsScalar(a.typ) then MarkAt(a.pos, 'only a single value goes to ...');
@@ -1270,6 +1353,7 @@
12701353 end;
12711354 c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar;
12721355 if p^.isVar then begin
1356+ NotReadOnly(a);
12731357 if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable');
12741358 if a.odd then MarkAt(a.pos, 'a field of a packed record can''t be a var parameter');
12751359 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 @@
13931477 begin
13941478 if x.typ^.form = fEnum then exit(ToSlot(x));
13951479 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 }
13961481 Address(x, RAX);
13971482 p := AllocTemp(8, 8);
13981483 Store(Mem(RBP, p), RAX, 8);
@@ -1571,7 +1656,7 @@
15711656 procedure IncDec(var v, k: TItem; dec: boolean);
15721657 var n: longint;
15731658 begin
1574- Coerce(k, v.typ);
1659+ CoerceExact(k, v.typ, '');
15751660 Value(k);
15761661 MovRR(RCX, RAX);
15771662 Address(v, RDX);

src/parse.pas modified +34 -14

@@ -76,7 +76,7 @@
7676 curResult: PType; { the result type of the procedure being compiled }
7777 inExtern: boolean; { reading an extern's signature: ... allowed }
7878 tArgv, tBodySig: PType;
79- nameRt, nameFail, nameMain, nameBody, nameStatic: longint;
79+ nameRt, nameFail, nameMain, nameBody, nameStatic, nameCheck, nameOff: longint;
8080 declaring: array[0..63] of longint; { the names the declaration being read declares }
8181 numDeclaring: longint;
8282 skipped: boolean; { the last statement had an error and was skipped }
@@ -667,7 +667,7 @@
667667 if i > 0 then Expect(sComma);
668668 Expression(a, nil);
669669 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);
671671 slots[i] := ToSlot(a);
672672 end;
673673 end;
@@ -678,8 +678,9 @@
678678 Expression(p, nil);
679679 if p.typ^.form <> fPtr then MarkAt(p.pos, 'expected a pointer, found ' + What(p));
680680 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));
683684 s[0] := ToSlot(p);
684685 if which = bCas then n := 2 else n := 1;
685686 for i := 1 to n do begin
@@ -710,6 +711,7 @@
710711 var y, z: TItem; t: PType; f: PObj; s: int64; c: TCall; L: longint;
711712 begin
712713 Expression(x, nil);
714+ NotReadOnly(x);
713715 if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then MarkAt(x.pos, 'NEW needs a pointer variable');
714716 t := x.typ^.base;
715717 Save(x);
@@ -728,9 +730,9 @@
728730 MakeConst(z, y.typ, 0);
729731 z.mode := mReg;
730732 PassArg(c, z);
731- MakeConst(z, tI64, t^.size);
733+ MakeConst(z, tInt, t^.size);
732734 PassArg(c, z);
733- MakeConst(z, tI64, t^.align);
735+ MakeConst(z, tInt, t^.align);
734736 PassArg(c, z);
735737 EndCall(c, z);
736738 L := NoLabel;
@@ -764,7 +766,7 @@
764766 MakeConst(x, tNone, 0);
765767 case which of
766768 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;
768770 bArgv: begin Load(RAX, MemRip(argvChunk, 0), 8, false); x.typ := tArgv; x.mode := mReg end;
769771 end;
770772 exit;
@@ -777,6 +779,7 @@
777779 end;
778780 bAdr: begin
779781 Expression(y, nil);
782+ NotReadOnly(y);
780783 if (y.mode <> mVar) or not y.isVar then MarkAt(y.pos, 'ADR needs a variable');
781784 if y.odd then MarkAt(y.pos, 'a field of a packed record has no address');
782785 t := NewPtr(y.typ, y.vol);
@@ -791,7 +794,7 @@
791794 else if (y.typ^.form = fSlice) and (y.mode = mVar) then begin
792795 Address(y, RAX);
793796 Load(RAX, Mem(RAX, 8), 8, false);
794- MakeConst(x, tI64, 0);
797+ MakeConst(x, tInt, 0);
795798 x.mode := mReg;
796799 end else MarkAt(y.pos, 'LEN needs an array or a slice, found ' + What(y));
797800 end;
@@ -802,19 +805,20 @@
802805 Next;
803806 Expression(y, nil);
804807 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);
806809 slots[n] := ToSlot(y);
807810 inc(n);
808811 end;
809812 for i := 0 to n - 1 do Load(SysRegs[i], Mem(RBP, slots[i]), 8, false);
810813 Syscall;
811- MakeConst(x, tI64, 0);
814+ MakeConst(x, tInt, 0);
812815 x.mode := mReg;
813816 end;
814817 bCas, bXchg, bXadd: Atomic(x, which);
815818 bMsg: begin Expression(x, tError); Msg(x) end;
816819 bInc, bDec: begin
817820 Expression(x, nil);
821+ NotReadOnly(x);
818822 if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then
819823 MarkAt(x.pos, IncOrDec(which) + ' needs an integer variable');
820824 Save(x);
@@ -1261,10 +1265,11 @@
12611265 MakeItem(v, o);
12621266 Save(v);
12631267 Expression(a, o^.typ);
1268+ CoerceExact(a, o^.typ, '');
12641269 Assign(v, a);
12651270 Expect(sTo);
12661271 Expression(b, o^.typ);
1267- Coerce(b, o^.typ);
1272+ CoerceExact(b, o^.typ, '');
12681273 bslot := ToSlot(b);
12691274 step := 1;
12701275 if tok = sBy then begin
@@ -1397,6 +1402,7 @@
13971402 d[0] := x;
13981403 dn[0] := first;
13991404 repeat
1405+ NotReadOnly(d[n]);
14001406 if (d[n].mode <> mVar) or not d[n].isVar then MarkAt(d[n].pos, 'can''t assign to ' + Subject(d[n], dn[n]));
14011407 Pin(d[n]);
14021408 inc(n);
@@ -1414,6 +1420,7 @@
14141420 for i := 0 to n - 1 do begin
14151421 z := y;
14161422 Field(z, f);
1423+ CoerceExact(z, d[i].typ, 'several results go to variables of just their types');
14171424 Assign(d[i], z);
14181425 f := f^.next;
14191426 end;
@@ -1477,6 +1484,7 @@
14771484 sIdent: begin
14781485 LeftSide(x, called);
14791486 if tok = sBecomes then begin
1487+ NotReadOnly(x);
14801488 if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, first));
14811489 Save(x);
14821490 Next;
@@ -2078,13 +2086,14 @@
20782086 function CompileFile(const path: shortstring; n: longint; const args: TArgs; checkOnly: boolean): PModule;
20792087 var
20802088 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;
20822090 lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs;
20832091 generic: boolean; argsAt: TScanState;
20842092 begin
20852093 SaveScan(st);
20862094 SaveScopes(d, saved);
2087- oldMod := curModule; oldCheck := checkMode; oldPath := curFile;
2095+ oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks;
2096+ checks := true;
20882097 curFile := Name(path);
20892098 if not Open(path) then Fatal('can''t read ' + path);
20902099 New(m);
@@ -2167,6 +2176,15 @@
21672176 Next;
21682177 Expect(sSemicolon);
21692178 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;
21702188 Declarations(true);
21712189 if tok = sBegin then begin
21722190 if checkMode then SkipBody
@@ -2203,7 +2221,7 @@
22032221 if lastModule = nil then firstModule := m else lastModule^.next := m;
22042222 lastModule := m;
22052223 end;
2206- curModule := oldMod; checkMode := oldCheck; curFile := oldPath;
2224+ curModule := oldMod; checkMode := oldCheck; curFile := oldPath; checks := oldChecks;
22072225 RestoreScopes(d, saved);
22082226 RestoreScan(st);
22092227 CompileFile := m;
@@ -2430,6 +2448,8 @@
24302448 nameMain := Name('main');
24312449 nameBody := Name('body');
24322450 nameStatic := Name('static');
2451+ nameCheck := Name('check');
2452+ nameOff := Name('off');
24332453 rtFail := NewChunk(secText, nameRt, nameFail);
24342454 argcChunk := NewChunk(secBss, -1, Name('argc'));
24352455 SetBss(argcChunk, 8, 8);

src/raz.pas modified +2 -2

@@ -153,8 +153,8 @@
153153 hasResult := false;
154154 if main <> nil then begin
155155 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');
158158 if errors > 0 then Finish;
159159 hasResult := main^.typ^.base <> nil;
160160 end;

src/sym.pas modified +3 -0

@@ -129,6 +129,7 @@
129129
130130 var
131131 tI8, tI16, tI32, tI64, tU8, tU16, tU32, tU64: PType;
132+ tInt, tUInt: PType; { INT and UINT, as big as an address: 8 bytes here }
132133 tBool, tF32, tReal, tRConst, tError, tConst, tNil, tStr, tNone, tPtrU8, tBytes: PType;
133134 tPoison: PType; { of a name reported as not declared }
134135 curModule: PModule;
@@ -557,6 +558,8 @@
557558 tU16 := Basic('U16', fInt, 2, false);
558559 tU32 := Basic('U32', fInt, 4, false);
559560 tU64 := Basic('U64', fInt, 8, false);
561+ tInt := Basic('INT', fInt, 8, true);
562+ tUInt := Basic('UINT', fInt, 8, false);
560563 tBool := Basic('BOOL', fBool, 1, false);
561564 tF32 := Basic('F32', fReal, 4, false);
562565 tReal := Basic('F64', fReal, 8, false);

test/doc/Opt.expect (history) modified +1 -1

@@ -24,7 +24,7 @@
2424 name: []U8; (* the program's, as the messages begin *)
2525 table: []Row;
2626 scope: []U8;
27- at: I64; (* the next word *)
27+ at: INT; (* the next word *)
2828 group: []U8; (* the letters left of a word of them, as -lw *)
2929 spelt: []U8; (* the option just read as written, without its dashes *)
3030 ended: BOOL; (* the scope's options have ended *)

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

@@ -3,7 +3,7 @@
33 module orders, searches and hashes them, reads and writes their
44 UTF-8, and reads a number from one.
55
6-proc cmp*(a, b: []U8): I64;
6+proc cmp*(a, b: []U8): INT;
77 -1, 0 or 1 as a sorts before, with or after b, byte by byte.
88
99 proc eq*(a, b: []U8): BOOL;
@@ -11,17 +11,17 @@
1111 proc hash*(s: []U8): U64;
1212 FNV-1a, 64 bits.
1313
14-proc find*(s, sub: []U8): I64;
14+proc find*(s, sub: []U8): INT;
1515 Where sub first starts in s, or -1.
1616
1717 proc hasPrefix*(s, p: []U8): BOOL;
1818
19-proc encode*(c: I64): ([4]U8, I64);
19+proc encode*(c: I32): ([4]U8, INT);
2020 c in UTF-8: its bytes, and how many. A number that isn't a
2121 character, a surrogate or one past 10FFFFH, becomes FFFDH, the
2222 character that stands for a wrong one.
2323
24-proc decode*(s: []U8): (I64, I64);
24+proc decode*(s: []U8): (I32, INT);
2525 The character s starts with, and its length in bytes: FFFDH and 1
2626 if its first byte doesn't start one rightly, being a continuation,
2727 or followed by too few continuations, or spelling a surrogate or a

test/doc/Thread.expect (history) modified +3 -3

@@ -11,14 +11,14 @@
1111 const Failed*: ERROR = "can't start a thread";
1212
1313 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 *)
1515 base: ^U8; (* its stack's mapping, the guard page first *)
16- size: I64;
16+ size: INT;
1717 fn: proc(arg: ^U8); (* what it runs, and with what *)
1818 arg: ^U8;
1919 end;
2020
21-type Mutex* = record state: I64; end;
21+type Mutex* = record state: INT; end;
2222 0 free, 1 taken, 2 taken with a thread waiting
2323
2424 proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR);

test/err/DeclAtomicSize.err (history) modified +1 -1

@@ -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
22 8 | n := XADD(p, 1);
33 | ^
44 raz: 1 error

test/err/DivLowestConst.err (history) added +4 -0

@@ -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

test/err/DivLowestConst.raz (history) added +7 -0

@@ -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.

test/genbench.py modified +8 -8

@@ -8,22 +8,22 @@
88 import Out;
99
1010 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;
1313
1414 var
15- g: [16]I64;
16- data: [64]I64;
15+ g: [16]INT;
16+ data: [64]INT;
1717 """)
18-print("""proc p0(a, b: I64; _s: []I64): I64;
18+print("""proc p0(a, b: INT; _s: []INT): INT;
1919 begin
2020 return a + b;
2121 end;
2222 """)
2323 for i in range(1, n + 1):
2424 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;
2727 begin
2828 t := 0;
2929 for i := 0 to LEN(s) - 1 do
@@ -51,7 +51,7 @@
5151 end;
5252 """)
5353 print(f"""proc main*;
54-var i: I64;
54+var i: INT;
5555 begin
5656 for i := 0 to 63 do data[i] := i; end;
5757 Out.int(p{n}(1, 2, data[0..4]));

test/msg/AtomicI64.err (history) added +4 -0

@@ -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

test/msg/ExportAdr.err (history) added +4 -0

@@ -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

test/msg/ExportAsSlice.err (history) added +4 -0

@@ -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

test/msg/ExportAssign.err (history) added +4 -0

@@ -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

test/msg/ExportElem.err (history) added +4 -0

@@ -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

test/msg/ExportInc.err (history) added +4 -0

@@ -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

test/msg/ExportSlice.err (history) added +4 -0

@@ -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

test/msg/ExportVarParam.err (history) added +4 -0

@@ -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

test/msg/IntFor.err added +5 -0

@@ -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

test/msg/IntFromPointer.err (history) added +4 -0

@@ -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

test/msg/IntInc.err added +5 -0

@@ -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

test/msg/IntMix.err added +5 -0

@@ -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

test/msg/IntNarrow.err (history) added +4 -0

@@ -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

test/msg/IntPointer.err (history) added +4 -0

@@ -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

test/msg/IntResults.err added +5 -0

@@ -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

test/msg/ScanMain.err (history) modified +1 -1

@@ -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
22 2 | proc main*(_n: I64);
33 | ^^^^
44 raz: 1 error

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

@@ -1,7 +1,7 @@
11 module Atomic;
22 import Out;
33
4-var counter: I64; flag: U64; p: ^I64;
4+var counter: INT; flag: UINT; p: ^INT;
55
66 proc add3*(a, b, c: I64): I64;
77 code 48H, 8DH, 04H, 37H, (* lea rax, [rdi+rsi] *)
@@ -9,7 +9,7 @@
99 0C3H; (* ret *)
1010
1111 proc main*;
12-var old: I64; ok: BOOL; v: ^VOLATILE I64; x: I64;
12+var old: INT; ok: BOOL; v: ^VOLATILE INT; x: INT;
1313 begin
1414 old := XADD(ADR(counter), 5);
1515 old := XADD(ADR(counter), 2);
@@ -28,7 +28,7 @@
2828 v^ := 5;
2929 v^ := v^ + 1;
3030 Out.int(x); Out.ln;
31- v := ^VOLATILE I64(ADR(counter));
31+ v := ^VOLATILE INT(ADR(counter));
3232 Out.int(v^); Out.ln;
3333 end;
3434

test/run/CheckOff.expect (history) added +1 -0

@@ -0,0 +1 @@
1+42 4

test/run/CheckOff.raz (history) added +18 -0

@@ -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.

test/run/CheckOff.status (history) added +1 -0

@@ -0,0 +1 @@
1+2

test/run/CheckOff.stderr (history) added +1 -0

@@ -0,0 +1 @@
1+test/run/CheckOff.raz:15:17: index 2 is out of range for a length of 2

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

@@ -66,7 +66,7 @@
6666 m.a := 1; m.b := -2; m.c := 65535;
6767 Out.int(m.b); Out.str(" "); Out.int(I64(m.c)); Out.ln;
6868 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;
7070 end;
7171
7272 end Data.

test/run/DivLowestI16.expect (history) added +1 -0

@@ -0,0 +1 @@
1+-2
\ No newline at end of file

test/run/DivLowestI16.raz (history) added +15 -0

@@ -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.

test/run/DivLowestI16.status (history) added +1 -0

@@ -0,0 +1 @@
1+136

test/run/DivLowestI16.stderr (history) added +1 -0

@@ -0,0 +1 @@
1+test/run/DivLowestI16.raz:12:5: stopped by a division fault

test/run/DivLowestI32.expect (history) added +1 -0

@@ -0,0 +1 @@
1+-1073741824
\ No newline at end of file

test/run/DivLowestI32.raz (history) added +14 -0

@@ -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.

test/run/DivLowestI32.status (history) added +1 -0

@@ -0,0 +1 @@
1+136

test/run/DivLowestI32.stderr (history) added +1 -0

@@ -0,0 +1 @@
1+test/run/DivLowestI32.raz:11:5: stopped by a division fault

test/run/DivLowestI8.expect (history) added +1 -0

@@ -0,0 +1 @@
1+64
\ No newline at end of file

test/run/DivLowestI8.raz (history) added +16 -0

@@ -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.

test/run/DivLowestI8.status (history) added +1 -0

@@ -0,0 +1 @@
1+136

test/run/DivLowestI8.stderr (history) added +1 -0

@@ -0,0 +1 @@
1+test/run/DivLowestI8.raz:13:5: stopped by a division fault

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

@@ -1,8 +1,8 @@
11 module DivZero;
22 (* Dividing by zero stops the program with SIGFPE, after saying where *)
33
4-proc main*: I64;
5-var a, b: I64;
4+proc main*: INT;
5+var a, b: INT;
66 begin
77 a := 7;
88 b := ARGC() - 1;

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

@@ -31,7 +31,7 @@
3131 end;
3232
3333 proc sumInner(xs: []Inner): I64;
34-var i, j, s: I64;
34+var i, j: INT; s: I64;
3535 begin
3636 s := 0;
3737 for i := 0 to LEN(xs) - 1 do

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

@@ -1,9 +1,9 @@
11 module NilProc;
22 (* Calling a nil procedure: the place is the call's *)
33
4-var f: proc(n: I64): I64;
4+var f: proc(n: INT): INT;
55
6-proc main*: I64;
6+proc main*: INT;
77 begin
88 return f(1)
99 + 1;

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

@@ -11,7 +11,7 @@
1111
1212 var
1313 m: Thread.Mutex;
14- count, atomic: I64;
14+ count: I64; atomic: INT;
1515
1616 proc work(arg: ^U8);
1717 var i: I64; p, list: ^Node;

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

@@ -4,14 +4,14 @@
44 zeroes it from the bottom: with a small one, where the stack starts
55 could put the guard page under the body's pushes instead. *)
66
7-proc down(n: I64): I64;
8-var pad: [65536]I64;
7+proc down(n: INT): INT;
8+var pad: [65536]INT;
99 begin
1010 pad[n mod 65536] := n;
1111 return down(n + 1) + pad[0];
1212 end;
1313
14-proc main*: I64;
14+proc main*: INT;
1515 begin
1616 return down(0);
1717 end;

test/run/mods/Unchecked.raz (history) added +17 -0

@@ -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.

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

@@ -15,7 +15,7 @@
1515 var
1616 sc: Scan.Scanner; (* the text being read, at the current symbol *)
1717 src: []U8;
18- docStart, docEnd: I64; (* the comment just before it, or -1 *)
18+ docStart, docEnd: INT; (* the comment just before it, or -1 *)
1919
2020 (* On to the next symbol that isn't a comment, keeping where the last
2121 comment that starts a line was: one after code on its line belongs
@@ -53,8 +53,8 @@
5353
5454 (* On to the ; that ends what starts here, past anything bracketed and
5555 any record or variant; returns where it ends. *)
56-proc toSemicolon: I64;
57-var depth: I64;
56+proc toSemicolon: INT;
57+var depth: INT;
5858 begin
5959 depth := 0;
6060 while sc.kind # Scan.eof do
@@ -68,7 +68,7 @@
6868 end;
6969
7070 (* 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;
7272 var t: Scan.Scanner;
7373 begin
7474 while (stop < LEN(src)) and ((src[stop] = ' ') or (src[stop] = 9)) do INC(stop); end;
@@ -80,7 +80,7 @@
8080 end;
8181
8282 (* Where the line holding p starts. *)
83-proc lineStart(p: I64): I64;
83+proc lineStart(p: INT): INT;
8484 begin
8585 while (p > 0) and (src[p - 1] # 10) do DEC(p); end;
8686 return p;
@@ -88,8 +88,8 @@
8888
8989 (* src[start..stop] as written, each line after the first moved left as
9090 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;
9393 begin
9494 col := start - lineStart(start);
9595 i := start;
@@ -106,8 +106,8 @@
106106
107107 (* The comment from start to stop, without its brackets, each line
108108 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;
111111 begin
112112 if start < 0 then return; end;
113113 i := start + 2;
@@ -128,7 +128,7 @@
128128 end;
129129
130130 (* 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);
132132 begin
133133 if not exported then return; end;
134134 Out.ln;
@@ -149,7 +149,7 @@
149149 (* A procedure's body: to the end that closes its begin, the procedure
150150 name after it and its ;. *)
151151 proc skipBody;
152-var depth: I64; sawBegin: BOOL;
152+var depth: INT; sawBegin: BOOL;
153153 begin
154154 depth := 0;
155155 sawBegin := false;
@@ -172,7 +172,7 @@
172172 end;
173173
174174 proc procedure;
175-var start, ds, de, stop: I64; exp: BOOL;
175+var start, ds, de, stop: INT; exp: BOOL;
176176 begin
177177 start := sc.start; ds := docStart; de := docEnd;
178178 exp := name();
@@ -186,7 +186,7 @@
186186 end;
187187
188188 proc section;
189-var word: []U8; start, ds, de, stop: I64; exp: BOOL;
189+var word: []U8; start, ds, de, stop: INT; exp: BOOL;
190190 begin
191191 word := text();
192192 next;
@@ -206,7 +206,7 @@
206206 end;
207207
208208 proc external;
209-var start, ds, de, stop: I64; exp: BOOL;
209+var start, ds, de, stop: INT; exp: BOOL;
210210 begin
211211 start := sc.start; ds := docStart; de := docEnd;
212212 next;
@@ -217,7 +217,7 @@
217217 end;
218218
219219 proc document(path: []U8);
220-var b: Buf.Buf; start, ds, de: I64;
220+var b: Buf.Buf; start, ds, de: INT;
221221 begin
222222 Buf.init(ADR(b), Heap.heap);
223223 if not Files.read(path, ADR(b)) then Rt.stop("Doc: can't read the file"); end;
@@ -243,7 +243,7 @@
243243
244244 (* line, without the spaces at its ends *)
245245 proc trim(line: []U8): []U8;
246-var i, j: I64;
246+var i, j: INT;
247247 begin
248248 i := 0;
249249 j := LEN(line);
@@ -255,7 +255,7 @@
255255 (* The report's examples that are whole modules, each to dir. *)
256256 proc examples(path, dir: []U8);
257257 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;
259259 inBlock, whole: BOOL;
260260 begin
261261 Buf.init(ADR(b), Heap.heap);

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

@@ -14,17 +14,17 @@
1414 state: U64; (* the generator: xorshift64 *)
1515
1616 (* A number from the generator, below n. *)
17-proc random(n: I64): I64;
17+proc random(n: INT): INT;
1818 begin
1919 state := state xor (state shl 13);
2020 state := state xor (state shr 7);
2121 state := state xor (state shl 17);
22- return I64(state mod U64(n));
22+ return INT(state mod U64(n));
2323 end;
2424
2525 (* The seed, as a nonzero state. *)
2626 proc seed(s: []U8);
27-var i: I64;
27+var i: INT;
2828 begin
2929 state := 88172645463325252;
3030 for i := 0 to LEN(s) - 1 do state := state * 31 + U64(s[i]); end;
@@ -33,8 +33,8 @@
3333 end;
3434
3535 (* 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;
3838 begin
3939 Scan.init(ADR(sc), src);
4040 Scan.next(ADR(sc));
@@ -47,7 +47,7 @@
4747 end;
4848
4949 (* Symbol k, counting from 0 and leaving out comments. *)
50-proc symbol(k: I64): Scan.Scanner;
50+proc symbol(k: INT): Scan.Scanner;
5151 var sc: Scan.Scanner;
5252 begin
5353 Scan.init(ADR(sc), src);
@@ -59,7 +59,7 @@
5959 end;
6060
6161 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;
6363 begin
6464 if ARGC() # 3 then Rt.stop("usage: Mutate File.raz seed"); end;
6565 Buf.init(ADR(buf), Heap.heap);

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

@@ -34,25 +34,25 @@
3434 sc: Scan.Scanner; (* the source, at the symbol being written *)
3535 src: []U8;
3636 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 *)
3939
4040 (* the blocks open, each with the indent of the statement that
4141 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 *)
4545 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 *)
4848
4949 (* the last symbol that wasn't a comment, and the one before it *)
5050 prev, prev2: Scan.Scanner;
5151 prevBinary, prevUnary: BOOL;
5252 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 *)
5454
55-proc spaces(n: I64);
55+proc spaces(n: INT);
5656 begin
5757 while n > 0 do Buf.add(ADR(out), ' '); DEC(n); end;
5858 end;
@@ -75,15 +75,15 @@
7575 end;
7676
7777 (* Where the line holding p starts in src. *)
78-proc lineStart(p: I64): I64;
78+proc lineStart(p: INT): INT;
7979 begin
8080 while (p > 0) and (src[p - 1] # '\n') do DEC(p); end;
8181 return p;
8282 end;
8383
8484 (* 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;
8787 begin
8888 col := 0;
8989 for i := lineStart(p) to p - 1 do
@@ -153,21 +153,21 @@
153153 end;
154154
155155 (* The indent of the block's own lines, or of its end. *)
156-proc inner: I64;
156+proc inner: INT;
157157 begin
158158 if depth > 0 then return bases[depth - 1] + width; end;
159159 if inSection then return width; end;
160160 return 0;
161161 end;
162162
163-proc outer: I64;
163+proc outer: INT;
164164 begin
165165 if depth > 0 then return bases[depth - 1]; end;
166166 return 0;
167167 end;
168168
169169 (* 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;
171171 var n: Scan.Scanner;
172172 begin
173173 if continues() then
@@ -192,7 +192,7 @@
192192
193193 (* Starts the line of the current symbol, at its indent. *)
194194 proc startLine;
195-var old, new: I64;
195+var old, new: INT;
196196 begin
197197 old := column(sc.start);
198198 new := indent(old);
@@ -207,7 +207,7 @@
207207 (* The spaces between the last symbol written and the current one, on
208208 the same line. *)
209209 proc gap(binaryNow: BOOL);
210-var n: I64;
210+var n: INT;
211211 begin
212212 if sc.kind = Scan.comment then
213213 n := column(sc.start) + lineDelta - (out.len - lineAt);
@@ -226,7 +226,7 @@
226226 (* The current symbol as written; each line of a comment after its
227227 first is moved as far as the line the comment starts on. *)
228228 proc write;
229-var i, k: I64;
229+var i, k: INT;
230230 begin
231231 i := sc.start;
232232 while i < sc.stop do
@@ -270,8 +270,8 @@
270270 end;
271271
272272 (* 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;
275275 begin
276276 for i := from to upto - 1 do
277277 if src[i] = '\n' then newLine; end;
@@ -317,7 +317,7 @@
317317 end;
318318
319319 proc main*;
320-var b: Buf.Buf; i: I64; path: []U8;
320+var b: Buf.Buf; i: INT; path: []U8;
321321 begin
322322 Buf.init(ADR(b), Heap.heap);
323323 Buf.init(ADR(out), Heap.heap);

tools/Scan.raz (history) modified +9 -9

@@ -13,9 +13,9 @@
1313 character; symbol an operator or delimiter. *)
1414 Scanner* = record
1515 src*: []U8;
16- pos*: I64; (* where the next symbol is looked for *)
16+ pos*: INT; (* where the next symbol is looked for *)
1717 kind*: Kind; (* the current symbol *)
18- start*, stop*: I64; (* its text: src[start..stop] *)
18+ start*, stop*: INT; (* its text: src[start..stop] *)
1919 lineBreak*: BOOL; (* a line break comes before it, or it is the first *)
2020 end;
2121
@@ -41,7 +41,7 @@
4141 (* Whether w is one of the words of list, which are separated by
4242 single spaces. *)
4343 proc among*(w, list: []U8): BOOL;
44-var i, j: I64;
44+var i, j: INT;
4545 begin
4646 i := 0;
4747 while i < LEN(list) do
@@ -66,8 +66,8 @@
6666 end;
6767
6868 (* 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;
7171 begin
7272 depth := 0;
7373 repeat
@@ -84,7 +84,7 @@
8484
8585 (* Past the number that starts at p: digits and letters, then a real's
8686 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;
8888 begin
8989 while (p < LEN(src)) and isWord(src[p]) do INC(p); end;
9090 if (p + 1 < LEN(src)) and (src[p] = '.') and isDigit(src[p + 1]) then
@@ -99,7 +99,7 @@
9999 end;
100100
101101 (* 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;
103103 var q: U8;
104104 begin
105105 q := src[p];
@@ -113,14 +113,14 @@
113113 end;
114114
115115 (* 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;
117117 begin
118118 return (p + LEN(t) <= LEN(src)) and (src[p..p + LEN(t)] = t);
119119 end;
120120
121121 (* On to the next symbol. *)
122122 proc next*(s: ^Scanner);
123-var src: []U8; p: I64; c: U8;
123+var src: []U8; p: INT; c: U8;
124124 begin
125125 src := s^.src;
126126 p := s^.pos;