raz / commit e0d008cd

commit
e0d008cd1d5e034744ab44d8b92198bc8d5c80f8
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
81cb2aee
lib/ held to report 2026-10.37 whole: import SYSTEM, []const, atomics on a variable

Every module that reaches memory other than through a variable imports
SYSTEM (CAbi too, from tools/cabi.c), its ADR, PTR and SYSCALL written
SYSTEM.; atomics take the variable; a slice only read is a []const,
Str.trim, cut and field return one, and so do Sys's environment, links
and names and Files.arg, which the caller mustn't write. Opt's rows are
taken by const. Each module compiles under raz -strict -Werror. Callers
in src/, tools/, examples/ and the tests mended to build as before;
their own move to -strict comes next.

patch · log

66 files changed, +1193 -1170

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

@@ -1,5 +1,5 @@
11 module FirstUse;
2-import Out, Str, Table := Table([]U8, Colour, Str.hash, Str.eq),
2+import Out, Str, Table := Table([]const U8, Colour, Str.hash, Str.eq),
33 Ints := Pile(I64), More := Pile(I64), Never := Loud(I64), Ones := Loud(U8);
44
55 type Colour = (red, green, blue);

doc/raz-lib.md (history) modified +122 -116

@@ -11,6 +11,12 @@
1111 beside the new; the release notes list the old forms, and the next
1212 version removes them. Nothing marks an old form in the source.
1313
14+A procedure that only reads a slice takes a `[]const T`, so that a string,
15+a constant and any other slice fit it; what a procedure hands back from
16+the environment, the arguments or a directory is a `[]const U8`. A
17+module that reaches memory, as the library's lower modules do, says
18+`import SYSTEM` (section 3 of the first volume).
19+
1420 Modules written in raz, in the compiler's `lib` directory:
1521
1622 | Module | What |
@@ -26,7 +32,7 @@
2632 | `Mem` | `Allocator`, the interface of every allocator, and pages from the system |
2733 | `Heap` | a general allocator, `Heap.heap`, safe to call from several threads; freeing a block twice, or one it never gave out, stops the program; `RAZ_HEAP=debug` finds writes past a block's end and after free |
2834 | `Arena` | an allocator that frees everything at once; `ADR(arena.base)` is its allocator |
29-| `Str` | operations on `[]U8` strings: comparing, hashing, finding, trimming and cutting, case, joining and replacing, UTF-8, numbers to and from text |
35+| `Str` | operations on strings, `[]const U8`: comparing, hashing, finding, trimming and cutting, case, joining and replacing, UTF-8, numbers to and from text |
3036 | `Bytes` | searches of bytes, many at a time: `index`, `last`, `count` and `find` in a `[]U8`; one file per target where the target has instructions for it |
3137 | `Buf` | a growable byte buffer |
3238 | `Fmt` | formatted output: `Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)])`, into a `Buf` with `Fmt.write`, or to standard error with `Fmt.eprint` |
@@ -58,7 +64,7 @@
5864 proc atExit*(p: proc): ERROR; (* p run when the program ends by exit *)
5965 proc exit*(status: INT); (* the atExit procedures, the last first, then the end *)
6066 proc exitStatus*: INT; (* the status exit was given, in an atExit procedure; 0 before *)
61-proc stop*(msg: []U8); (* msg, and a line feed, on standard error, then exit with status 2 *)
67+proc stop*(msg: []const U8); (* msg, and a line feed, on standard error, then exit with status 2 *)
6268 proc trace*; (* the calls under way, and their variables, on standard error *)
6369 ```
6470
@@ -182,7 +188,7 @@
182188
183189 ```
184190 module Out;
185-proc str*(s: []U8);
191+proc str*(s: []const U8);
186192 proc char*(c: U8);
187193 proc ln*; (* a line feed *)
188194 proc int*(n: I64); (* n in decimal *)
@@ -276,11 +282,11 @@
276282 Kind* = (unknown, isFile, isDir, isLink, isOther); (* what a directory says a name in it is *)
277283 Dir* = record ... end; (* an open directory; its fields are the target's *)
278284 Program* = record
279- path*: []U8;
280- args*: [][]U8; (* the first is its name *)
281- env*: [][]U8; (* NAME=value, each added to this program's environment *)
285+ path*: []const U8;
286+ args*: [][]const U8; (* the first is its name *)
287+ env*: [][]const U8; (* NAME=value, each added to this program's environment *)
282288 onlyEnv*: BOOL; (* env is its whole environment *)
283- dir*: []U8; (* its working directory; "" for this program's *)
289+ dir*: []const U8; (* its working directory; "" for this program's *)
284290 fds*: [3]INT; (* its standard input, output and error; 0 for this program's own *)
285291 group*: INT; (* the process group it joins: 0 for this program's, -1 a new one it leads *)
286292 foreground*: BOOL; (* its group takes the terminal on standard input *)
@@ -304,12 +310,12 @@
304310 ready*: BOOL; (* set by poll *)
305311 end;
306312
307-proc write*(fd: INT; s: []U8): INT; (* the bytes written *)
313+proc write*(fd: INT; s: []const U8): INT; (* the bytes written *)
308314 proc read*(fd: INT; buf: []U8): INT; (* the bytes read; 0 at the end *)
309-proc open*(path: []U8; how: Accesses): INT; (* its fd, closed on exec *)
310-proc openMode*(path: []U8; how: Accesses; mode: INT): INT; (* open, a file it makes given mode *)
311-proc openRead*(path: []U8): INT; (* open(path, {reading}) *)
312-proc create*(path: []U8): INT; (* open(path, {writing, creating, truncating}) *)
315+proc open*(path: []const U8; how: Accesses): INT; (* its fd, closed on exec *)
316+proc openMode*(path: []const U8; how: Accesses; mode: INT): INT; (* open, a file it makes given mode *)
317+proc openRead*(path: []const U8): INT; (* open(path, {reading}) *)
318+proc create*(path: []const U8): INT; (* open(path, {writing, creating, truncating}) *)
313319 proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *)
314320 proc position*(fd: INT): I64; (* where the next read or write is *)
315321 proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *)
@@ -331,26 +337,26 @@
331337 proc yield*; (* the processor given to another thread *)
332338 proc exit*(status: INT); (* the program ended at once, without Rt's atExit *)
333339
334-proc rename*(old, new: []U8): INT; (* replaces what new names *)
335-proc remove*(path: []U8): INT; (* a file, not a directory *)
336-proc removeDir*(path: []U8): INT; (* an empty directory *)
337-proc makeDir*(path: []U8): INT; (* readable by all, writable by its owner *)
338-proc makeDirMode*(path: []U8; mode: INT): INT; (* makeDir, given mode *)
339-proc chmod*(path: []U8; mode: INT): INT;
340-proc chown*(path: []U8; uid, gid: INT): INT; (* its owner and group; -1 leaves one as it is *)
341-proc makeFifo*(path: []U8; mode: INT): INT; (* a named pipe, given mode *)
342-proc setTime*(path: []U8; sec: I64; nsec: INT): INT; (* its mtime, and the time it was read, made sec and nsec *)
343-proc access*(path: []U8; how: Accesses): INT; (* 0 if this user may read, write or execute it *)
340+proc rename*(old, new: []const U8): INT; (* replaces what new names *)
341+proc remove*(path: []const U8): INT; (* a file, not a directory *)
342+proc removeDir*(path: []const U8): INT; (* an empty directory *)
343+proc makeDir*(path: []const U8): INT; (* readable by all, writable by its owner *)
344+proc makeDirMode*(path: []const U8; mode: INT): INT; (* makeDir, given mode *)
345+proc chmod*(path: []const U8; mode: INT): INT;
346+proc chown*(path: []const U8; uid, gid: INT): INT; (* its owner and group; -1 leaves one as it is *)
347+proc makeFifo*(path: []const U8; mode: INT): INT; (* a named pipe, given mode *)
348+proc setTime*(path: []const U8; sec: I64; nsec: INT): INT; (* its mtime, and the time it was read, made sec and nsec *)
349+proc access*(path: []const U8; how: Accesses): INT; (* 0 if this user may read, write or execute it *)
344350 proc umask*(mask: INT): INT; (* the bits taken from every file made; the mask it was *)
345-proc symlink*(target, path: []U8): INT; (* path made a link to target *)
346-proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *)
347-proc info*(path: []U8): (Info, INT); (* following a symbolic link *)
348-proc linkInfo*(path: []U8): (Info, INT); (* the link itself *)
351+proc symlink*(target, path: []const U8): INT; (* path made a link to target *)
352+proc readLink*(path: []const U8): ([]const U8, INT); (* what the link names, good until the next call *)
353+proc info*(path: []const U8): (Info, INT); (* following a symbolic link *)
354+proc linkInfo*(path: []const U8): (Info, INT); (* the link itself *)
349355 proc infoOf*(fd: INT): (Info, INT); (* the open file's *)
350-proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *)
356+proc space*(path: []const U8): (I64, I64, INT); (* the bytes free and in all on path's file system *)
351357
352-proc openDir*(var d: Dir; path: []U8): INT;
353-proc nextEntry*(var d: Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *)
358+proc openDir*(var d: Dir; path: []const U8): INT;
359+proc nextEntry*(var d: Dir): ([]const U8, BOOL); (* a name, good until the next call; false at the end *)
354360 proc entryKind*(const d: Dir): Kind; (* what the name nextEntry gave last is *)
355361 proc closeDir*(var d: Dir);
356362
@@ -360,27 +366,27 @@
360366 proc setMode*(fd: INT; m: Mode): INT; (* once what was written to it is sent *)
361367 proc termSize*(fd: INT): (INT, INT); (* columns and rows; 80 and 24 if unknown *)
362368 proc ready*(fd, ms: INT): BOOL; (* something to read within ms, or ever if ms < 0 *)
363-proc readyOf*(fds: []INT; ms: INT): INT; (* the first of fds with something to read within ms, or -1 *)
364-proc readyFor*(reads, writes: []INT; ms: INT): INT; (* readyOf, and the first of writes with room to write *)
369+proc readyOf*(fds: []const INT; ms: INT): INT; (* the first of fds with something to read within ms, or -1 *)
370+proc readyFor*(reads, writes: []const INT; ms: INT): INT; (* readyOf, and the first of writes with room to write *)
365371 proc poll*(var fds: []Poll; ms: INT): INT; (* sets each fd's ready, as each read and write say; the number ready, 0 on a timeout, or minus an errno *)
366372 proc setBlocking*(fd: INT; yes: BOOL): INT; (* if not yes, a read or write that would wait is -11 at once *)
367373 proc blocking*(fd: INT): INT; (* 1 if reads and writes wait, 0 if they are -11 at once, or minus an errno *)
368374
369-proc errorText*(err: INT): []U8; (* what errno err, or minus it, means, as C's strerror says *)
375+proc errorText*(err: INT): []const U8; (* what errno err, or minus it, means, as C's strerror says *)
370376
371-proc env*(name: []U8): []U8; (* the environment variable's value; "" if unset *)
372-proc findEnv*(name: []U8): ([]U8, BOOL); (* the value and true; "" and false if unset, "" and true if empty *)
373-proc envAt*(i: INT): ([]U8, BOOL); (* the environment's ith NAME=value, from 0; false past the last *)
374-proc setEnv*(name, value: []U8): INT; (* name set to value, for env and the programs started *)
375-proc workDir*: ([]U8, INT); (* the working directory, good until the next call *)
376-proc setWorkDir*(path: []U8): INT;
377+proc env*(name: []const U8): []const U8; (* the environment variable's value; "" if unset *)
378+proc findEnv*(name: []const U8): ([]const U8, BOOL); (* the value and true; "" and false if unset, "" and true if empty *)
379+proc envAt*(i: INT): ([]const U8, BOOL); (* the environment's ith NAME=value, from 0; false past the last *)
380+proc setEnv*(name, value: []const U8): INT; (* name set to value, for env and the programs started *)
381+proc workDir*: ([]const U8, INT); (* the working directory, good until the next call *)
382+proc setWorkDir*(path: []const U8): INT;
377383
378384 proc pipe*: (INT, INT); (* the fd to read and the fd to write; or minus an errno and -1 *)
379385 proc openPty*: INT; (* a pseudo-terminal: the fd of its controlling side *)
380386 proc setTermSize*(fd, cols, rows: INT): INT; (* the size its programs are told of *)
381387 proc spawn*(p: Program): INT; (* a program started: its process id *)
382388 proc exec*(p: Program): INT; (* p run in this program's place; returns only if it can't *)
383-proc execve*(path: []U8; args, env: [][]U8): INT; (* as the kernel's execve: no search *)
389+proc execve*(path: []const U8; args, env: [][]const U8): INT; (* as the kernel's execve: no search *)
384390 proc fork*: INT; (* this program copied: 0 in the copy, its process id in this one *)
385391 proc setsid*: INT; (* a session of its own, led by this program: its process id, or minus an errno *)
386392 proc wait*(pid: INT; block: BOOL): (INT, Status, INT); (* which program, how, and its code *)
@@ -393,13 +399,13 @@
393399 proc foregroundOf*(fd: INT): INT; (* the group the terminal on fd gives its keys to *)
394400 proc uid*: INT; (* the user this program runs as *)
395401 proc euid*: INT; (* the user whose rights it has: 0 is root *)
396-proc hostName*: ([]U8, INT); (* this machine's name, good until the next call *)
402+proc hostName*: ([]const U8, INT); (* this machine's name, good until the next call *)
397403 proc processors*: INT; (* the processors this program may run on, at least 1 *)
398404 proc cpuTime*(children: BOOL): (I64, I64); (* ns used in the program and in the system; or by its children *)
399405 proc limit*(which: INT): (I64, I64, INT); (* the soft limit and the hard; -1 for none *)
400406 proc setLimit*(which: INT; soft, hard: I64): INT;
401407
402-proc catch*(sigs: []INT): INT; (* sigs caught: an fd to wait on *)
408+proc catch*(sigs: []const INT): INT; (* sigs caught: an fd to wait on *)
403409 proc caught*(fd: INT): INT; (* the next signal caught, or 0 if none is waiting *)
404410 proc ignore*(sig: INT; yes: BOOL): INT; (* sig ignored; or, if not yes, back to what it does at first *)
405411 proc ignored*(sig: INT): BOOL; (* whether sig does nothing now *)
@@ -411,23 +417,23 @@
411417 proc sleep*(ms: INT);
412418 proc random*(b: []U8); (* b filled with random bytes; stops the program if it can't be *)
413419
414-proc connect*(path: []U8): INT; (* a stream socket, connected to the Unix socket at path: its fd *)
415-proc connectTcp*(addr: []U8; port: INT): INT; (* addr an IPv4 or IPv6 address, as numbers *)
416-proc connectUdp*(addr: []U8; port: INT): INT;
417-proc listen*(path: []U8): INT; (* a Unix socket made at path, taking connections *)
418-proc listenTcp*(addr: []U8; port: INT): INT;
420+proc connect*(path: []const U8): INT; (* a stream socket, connected to the Unix socket at path: its fd *)
421+proc connectTcp*(addr: []const U8; port: INT): INT; (* addr an IPv4 or IPv6 address, as numbers *)
422+proc connectUdp*(addr: []const U8; port: INT): INT;
423+proc listen*(path: []const U8): INT; (* a Unix socket made at path, taking connections *)
424+proc listenTcp*(addr: []const U8; port: INT): INT;
419425 proc accept*(fd: INT): INT; (* the next connection, waiting for one *)
420-proc send*(fd: INT; s: []U8): INT; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *)
421-proc sendNow*(fd: INT; s: []U8): INT; (* send, but -11 (EAGAIN) where it would wait *)
422-proc connectTcpWithin*(addr: []U8; port, ms: INT): INT; (* connectTcp, or -110 (ETIMEDOUT) after ms *)
423-proc listenUdp*(addr: []U8; port: INT): INT; (* a socket of datagrams on port at addr *)
426+proc send*(fd: INT; s: []const U8): INT; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *)
427+proc sendNow*(fd: INT; s: []const U8): INT; (* send, but -11 (EAGAIN) where it would wait *)
428+proc connectTcpWithin*(addr: []const U8; port, ms: INT): INT; (* connectTcp, or -110 (ETIMEDOUT) after ms *)
429+proc listenUdp*(addr: []const U8; port: INT): INT; (* a socket of datagrams on port at addr *)
424430 proc receive*(fd: INT; buf: []U8): (INT, Peer); (* the next datagram, in buf, and who sent it *)
425-proc reply*(fd: INT; peer: Peer; s: []U8): INT; (* s, as one datagram, to peer *)
431+proc reply*(fd: INT; peer: Peer; s: []const U8): INT; (* s, as one datagram, to peer *)
426432 proc localPort*(fd: INT): INT; (* the port the socket fd is bound to *)
427433 proc closeWrite*(fd: INT): INT; (* no more writing to the socket fd; the other end reads an end *)
428434 proc peer*(fd: INT): (Remote, INT); (* who is at the other end of the connected socket fd *)
429435 proc socketPair*: (INT, INT, INT); (* two connected stream sockets, and 0 *)
430-proc sendFds*(fd: INT; s: []U8; fds: []INT): INT; (* send, and with it fds, to a Unix socket *)
436+proc sendFds*(fd: INT; s: []const U8; fds: []const INT): INT; (* send, and with it fds, to a Unix socket *)
431437 proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); (* read, and the fds that came with it *)
432438
433439 proc memFile*(size: INT): INT; (* a file of size zero bytes, in memory, with no name: its fd *)
@@ -787,22 +793,22 @@
787793
788794 ```
789795 module Str;
790-proc cmp*(a, b: []U8): INT; (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *)
791-proc eq*(a, b: []U8): BOOL;
792-proc eqFold*(a, b: []U8): BOOL; (* eq, an ASCII letter's capital and small the same *)
793-proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL); (* s's bytes in memory from a; false if a has none *)
796+proc cmp*(a, b: []const U8): INT; (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *)
797+proc eq*(a, b: []const U8): BOOL;
798+proc eqFold*(a, b: []const U8): BOOL; (* eq, an ASCII letter's capital and small the same *)
799+proc copy*(a: ^Mem.Allocator; s: []const U8): ([]U8, BOOL); (* s's bytes in memory from a; false if a has none *)
794800 proc free*(a: ^Mem.Allocator; s: []U8); (* what copy gave from a, given back; "" is none *)
795-proc hash*(s: []U8): U64; (* FNV-1a, 64 bits *)
796-proc find*(s, sub: []U8): INT; (* where sub first starts in s, or -1 *)
797-proc findFrom*(s, sub: []U8; from: INT): INT; (* where sub first starts in s at or after from, or -1 *)
798-proc findLast*(s, sub: []U8): INT; (* where sub last starts in s, or -1 *)
799-proc hasPrefix*(s, p: []U8): BOOL;
800-proc hasSuffix*(s, x: []U8): BOOL;
801-proc trim*(s: []U8): []U8; (* s without the spaces at either end *)
802-proc trimLeft*(s: []U8): []U8; (* s without the spaces at its start *)
803-proc trimRight*(s: []U8): []U8; (* s without the spaces at its end *)
804-proc cut*(s, sep: []U8): ([]U8, []U8, BOOL); (* what comes before the first sep, and after it *)
805-proc field*(s: []U8): ([]U8, []U8); (* the first run of bytes in s that aren't spaces, and what follows it *)
801+proc hash*(s: []const U8): U64; (* FNV-1a, 64 bits *)
802+proc find*(s, sub: []const U8): INT; (* where sub first starts in s, or -1 *)
803+proc findFrom*(s, sub: []const U8; from: INT): INT; (* where sub first starts in s at or after from, or -1 *)
804+proc findLast*(s, sub: []const U8): INT; (* where sub last starts in s, or -1 *)
805+proc hasPrefix*(s, p: []const U8): BOOL;
806+proc hasSuffix*(s, x: []const U8): BOOL;
807+proc trim*(s: []const U8): []const U8; (* s without the spaces at either end *)
808+proc trimLeft*(s: []const U8): []const U8; (* s without the spaces at its start *)
809+proc trimRight*(s: []const U8): []const U8; (* s without the spaces at its end *)
810+proc cut*(s, sep: []const U8): ([]const U8, []const U8, BOOL); (* what comes before the first sep, and after it *)
811+proc field*(s: []const U8): ([]const U8, []const U8); (* the first run of bytes in s that aren't spaces, and what follows it *)
806812 proc isDigit*(c: U8): BOOL; (* 0 to 9 *)
807813 proc isLetter*(c: U8): BOOL; (* A to Z, a to z *)
808814 proc isSpace*(c: U8): BOOL; (* a space, as trim takes it *)
@@ -810,28 +816,28 @@
810816 proc hexVal*(c: U8): INT; (* c's value as a hexadecimal digit, or -1 *)
811817 proc lower*(s: []U8); (* s's ASCII capitals made small, in place *)
812818 proc upper*(s: []U8); (* s's ASCII small letters made capitals, in place *)
813-proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
814-proc replace*(var b: Buf.Buf; s, old, new: []U8); (* s added to b, with new for each old in it *)
819+proc join*(var b: Buf.Buf; parts: [][]const U8; sep: []const U8); (* the parts added to b, sep between each two *)
820+proc replace*(var b: Buf.Buf; s, old, new: []const U8); (* s added to b, with new for each old in it *)
815821 proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *)
816-proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *)
817-proc decodeLast*(s: []U8): (I32, INT); (* the character s ends with, and its length in bytes *)
818-proc next*(s: []U8; i: INT): (I32, INT); (* the character at i, and where the next starts; -1 at the end *)
819-proc valid*(s: []U8): BOOL; (* s is UTF-8, every character rightly spelled *)
820-proc chars*(s: []U8): INT; (* the characters in s, as decode reads them *)
821-proc toInt*(s: []U8): (I64, BOOL); (* s, in decimal; false if it isn't a number an I64 holds *)
822-proc toHex*(s: []U8): (U64, BOOL); (* s, in hexadecimal; false if it isn't a number a U64 holds *)
823-proc toU64*(s: []U8): (U64, BOOL); (* s, decimal digits only; false if it isn't one, or a U64 can't hold it *)
824-proc fromC*(p: ^U8): []U8; (* the bytes at p up to its zero byte, not copied; "" for nil *)
825-proc toC*(s, out: []U8): ^U8; (* s copied into out with a zero byte after it, which holds LEN(s) + 1 bytes at least: PTR(out) *)
822+proc decode*(s: []const U8): (I32, INT); (* the character s starts with, and its length in bytes *)
823+proc decodeLast*(s: []const U8): (I32, INT); (* the character s ends with, and its length in bytes *)
824+proc next*(s: []const U8; i: INT): (I32, INT); (* the character at i, and where the next starts; -1 at the end *)
825+proc valid*(s: []const U8): BOOL; (* s is UTF-8, every character rightly spelled *)
826+proc chars*(s: []const U8): INT; (* the characters in s, as decode reads them *)
827+proc toInt*(s: []const U8): (I64, BOOL); (* s, in decimal; false if it isn't a number an I64 holds *)
828+proc toHex*(s: []const U8): (U64, BOOL); (* s, in hexadecimal; false if it isn't a number a U64 holds *)
829+proc toU64*(s: []const U8): (U64, BOOL); (* s, decimal digits only; false if it isn't one, or a U64 can't hold it *)
830+proc fromC*(p: ^U8): []const U8; (* the bytes at p up to its zero byte, not copied; "" for nil *)
831+proc toC*(s: []const U8; out: []U8): ^U8; (* s copied into out with a zero byte after it, which holds LEN(s) + 1 bytes at least: PTR(out) *)
826832 const Base64*, Base64Url*; (* the digits of RFC 4648, sections 4 and 5 *)
827-proc base64With*(s, out, alphabet: []U8; pad: BOOL): INT; (* s in base64 with alphabet's 64 digits into out, which holds base64Size(LEN(s)) bytes at least, padded with = if pad: the bytes written *)
828-proc unbase64With*(s, out, alphabet: []U8; pad: BOOL): (INT, BOOL); (* s, base64 as base64With wrote it, into out, which holds (LEN(s) + 3) div 4 * 3 bytes at least: the bytes written; false if s is not that *)
833+proc base64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): INT; (* s in base64 with alphabet's 64 digits into out, which holds base64Size(LEN(s)) bytes at least, padded with = if pad: the bytes written *)
834+proc unbase64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): (INT, BOOL); (* s, base64 as base64With wrote it, into out, which holds (LEN(s) + 3) div 4 * 3 bytes at least: the bytes written; false if s is not that *)
829835 proc base64Size*(n: INT): INT; (* the bytes base64 makes of n bytes: 4 for each 3, or part of 3 *)
830-proc base64*(s, out: []U8): INT; (* s in base64 into out, which holds base64Size(LEN(s)) bytes at least: the bytes written *)
831-proc unbase64*(s, out: []U8): (INT, BOOL); (* s, base64, into out, which holds LEN(s) div 4 * 3 bytes at least: the bytes written; false if s is not base64 *)
836+proc base64*(s: []const U8; out: []U8): INT; (* s in base64 into out, which holds base64Size(LEN(s)) bytes at least: the bytes written *)
837+proc unbase64*(s: []const U8; out: []U8): (INT, BOOL); (* s, base64, into out, which holds LEN(s) div 4 * 3 bytes at least: the bytes written; false if s is not base64 *)
832838 proc fromInt*(n: I64): ([20]U8, INT); (* n in decimal: its bytes, and how many *)
833-proc le*(s: []U8): U64; (* s, at most 8 bytes, the first the lowest *)
834-proc be*(s: []U8): U64; (* s, at most 8 bytes, the first the highest *)
839+proc le*(s: []const U8): U64; (* s, at most 8 bytes, the first the lowest *)
840+proc be*(s: []const U8): U64; (* s, at most 8 bytes, the first the highest *)
835841 proc putLE*(s: []U8; v: U64); (* v into s, the lowest byte first *)
836842 proc putBE*(s: []U8; v: U64); (* v into s, the highest byte first *)
837843
@@ -840,7 +846,7 @@
840846 proc init*(var b: Buf; a: ^Mem.Allocator);
841847 proc room*(var b: Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *)
842848 proc add*(var b: Buf; c: U8);
843-proc str*(var b: Buf; s: []U8);
849+proc str*(var b: Buf; s: []const U8);
844850 proc spare*(var b: Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
845851 proc bytes*(const b: Buf): []U8; (* what it holds, until it next grows *)
846852 proc cut*(var b: Buf; n: INT); (* only the first n bytes kept, its memory kept *)
@@ -853,17 +859,17 @@
853859 uint(u: U64);
854860 hex(h: U64);
855861 lowHex(h: U64);
856- str(s: []U8);
862+ str(s: []const U8);
857863 char(c: U8);
858864 bool(b: BOOL);
859865 real(r: F64; places: INT);
860866 end;
861867 const ShortMost* = 24; (* the longest Fmt.short *)
862868 proc short*(x: F64; var out: [ShortMost]U8): []U8; (* x in the fewest digits that read back, in out *)
863-proc print*(f: []U8; args: []Arg); (* to standard output *)
864-proc eprint*(f: []U8; args: []Arg); (* to standard error, once Out is flushed *)
865-proc write*(var b: Buf.Buf; f: []U8; args: []Arg); (* added to b *)
866-proc into*(out: []U8; f: []U8; args: []Arg): (INT, BOOL); (* into out: the bytes, and false if cut short *)
869+proc print*(f: []const U8; args: []const Arg); (* to standard output *)
870+proc eprint*(f: []const U8; args: []const Arg); (* to standard error, once Out is flushed *)
871+proc write*(var b: Buf.Buf; f: []const U8; args: []const Arg); (* added to b *)
872+proc into*(out: []U8; f: []const U8; args: []const Arg): (INT, BOOL); (* into out: the bytes, and false if cut short *)
867873
868874 module List(T);
869875 type
@@ -927,7 +933,7 @@
927933 proc fromBits*(u: U64): F64; (* the F64 whose bits are u *)
928934 proc mul*(a, b: U64): (U64, U64); (* a times b: the low 64 bits of the product, and the high *)
929935 proc divMod*(hi, lo, d: U64): (U64, U64); (* hi, lo divided by d: the quotient and the remainder; hi < d *)
930-proc toReal*(s: []U8): (F64, BOOL); (* s as a real, the F64 nearest it; false if it isn't one *)
936+proc toReal*(s: []const U8): (F64, BOOL); (* s as a real, the F64 nearest it; false if it isn't one *)
931937 ```
932938
933939 A `Buf`, a `List`, a `Map` and a `Vec` take their memory from the
@@ -946,7 +952,7 @@
946952 room; `room` asks first: `import Lines := Vec([]U8);`. `Fmt`'s format takes the next argument at each
947953 `{}`; `{{` and `}}` stand for `{` and `}`. A `Map` hashes and
948954 compares its keys with the procedures it is given:
949-`import Count := Map([]U8, INT, Str.hash, Str.eq);`.
955+`import Count := Map([]const U8, INT, Str.hash, Str.eq);`.
950956
951957 `Str` reads and writes UTF-8. `encode` writes a character, of at most
952958 10FFFFH, in one to four bytes; a number that isn't one becomes FFFDH,
@@ -1101,37 +1107,37 @@
11011107
11021108 ```
11031109 module Files;
1104-proc arg*(i: INT): []U8; (* argument i; 0 is the program's name; "" if there is none *)
1105-proc read*(path: []U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
1106-proc load*(path: []U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
1107-proc write*(path, data: []U8): BOOL; (* the file made to hold data; false if it or its close failed *)
1108-proc writeAll*(fd: INT; s: []U8): INT; (* all of s written to fd; 0, or minus the errno *)
1109-proc realPath*(path: []U8; var b: Buf.Buf): INT; (* the absolute path of path, plain, added to b; 0, or minus an errno *)
1110-proc removeTree*(path: []U8): INT; (* the file, or the directory and all in it, removed; 0, or minus the first errno *)
1110+proc arg*(i: INT): []const U8; (* argument i; 0 is the program's name; "" if there is none *)
1111+proc read*(path: []const U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
1112+proc load*(path: []const U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
1113+proc write*(path, data: []const U8): BOOL; (* the file made to hold data; false if it or its close failed *)
1114+proc writeAll*(fd: INT; s: []const U8): INT; (* all of s written to fd; 0, or minus the errno *)
1115+proc realPath*(path: []const U8; var b: Buf.Buf): INT; (* the absolute path of path, plain, added to b; 0, or minus an errno *)
1116+proc removeTree*(path: []const U8): INT; (* the file, or the directory and all in it, removed; 0, or minus the first errno *)
11111117
11121118 module Opt;
11131119 type
11141120 Row* = variant
1115- usage(scope, line: []U8); (* a synopsis line, without "usage: " *)
1116- sub(scope, name, help: []U8); (* a subcommand *)
1117- option(scope: []U8; letter: U8; long, value, help: []U8);
1121+ usage(scope, line: []const U8); (* a synopsis line, without "usage: " *)
1122+ sub(scope, name, help: []const U8); (* a subcommand *)
1123+ option(scope: []const U8; letter: U8; long, value, help: []const U8);
11181124 end;
11191125 Parser* = record
11201126 letter*: U8; (* the option just read *)
1121- value*: []U8; (* its value; "" for a flag *)
1127+ value*: []const U8; (* its value; "" for a flag *)
11221128 long*: BOOL; (* it was written by its long name *)
1123- spelt*: []U8; (* as it was written, no dashes: "b" or "bar"; to read only *)
1129+ spelt*: []const U8; (* as it was written, no dashes: "b" or "bar"; to read only *)
11241130 ...
11251131 end;
1126-proc init*(var p: Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *)
1132+proc init*(var p: Parser; name: []const U8; table: []const Row); (* the arguments from 1 on, by table *)
11271133 proc next*(var p: Parser): BOOL; (* the next option; false when they end *)
1128-proc operand*(var p: Parser): ([]U8, BOOL); (* the next operand; false when there are no more *)
1134+proc operand*(var p: Parser): ([]const U8, BOOL); (* the next operand; false when there are no more *)
11291135 proc at*(var p: Parser): INT; (* the argument operand would give next *)
1130-proc scope*(var p: Parser; name: []U8); (* subcommand name's options, from the word after it *)
1136+proc scope*(var p: Parser; name: []const U8); (* subcommand name's options, from the word after it *)
11311137 proc number*(const p: Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
1132-proc refuse*(const p: Parser; wants: []U8); (* the value just read refused, as number refuses one *)
1133-proc fail*(const p: Parser; text: []U8); (* the program's own mistake *)
1134-proc misuse*(const p: Parser; text: []U8); (* the program's own mistake, with the synopsis *)
1138+proc refuse*(const p: Parser; wants: []const U8); (* the value just read refused, as number refuses one *)
1139+proc fail*(const p: Parser; text: []const U8); (* the program's own mistake *)
1140+proc misuse*(const p: Parser; text: []const U8); (* the program's own mistake, with the synopsis *)
11351141 ```
11361142
11371143 `Opt` reads a command line by the rules of the C library's `getopt`,
@@ -1268,7 +1274,7 @@
12681274 ```
12691275 module Width;
12701276 proc width*(c: I32): INT; (* the columns the character c takes: 0, 1 or 2 *)
1271-proc columns*(s: []U8): INT; (* the columns the UTF-8 text s takes *)
1277+proc columns*(s: []const U8): INT; (* the columns the UTF-8 text s takes *)
12721278 ```
12731279
12741280 A combining mark, a format character, a control and Hangul's medial
@@ -1336,9 +1342,9 @@
13361342
13371343 ```
13381344 module Check;
1339-proc ok*(cond: BOOL; what: []U8); (* fails, saying what, when cond is false *)
1340-proc str*(what, got, want: []U8); (* fails when got is not want; shows both, escaped, and the byte where they differ *)
1341-proc int*(what: []U8; got, want: I64); (* fails when got is not want; shows both *)
1345+proc ok*(cond: BOOL; what: []const U8); (* fails, saying what, when cond is false *)
1346+proc str*(what, got, want: []const U8); (* fails when got is not want; shows both, escaped, and the byte where they differ *)
1347+proc int*(what: []const U8; got, want: I64); (* fails when got is not want; shows both *)
13421348 proc mute*(on: BOOL); (* while on, checks say nothing and are not counted *)
13431349 proc mutedFailures*(): INT; (* how many failed since mute was turned on *)
13441350 ```
@@ -1384,7 +1390,7 @@
13841390 proc pick*(var s: Source; n: INT): INT; (* 0 to n - 1; n at least 1 *)
13851391 proc bool*(var s: Source): BOOL;
13861392 proc bytes*(var s: Source; max: INT; var b: Buf.Buf); (* b, emptied, then given at most max bytes *)
1387-proc check*(name: []U8; p: Property); (* runs p on the saved cases, then on fresh ones *)
1393+proc check*(name: []const U8; p: Property); (* runs p on the saved cases, then on fresh ones *)
13881394 ```
13891395
13901396 `check` runs `p` on each case saved in the directory `$PROP_DIR/name`

doc/raz-tutorial.7 (history) modified +2 -2

@@ -384,7 +384,7 @@
384384 end;
385385
386386 proc main*;
387-var a: [5]INT; i: INT; s, val: []U8; name: [8]U8; ok: BOOL;
387+var a: [5]INT; i: INT; s, val: []const U8; name: [8]U8; ok: BOOL;
388388 begin
389389 for i := 0 to 4 do a[i] := i * i; end;
390390 Out.int(sum(a)); Out.ln; (* the array, as a slice *)
@@ -1224,7 +1224,7 @@
12241224 .Cm Sort
12251225 are generic modules:
12261226 .Bd -literal -offset indent
1227-import Count := Map([]U8, INT, Str.hash, Str.eq);
1227+import Count := Map([]const U8, INT, Str.hash, Str.eq);
12281228 .Ed
12291229 .Sh 14. TALKING TO C
12301230 .Bd -literal -offset indent

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

@@ -159,7 +159,7 @@
159159 .Cm "import Ints := List(INT);"
160160 makes an instance of a generic module, one for each distinct list of
161161 arguments, its procedure arguments named after its types:
162-.Cm "Map([]U8, INT, Str.hash, Str.eq)" .
162+.Cm "Map([]const U8, INT, Str.hash, Str.eq)" .
163163 .It
164164 A module's body runs once, after those of the modules it imports, and
165165 before the main module's

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

@@ -312,7 +312,7 @@
312312 scope there.
313313
314314 ```
315-import Table := Map([]U8, Colour, Str.hash, Str.eq);
315+import Table := Map([]const U8, Colour, Str.hash, Str.eq);
316316
317317 type Colour = (red, green, blue);
318318
@@ -327,7 +327,7 @@
327327 ```
328328
329329 ```
330-import Names := Map([]U8, I64, Str.hash, Str.eq);
330+import Names := Map([]const U8, I64, Str.hash, Str.eq);
331331 ```
332332
333333 A procedure argument names a procedure, not a variable or an

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

@@ -18,12 +18,12 @@
1818 `;
1919
2020 var
21- title: []U8;
21+ title: []const U8;
2222 width, height: I64;
2323 scale: F64;
2424
2525 (* One setting: false if the name isn't known, or its value is wrong. *)
26-proc setting(name, value: []U8): BOOL;
26+proc setting(name, value: []const U8): BOOL;
2727 var ok: BOOL; lower: [16]U8;
2828 begin
2929 if LEN(name) > LEN(lower) then return false; end;
@@ -41,7 +41,7 @@
4141 end;
4242
4343 proc main*;
44-var line, rest, name, value: []U8; more, found: BOOL; n: INT;
44+var line, rest, name, value: []const U8; more, found: BOOL; n: INT;
4545 begin
4646 rest := Text;
4747 more := true;

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

@@ -20,9 +20,9 @@
2020
2121 type
2222 Command = record
23- args: [maxWords][]U8;
23+ args: [maxWords][]const U8;
2424 n: INT;
25- input, output, errors: []U8; (* the files of <, > or >>, and 2>; "" for none *)
25+ input, output, errors: []const U8; (* the files of <, > or >>, and 2>; "" for none *)
2626 append: BOOL; (* output is >> *)
2727 end;
2828 Pipeline = record
@@ -39,12 +39,12 @@
3939 interactive: BOOL; (* commands come from a terminal: job control *)
4040 group: INT; (* the shell's process group *)
4141 arena: Arena.Arena; (* the words of what is being run *)
42- s: []U8; (* the script being read *)
42+ s: []const U8; (* the script being read *)
4343 at: INT; (* where in it *)
44- text: []U8; (* the last word read *)
44+ text: []const U8; (* the last word read *)
4545
4646 (* "Sh: " and a message on standard error. *)
47-proc say(f: []U8; args: []Fmt.Arg);
47+proc say(f: []const U8; args: []Fmt.Arg);
4848 var b: Buf.Buf; _n: INT;
4949 begin
5050 Buf.init(b, Heap.heap);
@@ -175,8 +175,8 @@
175175
176176 (* The program a command names: the name itself if it has a /, else the
177177 first executable file of that name in a directory of $PATH. *)
178-proc find(name: []U8): ([]U8, BOOL);
179-var path, dir: []U8; i, start, err: INT; b: Buf.Buf; info: Sys.Info;
178+proc find(name: []const U8): ([]const U8, BOOL);
179+var path, dir: []const U8; i, start, err: INT; b: Buf.Buf; info: Sys.Info;
180180 begin
181181 if Str.find(name, "/") >= 0 then return name, true; end;
182182 path := Sys.env("PATH");
@@ -195,7 +195,7 @@
195195 end;
196196
197197 (* The fd of a redirection's file, or -1 after saying why not. *)
198-proc redirect(path: []U8; how: Sys.Accesses): INT;
198+proc redirect(path: []const U8; how: Sys.Accesses): INT;
199199 var fd: INT;
200200 begin
201201 fd := Sys.open(path, how);
@@ -206,7 +206,7 @@
206206 (* cd, wait and exit, which change the shell itself, so it can't start
207207 them as programs; true if c is one. *)
208208 proc builtin(c: ^Command): BOOL;
209-var dir: []U8; n: I64; pid, _code: INT; ok: BOOL; _st: Sys.Status;
209+var dir: []const U8; n: I64; pid, _code: INT; ok: BOOL; _st: Sys.Status;
210210 begin
211211 match c^.args[0] of
212212 | "cd":
@@ -231,7 +231,7 @@
231231
232232 (* What the shell itself says on standard output, out before any
233233 program it starts writes. *)
234-proc show(f: []U8; args: []Fmt.Arg);
234+proc show(f: []const U8; args: []Fmt.Arg);
235235 begin
236236 Fmt.print(f, args);
237237 Out.flush;
@@ -244,7 +244,7 @@
244244 proc start(p: ^Pipeline);
245245 var
246246 pids: [maxCmds]INT; fds: [3]INT; i, j, inNext, r, w, leader, joins, how, _pid: INT;
247- c: ^Command; path: []U8; found, _ok: BOOL; st: Sys.Status;
247+ c: ^Command; path: []const U8; found, _ok: BOOL; st: Sys.Status;
248248 begin
249249 if (p^.n = 1) and not p^.background and builtin(ADR(p^.cmds[0])) then return; end;
250250 leader := 0;
@@ -299,7 +299,7 @@
299299 end;
300300
301301 (* Runs script: each pipeline as it is read. *)
302-proc run(script: []U8);
302+proc run(script: []const U8);
303303 var p: Pipeline; t: Token; ok: BOOL;
304304 begin
305305 Arena.reset(arena);
@@ -364,7 +364,7 @@
364364 Opt.option("", 'c', "command", "script", "run script, not standard input")];
365365
366366 proc main*: INT;
367-var p: Opt.Parser; script, file: []U8; given, found: BOOL; b: Buf.Buf;
367+var p: Opt.Parser; script, file: []const U8; given, found: BOOL; b: Buf.Buf;
368368 begin
369369 if not Arena.init(arena, 1 shl 24) then Rt.stop("Sh: no memory"); end;
370370 Opt.init(p, "Sh", Options);

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

@@ -1,16 +1,16 @@
11 (* Generic modules: counts the words of a text, taken apart by
2- Str.field, in a Map from []U8 to INT, hashed and compared by Str's
2+ Str.field, in a Map from []const U8 to INT, hashed and compared by Str's
33 procedures, keeps them in order of
4- first sight in a List([]U8), and prints them with Fmt. *)
4+ first sight in a List([]const U8), and prints them with Fmt. *)
55 module Words;
6-import Fmt, Str, Heap, Count := Map([]U8, INT, Str.hash, Str.eq), Names := List([]U8);
6+import Fmt, Str, Heap, Count := Map([]const U8, INT, Str.hash, Str.eq), Names := List([]const U8);
77
88 const Text = "the cat and the hat and the bat";
99
1010 proc main*;
1111 var
1212 counts: Count.Map; order: Names.List; n: ^Names.Node;
13- k, total: INT; found, _ok: BOOL; w, rest: []U8;
13+ k, total: INT; found, _ok: BOOL; w, rest: []const U8;
1414 begin
1515 Count.init(counts, Heap.heap);
1616 Names.init(order, Heap.heap);

lib/Arena.raz (history) modified +3 -2

@@ -1,8 +1,9 @@
11 (* An allocator that hands out memory from one block and frees it all
22 at once: free does nothing, reset forgets everything. An Arena is
3- its allocator: ADR(arena.base) is the ^Mem.Allocator to give NEW. *)
3+ its allocator: SYSTEM.ADR(arena.base) is the ^Mem.Allocator to give NEW. *)
44 module Arena;
55 import Mem, Rt;
6+import SYSTEM;
67
78 type
89 Arena* = record
@@ -70,7 +71,7 @@
7071 var ar: Arena; a: ^Mem.Allocator; p, q: ^U8; m: INT;
7172 begin
7273 if not init(ar, 4096) then Rt.stop("Arena.init"); end;
73- a := ADR(ar.base);
74+ a := SYSTEM.ADR(ar.base);
7475 p := Mem.alloc(a, 3, 1);
7576 q := Mem.alloc(a, 8, 8);
7677 if (p = nil) or (q # p + 8) then Rt.stop("Arena: alignment"); end;

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

@@ -1,6 +1,7 @@
11 (* A growable byte buffer, its memory from an allocator. *)
22 module Buf;
33 import Mem, Arena, Rt, Sys;
4+import SYSTEM;
45
56 type
67 Buf* = record
@@ -61,7 +62,7 @@
6162 end;
6263
6364 (* Adds the bytes of s at the end. *)
64-proc str*(var b: Buf; s: []U8);
65+proc str*(var b: Buf; s: []const U8);
6566 begin
6667 need(b, LEN(s));
6768 COPY(b.data[b.len..b.len + LEN(s)], s);
@@ -73,7 +74,7 @@
7374 grows, as bytes is. *)
7475 proc spare*(var b: Buf; n: INT): []U8;
7576 begin
76- if n = 0 then return ""; end; (* a new buffer has no data to slice *)
77+ if n = 0 then return []; end; (* a new buffer has no data to slice *)
7778 need(b, n);
7879 return b.data[b.len..b.len + n];
7980 end;
@@ -81,7 +82,7 @@
8182 (* What the buffer holds, until it next grows. *)
8283 proc bytes*(const b: Buf): []U8;
8384 begin
84- if b.len = 0 then return ""; end;
85+ if b.len = 0 then return []; end;
8586 return b.data[0..b.len];
8687 end;
8788
@@ -118,7 +119,7 @@
118119 var ar: Arena.Arena; b: Buf; i: INT; s: []U8;
119120 begin
120121 if not Arena.init(ar, 1 shl 20) then Rt.stop("Buf: no arena"); end;
121- init(b, ADR(ar.base));
122+ init(b, SYSTEM.ADR(ar.base));
122123 if LEN(bytes(b)) # 0 then Rt.stop("Buf: not empty"); end;
123124 for i := 0 to 9999 do add(b, U8(i mod 251)); end;
124125 str(b, "end");

lib/Bytes.raz (history) modified +17 -16

@@ -6,6 +6,7 @@
66 interface is the same. *)
77 module Bytes;
88 import Rt;
9+import SYSTEM;
910
1011 const
1112 Ones = 0101010101010101H; (* a one in each byte *)
@@ -42,13 +43,13 @@
4243 end;
4344
4445 (* The first place of b in s, or -1. *)
45-proc index*(s: []U8; b: U8): INT;
46+proc index*(s: []const U8; b: U8): INT;
4647 var i: INT; m, v, bs: U64; p: ^U64;
4748 begin
4849 bs := U64(b) * Ones;
4950 i := 0;
5051 while i + 8 <= LEN(s) do
51- p := ^U64(ADR(s[i]));
52+ p := ^U64(SYSTEM.PTR(s[i..LEN(s)]));
5253 v := p^ xor bs;
5354 m := ~(((v & Lows) + Lows) | v | Lows) & Tops;
5455 if m # 0 then return i + INT((((m & (0 - m)) - 1) & Ones) * Ones shr 56) - 1; end;
@@ -62,13 +63,13 @@
6263 end;
6364
6465 (* The last place of b in s, or -1. *)
65-proc last*(s: []U8; b: U8): INT;
66+proc last*(s: []const U8; b: U8): INT;
6667 var i: INT; m, v, bs: U64; p: ^U64;
6768 begin
6869 bs := U64(b) * Ones;
6970 i := LEN(s);
7071 while i >= 8 do
71- p := ^U64(ADR(s[i - 8]));
72+ p := ^U64(SYSTEM.PTR(s[i - 8..LEN(s)]));
7273 v := p^ xor bs;
7374 m := ~(((v & Lows) + Lows) | v | Lows) & Tops;
7475 if m # 0 then return i - 8 + highest(m); end;
@@ -82,14 +83,14 @@
8283 end;
8384
8485 (* How many bytes of s are b. *)
85-proc count*(s: []U8; b: U8): INT;
86+proc count*(s: []const U8; b: U8): INT;
8687 var i, n: INT; v, bs: U64; p: ^U64;
8788 begin
8889 bs := U64(b) * Ones;
8990 i := 0;
9091 n := 0;
9192 while i + 8 <= LEN(s) do
92- p := ^U64(ADR(s[i]));
93+ p := ^U64(SYSTEM.PTR(s[i..LEN(s)]));
9394 v := p^ xor bs;
9495 n := n + INT(((~(((v & Lows) + Lows) | v | Lows) & Tops) shr 7) * Ones shr 56);
9596 i := i + 8;
@@ -107,7 +108,7 @@
107108 both agree. They are the two bytes farthest apart, so as far from
108109 being the same test as two can be, and need no table of which bytes
109110 are rare. *)
110-proc find*(s, sub: []U8): INT;
111+proc find*(s, sub: []const U8): INT;
111112 var i, j, n, lastStart: INT; m, v, w, b0, b1: U64; p: ^U64;
112113 begin
113114 n := LEN(sub);
@@ -119,9 +120,9 @@
119120 b1 := U64(sub[n - 1]) * Ones;
120121 i := 0;
121122 while i + 7 <= lastStart do
122- p := ^U64(ADR(s[i]));
123+ p := ^U64(SYSTEM.PTR(s[i..LEN(s)]));
123124 v := p^ xor b0;
124- p := ^U64(ADR(s[i + n - 1]));
125+ p := ^U64(SYSTEM.PTR(s[i + n - 1..LEN(s)]));
125126 w := p^ xor b1;
126127 m := ~(((v & Lows) + Lows) | v | Lows) & ~(((w & Lows) + Lows) | w | Lows) & Tops;
127128 while m # 0 do
@@ -153,7 +154,7 @@
153154 return INT((seed shr 33) mod U64(n));
154155 end;
155156
156-proc refIndex(s: []U8; b: U8): INT;
157+proc refIndex(s: []const U8; b: U8): INT;
157158 var i: INT;
158159 begin
159160 for i := 0 to LEN(s) - 1 do
@@ -162,7 +163,7 @@
162163 return -1;
163164 end;
164165
165-proc refLast(s: []U8; b: U8): INT;
166+proc refLast(s: []const U8; b: U8): INT;
166167 var i: INT;
167168 begin
168169 for i := LEN(s) - 1 to 0 by -1 do
@@ -171,7 +172,7 @@
171172 return -1;
172173 end;
173174
174-proc refCount(s: []U8; b: U8): INT;
175+proc refCount(s: []const U8; b: U8): INT;
175176 var i, n: INT;
176177 begin
177178 n := 0;
@@ -181,7 +182,7 @@
181182 return n;
182183 end;
183184
184-proc refFind(s, sub: []U8): INT;
185+proc refFind(s, sub: []const U8): INT;
185186 var i: INT;
186187 begin
187188 for i := 0 to LEN(s) - LEN(sub) do
@@ -191,14 +192,14 @@
191192 end;
192193
193194 (* index, last and count of b in s agree with the plain loops *)
194-proc checkByte(s: []U8; b: U8);
195+proc checkByte(s: []const U8; b: U8);
195196 begin
196197 if index(s, b) # refIndex(s, b) then Rt.stop("Bytes.index"); end;
197198 if last(s, b) # refLast(s, b) then Rt.stop("Bytes.last"); end;
198199 if count(s, b) # refCount(s, b) then Rt.stop("Bytes.count"); end;
199200 end;
200201
201-proc checkFind(s, sub: []U8);
202+proc checkFind(s, sub: []const U8);
202203 begin
203204 if find(s, sub) # refFind(s, sub) then Rt.stop("Bytes.find"); end;
204205 end;
@@ -244,7 +245,7 @@
244245 that are almost its bytes; the slice cut short just before and just
245246 after it; also subs longer than the slice, and empty ones *)
246247 proc testPlanted;
247-var n, p, i, f: INT; s: []U8;
248+var n, p, i, f: INT; s: []const U8;
248249 begin
249250 for f := 0 to 2 do
250251 for n := 1 to 24 do

lib/Bytes.x86_64.raz (history) modified +13 -12

@@ -5,13 +5,14 @@
55 64-bit target, eight at a time in a U64. *)
66 module Bytes;
77 import Rt;
8+import SYSTEM;
89
910 (* The first place of b in s, or -1. Sixteen bytes at a time are
1011 compared with b's sixteen copies (pcmpeqb), and pmovmskb makes of the
1112 result a number with a bit set for each byte that matched. The bytes
1213 left over, fewer than sixteen, are compared one by one. Where the
1314 machine finds them: s's address in rdi, its length in rsi, b in dl. *)
14-proc index*(s: []U8; b: U8): INT;
15+proc index*(s: []const U8; b: U8): INT;
1516 code
1617 movd xmm1, edx;
1718 punpcklbw xmm1, xmm1; (* b in the low two bytes... *)
@@ -49,7 +50,7 @@
4950 end index;
5051
5152 (* The last place of b in s, or -1: as index, from the end. *)
52-proc last*(s: []U8; b: U8): INT;
53+proc last*(s: []const U8; b: U8): INT;
5354 code
5455 movd xmm1, edx;
5556 punpcklbw xmm1, xmm1;
@@ -82,7 +83,7 @@
8283 end last;
8384
8485 (* How many bytes of s are b: the bits of each block's number, counted. *)
85-proc count*(s: []U8; b: U8): INT;
86+proc count*(s: []const U8; b: U8): INT;
8687 code
8788 movd xmm1, edx;
8889 punpcklbw xmm1, xmm1;
@@ -119,7 +120,7 @@
119120 once: sixteen bytes are compared with a, sixteen from gap places on
120121 with b, and the two results anded. The places in rdi and rsi (s),
121122 rdx (gap), cl (a), r8b (b) and r9 (from). *)
122-proc pair(s: []U8; gap: INT; a, b: U8; from: INT): INT;
123+proc pair(s: []const U8; gap: INT; a, b: U8; from: INT): INT;
123124 code
124125 mov r11, rcx; (* a, for the places one by one *)
125126 movd xmm1, ecx;
@@ -175,7 +176,7 @@
175176 its place (pair), and checked whole only where both agree. They are
176177 the two bytes farthest apart, so as far from being the same test as
177178 two can be, and need no table of which bytes are rare. *)
178-proc find*(s, sub: []U8): INT;
179+proc find*(s, sub: []const U8): INT;
179180 var i, n: INT;
180181 begin
181182 n := LEN(sub);
@@ -204,7 +205,7 @@
204205 return INT((seed shr 33) mod U64(n));
205206 end;
206207
207-proc refIndex(s: []U8; b: U8): INT;
208+proc refIndex(s: []const U8; b: U8): INT;
208209 var i: INT;
209210 begin
210211 for i := 0 to LEN(s) - 1 do
@@ -213,7 +214,7 @@
213214 return -1;
214215 end;
215216
216-proc refLast(s: []U8; b: U8): INT;
217+proc refLast(s: []const U8; b: U8): INT;
217218 var i: INT;
218219 begin
219220 for i := LEN(s) - 1 to 0 by -1 do
@@ -222,7 +223,7 @@
222223 return -1;
223224 end;
224225
225-proc refCount(s: []U8; b: U8): INT;
226+proc refCount(s: []const U8; b: U8): INT;
226227 var i, n: INT;
227228 begin
228229 n := 0;
@@ -232,7 +233,7 @@
232233 return n;
233234 end;
234235
235-proc refFind(s, sub: []U8): INT;
236+proc refFind(s, sub: []const U8): INT;
236237 var i: INT;
237238 begin
238239 for i := 0 to LEN(s) - LEN(sub) do
@@ -242,14 +243,14 @@
242243 end;
243244
244245 (* index, last and count of b in s agree with the plain loops *)
245-proc checkByte(s: []U8; b: U8);
246+proc checkByte(s: []const U8; b: U8);
246247 begin
247248 if index(s, b) # refIndex(s, b) then Rt.stop("Bytes.index"); end;
248249 if last(s, b) # refLast(s, b) then Rt.stop("Bytes.last"); end;
249250 if count(s, b) # refCount(s, b) then Rt.stop("Bytes.count"); end;
250251 end;
251252
252-proc checkFind(s, sub: []U8);
253+proc checkFind(s, sub: []const U8);
253254 begin
254255 if find(s, sub) # refFind(s, sub) then Rt.stop("Bytes.find"); end;
255256 end;
@@ -295,7 +296,7 @@
295296 that are almost its bytes; the slice cut short just before and just
296297 after it; also subs longer than the slice, and empty ones *)
297298 proc testPlanted;
298-var n, p, i, f: INT; s: []U8;
299+var n, p, i, f: INT; s: []const U8;
299300 begin
300301 for f := 0 to 2 do
301302 for n := 1 to 24 do

lib/C.raz (history) modified +1 -0

@@ -2,6 +2,7 @@
22 programs reach for. A program that imports C uses C, and so is
33 linked dynamically and starts through the C library. *)
44 module C;
5+import SYSTEM;
56
67 extern proc write*(fd: I32; buf: ^U8; n: UINT): INT;
78 extern proc read*(fd: I32; buf: ^U8; n: UINT): INT;

lib/CAbi.linux-x86_64.raz (history) modified +1 -0

@@ -6,6 +6,7 @@
66 Written by tools/cabi.c, from the system's own headers; not to be
77 edited, but written again. *)
88 module CAbi;
9+import SYSTEM;
910
1011 const
1112 (* open's flags, fcntl's requests, seek, flock, mmap, access *)

lib/Check.raz (history) modified +10 -10

@@ -27,7 +27,7 @@
2727 checks: INT; (* checks made *)
2828 failures: INT; (* of them, failed *)
2929 registered: BOOL; (* the exit procedure is on Rt's list *)
30- sink: proc(s: []U8); (* where text goes, or nil for standard error; a test sets it *)
30+ sink: proc(s: []const U8); (* where text goes, or nil for standard error; a test sets it *)
3131 muted: BOOL; (* checks say nothing and aren't counted, as Prop searches *)
3232 mutedFails: INT; (* checks failed since mute was turned on *)
3333
@@ -48,7 +48,7 @@
4848
4949 (* Writes s to standard error, trying again after a short or interrupted
5050 write; nothing while muted. *)
51-proc put(s: []U8);
51+proc put(s: []const U8);
5252 var n: INT;
5353 begin
5454 if muted then return; end;
@@ -90,7 +90,7 @@
9090 (* Writes s between quotes, with the quote, backslash and bytes below
9191 32 or 127 as escapes; the bytes from 128 are written as they are,
9292 so UTF-8 reads. *)
93-proc putQuoted(s: []U8);
93+proc putQuoted(s: []const U8);
9494 var i, from: INT; c: U8;
9595 begin
9696 put("\"");
@@ -114,7 +114,7 @@
114114
115115 (* The index of the first byte where a and b differ, or the shorter
116116 length if one is a prefix of the other. *)
117-proc firstDiff(a, b: []U8): INT;
117+proc firstDiff(a, b: []const U8): INT;
118118 var i, n: INT;
119119 begin
120120 n := LEN(a);
@@ -149,7 +149,7 @@
149149 (* Counts a failure and begins its report with the FAIL line. Standard
150150 output is flushed first, so the two come in order. While muted, it
151151 only counts it among the muted failures. *)
152-proc fail(what: []U8);
152+proc fail(what: []const U8);
153153 begin
154154 if muted then INC(mutedFails); return; end;
155155 INC(failures);
@@ -158,7 +158,7 @@
158158 end;
159159
160160 (* Fails, saying what, when cond is false. *)
161-proc ok*(cond: BOOL; what: []U8);
161+proc ok*(cond: BOOL; what: []const U8);
162162 begin
163163 count;
164164 if not cond then fail(what); end;
@@ -166,7 +166,7 @@
166166
167167 (* Fails, saying what, when got is not want; shows both, escaped, and
168168 where they first differ. *)
169-proc str*(what, got, want: []U8);
169+proc str*(what, got, want: []const U8);
170170 var at: INT;
171171 begin
172172 count;
@@ -179,7 +179,7 @@
179179 end;
180180
181181 (* Fails, saying what, when got is not want; shows both. *)
182-proc int*(what: []U8; got, want: I64);
182+proc int*(what: []const U8; got, want: I64);
183183 begin
184184 count;
185185 if got = want then return; end;
@@ -193,14 +193,14 @@
193193 capN: INT; (* bytes in cap *)
194194
195195 (* The test's sink: appends s to cap. *)
196-proc capture(s: []U8);
196+proc capture(s: []const U8);
197197 var i: INT;
198198 begin
199199 for i := 0 to LEN(s) - 1 do cap[capN] := s[i]; INC(capN); end;
200200 end;
201201
202202 (* Runs f with its output captured, and checks that it is want. *)
203-proc expect(what: []U8; f: proc; want: []U8);
203+proc expect(what: []const U8; f: proc; want: []const U8);
204204 begin
205205 capN := 0;
206206 f;

lib/Files.raz (history) modified +18 -17

@@ -5,14 +5,15 @@
55 (a program makes its own with Sys.openDir). *)
66 module Files;
77 import Sys, Buf, Heap, Rt;
8+import SYSTEM;
89
910 (* Argument i, a C string, as a slice; empty if there is no argument i,
1011 as for i below 0 or from ARGC() on. *)
11-proc arg*(i: INT): []U8;
12+proc arg*(i: INT): []const U8;
1213 var s: ^U8; n: INT;
1314 begin
1415 if (i < 0) or (i >= ARGC()) then return ""; end;
15- s := ARGV()[i];
16+ s := SYSTEM.ARGV()[i];
1617 n := 0;
1718 while s[n] # 0 do INC(n); end;
1819 return s[0..n];
@@ -22,7 +23,7 @@
2223 the read that failed, as Sys gives them: -2 (ENOENT) for no such
2324 file, -13 (EACCES) for one not allowed, -21 (EISDIR) for a
2425 directory. What was read before a read failed stays in b. *)
25-proc load*(path: []U8; var b: Buf.Buf): INT;
26+proc load*(path: []const U8; var b: Buf.Buf): INT;
2627 var fd, n: INT;
2728 begin
2829 fd := Sys.openRead(path);
@@ -36,14 +37,14 @@
3637 end;
3738
3839 (* Adds the file at path to b; false if it can't be read. *)
39-proc read*(path: []U8; var b: Buf.Buf): BOOL;
40+proc read*(path: []const U8; var b: Buf.Buf): BOOL;
4041 begin
4142 return load(path, b) = 0;
4243 end;
4344
4445 (* Writes all of s to fd, again after a short write (a pipe, a socket)
4546 or a signal: 0, or minus the errno of the write that failed. *)
46-proc writeAll*(fd: INT; s: []U8): INT;
47+proc writeAll*(fd: INT; s: []const U8): INT;
4748 var n, at: INT;
4849 begin
4950 at := 0;
@@ -58,7 +59,7 @@
5859
5960 (* Makes the file at path hold data; false if it can't be written, or
6061 the close, where a late write error shows, fails. *)
61-proc write*(path, data: []U8): BOOL;
62+proc write*(path, data: []const U8): BOOL;
6263 var fd, r: INT;
6364 begin
6465 fd := Sys.create(path);
@@ -100,7 +101,7 @@
100101 rest, from at. A relative target is read from the link's directory,
101102 which res keeps; an absolute one starts again from the root. *)
102103 proc followLink(var res, rest: Buf.Buf; mark: INT; var at, links: INT): INT;
103-var target: []U8; joined: Buf.Buf; r: INT;
104+var target: []const U8; joined: Buf.Buf; r: INT;
104105 begin
105106 INC(links);
106107 if links > MaxLinks then return -40; end; (* ELOOP *)
@@ -121,7 +122,7 @@
121122 (* Adds one name of a path to res: nothing for ".", the parent for
122123 "..", the name itself for a file or directory, and for a link what
123124 it names, to be read next. *)
124-proc enter(var res, rest: Buf.Buf; var at, links: INT; name: []U8): INT;
125+proc enter(var res, rest: Buf.Buf; var at, links: INT; name: []const U8): INT;
125126 var info: Sys.Info; mark, r: INT;
126127 begin
127128 if (name = ".") or (name = "..") then
@@ -147,8 +148,8 @@
147148 or symbolic link in it: 0, or minus an errno, -2 (ENOENT) if a part
148149 of it isn't there, -40 (ELOOP) after 40 links. The working
149150 directory stays as it is; b is left as it was on failure. *)
150-proc realPath*(path: []U8; var b: Buf.Buf): INT;
151-var res, rest: Buf.Buf; dir, name: []U8; at, links, r: INT;
151+proc realPath*(path: []const U8; var b: Buf.Buf): INT;
152+var res, rest: Buf.Buf; dir, name: []const U8; at, links, r: INT;
152153 begin
153154 if LEN(path) = 0 then return Sys.errNoEntry; end;
154155 Buf.init(res, Heap.heap);
@@ -174,12 +175,12 @@
174175 return r;
175176 end;
176177
177-proc removeTree*(path: []U8): INT; forward;
178+proc removeTree*(path: []const U8): INT; forward;
178179
179180 (* Removes what is in the directory at path: 0, or minus the first
180181 errno, going on with the rest after it. *)
181-proc removeContents(path: []U8): INT;
182-var d: Sys.Dir; child: Buf.Buf; name: []U8; more: BOOL; mark, r, first: INT;
182+proc removeContents(path: []const U8): INT;
183+var d: Sys.Dir; child: Buf.Buf; name: []const U8; more: BOOL; mark, r, first: INT;
183184 begin
184185 r := Sys.openDir(d, path);
185186 if r < 0 then return r; end;
@@ -204,7 +205,7 @@
204205 (* Removes the file at path and, if it is a directory, all within it,
205206 without following a symbolic link (the link goes, not what it
206207 names): 0, or minus the first errno. *)
207-proc removeTree*(path: []U8): INT;
208+proc removeTree*(path: []const U8): INT;
208209 var info: Sys.Info; r: INT;
209210 begin
210211 info, r := Sys.linkInfo(path);
@@ -216,7 +217,7 @@
216217 end;
217218
218219 (* Sets b to base and then rest, and gives it. *)
219-proc join(var b: Buf.Buf; base, rest: []U8): []U8;
220+proc join(var b: Buf.Buf; base, rest: []const U8): []U8;
220221 begin
221222 Buf.cut(b, 0);
222223 Buf.str(b, base);
@@ -226,7 +227,7 @@
226227
227228 (* Stops the test, saying what, unless realPath of path gives err and
228229 adds want to a buffer. *)
229-proc wantReal(path, want: []U8; err: INT; what: []U8);
230+proc wantReal(path, want: []const U8; err: INT; what: []const U8);
230231 var b: Buf.Buf; r: INT;
231232 begin
232233 Buf.init(b, Heap.heap);
@@ -265,7 +266,7 @@
265266 out of it. *)
266267 proc testTree;
267268 const T = "/tmp/raz-files-test.d"; Out = "/tmp/raz-files-test.out";
268-var p, q: Buf.Buf; here, now: []U8; r: INT;
269+var p, q: Buf.Buf; here, now: []const U8; r: INT;
269270 begin
270271 Buf.init(p, Heap.heap);
271272 Buf.init(q, Heap.heap);

lib/Fmt.raz (history) modified +18 -17

@@ -9,6 +9,7 @@
99 Left out: precision, other fills, argument numbers and names. *)
1010 module Fmt;
1111 import Out, Buf, Arena, Rt, Sys;
12+import SYSTEM;
1213
1314 const
1415 Limb = 1000000000; (* a Big's base, 10^9 *)
@@ -33,7 +34,7 @@
3334 uint(u: U64); (* in decimal *)
3435 hex(h: U64); (* in hexadecimal, capitals, no 0x *)
3536 lowHex(h: U64); (* in hexadecimal, lower case, no 0x *)
36- str(s: []U8);
37+ str(s: []const U8);
3738 char(c: U8); (* the one byte *)
3839 bool(b: BOOL); (* true or false *)
3940 real(r: F64; places: INT);
@@ -102,7 +103,7 @@
102103 end;
103104
104105 (* s to k. *)
105-proc put(var k: Sink; s: []U8);
106+proc put(var k: Sink; s: []const U8);
106107 var at, room: INT;
107108 begin
108109 at := k.n;
@@ -188,7 +189,7 @@
188189 proc bits(x: F64): U64;
189190 var p: ^U64;
190191 begin
191- p := ^U64(ADR(x));
192+ p := ^U64(SYSTEM.ADR(x));
192193 return p^;
193194 end;
194195
@@ -254,7 +255,7 @@
254255
255256 (* -1, 0 or 1 as 0.d times 10^e, d's first digit not 0, is below, at or
256257 above w. *)
257-proc compare(d: []U8; e: INT; const w: Exact): INT;
258+proc compare(d: []const U8; e: INT; const w: Exact): INT;
258259 var i, n: INT; a, c: U8;
259260 begin
260261 if e # w.e then
@@ -306,7 +307,7 @@
306307 (* Whether x, cut where rest begins, is nearer the number one more in
307308 the last place than to the cut one: rest is above a half, or a half
308309 and last, the cut one's last digit, odd. *)
309-proc nearerUp(rest: []U8; last: U8): BOOL;
310+proc nearerUp(rest: []const U8; last: U8): BOOL;
310311 var i: INT;
311312 begin
312313 if rest[0] # '5' then return rest[0] > '5'; end;
@@ -357,7 +358,7 @@
357358 end;
358359
359360 (* s added to out at n, which moves past it. *)
360-proc emit(var out: [ShortMost]U8; var n: INT; s: []U8);
361+proc emit(var out: [ShortMost]U8; var n: INT; s: []const U8);
361362 begin
362363 COPY(out[n..n + LEN(s)], s);
363364 INC(n, LEN(s));
@@ -465,7 +466,7 @@
465466
466467 (* If f[i], a {, starts a width, {2}, {02} or {-10}: it is read into s
467468 and the place of its } is the result; else the result is -1. *)
468-proc spec(f: []U8; i: INT; var s: Spec): INT;
469+proc spec(f: []const U8; i: INT; var s: Spec): INT;
469470 var count: INT;
470471 begin
471472 s.width := 0; s.zero := false; s.left := false;
@@ -481,7 +482,7 @@
481482 end;
482483
483484 (* f to k, each {} replaced by the next of args. *)
484-proc format(var k: Sink; f: []U8; args: []Arg);
485+proc format(var k: Sink; f: []const U8; args: []const Arg);
485486 var i, start, n, close: INT; s: Spec;
486487 begin
487488 i := 0; start := 0; n := 0;
@@ -510,7 +511,7 @@
510511 end;
511512
512513 (* Writes f to standard output, each {} replaced by the next of args. *)
513-proc print*(f: []U8; args: []Arg);
514+proc print*(f: []const U8; args: []const Arg);
514515 var k: Sink;
515516 begin
516517 k := sink(nil);
@@ -524,13 +525,13 @@
524525 program that doesn't call eprint carries no heap for it; its pages
525526 are mapped as they are written, and a text of more than a megabyte
526527 stops the program, as a Buf does when it can't grow. *)
527-proc eprint*(f: []U8; args: []Arg);
528+proc eprint*(f: []const U8; args: []const Arg);
528529 var ar: Arena.Arena; b: Buf.Buf; k: Sink; s: []U8; n: INT;
529530 begin
530531 Out.flush;
531532 if not Arena.init(ar, 1 shl 20) then Rt.stop("Fmt.eprint: no arena"); end;
532- Buf.init(b, ADR(ar.base));
533- k := sink(ADR(b));
533+ Buf.init(b, SYSTEM.ADR(ar.base));
534+ k := sink(SYSTEM.ADR(b));
534535 format(k, f, args);
535536 s := Buf.bytes(b);
536537 while LEN(s) > 0 do
@@ -543,17 +544,17 @@
543544 end;
544545
545546 (* Appends f to b, each {} replaced by the next of args. *)
546-proc write*(var b: Buf.Buf; f: []U8; args: []Arg);
547+proc write*(var b: Buf.Buf; f: []const U8; args: []const Arg);
547548 var k: Sink;
548549 begin
549- k := sink(ADR(b)); (* a sink's nil is standard output *)
550+ k := sink(SYSTEM.ADR(b)); (* a sink's nil is standard output *)
550551 format(k, f, args);
551552 end;
552553
553554 (* Formats f into out as write formats it: the bytes written, and false
554555 if out was too short and the text is cut there. It needs no memory
555556 of its own. *)
556-proc into*(out: []U8; f: []U8; args: []Arg): (INT, BOOL);
557+proc into*(out: []U8; f: []const U8; args: []const Arg): (INT, BOOL);
557558 var k: Sink;
558559 begin
559560 k := sink(nil);
@@ -564,7 +565,7 @@
564565 end;
565566
566567 (* Each of xs, shorts, with a space between, added to b. *)
567-proc shorts(var b: Buf.Buf; xs: []F64);
568+proc shorts(var b: Buf.Buf; xs: []const F64);
568569 var d: [ShortMost]U8; i: INT;
569570 begin
570571 for i := 0 to LEN(xs) - 1 do
@@ -578,7 +579,7 @@
578579 var ar: Arena.Arena; b: Buf.Buf; zero: F64; small: [8]U8; d: [ShortMost]U8; n: INT; whole: BOOL;
579580 begin
580581 if not Arena.init(ar, 1 shl 16) then Rt.stop("Fmt: no arena"); end;
581- Buf.init(b, ADR(ar.base));
582+ Buf.init(b, SYSTEM.ADR(ar.base));
582583 write(b, "{} {} {} {}|{}{}{} {{}}", [int(-42), uint(0FFFFFFFFFFFFFFFFH), hex(48879),
583584 str("s"), char('c'), bool(true), int(0)]);
584585 if Buf.bytes(b) # "-42 18446744073709551615 BEEF s|ctrue0 {}" then Rt.stop("Fmt.write"); end;

lib/Heap.raz (history) modified +6 -5

@@ -27,6 +27,7 @@
2727 the block has left the quarantine. *)
2828 module Heap;
2929 import Mem, Lock, Rt, Sys;
30+import SYSTEM;
3031
3132 const
3233 Classes = 9;
@@ -134,7 +135,7 @@
134135
135136 (* Stops the program, saying what was found of the debug block with
136137 header h, its address and its size, and the calls under way. *)
137-proc found(what: []U8; h: ^Head);
138+proc found(what: []const U8; h: ^Head);
138139 var d: [20]U8; i, n: INT;
139140 begin
140141 _ := Sys.write(Sys.stderr, "Heap: ");
@@ -164,7 +165,7 @@
164165
165166 (* found, with the heap's lock held, which is let go first, so that
166167 what runs as the program ends may use the heap *)
167-proc badBlock(what: []U8; h: ^Head);
168+proc badBlock(what: []const U8; h: ^Head);
168169 begin
169170 Lock.give(lock);
170171 found(what, h);
@@ -279,7 +280,7 @@
279280 proc allocSure(_a: ^Mem.Allocator; size, align: INT): ^U8;
280281 var p: ^U8;
281282 begin
282- p := std.alloc(ADR(std), size, align);
283+ p := std.alloc(SYSTEM.ADR(std), size, align);
283284 if p = nil then
284285 _ := Sys.write(Sys.stderr, "Heap: out of memory\n");
285286 Rt.trace;
@@ -357,8 +358,8 @@
357358
358359 begin
359360 std := {alloc: alloc, free: free};
360- heap := ADR(std);
361+ heap := SYSTEM.ADR(std);
361362 surer := {alloc: allocSure, free: free};
362- sure := ADR(surer);
363+ sure := SYSTEM.ADR(surer);
363364 if Sys.env("RAZ_HEAP") = "debug" then debug(true); end;
364365 end Heap.

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

@@ -1,6 +1,7 @@
11 (* A singly linked list of T, its nodes from an allocator. *)
22 module List(T);
33 import Mem;
4+import SYSTEM;
45
56 type
67 Node* = record

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

@@ -13,7 +13,7 @@
1313 var tries: INT;
1414 begin
1515 tries := 0;
16- while not CAS(ADR(l.held), 0, 1) do
16+ while not CAS(l.held, 0, 1) do
1717 INC(tries);
1818 if tries = 64 then Sys.yield; tries := 0; end;
1919 end;
@@ -22,7 +22,7 @@
2222 (* Gives up l, which the caller holds. *)
2323 proc give*(var l: Lock);
2424 begin
25- _ := XCHG(ADR(l.held), 0);
25+ _ := XCHG(l.held, 0);
2626 end;
2727
2828 (* The module's test, in one thread: taken, given, taken again. *)

lib/Map.raz (history) modified +2 -1

@@ -1,8 +1,9 @@
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, INT, Str.hash, Str.eq); *)
3+ import Count := Map([]const 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;
6+import SYSTEM;
67
78 type
89 Entry = record

lib/Math.raz (history) modified +5 -4

@@ -8,6 +8,7 @@
88 Left out: sinh, cosh, fmod and hypot, until a program needs them. *)
99 module Math;
1010 import Check, Rt;
11+import SYSTEM;
1112
1213 const
1314 pi* = 3.141592653589793; (* the F64 nearest to pi *)
@@ -461,7 +462,7 @@
461462 end divMod;
462463
463464 (* 64 bits of t from bit s on, the first bit of t[0] being 0. *)
464-proc window(t: []U64; s: INT): U64;
465+proc window(t: []const U64; s: INT): U64;
465466 var q, r: INT;
466467 begin
467468 q := s div 64;
@@ -905,7 +906,7 @@
905906 end;
906907
907908 (* Whether s[i] is a decimal digit. *)
908-proc digitAt(s: []U8; i: INT): BOOL;
909+proc digitAt(s: []const U8; i: INT): BOOL;
909910 begin
910911 return (i < LEN(s)) and (s[i] >= '0') and (s[i] <= '9');
911912 end;
@@ -914,7 +915,7 @@
914915 or e, a sign if any and digits if any; nothing else. The F64 nearest
915916 it, ties to the even one, and false if s isn't one, or is past the
916917 largest F64; one below the smallest is 0. *)
917-proc toReal*(s: []U8): (F64, BOOL);
918+proc toReal*(s: []const U8): (F64, BOOL);
918919 var
919920 num, den, d: Big; i, digits, e, ex: INT; neg, eneg, point, half, sticky: BOOL;
920921 q, b: U64; x: F64;
@@ -1011,7 +1012,7 @@
10111012 end;
10121013
10131014 (* Whether toReal reads s as want, exactly, or as nothing if not ok. *)
1014-proc reads(s: []U8; want: F64; ok: BOOL): BOOL;
1015+proc reads(s: []const U8; want: F64; ok: BOOL): BOOL;
10151016 var x: F64; o: BOOL;
10161017 begin
10171018 x, o := toReal(s);

lib/Mem.raz (history) modified +1 -0

@@ -2,6 +2,7 @@
22 from the system. NEW(p, a) calls a^.alloc. *)
33 module Mem;
44 import Sys, Rt;
5+import SYSTEM;
56
67 type
78 Allocator* = record

lib/Opt.raz (history) modified +43 -46

@@ -13,21 +13,21 @@
1313
1414 type
1515 Row* = variant
16- usage(scope, line: []U8); (* a synopsis, without "usage: " *)
17- sub(scope, name, help: []U8); (* a subcommand *)
18- option(scope: []U8; letter: U8; long, value, help: []U8);
16+ usage(scope, line: []const U8); (* a synopsis, without "usage: " *)
17+ sub(scope, name, help: []const U8); (* a subcommand *)
18+ option(scope: []const U8; letter: U8; long, value, help: []const U8);
1919 end;
2020 Parser* = record
2121 letter*: U8; (* the option just read *)
22- value*: []U8; (* its value; "" for a flag *)
22+ value*: []const U8; (* its value; "" for a flag *)
2323 long*: BOOL; (* it was written by its long name *)
24- spelt*: []U8; (* as it was written, no dashes: "b" or "bar"; the program's to read only *)
24+ spelt*: []const U8; (* as it was written, no dashes: "b" or "bar"; the program's to read only *)
2525 (* the rest are Opt's own *)
26- name: []U8; (* the program's, as the messages begin *)
27- table: []Row;
28- scope: []U8;
26+ name: []const U8; (* the program's, as the messages begin *)
27+ table: []const Row;
28+ scope: []const U8;
2929 at: INT; (* the next word *)
30- group: []U8; (* the letters left of a word of them, as -lw *)
30+ group: []const U8; (* the letters left of a word of them, as -lw *)
3131 ended: BOOL; (* the scope's options have ended *)
3232 help: BOOL; (* the option just read is -h or --help *)
3333 end;
@@ -39,7 +39,7 @@
3939
4040 (* b written whole to fd, then freed. *)
4141 proc say(fd: INT; var b: Buf.Buf);
42-var s: []U8; n: INT;
42+var s: []const U8; n: INT;
4343 begin
4444 s := Buf.bytes(b);
4545 while LEN(s) > 0 do
@@ -90,7 +90,7 @@
9090
9191 (* A mistake on the command line: the sentence f, the scope's synopsis
9292 lines under it, and status 2. *)
93-proc mistake(const p: Parser; f: []U8; args: []Fmt.Arg);
93+proc mistake(const p: Parser; f: []const U8; args: []const Fmt.Arg);
9494 var b: Buf.Buf;
9595 begin
9696 Buf.init(b, Heap.heap);
@@ -102,7 +102,7 @@
102102 Rt.exit(2);
103103 end;
104104
105-proc dashes(const p: Parser): []U8;
105+proc dashes(const p: Parser): []const U8;
106106 begin
107107 if p.long then return "--"; end;
108108 return "-";
@@ -111,7 +111,7 @@
111111 (* Whether an option's value may be left out, written [name] in its
112112 row: given only in the option's own word, --color=when or -cwhen,
113113 never as the next word, as getopt's :: has it. *)
114-proc optional(value: []U8): BOOL;
114+proc optional(value: []const U8): BOOL;
115115 begin
116116 return (LEN(value) > 2) and (value[0] = '[') and (value[LEN(value) - 1] = ']');
117117 end;
@@ -119,9 +119,9 @@
119119 (* The left column of a row in the help, as "-b, --bar label", or, for
120120 a value that may be left out, "-c, --color[=when]", as grep's help
121121 has it. *)
122-proc left(var b: Buf.Buf; r: ^Row);
122+proc left(var b: Buf.Buf; const r: Row);
123123 begin
124- match r^ of
124+ match r of
125125 | sub(_s, name, _help): Buf.str(b, name);
126126 | option(_s, letter, long, value, _help):
127127 if letter >= '!' then Fmt.write(b, "-{}", [Fmt.char(letter)]); else Buf.str(b, " "); end;
@@ -137,7 +137,7 @@
137137 end;
138138 end;
139139
140-proc leftWidth(r: ^Row): INT;
140+proc leftWidth(const r: Row): INT;
141141 var b: Buf.Buf; n: INT;
142142 begin
143143 Buf.init(b, Heap.heap);
@@ -149,13 +149,13 @@
149149
150150 (* A line of the list: the left column, padded to width and three
151151 spaces more, and the line of help. *)
152-proc item(var b: Buf.Buf; r: ^Row; width: INT);
152+proc item(var b: Buf.Buf; const r: Row; width: INT);
153153 var i: INT;
154154 begin
155155 Buf.str(b, " ");
156156 left(b, r);
157157 for i := leftWidth(r) to width + 2 do Buf.add(b, ' '); end;
158- match r^ of
158+ match r of
159159 | sub(_s, _name, help): Fmt.write(b, "{}\n", [Fmt.str(help)]);
160160 | option(_s, _l, _long, _v, help): Fmt.write(b, "{}\n", [Fmt.str(help)]);
161161 | else:
@@ -164,7 +164,7 @@
164164
165165 (* The scope's option with the letter c, or with the long name long:
166166 its row, or -1, and its letter and the name of its value. *)
167-proc find(const p: Parser; c: U8; long: []U8): (INT, U8, []U8);
167+proc find(const p: Parser; c: U8; long: []const U8): (INT, U8, []const U8);
168168 var i: INT;
169169 begin
170170 for i := 0 to LEN(p.table) - 1 do
@@ -182,7 +182,7 @@
182182 (* Whether the scope has an option -h of its own, so that help is
183183 --help alone there, as it is for grep, whose -h is "no file names". *)
184184 proc ownsH(const p: Parser): BOOL;
185-var r: INT; _l: U8; _v: []U8;
185+var r: INT; _l: U8; _v: []const U8;
186186 begin
187187 r, _l, _v := find(p, 'h', "");
188188 return r >= 0;
@@ -193,7 +193,7 @@
193193 help's own row is made as the table's are, with no letter if the
194194 scope has -h. *)
195195 proc printHelp(const p: Parser);
196-var b: Buf.Buf; i, width: INT; r: ^Row; own: Row; h: U8;
196+var b: Buf.Buf; i, width: INT; own: Row; h: U8;
197197 begin
198198 h := 'h';
199199 if ownsH(p) then h := 0; end;
@@ -201,26 +201,23 @@
201201 Buf.init(b, Heap.heap);
202202 usageOf(p, b);
203203 Buf.add(b, 10);
204- width := leftWidth(ADR(own));
204+ width := leftWidth(own);
205205 for i := 0 to LEN(p.table) - 1 do
206- r := ADR(p.table[i]);
207- if inScope(p, r^) and (leftWidth(r) > width) then width := leftWidth(r); end;
206+ if inScope(p, p.table[i]) and (leftWidth(p.table[i]) > width) then width := leftWidth(p.table[i]); end;
208207 end;
209208 for i := 0 to LEN(p.table) - 1 do
210- r := ADR(p.table[i]);
211- match r^ of
212- | sub(s, _name, _help): if s = p.scope then item(b, r, width); end;
209+ match p.table[i] of
210+ | sub(s, _name, _help): if s = p.scope then item(b, p.table[i], width); end;
213211 | else:
214212 end;
215213 end;
216214 for i := 0 to LEN(p.table) - 1 do
217- r := ADR(p.table[i]);
218- match r^ of
219- | option(s, _l, _long, _v, _help): if s = p.scope then item(b, r, width); end;
215+ match p.table[i] of
216+ | option(s, _l, _long, _v, _help): if s = p.scope then item(b, p.table[i], width); end;
220217 | else:
221218 end;
222219 end;
223- item(b, ADR(own), width);
220+ item(b, own, width);
224221 say(Sys.stdout, b);
225222 Rt.exit(0);
226223 end;
@@ -244,7 +241,7 @@
244241 readEnd at the end of the options. A mistake is refused, or, if
245242 quiet, passed over, as readSkip. *)
246243 proc read(var p: Parser; quiet: BOOL): INT;
247-var w, val: []U8; r, eq: INT; c: U8;
244+var w, val: []const U8; r, eq: INT; c: U8;
248245 begin
249246 p.help := false;
250247 p.value := "";
@@ -331,7 +328,7 @@
331328 end;
332329
333330 (* A mistake in the table: the program's, with status 1. *)
334-proc badTable(const p: Parser; row: INT; why: []U8);
331+proc badTable(const p: Parser; row: INT; why: []const U8);
335332 var b: Buf.Buf;
336333 begin
337334 Buf.init(b, Heap.heap);
@@ -373,7 +370,7 @@
373370
374371 (* p reads the arguments from 1 on, by table, in the program's own
375372 scope; name begins the messages. *)
376-proc init*(var p: Parser; name: []U8; table: []Row);
373+proc init*(var p: Parser; name: []const U8; table: []const Row);
377374 begin
378375 p := {name: name, table: table, at: 1};
379376 check(p);
@@ -391,7 +388,7 @@
391388
392389 (* The next operand, after what options are left; false when there are
393390 no more. *)
394-proc operand*(var p: Parser): ([]U8, BOOL);
391+proc operand*(var p: Parser): ([]const U8, BOOL);
395392 begin
396393 while next(p) do end;
397394 if p.at >= ARGC() then return "", false; end;
@@ -410,7 +407,7 @@
410407
411408 (* The options of the subcommand name, from the word after its own,
412409 which operand has given. *)
413-proc scope*(var p: Parser; name: []U8);
410+proc scope*(var p: Parser; name: []const U8);
414411 begin
415412 p.scope := name;
416413 p.ended := false;
@@ -439,7 +436,7 @@
439436 (* The value of the option just read refused, as number refuses one:
440437 "-b wants wants, not 'value'", the option as it was written, with
441438 the scope's synopsis lines, and status 2. *)
442-proc refuse*(const p: Parser; wants: []U8);
439+proc refuse*(const p: Parser; wants: []const U8);
443440 begin
444441 mistake(p, "{}{} wants {}, not '{}'",
445442 [Fmt.str(dashes(p)), Fmt.str(p.spelt), Fmt.str(wants), Fmt.str(p.value)]);
@@ -447,7 +444,7 @@
447444
448445 (* The program's own mistake, written as Opt's are but alone, and
449446 status 2. *)
450-proc fail*(const p: Parser; text: []U8);
447+proc fail*(const p: Parser; text: []const U8);
451448 var b: Buf.Buf;
452449 begin
453450 Buf.init(b, Heap.heap);
@@ -458,7 +455,7 @@
458455
459456 (* The program's own mistake, written as Opt's are, with the scope's
460457 synopsis lines after it, and status 2. *)
461-proc misuse*(const p: Parser; text: []U8);
458+proc misuse*(const p: Parser; text: []const U8);
462459 begin
463460 mistake(p, "{}", [Fmt.str(text)]);
464461 end;
@@ -478,7 +475,7 @@
478475 option("", jobs, "jobs", "n", "keep n jobs at most"),
479476 usage("start", "keep start [-b label] name command [argument ...]"),
480477 option("start", 'b', "bar", "label", "show the job in the bar as label")];
481-var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []U8; b: Buf.Buf; i: INT;
478+var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []const U8; b: Buf.Buf; i: INT;
482479 begin
483480 secs := 10;
484481 init(p, "keep", Rows);
@@ -516,7 +513,7 @@
516513
517514 (* A scope with no digit option, and one with -5. *)
518515 proc digits;
519-var p: Parser; w: []U8; ok: BOOL; n: INT;
516+var p: Parser; w: []const U8; ok: BOOL; n: INT;
520517 begin
521518 init(p, "digits", [
522519 usage("", "digits [-v] x y"),
@@ -550,7 +547,7 @@
550547 (* Subcommands of subcommands, no synopsis lines, and a -h of the
551548 program's own. *)
552549 proc plain;
553-var p: Parser; _w: []U8; _ok: BOOL;
550+var p: Parser; _w: []const U8; _ok: BOOL;
554551 begin
555552 init(p, "plain", [
556553 sub("", "remote", "the remotes"),
@@ -566,9 +563,9 @@
566563 end;
567564
568565 type Case = record
569- mode: []U8; (* OPTTEST=... *)
570- args: [][]U8;
571- out, err: []U8;
566+ mode: []const U8; (* OPTTEST=... *)
567+ args: [][]const U8;
568+ out, err: []const U8;
572569 status: INT;
573570 end;
574571
@@ -611,7 +608,7 @@
611608 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 --jobs n keep n jobs at most\n -h, --help print this and exit\n";
612609 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";
613610 k = "OPTTEST=keep";
614-var cases: []Case; i: INT; mode: []U8;
611+var cases: []Case; i: INT; mode: []const U8;
615612 begin
616613 mode := Sys.env("OPTTEST");
617614 if mode = "keep" then keep; return;

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

@@ -50,7 +50,7 @@
5050 end;
5151
5252 (* Writes the bytes of s. *)
53-proc str*(s: []U8);
53+proc str*(s: []const U8);
5454 var i: INT;
5555 begin
5656 Lock.take(lock);

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

@@ -54,7 +54,7 @@
5454 cand: Buf.Buf; (* a case to try: a shrink of best, or a saved one *)
5555 runs: INT; (* runs the shrink under way has made *)
5656 found: INT; (* bytes of the failing fresh case, before shrinking *)
57- name: []U8; (* the property being checked *)
57+ name: []const U8; (* the property being checked *)
5858 dir: Buf.Buf; (* where its cases are saved *)
5959 path: Buf.Buf; (* the file of a saved case *)
6060 seed: U64; (* the seed of the fresh cases *)
@@ -132,7 +132,7 @@
132132 end;
133133
134134 (* Makes s replay the case data; past its end, bytes are 0. *)
135-proc replay(var s: Source; data: []U8);
135+proc replay(var s: Source; data: []const U8);
136136 begin
137137 Buf.reset(s.data);
138138 Buf.str(s.data, data);
@@ -152,7 +152,7 @@
152152
153153 (* Runs p on data once more, with Check heard, so that it shows the
154154 failure and counts it. *)
155-proc aloud(p: Property; data: []U8);
155+proc aloud(p: Property; data: []const U8);
156156 begin
157157 Check.mute(false);
158158 replay(src, data);
@@ -161,7 +161,7 @@
161161
162162 (* Whether case a is simpler than b: shorter, or as long and smaller
163163 byte by byte. *)
164-proc simpler(a, b: []U8): BOOL;
164+proc simpler(a, b: []const U8): BOOL;
165165 begin
166166 return (LEN(a) < LEN(b)) or ((LEN(a) = LEN(b)) and (Str.cmp(a, b) < 0));
167167 end;
@@ -169,7 +169,7 @@
169169 (* Runs p on cand, within the budget; if it fails and the bytes it drew
170170 are simpler than best, they become best, and the result is true. *)
171171 proc improves(p: Property): BOOL;
172-var drawn: []U8;
172+var drawn: []const U8;
173173 begin
174174 if runs >= Budget then return false; end;
175175 INC(runs);
@@ -190,7 +190,7 @@
190190
191191 (* Makes cand best without its w bytes from i. *)
192192 proc without(i, w: INT);
193-var b: []U8;
193+var b: []const U8;
194194 begin
195195 b := Buf.bytes(best);
196196 Buf.reset(cand);
@@ -290,7 +290,7 @@
290290
291291 (* Stops the program: the environment variable called key is not a
292292 number, as it must be. *)
293-proc badEnv(key: []U8);
293+proc badEnv(key: []const U8);
294294 begin
295295 Fmt.eprint("Prop: ${} is not a whole number\n", [Fmt.str(key)]);
296296 Rt.exit(2);
@@ -298,7 +298,7 @@
298298
299299 (* The environment variable called key, a number from 0; otherwise
300300 unset, and 0. *)
301-proc envNumber(key: []U8): I64;
301+proc envNumber(key: []const U8): I64;
302302 var n: I64; ok: BOOL;
303303 begin
304304 if LEN(Sys.env(key)) = 0 then return 0; end;
@@ -355,7 +355,7 @@
355355 end;
356356
357357 (* Makes path the file called file in dir. *)
358-proc caseFile(file: []U8);
358+proc caseFile(file: []const U8);
359359 begin
360360 Buf.reset(path);
361361 Buf.str(path, Buf.bytes(dir));
@@ -366,8 +366,8 @@
366366 (* Saves data in dir, made with the directories it needs, in a file
367367 named by the hash of data, so that a case is saved once; whether it
368368 was written. path names the file. *)
369-proc save(data: []U8): BOOL;
370-var d: []U8; i: INT; h: [16]U8;
369+proc save(data: []const U8): BOOL;
370+var d: []const U8; i: INT; h: [16]U8;
371371 begin
372372 d := Buf.bytes(dir);
373373 for i := 1 to LEN(d) - 1 do
@@ -380,7 +380,7 @@
380380 end;
381381
382382 (* What became of a case save tried to save, for a message. *)
383-proc saved(ok: BOOL): []U8;
383+proc saved(ok: BOOL): []const U8;
384384 begin
385385 if ok then return "saved"; end;
386386 return "could not save";
@@ -389,7 +389,7 @@
389389 (* Runs each case saved in dir; if one fails, it is in cand, its file
390390 in path, and the result is true. *)
391391 proc savedFailing(p: Property): BOOL;
392-var d: Sys.Dir; file: []U8; more: BOOL;
392+var d: Sys.Dir; file: []const U8; more: BOOL;
393393 begin
394394 if Sys.openDir(d, Buf.bytes(dir)) < 0 then return false; end; (* none saved yet *)
395395 file, more := Sys.nextEntry(d);
@@ -420,8 +420,8 @@
420420
421421 (* Makes the buffers and registers crashed, the first time; then sets
422422 the property's name and directory. *)
423-proc prepare(n: []U8);
424-var root: []U8;
423+proc prepare(n: []const U8);
424+var root: []const U8;
425425 begin
426426 if not ready then
427427 Buf.init(src.data, Heap.heap);
@@ -443,7 +443,7 @@
443443
444444 (* Checks the property p, called name: the saved cases, then fresh
445445 ones; the first that fails is said, saved if fresh, and run aloud. *)
446-proc check*(name: []U8; p: Property);
446+proc check*(name: []const U8; p: Property);
447447 var ok: BOOL;
448448 begin
449449 prepare(name);

lib/Rt.raz (history) modified +15 -14

@@ -22,6 +22,7 @@
2222 handlers and no profiler. *)
2323 module Rt;
2424 import Sys;
25+import SYSTEM;
2526
2627 const
2728 Full*: ERROR = "too many procedures to run at exit"; (* atExit's *)
@@ -144,7 +145,7 @@
144145
145146 (* Stops the program: says msg, and then a line feed, on standard
146147 error, then ends it by exit with status 2, as a failed check does. *)
147-proc stop*(msg: []U8);
148+proc stop*(msg: []const U8);
148149 begin
149150 _ := Sys.write(Sys.stderr, msg);
150151 _ := Sys.write(Sys.stderr, "\n");
@@ -153,7 +154,7 @@
153154
154155 (* Messages, made in line, one byte kept for the line feed, and
155156 written by say in one piece *)
156-proc put(s: []U8);
157+proc put(s: []const U8);
157158 var i: INT;
158159 begin
159160 for i := 0 to LEN(s) - 1 do
@@ -408,7 +409,7 @@
408409 var a: ^U8; w: ^UINT; h: ^U16; s: ^U32; f: ^F32; d: ^F64; v: UINT; bits: INT;
409410 begin
410411 a := ^U8(bp) + INT(l^.off);
411- if l^.kind shr 9 # 0 then a := ^U8(ADR(regs[INT(l^.kind shr 9) - 1])); end;
412+ if l^.kind shr 9 # 0 then a := ^U8(SYSTEM.ADR(regs[INT(l^.kind shr 9) - 1])); end;
412413 w := ^UINT(a);
413414 if l^.kind & 256 # 0 then a := ^U8(w^); w := ^UINT(a); end;
414415 h := ^U16(a); s := ^U32(a); f := ^F32(a); d := ^F64(a);
@@ -486,7 +487,7 @@
486487 begin
487488 (* the registers as they are, then as each frame from this one out
488489 to bp's found them *)
489- liveRegs(ADR(regs[0]));
490+ liveRegs(SYSTEM.ADR(regs[0]));
490491 x := framePtr();
491492 xip := here();
492493 while (x # bp) and (x & 7 = 0) and (x # 0) do
@@ -613,7 +614,7 @@
613614 error, then ends the program by exit with status 2, as a failed
614615 check does. info and ctx are the kernel's siginfo and ucontext. *)
615616 proc onSignal(sig: INT; info, ctx: ^U8);
616-var adr, sp, ip, bp: UINT; q: ^UINT; why: []U8;
617+var adr, sp, ip, bp: UINT; q: ^UINT; why: []const U8;
617618 begin
618619 q := ^UINT(ctx + 104); (* uc_mcontext's rdi, then rsi, then rbp *)
619620 regs[5] := q[0];
@@ -655,7 +656,7 @@
655656 proc onProf(_sig: INT; _info, ctx: ^U8);
656657 var n, k: INT; q, f, row: ^UINT; ip, bp: UINT;
657658 begin
658- n := XADD(ADR(numSamples), 1);
659+ n := XADD(numSamples, 1);
659660 if n >= MaxSamples then return; end;
660661 q := ^UINT(ctx + 120); (* uc_mcontext's rbp *)
661662 bp := q^;
@@ -707,7 +708,7 @@
707708
708709 (* Says the ten that took most of count's n samples, by name, with
709710 their totals beside them if total isn't empty *)
710-proc top(count, total: []INT; n: INT; byPlace: BOOL);
711+proc top(count: []INT; total: []const INT; n: INT; byPlace: BOOL);
711712 var i, k, best: INT; p: ^Proc; r: Row;
712713 begin
713714 p := ^Proc(places + 5);
@@ -739,9 +740,9 @@
739740 chains := ^UINT(Sys.mmap(MaxSamples * Depth * SIZE(UINT)));
740741 if chains = nil then return; end;
741742 act := {handler: onProf, flags: ProfFlags, restorer: sigReturn};
742- _ := SYSCALL(13, SigProf, ADR(act), 0, 8);
743+ _ := SYSTEM.SYSCALL(13, SigProf, SYSTEM.ADR(act), 0, 8);
743744 timerv := [0, 1000, 0, 1000]; (* every millisecond, from one on *)
744- _ := SYSCALL(38, 2, ADR(timerv), 0); (* setitimer(ITIMER_PROF) *)
745+ _ := SYSTEM.SYSCALL(38, 2, SYSTEM.ADR(timerv), 0); (* setitimer(ITIMER_PROF) *)
745746 _ := atExit(profile);
746747 end;
747748
@@ -751,7 +752,7 @@
751752 var t: [4]INT; i, n, k, j, m, s: INT; seen: [Depth + 1]INT; row: ^UINT;
752753 begin
753754 t := [0, 0, 0, 0];
754- _ := SYSCALL(38, 2, ADR(t), 0); (* setitimer(ITIMER_PROF): no more *)
755+ _ := SYSTEM.SYSCALL(38, 2, SYSTEM.ADR(t), 0); (* setitimer(ITIMER_PROF): no more *)
755756 n := numSamples;
756757 if n > MaxSamples then n := MaxSamples; end;
757758 if (places = nil) or (n = 0) then return; end;
@@ -787,10 +788,10 @@
787788 end;
788789
789790 begin
790- alt := {sp: ADR(altStack[0]), size: LEN(altStack)};
791- _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
791+ alt := {sp: SYSTEM.ADR(altStack[0]), size: LEN(altStack)};
792+ _ := SYSTEM.SYSCALL(131, SYSTEM.ADR(alt), 0); (* sigaltstack *)
792793 act := {handler: onSignal, flags: Flags, restorer: sigReturn};
793- _ := SYSCALL(13, SigSegv, ADR(act), 0, 8); (* rt_sigaction *)
794- _ := SYSCALL(13, SigFpe, ADR(act), 0, 8);
794+ _ := SYSTEM.SYSCALL(13, SigSegv, SYSTEM.ADR(act), 0, 8); (* rt_sigaction *)
795+ _ := SYSTEM.SYSCALL(13, SigFpe, SYSTEM.ADR(act), 0, 8);
795796 if profiler # nil then profiler(); end;
796797 end Rt.

lib/Str.raz (history) modified +50 -49

@@ -1,4 +1,4 @@
1-(* Operations on strings, which are []U8. = and # compare them; this
1+(* Operations on strings, which are []const U8. = and # compare them; this
22 module orders, searches and hashes them, trims them and takes them
33 apart, tells an ASCII character's kind and changes a letter's case,
44 joins them and replaces in them, reads and writes their UTF-8, reads
@@ -7,17 +7,18 @@
77 own. *)
88 module Str;
99 import Mem, Heap, Rt, Bytes, Buf;
10+import SYSTEM;
1011
1112 const least = -9223372036854775807 - 1; (* the smallest I64 *)
1213
1314 (* s's bytes, copied into memory from a, to keep after s's own are
1415 gone; "" and false if a has no room. *)
15-proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL);
16+proc copy*(a: ^Mem.Allocator; s: []const U8): ([]U8, BOOL);
1617 var p: ^U8;
1718 begin
18- if LEN(s) = 0 then return "", true; end;
19+ if LEN(s) = 0 then return [], true; end;
1920 p := Mem.alloc(a, LEN(s), 1);
20- if p = nil then return "", false; end;
21+ if p = nil then return [], false; end;
2122 COPY(p[0..LEN(s)], s);
2223 return p[0..LEN(s)], true;
2324 end;
@@ -26,11 +27,11 @@
2627 for an empty string, was never a's, and is left alone. *)
2728 proc free*(a: ^Mem.Allocator; s: []U8);
2829 begin
29- if LEN(s) > 0 then Mem.free(a, ADR(s[0])); end;
30+ if LEN(s) > 0 then Mem.free(a, SYSTEM.ADR(s[0])); end;
3031 end;
3132
3233 (* -1, 0 or 1 as a sorts before, with or after b, byte by byte. *)
33-proc cmp*(a, b: []U8): INT;
34+proc cmp*(a, b: []const U8): INT;
3435 var i, n: INT;
3536 begin
3637 n := LEN(a);
@@ -47,7 +48,7 @@
4748 end;
4849
4950 (* Whether a and b hold the same bytes: a = b, as a procedure value. *)
50-proc eq*(a, b: []U8): BOOL;
51+proc eq*(a, b: []const U8): BOOL;
5152 begin
5253 return a = b;
5354 end;
@@ -60,7 +61,7 @@
6061 end;
6162
6263 (* Whether a and b are the same but for the case of ASCII letters. *)
63-proc eqFold*(a, b: []U8): BOOL;
64+proc eqFold*(a, b: []const U8): BOOL;
6465 var i: INT;
6566 begin
6667 if LEN(a) # LEN(b) then return false; end;
@@ -71,7 +72,7 @@
7172 end;
7273
7374 (* FNV-1a, 64 bits. *)
74-proc hash*(s: []U8): U64;
75+proc hash*(s: []const U8): U64;
7576 var h: U64; i: INT;
7677 begin
7778 h := 0CBF29CE484222325H;
@@ -82,14 +83,14 @@
8283 end;
8384
8485 (* Where sub first starts in s, or -1. *)
85-proc find*(s, sub: []U8): INT;
86+proc find*(s, sub: []const U8): INT;
8687 begin
8788 return Bytes.find(s, sub);
8889 end;
8990
9091 (* Where sub first starts in s at or after from, or -1; from is at
9192 most LEN(s). *)
92-proc findFrom*(s, sub: []U8; from: INT): INT;
93+proc findFrom*(s, sub: []const U8; from: INT): INT;
9394 var i: INT;
9495 begin
9596 i := Bytes.find(s[from..LEN(s)], sub);
@@ -98,7 +99,7 @@
9899 end;
99100
100101 (* Where sub last starts in s, or -1. *)
101-proc findLast*(s, sub: []U8): INT;
102+proc findLast*(s, sub: []const U8): INT;
102103 var i: INT;
103104 begin
104105 for i := LEN(s) - LEN(sub) to 0 by -1 do
@@ -108,13 +109,13 @@
108109 end;
109110
110111 (* Whether s starts with p. *)
111-proc hasPrefix*(s, p: []U8): BOOL;
112+proc hasPrefix*(s, p: []const U8): BOOL;
112113 begin
113114 return (LEN(s) >= LEN(p)) and (s[0..LEN(p)] = p);
114115 end;
115116
116117 (* Whether s ends with x. *)
117-proc hasSuffix*(s, x: []U8): BOOL;
118+proc hasSuffix*(s, x: []const U8): BOOL;
118119 begin
119120 return (LEN(s) >= LEN(x)) and (s[LEN(s) - LEN(x)..LEN(s)] = x);
120121 end;
@@ -157,7 +158,7 @@
157158 end;
158159
159160 (* s without the spaces at its start. *)
160-proc trimLeft*(s: []U8): []U8;
161+proc trimLeft*(s: []const U8): []const U8;
161162 var i: INT;
162163 begin
163164 i := 0;
@@ -166,7 +167,7 @@
166167 end;
167168
168169 (* s without the spaces at its end. *)
169-proc trimRight*(s: []U8): []U8;
170+proc trimRight*(s: []const U8): []const U8;
170171 var n: INT;
171172 begin
172173 n := LEN(s);
@@ -175,14 +176,14 @@
175176 end;
176177
177178 (* s without the spaces at either end. *)
178-proc trim*(s: []U8): []U8;
179+proc trim*(s: []const U8): []const U8;
179180 begin
180181 return trimRight(trimLeft(s));
181182 end;
182183
183184 (* What comes before the first sep in s, what comes after it, and true;
184185 or s, an empty string and false if s has no sep. *)
185-proc cut*(s, sep: []U8): ([]U8, []U8, BOOL);
186+proc cut*(s, sep: []const U8): ([]const U8, []const U8, BOOL);
186187 var i: INT;
187188 begin
188189 i := find(s, sep);
@@ -193,7 +194,7 @@
193194 (* The first word of s, the bytes after the spaces at its start up to
194195 the next space or the end, and the rest of s from there; two empty
195196 strings if s holds only spaces. *)
196-proc field*(s: []U8): ([]U8, []U8);
197+proc field*(s: []const U8): ([]const U8, []const U8);
197198 var i: INT;
198199 begin
199200 s := trimLeft(s);
@@ -219,7 +220,7 @@
219220 end;
220221
221222 (* The parts added to b, with sep between each two. *)
222-proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8);
223+proc join*(var b: Buf.Buf; parts: [][]const U8; sep: []const U8);
223224 var i: INT;
224225 begin
225226 for i := 0 to LEN(parts) - 1 do
@@ -230,7 +231,7 @@
230231
231232 (* s added to b, with new for each old in it, from the left, none
232233 overlapping another; s as it is if old is empty. *)
233-proc replace*(var b: Buf.Buf; s, old, new: []U8);
234+proc replace*(var b: Buf.Buf; s, old, new: []const U8);
234235 var i: INT;
235236 begin
236237 i := -1;
@@ -275,7 +276,7 @@
275276 if its first byte doesn't start one rightly, being a continuation,
276277 or followed by too few continuations, or spelling a surrogate or a
277278 character in more bytes than it needs; 0 and 0 if s is empty. *)
278-proc decode*(s: []U8): (I32, INT);
279+proc decode*(s: []const U8): (I32, INT);
279280 var c, least: I32; n, i: INT;
280281 begin
281282 if LEN(s) = 0 then return 0, 0; end;
@@ -299,7 +300,7 @@
299300 (* The character s ends with, and its length in bytes, read as decode
300301 reads one: FFFDH and 1 if the last byte doesn't end one rightly; 0
301302 and 0 if s is empty. *)
302-proc decodeLast*(s: []U8): (I32, INT);
303+proc decodeLast*(s: []const U8): (I32, INT);
303304 var c: I32; i, n: INT;
304305 begin
305306 if LEN(s) = 0 then return 0, 0; end;
@@ -313,7 +314,7 @@
313314
314315 (* The character at i in s, as decode reads it, and where the one after
315316 it starts; 0 and -1 if i is at the end or past it. *)
316-proc next*(s: []U8; i: INT): (I32, INT);
317+proc next*(s: []const U8; i: INT): (I32, INT);
317318 var c: I32; n: INT;
318319 begin
319320 if i >= LEN(s) then return 0, -1; end;
@@ -323,7 +324,7 @@
323324
324325 (* The characters in s, as decode reads them, each byte that doesn't
325326 start one rightly counted as one. *)
326-proc chars*(s: []U8): INT;
327+proc chars*(s: []const U8): INT;
327328 var i, n: INT;
328329 begin
329330 _, i := next(s, 0);
@@ -336,7 +337,7 @@
336337
337338 (* Whether s is UTF-8: decode finds no byte that doesn't start a
338339 character rightly. *)
339-proc valid*(s: []U8): BOOL;
340+proc valid*(s: []const U8): BOOL;
340341 var c: I32; i, n: INT;
341342 begin
342343 while i < LEN(s) do
@@ -349,7 +350,7 @@
349350
350351 (* s as a decimal number, with a - or + before it if any, and nothing
351352 else; false if it isn't one, or an I64 can't hold it. *)
352-proc toInt*(s: []U8): (I64, BOOL);
353+proc toInt*(s: []const U8): (I64, BOOL);
353354 var n, d: I64; i: INT; neg: BOOL;
354355 begin
355356 neg := (LEN(s) > 0) and (s[0] = '-');
@@ -372,7 +373,7 @@
372373
373374 (* s in hexadecimal, digits only, capitals or not; false if it isn't
374375 that, or a U64 can't hold it. *)
375-proc toHex*(s: []U8): (U64, BOOL);
376+proc toHex*(s: []const U8): (U64, BOOL);
376377 var v: U64; d, i: INT;
377378 begin
378379 if LEN(s) = 0 then return 0, false; end;
@@ -402,7 +403,7 @@
402403 does. alphabet holds the 64 digits (Base64 or Base64Url, or one's
403404 own). A last group of 1 or 2 bytes is padded with = to four if pad,
404405 and else has 2 or 3 digits. The bytes written. *)
405-proc base64With*(s, out, alphabet: []U8; pad: BOOL): INT;
406+proc base64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): INT;
406407 var i, k, v, left: INT;
407408 begin
408409 k := 0;
@@ -436,13 +437,13 @@
436437
437438 (* s in base64 (RFC 4648, section 4), padded, into out as base64With
438439 writes it. *)
439-proc base64*(s, out: []U8): INT;
440+proc base64*(s: []const U8; out: []U8): INT;
440441 begin
441442 return base64With(s, out, Base64, true);
442443 end;
443444
444445 (* c's value as a digit of alphabet, 0 to 63, or -1 if it isn't one; = is -1. *)
445-proc base64Val(c: U8; alphabet: []U8): INT;
446+proc base64Val(c: U8; alphabet: []const U8): INT;
446447 var i: INT;
447448 begin
448449 for i := 0 to 63 do
@@ -454,7 +455,7 @@
454455 (* The last 2 or 3 digits of an unpadded s, at s, decoded into out:
455456 the bytes written, 1 or 2; or -1 if a digit isn't one, or the bits
456457 that no byte uses aren't 0. *)
457-proc unbase64Tail(s, out, alphabet: []U8): INT;
458+proc unbase64Tail(s: []const U8; out: []U8; alphabet: []const U8): INT;
458459 var a, b, c: INT;
459460 begin
460461 a := base64Val(s[0], alphabet);
@@ -483,7 +484,7 @@
483484 uses are 0, so a byte string has the one spelling that base64 gives
484485 it (RFC 4648, section 3.5 allows a decoder to take that). Line
485486 breaks, and padding or its lack, are the caller's to mend first. *)
486-proc unbase64With*(s, out, alphabet: []U8; pad: BOOL): (INT, BOOL);
487+proc unbase64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): (INT, BOOL);
487488 var i, k, a, b, c, d, v, whole, n: INT; last: BOOL;
488489 begin
489490 whole := LEN(s); (* the bytes in groups of 4 *)
@@ -532,14 +533,14 @@
532533
533534 (* s, base64 (RFC 4648, section 4), padded, decoded into out as
534535 unbase64With reads it; out holds LEN(s) div 4 * 3 bytes at least. *)
535-proc unbase64*(s, out: []U8): (INT, BOOL);
536+proc unbase64*(s: []const U8; out: []U8): (INT, BOOL);
536537 begin
537538 return unbase64With(s, out, Base64, true);
538539 end;
539540
540541 (* s as a decimal number, digits only; false if it isn't one, or a U64
541542 can't hold it. *)
542-proc toU64*(s: []U8): (U64, BOOL);
543+proc toU64*(s: []const U8): (U64, BOOL);
543544 var v, d: U64; i: INT;
544545 begin
545546 if LEN(s) = 0 then return 0, false; end;
@@ -553,7 +554,7 @@
553554 end;
554555
555556 (* The bytes at p up to its zero byte, not copied; "" for nil. *)
556-proc fromC*(p: ^U8): []U8;
557+proc fromC*(p: ^U8): []const U8;
557558 var n: INT;
558559 begin
559560 if p = nil then return ""; end;
@@ -563,13 +564,13 @@
563564
564565 (* s copied into out with a zero byte after it, for C: out holds
565566 LEN(s) + 1 bytes at least, or the program stops at the byte it
566- lacks, as any slice does. The pointer C is given, PTR(out). *)
567-proc toC*(s, out: []U8): ^U8;
567+ lacks, as any slice does. The pointer C is given, SYSTEM.PTR(out). *)
568+proc toC*(s: []const U8; out: []U8): ^U8;
568569 var i: INT;
569570 begin
570571 for i := 0 to LEN(s) - 1 do out[i] := s[i]; end;
571572 out[LEN(s)] := 0;
572- return PTR(out);
573+ return SYSTEM.PTR(out);
573574 end;
574575
575576 (* n in decimal, as Out.int writes it: its bytes, the first of the 20,
@@ -593,7 +594,7 @@
593594 (* The bytes of s, at most 8, as an unsigned number, the first byte
594595 the lowest: how a file or a message in little-endian order is read,
595596 whatever the machine's own order. *)
596-proc le*(s: []U8): U64;
597+proc le*(s: []const U8): U64;
597598 var v: U64; i: INT;
598599 begin
599600 if LEN(s) > 8 then Rt.stop("Str.le: more than 8 bytes"); end;
@@ -602,7 +603,7 @@
602603 end;
603604
604605 (* As le, the first byte the highest: big-endian, network order. *)
605-proc be*(s: []U8): U64;
606+proc be*(s: []const U8): U64;
606607 var v: U64; i: INT;
607608 begin
608609 if LEN(s) > 8 then Rt.stop("Str.be: more than 8 bytes"); end;
@@ -708,7 +709,7 @@
708709 end;
709710
710711 proc testParts;
711-var b: Buf.Buf; w, rest, k, v: []U8; ok: BOOL; up: [5]U8;
712+var b: Buf.Buf; w, rest, k, v: []const U8; ok: BOOL; up: [5]U8;
712713 begin
713714 if not eqFold("Hello", "hELLO") or eqFold("a", "b") or eqFold("a", "ab") or not eqFold("", "")
714715 or eqFold("@", "`") then Rt.stop("Str.eqFold"); end;
@@ -834,18 +835,18 @@
834835 begin
835836 if LEN(fromC(nil)) # 0 then Rt.stop("Str.fromC: nil"); end;
836837 c := "abc\x00";
837- if fromC(ADR(c[0])) # "abc" then Rt.stop("Str.fromC: abc"); end;
838+ if fromC(SYSTEM.ADR(c[0])) # "abc" then Rt.stop("Str.fromC: abc"); end;
838839 c[0] := 0;
839- if LEN(fromC(ADR(c[0]))) # 0 then Rt.stop("Str.fromC: empty"); end;
840+ if LEN(fromC(SYSTEM.ADR(c[0]))) # 0 then Rt.stop("Str.fromC: empty"); end;
840841 room := "xxxx";
841842 p := toC("abc", room);
842- if (p # ADR(room[0])) or (room[0..3] # "abc") or (room[3] # 0) then Rt.stop("Str.toC: abc"); end;
843+ if (p # SYSTEM.ADR(room[0])) or (room[0..3] # "abc") or (room[3] # 0) then Rt.stop("Str.toC: abc"); end;
843844 p := toC("", room);
844845 if room[0] # 0 then Rt.stop("Str.toC: empty"); end;
845846 end;
846847
847848 (* One of the RFC 4648 section 10 vectors: plain codes to coded and back. *)
848-proc testVector(plain, coded: []U8);
849+proc testVector(plain, coded: []const U8);
849850 var buf: [16]U8; n: INT; ok: BOOL;
850851 begin
851852 if base64Size(LEN(plain)) # LEN(coded) then Rt.stop("Str.base64Size"); end;
@@ -856,7 +857,7 @@
856857 end;
857858
858859 (* s must not decode. *)
859-proc testBad(s: []U8);
860+proc testBad(s: []const U8);
860861 var buf: [16]U8; ok: BOOL;
861862 begin
862863 _, ok := unbase64(s, buf[0..LEN(s) div 4 * 3]);
@@ -878,7 +879,7 @@
878879
879880 (* plain in the other alphabet and unpadded, and back; in the padded
880881 form too, with the - and _ of base64url. *)
881-proc testUrlVector(plain, bare, padded: []U8);
882+proc testUrlVector(plain, bare, padded: []const U8);
882883 var buf: [16]U8; n: INT; ok: BOOL;
883884 begin
884885 n := base64With(plain, buf[0..base64Size(LEN(plain))], Base64Url, false);
@@ -892,7 +893,7 @@
892893 end;
893894
894895 (* s must not decode, unpadded, in base64url's alphabet. *)
895-proc testUrlBad(s: []U8);
896+proc testUrlBad(s: []const U8);
896897 var buf: [16]U8; ok: BOOL;
897898 begin
898899 _, ok := unbase64With(s, buf[0..(LEN(s) + 3) div 4 * 3], Base64Url, false);

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

@@ -1,6 +1,7 @@
11 (* System calls on Linux for x86-64. Other targets supply their own
22 Sys, with the same exports. *)
33 module Sys;
4+import SYSTEM;
45
56 const
67 stdin* = 0; (* standard input's file descriptor *)
@@ -85,11 +86,11 @@
8586
8687 (* A program for spawn to start. *)
8788 Program* = record
88- path*: []U8;
89- args*: [][]U8; (* the first is its name *)
90- env*: [][]U8; (* NAME=value, each added to this environment *)
89+ path*: []const U8;
90+ args*: [][]const U8; (* the first is its name *)
91+ env*: [][]const U8; (* NAME=value, each added to this environment *)
9192 onlyEnv*: BOOL; (* env is its whole environment *)
92- dir*: []U8; (* its working directory; "" for this program's *)
93+ dir*: []const U8; (* its working directory; "" for this program's *)
9394 fds*: [3]INT; (* stdin, stdout, stderr; 0 for this program's *)
9495 group*: INT; (* its group: 0 for this program's, -1 a new one *)
9596 foreground*: BOOL; (* its group gets the terminal on standard input *)
@@ -183,10 +184,10 @@
183184
184185 (* Writes s to the file descriptor fd; the number of bytes written, or
185186 minus an errno. *)
186-proc write*(fd: INT; s: []U8): INT;
187+proc write*(fd: INT; s: []const U8): INT;
187188 begin
188189 if LEN(s) = 0 then return 0; end;
189- return SYSCALL(1, fd, ADR(s[0]), LEN(s));
190+ return SYSTEM.SYSCALL(1, fd, SYSTEM.PTR(s), LEN(s));
190191 end;
191192
192193 (* Reads into buf from fd; the number of bytes read, 0 at the end, or
@@ -194,11 +195,11 @@
194195 proc read*(fd: INT; buf: []U8): INT;
195196 begin
196197 if LEN(buf) = 0 then return 0; end;
197- return SYSCALL(0, fd, ADR(buf[0]), LEN(buf));
198+ return SYSTEM.SYSCALL(0, fd, SYSTEM.ADR(buf[0]), LEN(buf));
198199 end;
199200
200201 (* path, a C string in buf, or false if it doesn't fit. *)
201-proc cstr(path, buf: []U8): BOOL;
202+proc cstr(path: []const U8; buf: []U8): BOOL;
202203 begin
203204 if LEN(path) >= LEN(buf) then return false; end;
204205 COPY(buf, path);
@@ -226,31 +227,31 @@
226227 (* The file at path, opened as how asks: its file descriptor, closed in
227228 a program exec starts, or minus an errno. A file it creates has the
228229 permission bits mode, less those the umask takes away. *)
229-proc openMode*(path: []U8; how: Accesses; mode: INT): INT;
230+proc openMode*(path: []const U8; how: Accesses; mode: INT): INT;
230231 var buf: [4096]U8;
231232 begin
232233 if executing in how then return -22; end; (* EINVAL: access asks it, open can't *)
233234 if not cstr(path, buf) then return -36; end; (* ENAMETOOLONG *)
234- return SYSCALL(2, ADR(buf), flags(how), mode);
235+ return SYSTEM.SYSCALL(2, SYSTEM.ADR(buf), flags(how), mode);
235236 end;
236237
237238 (* openMode with 644: a file it creates is readable by all, writable
238239 by its owner. *)
239-proc open*(path: []U8; how: Accesses): INT;
240+proc open*(path: []const U8; how: Accesses): INT;
240241 begin
241242 return openMode(path, how, 1A4H); (* 644 *)
242243 end;
243244
244245 (* The file at path, opened for reading, closed in a program exec
245246 starts. *)
246-proc openRead*(path: []U8): INT;
247+proc openRead*(path: []const U8): INT;
247248 begin
248249 return open(path, {reading});
249250 end;
250251
251252 (* The file at path, made empty or new, opened for writing, closed in a
252253 program exec starts. *)
253-proc create*(path: []U8): INT;
254+proc create*(path: []const U8): INT;
254255 begin
255256 return open(path, {writing, creating, truncating});
256257 end;
@@ -259,29 +260,29 @@
259260 fromEnd: the new position, or minus an errno. *)
260261 proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64;
261262 begin
262- if fromEnd then return SYSCALL(8, fd, pos, 2); end; (* lseek, SEEK_END *)
263- return SYSCALL(8, fd, pos, 0); (* SEEK_SET *)
263+ if fromEnd then return SYSTEM.SYSCALL(8, fd, pos, 2); end; (* lseek, SEEK_END *)
264+ return SYSTEM.SYSCALL(8, fd, pos, 0); (* SEEK_SET *)
264265 end;
265266
266267 (* Where in its file fd is, without moving: the next read or write's
267268 position, or minus an errno. *)
268269 proc position*(fd: INT): I64;
269270 begin
270- return SYSCALL(8, fd, 0, 1); (* lseek, SEEK_CUR *)
271+ return SYSTEM.SYSCALL(8, fd, 0, 1); (* lseek, SEEK_CUR *)
271272 end;
272273
273274 (* The file fd makes size bytes long, cut or filled with zeros; its
274275 position stays. 0, or minus an errno. *)
275276 proc truncate*(fd: INT; size: I64): INT;
276277 begin
277- return SYSCALL(77, fd, size); (* ftruncate *)
278+ return SYSTEM.SYSCALL(77, fd, size); (* ftruncate *)
278279 end;
279280
280281 (* Returns once what was written to fd is on the disk: 0, or minus an
281282 errno. *)
282283 proc sync*(fd: INT): INT;
283284 begin
284- return SYSCALL(74, fd); (* fsync *)
285+ return SYSTEM.SYSCALL(74, fd); (* fsync *)
285286 end;
286287
287288 (* Returns once everything written to the file system that holds fd
@@ -289,7 +290,7 @@
289290 minus an errno. *)
290291 proc syncAll*(fd: INT): INT;
291292 begin
292- return SYSCALL(306, fd); (* syncfs *)
293+ return SYSTEM.SYSCALL(306, fd); (* syncfs *)
293294 end;
294295
295296 (* Takes the lock on the open file fd, which only one program holds at
@@ -298,8 +299,8 @@
298299 and otherwise returns -11 (EAGAIN). 0, or minus an errno. *)
299300 proc lock*(fd: INT; wait: BOOL): INT;
300301 begin
301- if wait then return SYSCALL(73, fd, 2); end; (* flock, LOCK_EX *)
302- return SYSCALL(73, fd, 2 | 4); (* LOCK_EX | LOCK_NB *)
302+ if wait then return SYSTEM.SYSCALL(73, fd, 2); end; (* flock, LOCK_EX *)
303+ return SYSTEM.SYSCALL(73, fd, 2 | 4); (* LOCK_EX | LOCK_NB *)
303304 end;
304305
305306 (* Takes the lock on the open file fd as lock does, but shared: any
@@ -307,14 +308,14 @@
307308 holds it as lock takes it. 0, or minus an errno. *)
308309 proc lockShared*(fd: INT; wait: BOOL): INT;
309310 begin
310- if wait then return SYSCALL(73, fd, 1); end; (* flock, LOCK_SH *)
311- return SYSCALL(73, fd, 1 | 4); (* LOCK_SH | LOCK_NB *)
311+ if wait then return SYSTEM.SYSCALL(73, fd, 1); end; (* flock, LOCK_SH *)
312+ return SYSTEM.SYSCALL(73, fd, 1 | 4); (* LOCK_SH | LOCK_NB *)
312313 end;
313314
314315 (* Closes the file descriptor fd. *)
315316 proc close*(fd: INT);
316317 begin
317- _ := SYSCALL(3, fd);
318+ _ := SYSTEM.SYSCALL(3, fd);
318319 end;
319320
320321 (* Closes the file descriptor fd, as close does, and says whether that
@@ -325,21 +326,21 @@
325326 closed again, after -4 (EINTR) too. *)
326327 proc closeChecked*(fd: INT): INT;
327328 begin
328- return SYSCALL(3, fd);
329+ return SYSTEM.SYSCALL(3, fd);
329330 end;
330331
331332 (* A new file descriptor for the file fd is open on, the lowest free:
332333 it, or minus an errno. *)
333334 proc dup*(fd: INT): INT;
334335 begin
335- return SYSCALL(32, fd); (* dup *)
336+ return SYSTEM.SYSCALL(32, fd); (* dup *)
336337 end;
337338
338339 (* Makes the file descriptor into stand for the file fd is open on,
339340 closing what into was first: into, or minus an errno. *)
340341 proc dupTo*(fd, into: INT): INT;
341342 begin
342- return SYSCALL(33, fd, into); (* dup2 *)
343+ return SYSTEM.SYSCALL(33, fd, into); (* dup2 *)
343344 end;
344345
345346 (* A new file descriptor for the file fd is open on, the lowest free
@@ -348,7 +349,7 @@
348349 names. *)
349350 proc dupAbove*(fd, least: INT): INT;
350351 begin
351- return SYSCALL(72, fd, 1030, least); (* fcntl: F_DUPFD_CLOEXEC *)
352+ return SYSTEM.SYSCALL(72, fd, 1030, least); (* fcntl: F_DUPFD_CLOEXEC *)
352353 end;
353354
354355 (* Whether fd stays open in the program exec runs in this one's place:
@@ -358,10 +359,10 @@
358359 proc keepOnExec*(fd: INT; yes: BOOL): INT;
359360 var f: INT;
360361 begin
361- f := SYSCALL(72, fd, 1); (* fcntl: F_GETFD *)
362+ f := SYSTEM.SYSCALL(72, fd, 1); (* fcntl: F_GETFD *)
362363 if f < 0 then return f; end;
363364 if yes then f := f & ~1; else f := f | 1; end; (* FD_CLOEXEC *)
364- return SYSCALL(72, fd, 2, f); (* F_SETFD *)
365+ return SYSTEM.SYSCALL(72, fd, 2, f); (* F_SETFD *)
365366 end;
366367
367368 (* size bytes of fresh, zeroed memory from the system, a multiple of
@@ -369,7 +370,7 @@
369370 proc mmap*(size: INT): ^U8;
370371 var p: INT;
371372 begin
372- p := SYSCALL(9, 0, size, 3, 22H, -1, 0); (* read, write; private, anonymous *)
373+ p := SYSTEM.SYSCALL(9, 0, size, 3, 22H, -1, 0); (* read, write; private, anonymous *)
373374 if p < 0 then return nil; end;
374375 return ^U8(p);
375376 end;
@@ -377,7 +378,7 @@
377378 (* Gives back to the system the size bytes at p that mmap gave. *)
378379 proc munmap*(p: ^U8; size: INT);
379380 begin
380- _ := SYSCALL(11, p, size);
381+ _ := SYSTEM.SYSCALL(11, p, size);
381382 end;
382383
383384 (* A file in memory, with no name, of size zeroed bytes: its fd, or
@@ -386,9 +387,9 @@
386387 var name: [4]U8; fd, r: INT;
387388 begin
388389 _ := cstr("raz", name); (* the name /proc shows *)
389- fd := SYSCALL(319, ADR(name[0]), 1); (* memfd_create, MFD_CLOEXEC *)
390+ fd := SYSTEM.SYSCALL(319, SYSTEM.ADR(name[0]), 1); (* memfd_create, MFD_CLOEXEC *)
390391 if fd < 0 then return fd; end;
391- r := SYSCALL(77, fd, size); (* ftruncate *)
392+ r := SYSTEM.SYSCALL(77, fd, size); (* ftruncate *)
392393 if r < 0 then close(fd); return r; end;
393394 return fd;
394395 end;
@@ -399,7 +400,7 @@
399400 proc mapFile*(fd, size: INT): ^U8;
400401 var p: INT;
401402 begin
402- p := SYSCALL(9, 0, size, 3, 1, fd, 0); (* mmap: read, write; MAP_SHARED *)
403+ p := SYSTEM.SYSCALL(9, 0, size, 3, 1, fd, 0); (* mmap: read, write; MAP_SHARED *)
403404 if p < 0 then return nil; end;
404405 return ^U8(p);
405406 end;
@@ -410,7 +411,7 @@
410411 proc mapRead*(fd, size: INT): ^U8;
411412 var p: INT;
412413 begin
413- p := SYSCALL(9, 0, size, 1, 2, fd, 0); (* mmap: read; MAP_PRIVATE *)
414+ p := SYSTEM.SYSCALL(9, 0, size, 1, 2, fd, 0); (* mmap: read; MAP_PRIVATE *)
414415 if p < 0 then return nil; end;
415416 return ^U8(p);
416417 end;
@@ -424,7 +425,7 @@
424425 prot := 0; (* PROT_NONE *)
425426 if read then prot := 1; end;
426427 if write then prot := prot | 2; end;
427- return SYSCALL(10, p, size, prot); (* mprotect *)
428+ return SYSTEM.SYSCALL(10, p, size, prot); (* mprotect *)
428429 end;
429430
430431 (* Whether the file descriptor fd is a terminal: whether it has a
@@ -432,85 +433,85 @@
432433 proc isTerminal*(fd: INT): BOOL;
433434 var t: [8]INT; (* struct termios: 60 bytes *)
434435 begin
435- return SYSCALL(16, fd, 5401H, ADR(t)) = 0;
436+ return SYSTEM.SYSCALL(16, fd, 5401H, SYSTEM.ADR(t)) = 0;
436437 end;
437438
438439 (* Renames old to new, replacing what new names: 0, or minus an errno. *)
439-proc rename*(old, new: []U8): INT;
440+proc rename*(old, new: []const U8): INT;
440441 var a, b: [4096]U8;
441442 begin
442443 if not cstr(old, a) or not cstr(new, b) then return -36; end;
443- return SYSCALL(82, ADR(a), ADR(b));
444+ return SYSTEM.SYSCALL(82, SYSTEM.ADR(a), SYSTEM.ADR(b));
444445 end;
445446
446447 (* Removes the file at path; not a directory. *)
447-proc remove*(path: []U8): INT;
448+proc remove*(path: []const U8): INT;
448449 var a: [4096]U8;
449450 begin
450451 if not cstr(path, a) then return -36; end;
451- return SYSCALL(87, ADR(a)); (* unlink *)
452+ return SYSTEM.SYSCALL(87, SYSTEM.ADR(a)); (* unlink *)
452453 end;
453454
454455 (* Makes a directory at path, readable by all, writable by its owner. *)
455-proc makeDir*(path: []U8): INT;
456+proc makeDir*(path: []const U8): INT;
456457 var a: [4096]U8;
457458 begin
458459 if not cstr(path, a) then return -36; end;
459- return SYSCALL(83, ADR(a), 1EDH); (* mkdir, mode 755 *)
460+ return SYSTEM.SYSCALL(83, SYSTEM.ADR(a), 1EDH); (* mkdir, mode 755 *)
460461 end;
461462
462463 (* Makes a directory at path with the permission bits mode, less those
463464 the umask takes away: 1C0H (700) for one only its owner may enter. Of
464465 the bits above them Linux keeps only sticky, 200H. *)
465-proc makeDirMode*(path: []U8; mode: INT): INT;
466+proc makeDirMode*(path: []const U8; mode: INT): INT;
466467 var a: [4096]U8;
467468 begin
468469 if not cstr(path, a) then return -36; end;
469- return SYSCALL(83, ADR(a), mode); (* mkdir *)
470+ return SYSTEM.SYSCALL(83, SYSTEM.ADR(a), mode); (* mkdir *)
470471 end;
471472
472473 (* Makes a fifo (a named pipe) at path with the permission bits mode,
473474 less those the umask takes away. 0, or minus an errno. *)
474-proc makeFifo*(path: []U8; mode: INT): INT;
475+proc makeFifo*(path: []const U8; mode: INT): INT;
475476 var a: [4096]U8;
476477 begin
477478 if not cstr(path, a) then return -36; end;
478- return SYSCALL(133, ADR(a), 1000H | (mode & 1FFH), 0); (* mknod, S_IFIFO *)
479+ return SYSTEM.SYSCALL(133, SYSTEM.ADR(a), 1000H | (mode & 1FFH), 0); (* mknod, S_IFIFO *)
479480 end;
480481
481482
482483 (* Sets the owner and group of what path names, following a symbolic
483484 link: a user or group number, or -1 to leave it as it is. Only
484485 root may give a file away. 0, or minus an errno. *)
485-proc chown*(path: []U8; uid, gid: INT): INT;
486+proc chown*(path: []const U8; uid, gid: INT): INT;
486487 var a: [4096]U8;
487488 begin
488489 if not cstr(path, a) then return -36; end;
489- return SYSCALL(92, ADR(a), uid, gid); (* chown *)
490+ return SYSTEM.SYSCALL(92, SYSTEM.ADR(a), uid, gid); (* chown *)
490491 end;
491492
492493
493494 (* Removes the directory at path, which must be empty. *)
494-proc removeDir*(path: []U8): INT;
495+proc removeDir*(path: []const U8): INT;
495496 var a: [4096]U8;
496497 begin
497498 if not cstr(path, a) then return -36; end;
498- return SYSCALL(84, ADR(a)); (* rmdir *)
499+ return SYSTEM.SYSCALL(84, SYSTEM.ADR(a)); (* rmdir *)
499500 end;
500501
501502 (* Sets the permission bits of what path names. *)
502-proc chmod*(path: []U8; mode: INT): INT;
503+proc chmod*(path: []const U8; mode: INT): INT;
503504 var a: [4096]U8;
504505 begin
505506 if not cstr(path, a) then return -36; end;
506- return SYSCALL(90, ADR(a), mode);
507+ return SYSTEM.SYSCALL(90, SYSTEM.ADR(a), mode);
507508 end;
508509
509510 (* Sets when the contents of what path names last changed, and when it
510511 was last read, to sec seconds and nsec nanoseconds since 1970, as a
511512 program copying a file keeps its time: Info.seconds gives sec back,
512513 whatever the time. *)
513-proc setTime*(path: []U8; sec: I64; nsec: INT): INT;
514+proc setTime*(path: []const U8; sec: I64; nsec: INT): INT;
514515 var a: [4096]U8; t: [2]Timespec;
515516 begin
516517 if not cstr(path, a) then return -36; end;
@@ -518,13 +519,13 @@
518519 t[0].sec := sec;
519520 t[0].nsec := nsec;
520521 t[1] := t[0];
521- return SYSCALL(280, -100, ADR(a), ADR(t), 0); (* utimensat, from the working directory *)
522+ return SYSTEM.SYSCALL(280, -100, SYSTEM.ADR(a), SYSTEM.ADR(t), 0); (* utimensat, from the working directory *)
522523 end;
523524
524525 (* 0 if this user, by its real ids, may do with path what how asks:
525526 reading, writing and executing; minus an errno, -13 (EACCES) if not.
526527 An empty how asks only whether path is there. *)
527-proc access*(path: []U8; how: Accesses): INT;
528+proc access*(path: []const U8; how: Accesses): INT;
528529 var a: [4096]U8; m: INT;
529530 begin
530531 if not cstr(path, a) then return -36; end;
@@ -532,31 +533,31 @@
532533 if reading in how then m := m | 4; end; (* R_OK *)
533534 if writing in how then m := m | 2; end; (* W_OK *)
534535 if executing in how then m := m | 1; end; (* X_OK *)
535- return SYSCALL(21, ADR(a), m); (* access *)
536+ return SYSTEM.SYSCALL(21, SYSTEM.ADR(a), m); (* access *)
536537 end;
537538
538539 (* Sets the bits taken from every file this program, and the programs
539540 it starts, make: the mask it was. *)
540541 proc umask*(mask: INT): INT;
541542 begin
542- return SYSCALL(95, mask & 1FFH); (* umask *)
543+ return SYSTEM.SYSCALL(95, mask & 1FFH); (* umask *)
543544 end;
544545
545546 (* Makes path a symbolic link to target. *)
546-proc symlink*(target, path: []U8): INT;
547+proc symlink*(target, path: []const U8): INT;
547548 var a, b: [4096]U8;
548549 begin
549550 if not cstr(target, a) or not cstr(path, b) then return -36; end;
550- return SYSCALL(88, ADR(a), ADR(b));
551+ return SYSTEM.SYSCALL(88, SYSTEM.ADR(a), SYSTEM.ADR(b));
551552 end;
552553
553554 (* What the symbolic link at path names, good until the next call; and
554555 0, or minus an errno. *)
555-proc readLink*(path: []U8): ([]U8, INT);
556+proc readLink*(path: []const U8): ([]const U8, INT);
556557 var a: [4096]U8; n: INT;
557558 begin
558559 if not cstr(path, a) then return "", -36; end;
559- n := SYSCALL(89, ADR(a), ADR(linked), LEN(linked)); (* readlink *)
560+ n := SYSTEM.SYSCALL(89, SYSTEM.ADR(a), SYSTEM.ADR(linked), LEN(linked)); (* readlink *)
560561 if n < 0 then return "", n; end;
561562 if n = LEN(linked) then return "", -36; end; (* it may be cut short *)
562563 return linked[0..n], 0;
@@ -584,14 +585,14 @@
584585 (* The size of what path names, whether it is a directory or a regular
585586 file, following a symbolic link, and whether path is one; and 0, or
586587 minus an errno. *)
587-proc info*(path: []U8): (Info, INT);
588+proc info*(path: []const U8): (Info, INT);
588589 var a: [4096]U8; st: [18]INT; i: Info; r: INT; isLink: BOOL; (* struct stat: 144 bytes *)
589590 begin
590591 if not cstr(path, a) then return i, -36; end;
591- r := SYSCALL(6, ADR(a), ADR(st)); (* lstat *)
592+ r := SYSTEM.SYSCALL(6, SYSTEM.ADR(a), SYSTEM.ADR(st)); (* lstat *)
592593 if r # 0 then return i, r; end;
593594 isLink := st[3] & 0F000H = 0A000H; (* st_mode is S_IFLNK *)
594- r := SYSCALL(4, ADR(a), ADR(st)); (* stat *)
595+ r := SYSTEM.SYSCALL(4, SYSTEM.ADR(a), SYSTEM.ADR(st)); (* stat *)
595596 if r # 0 then return i, r; end;
596597 i := fromStat(st);
597598 i.symlink := isLink;
@@ -601,11 +602,11 @@
601602 (* info of path itself: if it is a symbolic link, of the link, not of
602603 what it names, so that symlink is true, dir and file false, and the
603604 size the length of what it names. *)
604-proc linkInfo*(path: []U8): (Info, INT);
605+proc linkInfo*(path: []const U8): (Info, INT);
605606 var a: [4096]U8; st: [18]INT; i: Info; r: INT;
606607 begin
607608 if not cstr(path, a) then return i, -36; end;
608- r := SYSCALL(6, ADR(a), ADR(st)); (* lstat *)
609+ r := SYSTEM.SYSCALL(6, SYSTEM.ADR(a), SYSTEM.ADR(st)); (* lstat *)
609610 if r # 0 then return i, r; end;
610611 i := fromStat(st);
611612 i.symlink := st[3] & 0F000H = 0A000H; (* S_IFLNK *)
@@ -616,18 +617,18 @@
616617 proc infoOf*(fd: INT): (Info, INT);
617618 var st: [18]INT; i: Info; r: INT;
618619 begin
619- r := SYSCALL(5, fd, ADR(st)); (* fstat *)
620+ r := SYSTEM.SYSCALL(5, fd, SYSTEM.ADR(st)); (* fstat *)
620621 if r # 0 then return i, r; end;
621622 return fromStat(st), 0;
622623 end;
623624
624625 (* The bytes free to an ordinary user on path's file system, and the
625626 bytes in all. *)
626-proc space*(path: []U8): (I64, I64, INT);
627+proc space*(path: []const U8): (I64, I64, INT);
627628 var a: [4096]U8; st: [15]INT; r, unit: INT; (* struct statfs: 120 bytes *)
628629 begin
629630 if not cstr(path, a) then return 0, 0, -36; end;
630- r := SYSCALL(137, ADR(a), ADR(st)); (* statfs *)
631+ r := SYSTEM.SYSCALL(137, SYSTEM.ADR(a), SYSTEM.ADR(st)); (* statfs *)
631632 if r # 0 then return 0, 0, r; end;
632633 unit := st[9]; (* f_frsize, the unit blocks are counted in *)
633634 if unit = 0 then unit := st[1]; end; (* f_bsize *)
@@ -648,26 +649,26 @@
648649 end;
649650
650651 (* Opens the directory at path, for nextEntry. *)
651-proc openDir*(var d: Dir; path: []U8): INT;
652+proc openDir*(var d: Dir; path: []const U8): INT;
652653 var a: [4096]U8;
653654 begin
654655 d.kind := unknown;
655656 d.pos := 0;
656657 d.len := 0;
657658 if not cstr(path, a) then return -36; end;
658- d.fd := SYSCALL(2, ADR(a), 90000H); (* open, O_RDONLY, O_DIRECTORY, O_CLOEXEC *)
659+ d.fd := SYSTEM.SYSCALL(2, SYSTEM.ADR(a), 90000H); (* open, O_RDONLY, O_DIRECTORY, O_CLOEXEC *)
659660 if d.fd < 0 then return d.fd; end;
660661 return 0;
661662 end;
662663
663664 (* The next name in the directory, good until the next call, but . and
664665 .., in no order; false at the end. *)
665-proc nextEntry*(var d: Dir): ([]U8, BOOL);
666+proc nextEntry*(var d: Dir): ([]const U8, BOOL);
666667 var n, at: INT;
667668 begin
668669 while true do
669670 if d.pos >= d.len then
670- d.len := SYSCALL(217, d.fd, ADR(d.buf), LEN(d.buf)); (* getdents64 *)
671+ d.len := SYSTEM.SYSCALL(217, d.fd, SYSTEM.ADR(d.buf), LEN(d.buf)); (* getdents64 *)
671672 d.pos := 0;
672673 if d.len <= 0 then return "", false; end;
673674 end;
@@ -696,7 +697,7 @@
696697 (* Closes the directory d that openDir opened. *)
697698 proc closeDir*(var d: Dir);
698699 begin
699- _ := SYSCALL(3, d.fd);
700+ _ := SYSTEM.SYSCALL(3, d.fd);
700701 end;
701702
702703 (* Puts the terminal on fd into raw mode: no echo, no lines, no signals,
@@ -705,7 +706,7 @@
705706 proc rawMode*(fd: INT): BOOL;
706707 var t: Termios;
707708 begin
708- if SYSCALL(16, fd, 5401H, ADR(saved)) # 0 then return false; end; (* TCGETS *)
709+ if SYSTEM.SYSCALL(16, fd, 5401H, SYSTEM.ADR(saved)) # 0 then return false; end; (* TCGETS *)
709710 t := saved;
710711 t.iflag := t.iflag & ~U32(5EBH); (* IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON *)
711712 t.oflag := t.oflag & ~U32(1); (* OPOST *)
@@ -713,13 +714,13 @@
713714 t.lflag := t.lflag & ~U32(804BH); (* ISIG ICANON ECHO ECHONL IEXTEN *)
714715 t.cc[5] := 0; (* VTIME: no time limit *)
715716 t.cc[6] := 1; (* VMIN: a byte at least *)
716- return SYSCALL(16, fd, 5402H, ADR(t)) = 0; (* TCSETS *)
717+ return SYSTEM.SYSCALL(16, fd, 5402H, SYSTEM.ADR(t)) = 0; (* TCSETS *)
717718 end;
718719
719720 (* The terminal on fd as rawMode found it. *)
720721 proc restoreMode*(fd: INT);
721722 begin
722- _ := SYSCALL(16, fd, 5402H, ADR(saved));
723+ _ := SYSTEM.SYSCALL(16, fd, 5402H, SYSTEM.ADR(saved));
723724 end;
724725
725726 (* The modes of the terminal on fd, as a shell keeps them for each job;
@@ -727,7 +728,7 @@
727728 proc getMode*(fd: INT): (Mode, INT);
728729 var m: Mode; r: INT;
729730 begin
730- r := SYSCALL(16, fd, 5401H, ADR(m.t)); (* TCGETS *)
731+ r := SYSTEM.SYSCALL(16, fd, 5401H, SYSTEM.ADR(m.t)); (* TCGETS *)
731732 return m, r;
732733 end;
733734
@@ -735,7 +736,7 @@
735736 is sent: 0, or minus an errno. *)
736737 proc setMode*(fd: INT; m: Mode): INT;
737738 begin
738- return SYSCALL(16, fd, 5403H, ADR(m.t)); (* TCSETSW *)
739+ return SYSTEM.SYSCALL(16, fd, 5403H, SYSTEM.ADR(m.t)); (* TCSETSW *)
739740 end;
740741
741742 (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't
@@ -743,7 +744,7 @@
743744 proc termSize*(fd: INT): (INT, INT);
744745 var w: Winsize;
745746 begin
746- if (SYSCALL(16, fd, 5413H, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then (* TIOCGWINSZ *)
747+ if (SYSTEM.SYSCALL(16, fd, 5413H, SYSTEM.ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then (* TIOCGWINSZ *)
747748 return 80, 24;
748749 end;
749750 return INT(w.cols), INT(w.rows);
@@ -755,7 +756,7 @@
755756 var p: Pollfd;
756757 begin
757758 p := {fd: I32(fd), events: 1}; (* POLLIN *)
758- return SYSCALL(7, ADR(p), 1, ms) > 0; (* poll *)
759+ return SYSTEM.SYSCALL(7, SYSTEM.ADR(p), 1, ms) > 0; (* poll *)
759760 end;
760761
761762 (* The clock that only goes forward, in nanoseconds: for how long
@@ -763,7 +764,7 @@
763764 proc clock*: I64;
764765 var t: Timespec;
765766 begin
766- _ := SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *)
767+ _ := SYSTEM.SYSCALL(228, 1, SYSTEM.ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *)
767768 return t.sec * 1000000000 + t.nsec;
768769 end;
769770
@@ -771,7 +772,7 @@
771772 proc now*: I64;
772773 var t: Timespec;
773774 begin
774- _ := SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *)
775+ _ := SYSTEM.SYSCALL(228, 0, SYSTEM.ADR(t)); (* clock_gettime: CLOCK_REALTIME *)
775776 return t.sec * 1000000000 + t.nsec;
776777 end;
777778
@@ -781,14 +782,14 @@
781782 begin
782783 at := clock() + I64(ms) * 1000000;
783784 t := {sec: at div 1000000000, nsec: at mod 1000000000};
784- repeat until SYSCALL(230, 1, 1, ADR(t), 0) # -4; (* clock_nanosleep until t, again after EINTR *)
785+ repeat until SYSTEM.SYSCALL(230, 1, 1, SYSTEM.ADR(t), 0) # -4; (* clock_nanosleep until t, again after EINTR *)
785786 end;
786787
787788 (* Ends the program: random bytes can't be faked. *)
788789 proc noRandom;
789790 begin
790791 _ := write(stderr, "Sys.random: the kernel gave no random bytes\n");
791- _ := SYSCALL(231, 2); (* exit *)
792+ _ := SYSTEM.SYSCALL(231, 2); (* exit *)
792793 end;
793794
794795 (* Fills b with random bytes, from the kernel. Random bytes can't be
@@ -800,7 +801,7 @@
800801 begin
801802 n := 0;
802803 while n < LEN(b) do (* a signal may cut it short *)
803- r := SYSCALL(318, ADR(b[n]), LEN(b) - n, 0); (* getrandom *)
804+ r := SYSTEM.SYSCALL(318, SYSTEM.ADR(b[n]), LEN(b) - n, 0); (* getrandom *)
804805 if r > 0 then INC(n, r);
805806 elsif r # errIntr then noRandom();
806807 end;
@@ -814,17 +815,17 @@
814815 proc socket(family, kind: INT; a: ^U8; size: INT; serving: BOOL): INT;
815816 var fd, r, one: INT;
816817 begin
817- fd := SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *)
818+ fd := SYSTEM.SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *)
818819 if fd < 0 then return fd; end;
819820 if serving then
820821 one := 1; (* so that a server can start again at once *)
821- _ := SYSCALL(54, fd, 1, 2, ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *)
822- r := SYSCALL(49, fd, a, size); (* bind *)
822+ _ := SYSTEM.SYSCALL(54, fd, 1, 2, SYSTEM.ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *)
823+ r := SYSTEM.SYSCALL(49, fd, a, size); (* bind *)
823824 if (r = 0) and (kind = 1) then (* a stream socket takes connections; *)
824- r := SYSCALL(50, fd, 4096); (* one of datagrams only receives *)
825+ r := SYSTEM.SYSCALL(50, fd, 4096); (* one of datagrams only receives *)
825826 end;
826827 else
827- r := SYSCALL(42, fd, a, size); (* connect *)
828+ r := SYSTEM.SYSCALL(42, fd, a, size); (* connect *)
828829 end;
829830 if r < 0 then close(fd); return r; end;
830831 return fd;
@@ -834,7 +835,7 @@
834835 -36 (ENAMETOOLONG) if it is too long. A path that starts with a zero
835836 byte is one of Linux's abstract names, which has no file and no
836837 trailing zero: its length ends with the name's. *)
837-proc unixAddr(path: []U8; a: ^SockaddrUn): INT;
838+proc unixAddr(path: []const U8; a: ^SockaddrUn): INT;
838839 begin
839840 if LEN(path) >= LEN(a^.path) then return -36; end;
840841 a^.family := 1; (* AF_UNIX *)
@@ -844,22 +845,22 @@
844845 end;
845846
846847 (* A stream socket connected to the Unix socket at path. *)
847-proc connect*(path: []U8): INT;
848+proc connect*(path: []const U8): INT;
848849 var a: SockaddrUn; size: INT;
849850 begin
850- size := unixAddr(path, ADR(a));
851+ size := unixAddr(path, SYSTEM.ADR(a));
851852 if size < 0 then return size; end;
852- return socket(1, 1, ^U8(ADR(a)), size, false); (* SOCK_STREAM *)
853+ return socket(1, 1, ^U8(SYSTEM.ADR(a)), size, false); (* SOCK_STREAM *)
853854 end;
854855
855856 (* A stream socket made at path, which must not be there yet, taking
856857 connections. *)
857-proc listen*(path: []U8): INT;
858+proc listen*(path: []const U8): INT;
858859 var a: SockaddrUn; size: INT;
859860 begin
860- size := unixAddr(path, ADR(a));
861+ size := unixAddr(path, SYSTEM.ADR(a));
861862 if size < 0 then return size; end;
862- return socket(1, 1, ^U8(ADR(a)), size, true);
863+ return socket(1, 1, ^U8(SYSTEM.ADR(a)), size, true);
863864 end;
864865
865866 (* The value of the hexadecimal digit c, or -1 if it isn't one. *)
@@ -873,7 +874,7 @@
873874
874875 (* The IPv4 address s, four numbers and dots, in out's 4 bytes, or false
875876 if it isn't one. *)
876-proc ipv4(s, out: []U8): BOOL;
877+proc ipv4(s: []const U8; out: []U8): BOOL;
877878 var b: [4]U8; n, i, v, d: INT;
878879 begin
879880 i := 0;
@@ -900,7 +901,7 @@
900901 (* The IPv6 address s, groups of hexadecimal digits and colons, one ::
901902 standing for groups of zeros, in out's 16 bytes, or false if it isn't
902903 one. *)
903-proc ipv6(s, out: []U8): BOOL;
904+proc ipv6(s: []const U8; out: []U8): BOOL;
904905 var g: [8]INT; n, gap, i, v, d, k: INT;
905906 begin
906907 n := 0;
@@ -944,7 +945,7 @@
944945 (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size
945946 of its struct sockaddr_in or sockaddr_in6, or 0 if either is
946947 wrong. *)
947-proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT;
948+proc inetAddr(addr: []const U8; port: INT; a: ^Sockaddr): INT;
948949 begin
949950 if (port < 0) or (port > 65535) then return 0; end;
950951 a^.port[0] := U8(port shr 8); (* in the network's order, the high byte first *)
@@ -956,37 +957,37 @@
956957
957958 (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL)
958959 if they are wrong. *)
959-proc inet(addr: []U8; port, kind: INT; serving: BOOL): INT;
960+proc inet(addr: []const U8; port, kind: INT; serving: BOOL): INT;
960961 var a: Sockaddr; size: INT;
961962 begin
962- size := inetAddr(addr, port, ADR(a));
963+ size := inetAddr(addr, port, SYSTEM.ADR(a));
963964 if size = 0 then return -22; end;
964- return socket(INT(a.family), kind, ^U8(ADR(a)), size, serving);
965+ return socket(INT(a.family), kind, ^U8(SYSTEM.ADR(a)), size, serving);
965966 end;
966967
967968 (* A stream socket connected to port at addr, an IPv4 or IPv6 address
968969 as numbers. *)
969-proc connectTcp*(addr: []U8; port: INT): INT;
970+proc connectTcp*(addr: []const U8; port: INT): INT;
970971 begin
971972 return inet(addr, port, 1, false); (* SOCK_STREAM *)
972973 end;
973974
974975 (* A socket of datagrams to and from port at addr. *)
975-proc connectUdp*(addr: []U8; port: INT): INT;
976+proc connectUdp*(addr: []const U8; port: INT): INT;
976977 begin
977978 return inet(addr, port, 2, false); (* SOCK_DGRAM *)
978979 end;
979980
980981 (* A stream socket taking connections on port at addr; "0.0.0.0" or
981982 "::" is every address the machine has. *)
982-proc listenTcp*(addr: []U8; port: INT): INT;
983+proc listenTcp*(addr: []const U8; port: INT): INT;
983984 begin
984985 return inet(addr, port, 1, true);
985986 end;
986987
987988 (* A socket of datagrams on port at addr, from anyone, for receive and
988989 reply. *)
989-proc listenUdp*(addr: []U8; port: INT): INT;
990+proc listenUdp*(addr: []const U8; port: INT): INT;
990991 begin
991992 return inet(addr, port, 2, true);
992993 end;
@@ -995,7 +996,7 @@
995996 its own, closed in a program exec starts; or minus an errno. *)
996997 proc accept*(fd: INT): INT;
997998 begin
998- return SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *)
999+ return SYSTEM.SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *)
9991000 end;
10001001
10011002 (* Ends this side's writing to the socket fd, so that the other end
@@ -1003,7 +1004,7 @@
10031004 errno. *)
10041005 proc closeWrite*(fd: INT): INT;
10051006 begin
1006- return SYSCALL(48, fd, 1); (* shutdown, SHUT_WR *)
1007+ return SYSTEM.SYSCALL(48, fd, 1); (* shutdown, SHUT_WR *)
10071008 end;
10081009
10091010 (* Who is at the other end of the connected socket fd, and 0; or minus
@@ -1013,11 +1014,11 @@
10131014 begin
10141015 r := {unix: false, ipv6: false};
10151016 size := I32(SIZE(Sockaddr));
1016- e := SYSCALL(52, fd, ADR(a), ADR(size)); (* getpeername *)
1017+ e := SYSTEM.SYSCALL(52, fd, SYSTEM.ADR(a), SYSTEM.ADR(size)); (* getpeername *)
10171018 if e < 0 then return r, e; end;
10181019 if a.family = 1 then (* AF_UNIX: ask who made the connection *)
10191020 credSize := I32(4 * LEN(cred));
1020- e := SYSCALL(55, fd, 1, 17, ADR(cred), ADR(credSize)); (* getsockopt: SOL_SOCKET, SO_PEERCRED *)
1021+ e := SYSTEM.SYSCALL(55, fd, 1, 17, SYSTEM.ADR(cred), SYSTEM.ADR(credSize)); (* getsockopt: SOL_SOCKET, SO_PEERCRED *)
10211022 if e < 0 then return r, e; end;
10221023 r.unix := true;
10231024 r.pid := INT(cred[0]);
@@ -1040,7 +1041,7 @@
10401041 proc socketPair*: (INT, INT, INT);
10411042 var fds: [2]I32; r: INT;
10421043 begin
1043- r := SYSCALL(53, 1, 1 | 80000H, 0, ADR(fds)); (* socketpair: AF_UNIX, SOCK_STREAM, SOCK_CLOEXEC *)
1044+ r := SYSTEM.SYSCALL(53, 1, 1 | 80000H, 0, SYSTEM.ADR(fds)); (* socketpair: AF_UNIX, SOCK_STREAM, SOCK_CLOEXEC *)
10441045 if r < 0 then return -1, -1, r; end;
10451046 return INT(fds[0]), INT(fds[1]), 0;
10461047 end;
@@ -1048,18 +1049,18 @@
10481049 (* Writes s to the socket fd, as write does, but returns -32 (EPIPE)
10491050 where write would stop the program with SIGPIPE: when the other end
10501051 has closed it. *)
1051-proc send*(fd: INT; s: []U8): INT;
1052+proc send*(fd: INT; s: []const U8): INT;
10521053 begin
10531054 if LEN(s) = 0 then return 0; end;
1054- return SYSCALL(44, fd, ADR(s[0]), LEN(s), 4000H, 0, 0); (* sendto, MSG_NOSIGNAL, no address *)
1055+ return SYSTEM.SYSCALL(44, fd, SYSTEM.PTR(s), LEN(s), 4000H, 0, 0); (* sendto, MSG_NOSIGNAL, no address *)
10551056 end;
10561057
10571058 (* send, but never waits: returns -11 (EAGAIN) where send would wait for
10581059 room, and doesn't make reads on fd non-blocking too. *)
1059-proc sendNow*(fd: INT; s: []U8): INT;
1060+proc sendNow*(fd: INT; s: []const U8): INT;
10601061 begin
10611062 if LEN(s) = 0 then return 0; end;
1062- return SYSCALL(44, fd, ADR(s[0]), LEN(s), 4040H, 0, 0); (* sendto, MSG_NOSIGNAL | MSG_DONTWAIT, no address *)
1063+ return SYSTEM.SYSCALL(44, fd, SYSTEM.PTR(s), LEN(s), 4040H, 0, 0); (* sendto, MSG_NOSIGNAL | MSG_DONTWAIT, no address *)
10631064 end;
10641065
10651066
@@ -1087,7 +1088,7 @@
10871088 if fds[i].write then events := events | 4; end; (* POLLOUT *)
10881089 list[i] := {fd: I32(fds[i].fd), events: events};
10891090 end;
1090- r := SYSCALL(7, PTR(list), n, ms); (* poll *)
1091+ r := SYSTEM.SYSCALL(7, SYSTEM.PTR(list), n, ms); (* poll *)
10911092 for i := 0 to n - 1 do
10921093 fds[i].ready := (r > 0) and (list[i].revents # 0);
10931094 end;
@@ -1100,7 +1101,7 @@
11001101 reached its end or failed, so that a read or a write won't wait; -1
11011102 if none has. ms < 0 waits as long as it takes. At most 64 fds in
11021103 all. *)
1103-proc readyFor*(reads, writes: []INT; ms: INT): INT;
1104+proc readyFor*(reads, writes: []const INT; ms: INT): INT;
11041105 var p: [64]Poll; ps: []Poll; n, i: INT;
11051106 begin
11061107 n := 0;
@@ -1127,7 +1128,7 @@
11271128 (* The first of fds that has something to read within ms milliseconds,
11281129 or that has reached its end or failed, so that a read won't wait; -1
11291130 if none has. ms < 0 waits as long as it takes. At most 64 fds. *)
1130-proc readyOf*(fds: []INT; ms: INT): INT;
1131+proc readyOf*(fds: []const INT; ms: INT): INT;
11311132 begin
11321133 return readyFor(fds, [], ms);
11331134 end;
@@ -1138,10 +1139,10 @@
11381139 proc setBlocking*(fd: INT; yes: BOOL): INT;
11391140 var flags: INT;
11401141 begin
1141- flags := SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *)
1142+ flags := SYSTEM.SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *)
11421143 if flags < 0 then return flags; end;
11431144 if yes then flags := flags & ~INT(800H); else flags := flags | 800H; end; (* O_NONBLOCK *)
1144- return SYSCALL(72, fd, 4, flags); (* F_SETFL *)
1145+ return SYSTEM.SYSCALL(72, fd, 4, flags); (* F_SETFL *)
11451146 end;
11461147
11471148 (* Whether reads and writes on fd wait, as they do at first: 1 if they
@@ -1149,7 +1150,7 @@
11491150 proc blocking*(fd: INT): INT;
11501151 var flags: INT;
11511152 begin
1152- flags := SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *)
1153+ flags := SYSTEM.SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *)
11531154 if flags < 0 then return flags; end;
11541155 if flags & 800H # 0 then return 0; end; (* O_NONBLOCK *)
11551156 return 1;
@@ -1159,19 +1160,19 @@
11591160 or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds.
11601161 It starts to connect without waiting, then waits for the socket to
11611162 be writable, which it is once connected or refused, and asks which. *)
1162-proc connectTcpWithin*(addr: []U8; port, ms: INT): INT;
1163+proc connectTcpWithin*(addr: []const U8; port, ms: INT): INT;
11631164 var a: Sockaddr; size, fd, r: INT; err, errSize: I32;
11641165 begin
1165- size := inetAddr(addr, port, ADR(a));
1166+ size := inetAddr(addr, port, SYSTEM.ADR(a));
11661167 if size = 0 then return -22; end;
1167- fd := SYSCALL(41, INT(a.family), 1 | 80800H, 0); (* socket: SOCK_STREAM, SOCK_CLOEXEC, SOCK_NONBLOCK *)
1168+ fd := SYSTEM.SYSCALL(41, INT(a.family), 1 | 80800H, 0); (* socket: SOCK_STREAM, SOCK_CLOEXEC, SOCK_NONBLOCK *)
11681169 if fd < 0 then return fd; end;
1169- r := SYSCALL(42, fd, ADR(a), size); (* connect *)
1170+ r := SYSTEM.SYSCALL(42, fd, SYSTEM.ADR(a), size); (* connect *)
11701171 if r = -115 then (* EINPROGRESS *)
11711172 r := -110;
11721173 if readyFor([], [fd], ms) = fd then
11731174 errSize := 4;
1174- r := SYSCALL(55, fd, 1, 4, ADR(err), ADR(errSize)); (* getsockopt: SOL_SOCKET, SO_ERROR *)
1175+ r := SYSTEM.SYSCALL(55, fd, 1, 4, SYSTEM.ADR(err), SYSTEM.ADR(errSize)); (* getsockopt: SOL_SOCKET, SO_ERROR *)
11751176 if r = 0 then r := -INT(err); end;
11761177 end;
11771178 end;
@@ -1186,7 +1187,7 @@
11861187 var a: Sockaddr; size: I32; r: INT;
11871188 begin
11881189 size := I32(SIZE(Sockaddr));
1189- r := SYSCALL(51, fd, ADR(a), ADR(size)); (* getsockname *)
1190+ r := SYSTEM.SYSCALL(51, fd, SYSTEM.ADR(a), SYSTEM.ADR(size)); (* getsockname *)
11901191 if r < 0 then return r; end;
11911192 return (INT(a.port[0]) shl 8) | INT(a.port[1]);
11921193 end;
@@ -1198,34 +1199,34 @@
11981199 var p: Peer; size: I32; n: INT;
11991200 begin
12001201 size := I32(SIZE(Sockaddr));
1201- n := SYSCALL(45, fd, PTR(buf), LEN(buf), 0, ADR(p.a), ADR(size)); (* recvfrom *)
1202+ n := SYSTEM.SYSCALL(45, fd, SYSTEM.PTR(buf), LEN(buf), 0, SYSTEM.ADR(p.a), SYSTEM.ADR(size)); (* recvfrom *)
12021203 p.size := INT(size);
12031204 return n, p;
12041205 end;
12051206
12061207 (* Sends s, as one datagram, from the socket fd to peer, as receive
12071208 gave it: the bytes sent, or minus an errno. *)
1208-proc reply*(fd: INT; peer: Peer; s: []U8): INT;
1209+proc reply*(fd: INT; peer: Peer; s: []const U8): INT;
12091210 begin
1210- return SYSCALL(44, fd, PTR(s), LEN(s), 4000H, ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *)
1211+ return SYSTEM.SYSCALL(44, fd, SYSTEM.PTR(s), LEN(s), 4000H, SYSTEM.ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *)
12111212 end;
12121213
12131214 (* Sends s, at least one byte, to the Unix socket fd, as send does, and
12141215 with it the files fds, at most 16, which the program that receives
12151216 them then has open too: the bytes sent, or minus an errno. *)
1216-proc sendFds*(fd: INT; s: []U8; fds: []INT): INT;
1217+proc sendFds*(fd: INT; s: []const U8; fds: []const INT): INT;
12171218 var m: Msghdr; v: Iovec; c: Rights; i: INT;
12181219 begin
12191220 if (LEN(s) = 0) or (LEN(fds) > LEN(c.fds)) then return -22; end;
1220- v := {base: ADR(s[0]), size: LEN(s)};
1221- m := {iov: ADR(v), iovLen: 1};
1221+ v := {base: SYSTEM.PTR(s), size: LEN(s)};
1222+ m := {iov: SYSTEM.ADR(v), iovLen: 1};
12221223 if LEN(fds) > 0 then
12231224 c := {size: 16 + 4 * LEN(fds), level: 1, kind: 1}; (* SOL_SOCKET, SCM_RIGHTS *)
12241225 for i := 0 to LEN(fds) - 1 do c.fds[i] := I32(fds[i]); end;
1225- m.control := ^U8(ADR(c));
1226+ m.control := ^U8(SYSTEM.ADR(c));
12261227 m.controlSize := (c.size + 7) & ~7; (* CMSG_SPACE: whole quadwords *)
12271228 end;
1228- return SYSCALL(46, fd, ADR(m), 4000H); (* sendmsg, MSG_NOSIGNAL *)
1229+ return SYSTEM.SYSCALL(46, fd, SYSTEM.ADR(m), 4000H); (* sendmsg, MSG_NOSIGNAL *)
12291230 end;
12301231
12311232 (* Reads into buf from the Unix socket fd, as read does, and puts the
@@ -1235,9 +1236,9 @@
12351236 proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT);
12361237 var m: Msghdr; v: Iovec; c: Rights; n, k, i: INT;
12371238 begin
1238- v := {base: PTR(buf), size: LEN(buf)};
1239- m := {iov: ADR(v), iovLen: 1, control: ^U8(ADR(c)), controlSize: SIZE(Rights)};
1240- n := SYSCALL(47, fd, ADR(m), 40000000H); (* recvmsg, MSG_CMSG_CLOEXEC *)
1239+ v := {base: SYSTEM.PTR(buf), size: LEN(buf)};
1240+ m := {iov: SYSTEM.ADR(v), iovLen: 1, control: ^U8(SYSTEM.ADR(c)), controlSize: SIZE(Rights)};
1241+ n := SYSTEM.SYSCALL(47, fd, SYSTEM.ADR(m), 40000000H); (* recvmsg, MSG_CMSG_CLOEXEC *)
12411242 if n < 0 then return n, 0; end;
12421243 k := 0;
12431244 if (m.controlSize >= 16) and (c.level = 1) and (c.kind = 1) then
@@ -1256,7 +1257,7 @@
12561257 const
12571258 (* what each errno means, as glibc's strerror says it; 41 and 58
12581259 are none *)
1259- errorTexts: [134][]U8 = [
1260+ errorTexts: [134][]const U8 = [
12601261 "Success", (* 0 *)
12611262 "Operation not permitted", (* 1, EPERM *)
12621263 "No such file or directory", (* 2, ENOENT *)
@@ -1394,7 +1395,7 @@
13941395
13951396 (* What errno err, or minus it, means, as C's strerror says it;
13961397 "unknown error" for a number that is no errno. *)
1397-proc errorText*(err: INT): []U8;
1398+proc errorText*(err: INT): []const U8;
13981399 begin
13991400 if (err < 0) and (err > -LEN(errorTexts)) then err := -err; end;
14001401 if (err < 0) or (err >= LEN(errorTexts)) then return "unknown error"; end;
@@ -1407,11 +1408,11 @@
14071408 proc environment: ^^U8;
14081409 begin
14091410 if envp # nil then return envp; end;
1410- return ARGV() + (ARGC() + 1);
1411+ return SYSTEM.ARGV() + (ARGC() + 1);
14111412 end;
14121413
14131414 (* Whether the NAME=value s, a C string, is name's. *)
1414-proc named(s: ^U8; name: []U8): BOOL;
1415+proc named(s: ^U8; name: []const U8): BOOL;
14151416 var n: INT;
14161417 begin
14171418 n := 0;
@@ -1424,11 +1425,11 @@
14241425 program calls env, from Rt, so this reads the environment itself
14251426 rather than through environment and named, which would add their
14261427 code to every executable. *)
1427-proc findEnv*(name: []U8): ([]U8, BOOL);
1428+proc findEnv*(name: []const U8): ([]const U8, BOOL);
14281429 var e: ^^U8; s: ^U8; i, n, m: INT;
14291430 begin
14301431 e := envp;
1431- if e = nil then e := ARGV() + (ARGC() + 1); end;
1432+ if e = nil then e := SYSTEM.ARGV() + (ARGC() + 1); end;
14321433 i := 0;
14331434 while e[i] # nil do
14341435 s := e[i];
@@ -1445,8 +1446,8 @@
14451446 end;
14461447
14471448 (* The value of the environment variable name; "" if it isn't set. *)
1448-proc env*(name: []U8): []U8;
1449-var v: []U8;
1449+proc env*(name: []const U8): []const U8;
1450+var v: []const U8;
14501451 begin
14511452 v, _ := findEnv(name);
14521453 return v;
@@ -1454,7 +1455,7 @@
14541455
14551456 (* The environment's ith NAME=value, from 0, and true; "" and false
14561457 past the last. *)
1457-proc envAt*(i: INT): ([]U8, BOOL);
1458+proc envAt*(i: INT): ([]const U8, BOOL);
14581459 var e: ^^U8; s: ^U8; j, n: INT;
14591460 begin
14601461 if i < 0 then return "", false; end;
@@ -1470,20 +1471,20 @@
14701471
14711472 (* The working directory, good until the next call; and 0, or minus an
14721473 errno. *)
1473-proc workDir*: ([]U8, INT);
1474+proc workDir*: ([]const U8, INT);
14741475 var r: INT;
14751476 begin
1476- r := SYSCALL(79, ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *)
1477+ r := SYSTEM.SYSCALL(79, SYSTEM.ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *)
14771478 if r < 0 then return "", r; end;
14781479 return cwd[0..r - 1], 0;
14791480 end;
14801481
14811482 (* Makes path the working directory. *)
1482-proc setWorkDir*(path: []U8): INT;
1483+proc setWorkDir*(path: []const U8): INT;
14831484 var a: [4096]U8;
14841485 begin
14851486 if not cstr(path, a) then return -36; end;
1486- return SYSCALL(80, ADR(a)); (* chdir *)
1487+ return SYSTEM.SYSCALL(80, SYSTEM.ADR(a)); (* chdir *)
14871488 end;
14881489
14891490 (* A pseudo-terminal: the file descriptor of its controlling side, or
@@ -1493,10 +1494,10 @@
14931494 var a: [4096]U8; fd, unlock: INT;
14941495 begin
14951496 _ := cstr("/dev/ptmx", a);
1496- fd := SYSCALL(2, ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *)
1497+ fd := SYSTEM.SYSCALL(2, SYSTEM.ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *)
14971498 if fd < 0 then return fd; end;
14981499 unlock := 0;
1499- if SYSCALL(16, fd, 40045431H, ADR(unlock)) # 0 then (* TIOCSPTLCK *)
1500+ if SYSTEM.SYSCALL(16, fd, 40045431H, SYSTEM.ADR(unlock)) # 0 then (* TIOCSPTLCK *)
15001501 close(fd);
15011502 return -5; (* EIO *)
15021503 end;
@@ -1509,11 +1510,11 @@
15091510 var w: Winsize;
15101511 begin
15111512 w := {rows: U16(rows), cols: U16(cols)};
1512- return SYSCALL(16, fd, 5414H, ADR(w)); (* TIOCSWINSZ *)
1513+ return SYSTEM.SYSCALL(16, fd, 5414H, SYSTEM.ADR(w)); (* TIOCSWINSZ *)
15131514 end;
15141515
15151516 (* Copies s and a zero to at: the byte after them. *)
1516-proc put(s: []U8; at: ^U8): ^U8;
1517+proc put(s: []const U8; at: ^U8): ^U8;
15171518 begin
15181519 COPY(at[0..LEN(s)], s);
15191520 at[LEN(s)] := 0;
@@ -1522,7 +1523,7 @@
15221523
15231524 (* Whether the NAME=value s, a C string, names a variable that one of
15241525 env gives. *)
1525-proc replaced(s: ^U8; env: [][]U8): BOOL;
1526+proc replaced(s: ^U8; env: [][]const U8): BOOL;
15261527 var i, n: INT;
15271528 begin
15281529 for i := 0 to LEN(env) - 1 do
@@ -1537,7 +1538,7 @@
15371538 strings and a nil, then the environment old with each NAME=value of
15381539 env in place of its variable or added, and a nil; or nil. The
15391540 environment follows the arguments. *)
1540-proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, INT);
1541+proc argsAndEnv(args, env: [][]const U8; old: ^^U8): (^^U8, INT);
15411542 var p: ^^U8; s: ^U8; size, n, i, k: INT;
15421543 begin
15431544 n := 0;
@@ -1570,7 +1571,7 @@
15701571 stays good for the rest of the run; they are taken in turn from
15711572 blocks of 64 KB. It isn't safe while another thread reads the
15721573 environment or starts a program, as C's setenv isn't. *)
1573-proc setEnv*(name, value: []U8): INT;
1574+proc setEnv*(name, value: []const U8): INT;
15741575 var e, p: ^^U8; s: ^U8; size, cap, n, i: INT;
15751576 begin
15761577 if LEN(name) = 0 then return -22; end; (* EINVAL *)
@@ -1630,7 +1631,7 @@
16301631 proc pipe*: (INT, INT);
16311632 var fds: [2]I32; r: INT;
16321633 begin
1633- r := SYSCALL(293, ADR(fds), 80000H); (* pipe2, O_CLOEXEC *)
1634+ r := SYSTEM.SYSCALL(293, SYSTEM.ADR(fds), 80000H); (* pipe2, O_CLOEXEC *)
16341635 if r < 0 then return r, -1; end;
16351636 return INT(fds[0]), INT(fds[1]);
16361637 end;
@@ -1638,28 +1639,28 @@
16381639 (* This program's process id. *)
16391640 proc pid*: INT;
16401641 begin
1641- return SYSCALL(39); (* getpid *)
1642+ return SYSTEM.SYSCALL(39); (* getpid *)
16421643 end;
16431644
16441645 (* The user this program runs as: its real id. *)
16451646 proc uid*: INT;
16461647 begin
1647- return SYSCALL(102); (* getuid *)
1648+ return SYSTEM.SYSCALL(102); (* getuid *)
16481649 end;
16491650
16501651 (* The user whose rights this program has, its effective id: 0 is
16511652 root. *)
16521653 proc euid*: INT;
16531654 begin
1654- return SYSCALL(107); (* geteuid *)
1655+ return SYSTEM.SYSCALL(107); (* geteuid *)
16551656 end;
16561657
16571658 (* The name of this machine, good until the next call; and 0, or minus
16581659 an errno. *)
1659-proc hostName*: ([]U8, INT);
1660+proc hostName*: ([]const U8, INT);
16601661 var r, n: INT;
16611662 begin
1662- r := SYSCALL(63, ADR(uts)); (* uname *)
1663+ r := SYSTEM.SYSCALL(63, SYSTEM.ADR(uts)); (* uname *)
16631664 if r < 0 then return "", r; end;
16641665 n := 0;
16651666 while (n < 64) and (uts[65 + n] # 0) do INC(n); end; (* the nodename, at 65 *)
@@ -1670,7 +1671,7 @@
16701671 proc processors*: INT;
16711672 var mask: [1024]U8; n, i, b, count: INT;
16721673 begin
1673- n := SYSCALL(204, 0, LEN(mask), ADR(mask)); (* sched_getaffinity: this thread, the bytes it filled in *)
1674+ n := SYSTEM.SYSCALL(204, 0, LEN(mask), SYSTEM.ADR(mask)); (* sched_getaffinity: this thread, the bytes it filled in *)
16741675 count := 0;
16751676 for i := 0 to n - 1 do
16761677 for b := 0 to 7 do
@@ -1687,8 +1688,8 @@
16871688 proc cpuTime*(children: BOOL): (I64, I64);
16881689 var ru: [18]I64; (* struct rusage: two struct timeval first *)
16891690 begin
1690- if children then _ := SYSCALL(98, -1, ADR(ru)); (* getrusage: RUSAGE_CHILDREN *)
1691- else _ := SYSCALL(98, 0, ADR(ru)); (* RUSAGE_SELF *)
1691+ if children then _ := SYSTEM.SYSCALL(98, -1, SYSTEM.ADR(ru)); (* getrusage: RUSAGE_CHILDREN *)
1692+ else _ := SYSTEM.SYSCALL(98, 0, SYSTEM.ADR(ru)); (* RUSAGE_SELF *)
16921693 end;
16931694 return ru[0] * 1000000000 + ru[1] * 1000, ru[2] * 1000000000 + ru[3] * 1000;
16941695 end;
@@ -1699,7 +1700,7 @@
16991700 proc limit*(which: INT): (I64, I64, INT);
17001701 var r: [2]I64; err: INT;
17011702 begin
1702- err := SYSCALL(97, which, ADR(r)); (* getrlimit; RLIM_INFINITY is -1 *)
1703+ err := SYSTEM.SYSCALL(97, which, SYSTEM.ADR(r)); (* getrlimit; RLIM_INFINITY is -1 *)
17031704 return r[0], r[1], err;
17041705 end;
17051706
@@ -1709,20 +1710,20 @@
17091710 var r: [2]I64;
17101711 begin
17111712 r := [soft, hard];
1712- return SYSCALL(160, which, ADR(r)); (* setrlimit *)
1713+ return SYSTEM.SYSCALL(160, which, SYSTEM.ADR(r)); (* setrlimit *)
17131714 end;
17141715
17151716 (* Moves the program pid, or this one if pid is 0, to the process group
17161717 group, or to a new one it leads if group is 0. *)
17171718 proc setGroup*(pid, group: INT): INT;
17181719 begin
1719- return SYSCALL(109, pid, group); (* setpgid *)
1720+ return SYSTEM.SYSCALL(109, pid, group); (* setpgid *)
17201721 end;
17211722
17221723 (* The process group this program is in. *)
17231724 proc group*: INT;
17241725 begin
1725- return SYSCALL(111); (* getpgrp *)
1726+ return SYSTEM.SYSCALL(111); (* getpgrp *)
17261727 end;
17271728
17281729 (* Gives the keys of the terminal on fd, and its signals, to the process
@@ -1731,7 +1732,7 @@
17311732 var g: I32;
17321733 begin
17331734 g := I32(group);
1734- return SYSCALL(16, fd, 5410H, ADR(g)); (* TIOCSPGRP *)
1735+ return SYSTEM.SYSCALL(16, fd, 5410H, SYSTEM.ADR(g)); (* TIOCSPGRP *)
17351736 end;
17361737
17371738 (* The process group the terminal on fd gives its keys to, or minus an
@@ -1739,7 +1740,7 @@
17391740 proc foregroundOf*(fd: INT): INT;
17401741 var g: I32; r: INT;
17411742 begin
1742- r := SYSCALL(16, fd, 540FH, ADR(g)); (* TIOCGPGRP *)
1743+ r := SYSTEM.SYSCALL(16, fd, 540FH, SYSTEM.ADR(g)); (* TIOCGPGRP *)
17431744 if r < 0 then return r; end;
17441745 return INT(g);
17451746 end;
@@ -1751,7 +1752,7 @@
17511752 (* The ith directory of search, a list of them with : between, as PATH
17521753 is: dir, "." if it is empty, and where the next starts; -1 past the
17531754 last. *)
1754-proc pathDir(search: []U8; i: INT): ([]U8, INT);
1755+proc pathDir(search: []const U8; i: INT): ([]const U8, INT);
17551756 var j: INT;
17561757 begin
17571758 if i > LEN(search) then return "", -1; end;
@@ -1762,7 +1763,7 @@
17621763 end;
17631764
17641765 (* dir, a /, and name, a C string in buf; false if it doesn't fit. *)
1765-proc joinPath(dir, name, buf: []U8): BOOL;
1766+proc joinPath(dir, name: []const U8; buf: []U8): BOOL;
17661767 var n: INT;
17671768 begin
17681769 n := LEN(dir) + 1 + LEN(name);
@@ -1775,7 +1776,7 @@
17751776 end;
17761777
17771778 (* Whether name holds a /, and so is a path, not a name to look for. *)
1778-proc isPath(name: []U8): BOOL;
1779+proc isPath(name: []const U8): BOOL;
17791780 var i: INT;
17801781 begin
17811782 for i := 0 to LEN(name) - 1 do
@@ -1789,16 +1790,16 @@
17891790 execvp does: each in turn, an empty one being the working directory.
17901791 It returns only if none could be run. It runs in spawn's child, after
17911792 the fork, so it takes no memory: each path is made in buf. *)
1792-proc run(name, search, buf: []U8; argv, envp: ^^U8);
1793-var dir: []U8; i: INT;
1793+proc run(name, search: []const U8; buf: []U8; argv, envp: ^^U8);
1794+var dir: []const U8; i: INT;
17941795 begin
17951796 if isPath(name) or (LEN(name) = 0) then
1796- if cstr(name, buf) then _ := SYSCALL(59, ADR(buf[0]), argv, envp); end; (* execve *)
1797+ if cstr(name, buf) then _ := SYSTEM.SYSCALL(59, SYSTEM.ADR(buf[0]), argv, envp); end; (* execve *)
17971798 return;
17981799 end;
17991800 dir, i := pathDir(search, 0);
18001801 while i >= 0 do
1801- if joinPath(dir, name, buf) then _ := SYSCALL(59, ADR(buf[0]), argv, envp); end; (* execve *)
1802+ if joinPath(dir, name, buf) then _ := SYSTEM.SYSCALL(59, SYSTEM.ADR(buf[0]), argv, envp); end; (* execve *)
18021803 dir, i := pathDir(search, i);
18031804 end;
18041805 end;
@@ -1808,8 +1809,8 @@
18081809 directories of search that is no directory and that this user may
18091810 run. 0; or -2 (ENOENT) if there is none, or -13 (EACCES) if one is
18101811 there and can't be run. *)
1811-proc find(name, search, buf: []U8): INT;
1812-var dir: []U8; i, err, r: INT; f: Info;
1812+proc find(name, search: []const U8; buf: []U8): INT;
1813+var dir: []const U8; i, err, r: INT; f: Info;
18131814 begin
18141815 if isPath(name) then
18151816 if not cstr(name, buf) then return -36; end;
@@ -1821,7 +1822,7 @@
18211822 if joinPath(dir, name, buf) then
18221823 f, err := info(buf[0..LEN(dir) + 1 + LEN(name)]);
18231824 if (err = 0) and not f.dir then
1824- if SYSCALL(21, ADR(buf[0]), 1) = 0 then return 0; end; (* access, X_OK *)
1825+ if SYSTEM.SYSCALL(21, SYSTEM.ADR(buf[0]), 1) = 0 then return 0; end; (* access, X_OK *)
18251826 r := -13; (* EACCES *)
18261827 end;
18271828 end;
@@ -1837,8 +1838,8 @@
18371838 var n, i, size: INT;
18381839 begin
18391840 n := 0;
1840- if SYSCALL(16, fd, 80045430H, ADR(n)) # 0 then return -25; end; (* TIOCGPTN; ENOTTY *)
1841- i := put("/dev/pts/", ADR(name[0])) - ADR(name[0]) - 1; (* at its zero *)
1841+ if SYSTEM.SYSCALL(16, fd, 80045430H, SYSTEM.ADR(n)) # 0 then return -25; end; (* TIOCGPTN; ENOTTY *)
1842+ i := put("/dev/pts/", SYSTEM.ADR(name[0])) - SYSTEM.ADR(name[0]) - 1; (* at its zero *)
18421843 size := n;
18431844 repeat INC(i); size := size div 10; until size = 0;
18441845 name[i] := 0;
@@ -1850,7 +1851,7 @@
18501851 program exec starts. It runs in spawn's child, after the fork, so it
18511852 takes no memory: it closes the runs between the fds kept, the lowest
18521853 first, each with one close_range. *)
1853-proc closeAllBut(keep: []INT);
1854+proc closeAllBut(keep: []const INT);
18541855 var lo, next, i: INT;
18551856 begin
18561857 lo := 3;
@@ -1860,10 +1861,10 @@
18601861 if (keep[i] >= lo) and ((next < 0) or (keep[i] < next)) then next := keep[i]; end;
18611862 end;
18621863 if next < 0 then
1863- _ := SYSCALL(436, lo, 0FFFFFFFFH, 0); (* close_range: the rest *)
1864+ _ := SYSTEM.SYSCALL(436, lo, 0FFFFFFFFH, 0); (* close_range: the rest *)
18641865 else
1865- if next > lo then _ := SYSCALL(436, lo, next - 1, 0); end;
1866- _ := SYSCALL(72, next, 2, 0); (* fcntl: F_SETFD, kept on exec *)
1866+ if next > lo then _ := SYSTEM.SYSCALL(436, lo, next - 1, 0); end;
1867+ _ := SYSTEM.SYSCALL(72, next, 2, 0); (* fcntl: F_SETFD, kept on exec *)
18671868 lo := next + 1;
18681869 end;
18691870 until next < 0;
@@ -1874,30 +1875,30 @@
18741875 terminal's foreground; then its standard input, output and error,
18751876 each p.fds names over the terminal's; then its working directory,
18761877 the C string dir. 0, or minus an errno. *)
1877-proc takeOn(p: Program; name, dir: []U8): INT;
1878+proc takeOn(p: Program; name, dir: []const U8): INT;
18781879 var fd, i, r: INT;
18791880 begin
18801881 if p.tty # 0 then
1881- _ := SYSCALL(112); (* setsid *)
1882- fd := SYSCALL(2, ADR(name[0]), 2); (* open, O_RDWR *)
1882+ _ := SYSTEM.SYSCALL(112); (* setsid *)
1883+ fd := SYSTEM.SYSCALL(2, SYSTEM.PTR(name), 2); (* open, O_RDWR *)
18831884 if fd < 0 then return fd; end;
1884- r := SYSCALL(16, fd, 540EH, 0); (* TIOCSCTTY *)
1885+ r := SYSTEM.SYSCALL(16, fd, 540EH, 0); (* TIOCSCTTY *)
18851886 if r # 0 then return r; end;
1886- for i := 0 to 2 do _ := SYSCALL(33, fd, i); end; (* dup2 *)
1887+ for i := 0 to 2 do _ := SYSTEM.SYSCALL(33, fd, i); end; (* dup2 *)
18871888 else
1888- if p.group = -1 then _ := SYSCALL(109, 0, 0); (* setpgid *)
1889- elsif p.group # 0 then _ := SYSCALL(109, 0, p.group);
1889+ if p.group = -1 then _ := SYSTEM.SYSCALL(109, 0, 0); (* setpgid *)
1890+ elsif p.group # 0 then _ := SYSTEM.SYSCALL(109, 0, p.group);
18901891 end;
1891- if p.foreground then _ := foreground(0, SYSCALL(111)); end; (* getpgrp *)
1892+ if p.foreground then _ := foreground(0, SYSTEM.SYSCALL(111)); end; (* getpgrp *)
18921893 end;
18931894 for i := 0 to 2 do
18941895 if p.fds[i] = i then
18951896 _ := keepOnExec(i, true); (* dup2 of a file onto itself would leave it closed on exec *)
18961897 elsif p.fds[i] # 0 then
1897- _ := SYSCALL(33, p.fds[i], i); (* dup2 *)
1898+ _ := SYSTEM.SYSCALL(33, p.fds[i], i); (* dup2 *)
18981899 end;
18991900 end;
1900- if LEN(p.dir) > 0 then return SYSCALL(80, ADR(dir[0])); end; (* chdir *)
1901+ if LEN(p.dir) > 0 then return SYSTEM.SYSCALL(80, SYSTEM.PTR(dir)); end; (* chdir *)
19011902 return 0;
19021903 end;
19031904
@@ -1906,7 +1907,7 @@
19061907 proc ignored*(sig: INT): BOOL;
19071908 var act: [4]U64; (* struct sigaction *)
19081909 begin
1909- _ := SYSCALL(13, sig, 0, ADR(act), 8); (* rt_sigaction *)
1910+ _ := SYSTEM.SYSCALL(13, sig, 0, SYSTEM.ADR(act), 8); (* rt_sigaction *)
19101911 return act[0] = 1;
19111912 end;
19121913
@@ -1919,13 +1920,13 @@
19191920 proc spawn*(p: Program): INT;
19201921 var
19211922 a, dir: [4096]U8; name: [32]U8; dfl: [4]U64; (* struct sigaction: SIG_DFL *)
1922- argv: ^^U8; none: ^U8; all, old, empty: U64; size, pid, i, g, r: INT; search: []U8;
1923+ argv: ^^U8; none: ^U8; all, old, empty: U64; size, pid, i, g, r: INT; search: []const U8;
19231924 begin
19241925 if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
19251926 if (p.tty # 0) and (ptyName(p.tty, name) # 0) then return -25; end; (* ENOTTY *)
19261927 none := nil;
19271928 if p.onlyEnv then
1928- argv, size := argsAndEnv(p.args, p.env, ADR(none));
1929+ argv, size := argsAndEnv(p.args, p.env, SYSTEM.ADR(none));
19291930 else
19301931 argv, size := argsAndEnv(p.args, p.env, environment());
19311932 end;
@@ -1935,26 +1936,26 @@
19351936 r := find(p.path, search, a);
19361937 if r < 0 then munmap(^U8(argv), size); return r; end;
19371938 all := 0FFFFFFFFFFFFFFFFH;
1938- _ := SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
1939- pid := SYSCALL(57); (* fork *)
1939+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(all), SYSTEM.ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
1940+ pid := SYSTEM.SYSCALL(57); (* fork *)
19401941 if pid = 0 then
1941- if takeOn(p, name, dir) # 0 then _ := SYSCALL(231, 127); end; (* exit *)
1942+ if takeOn(p, name, dir) # 0 then _ := SYSTEM.SYSCALL(231, 127); end; (* exit *)
19421943 closeAllBut(p.more);
19431944 for i := 1 to 64 do
1944- if not (p.keepIgnored and ignored(i)) then _ := SYSCALL(13, i, ADR(dfl), 0, 8); end; (* rt_sigaction *)
1945+ if not (p.keepIgnored and ignored(i)) then _ := SYSTEM.SYSCALL(13, i, SYSTEM.ADR(dfl), 0, 8); end; (* rt_sigaction *)
19451946 end;
1946- _ := SYSCALL(14, 2, ADR(empty), 0, 8); (* no signal blocked *)
1947+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(empty), 0, 8); (* no signal blocked *)
19471948 run(p.path, search, a, argv, argv + (LEN(p.args) + 1));
1948- _ := SYSCALL(231, 127); (* exit *)
1949+ _ := SYSTEM.SYSCALL(231, 127); (* exit *)
19491950 end;
19501951 if (pid > 0) and (p.tty = 0) then
19511952 (* as the program does, for whichever of the two runs first *)
19521953 g := p.group;
1953- if g = -1 then g := pid; elsif g = 0 then g := SYSCALL(111); end;
1954- if p.group # 0 then _ := SYSCALL(109, pid, g); end;
1954+ if g = -1 then g := pid; elsif g = 0 then g := SYSTEM.SYSCALL(111); end;
1955+ if p.group # 0 then _ := SYSTEM.SYSCALL(109, pid, g); end;
19551956 if p.foreground then _ := foreground(0, g); end;
19561957 end;
1957- _ := SYSCALL(14, 2, ADR(old), 0, 8);
1958+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(old), 0, 8);
19581959 munmap(^U8(argv), size);
19591960 return pid;
19601961 end;
@@ -1971,7 +1972,7 @@
19711972 proc exec*(p: Program): INT;
19721973 var
19731974 a, dir: [4096]U8; name: [32]U8; dfl: [4]U64; acts: [65][4]U64; (* struct sigaction *)
1974- argv: ^^U8; none: ^U8; all, old, empty: U64; size, r, i: INT; search: []U8;
1975+ argv: ^^U8; none: ^U8; all, old, empty: U64; size, r, i: INT; search: []const U8;
19751976 begin
19761977 if not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
19771978 if (p.tty # 0) and (ptyName(p.tty, name) # 0) then return -25; end; (* ENOTTY *)
@@ -1981,7 +1982,7 @@
19811982 if r < 0 then return r; end;
19821983 none := nil;
19831984 if p.onlyEnv then
1984- argv, size := argsAndEnv(p.args, p.env, ADR(none));
1985+ argv, size := argsAndEnv(p.args, p.env, SYSTEM.ADR(none));
19851986 else
19861987 argv, size := argsAndEnv(p.args, p.env, environment());
19871988 end;
@@ -1994,16 +1995,16 @@
19941995 (* every signal as it is at first and none blocked, as spawn
19951996 gives them, each kept to give back if execve fails *)
19961997 all := 0FFFFFFFFFFFFFFFFH;
1997- _ := SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
1998+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(all), SYSTEM.ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
19981999 for i := 1 to 64 do
1999- _ := SYSCALL(13, i, 0, ADR(acts[i]), 8); (* rt_sigaction: as it is *)
2000- if not (p.keepIgnored and (acts[i][0] = 1)) then _ := SYSCALL(13, i, ADR(dfl), 0, 8); end;
2000+ _ := SYSTEM.SYSCALL(13, i, 0, SYSTEM.ADR(acts[i]), 8); (* rt_sigaction: as it is *)
2001+ if not (p.keepIgnored and (acts[i][0] = 1)) then _ := SYSTEM.SYSCALL(13, i, SYSTEM.ADR(dfl), 0, 8); end;
20012002 end;
2002- _ := SYSCALL(14, 2, ADR(empty), 0, 8);
2003- r := SYSCALL(59, ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *)
2004- _ := SYSCALL(14, 2, ADR(all), 0, 8);
2005- for i := 1 to 64 do _ := SYSCALL(13, i, ADR(acts[i]), 0, 8); end;
2006- _ := SYSCALL(14, 2, ADR(old), 0, 8);
2003+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(empty), 0, 8);
2004+ r := SYSTEM.SYSCALL(59, SYSTEM.ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *)
2005+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(all), 0, 8);
2006+ for i := 1 to 64 do _ := SYSTEM.SYSCALL(13, i, SYSTEM.ADR(acts[i]), 0, 8); end;
2007+ _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(old), 0, 8);
20072008 end;
20082009 munmap(^U8(argv), size);
20092010 return r;
@@ -2014,14 +2015,14 @@
20142015 kernel's execve does and a shell wants: no search, and every fd and
20152016 signal as it is, but that a handled signal does what it does at
20162017 first. It returns only if it can't: minus an errno. *)
2017-proc execve*(path: []U8; args, env: [][]U8): INT;
2018+proc execve*(path: []const U8; args, env: [][]const U8): INT;
20182019 var a: [4096]U8; argv: ^^U8; none: ^U8; size, r: INT;
20192020 begin
20202021 if not cstr(path, a) then return -36; end; (* ENAMETOOLONG *)
20212022 none := nil;
2022- argv, size := argsAndEnv(args, env, ADR(none));
2023+ argv, size := argsAndEnv(args, env, SYSTEM.ADR(none));
20232024 if argv = nil then return -12; end; (* ENOMEM *)
2024- r := SYSCALL(59, ADR(a), argv, argv + (LEN(args) + 1)); (* execve *)
2025+ r := SYSTEM.SYSCALL(59, SYSTEM.ADR(a), argv, argv + (LEN(args) + 1)); (* execve *)
20252026 munmap(^U8(argv), size);
20262027 return r;
20272028 end;
@@ -2030,7 +2031,7 @@
20302031 proc waitFor(pid, options: INT): (INT, Status, INT);
20312032 var status: I32; r: INT;
20322033 begin
2033- r := SYSCALL(61, pid, ADR(status), options, 0); (* wait4 *)
2034+ r := SYSTEM.SYSCALL(61, pid, SYSTEM.ADR(status), options, 0); (* wait4 *)
20342035 if r <= 0 then return r, running, 0; end;
20352036 if status & 7FH = 0 then return r, exited, INT(status) shr 8 & 0FFH; end;
20362037 if status & 0FFH = 7FH then return r, stopped, INT(status) shr 8 & 0FFH; end;
@@ -2062,14 +2063,14 @@
20622063 errno. *)
20632064 proc kill*(pid, signal: INT): INT;
20642065 begin
2065- return SYSCALL(62, pid, signal);
2066+ return SYSTEM.SYSCALL(62, pid, signal);
20662067 end;
20672068
20682069 (* Catches the signals sigs: blocks them, so that they don't do what
20692070 they would, and gives them on an fd, which a later catch adds to and
20702071 gives again; or minus an errno. Only the thread that catches them
20712072 blocks them, and threads it starts later. ignore gives a signal up. *)
2072-proc catch*(sigs: []INT): INT;
2073+proc catch*(sigs: []const INT): INT;
20732074 var m: U64; i, fd: INT;
20742075 begin
20752076 m := caughtSigs;
@@ -2082,8 +2083,8 @@
20822083 end;
20832084 fd := -1;
20842085 if caughtSigs # 0 then fd := sigFd; end;
2085- _ := SYSCALL(14, 0, ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *)
2086- fd := SYSCALL(289, fd, ADR(m), 8, 80800H); (* signalfd4: SFD_NONBLOCK, SFD_CLOEXEC *)
2086+ _ := SYSTEM.SYSCALL(14, 0, SYSTEM.ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *)
2087+ fd := SYSTEM.SYSCALL(289, fd, SYSTEM.ADR(m), 8, 80800H); (* signalfd4: SFD_NONBLOCK, SFD_CLOEXEC *)
20872088 if fd < 0 then return fd; end;
20882089 caughtSigs := m;
20892090 sigFd := fd;
@@ -2110,11 +2111,11 @@
21102111 if caughtSigs & bit # 0 then
21112112 caughtSigs := caughtSigs & ~bit;
21122113 m := caughtSigs;
2113- _ := SYSCALL(289, sigFd, ADR(m), 8, 80800H); (* signalfd4: the signals still caught *)
2114- _ := SYSCALL(14, 1, ADR(bit), 0, 8); (* rt_sigprocmask: SIG_UNBLOCK *)
2114+ _ := SYSTEM.SYSCALL(289, sigFd, SYSTEM.ADR(m), 8, 80800H); (* signalfd4: the signals still caught *)
2115+ _ := SYSTEM.SYSCALL(14, 1, SYSTEM.ADR(bit), 0, 8); (* rt_sigprocmask: SIG_UNBLOCK *)
21152116 end;
21162117 end;
2117- return SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *)
2118+ return SYSTEM.SYSCALL(13, sig, SYSTEM.ADR(act), 0, 8); (* rt_sigaction *)
21182119 end;
21192120
21202121 (* Returns from a signal handler, as the kernel asks: rt_sigreturn,
@@ -2130,7 +2131,7 @@
21302131 program, perhaps while Out or Heap holds its lock. *)
21312132 proc onNoted(sig: INT);
21322133 begin
2133- _ := XCHG(ADR(noted[sig]), 1);
2134+ _ := XCHG(noted[sig], 1);
21342135 end;
21352136
21362137 (* Takes the signal sig away from what it would do: it is noted, for
@@ -2146,7 +2147,7 @@
21462147 return -22; (* EINVAL *)
21472148 end;
21482149 act := {handler: onNoted, flags: 4000000H, restorer: sigReturn}; (* SA_RESTORER, and no SA_RESTART *)
2149- return SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *)
2150+ return SYSTEM.SYSCALL(13, sig, SYSTEM.ADR(act), 0, 8); (* rt_sigaction *)
21502151 end;
21512152
21522153 (* Whether the signal sig, which handle took, came since the last time
@@ -2154,7 +2155,7 @@
21542155 proc came*(sig: INT): BOOL;
21552156 begin
21562157 if (sig < 1) or (sig > 64) then return false; end;
2157- return XCHG(ADR(noted[sig]), 0) = 1;
2158+ return XCHG(noted[sig], 0) = 1;
21582159 end;
21592160
21602161 (* A copy of this program, which goes on from here: 0 in the copy, its
@@ -2164,7 +2165,7 @@
21642165 first. *)
21652166 proc fork*: INT;
21662167 begin
2167- return SYSCALL(57); (* fork *)
2168+ return SYSTEM.SYSCALL(57); (* fork *)
21682169 end;
21692170
21702171 (* A new session and process group, led by this program, with no
@@ -2173,19 +2174,19 @@
21732174 doesn't). *)
21742175 proc setsid*: INT;
21752176 begin
2176- return SYSCALL(112); (* setsid *)
2177+ return SYSTEM.SYSCALL(112); (* setsid *)
21772178 end;
21782179
21792180 (* Gives the processor to another thread. *)
21802181 proc yield*;
21812182 begin
2182- _ := SYSCALL(24);
2183+ _ := SYSTEM.SYSCALL(24);
21832184 end;
21842185
21852186 (* Ends the program, at once, with status. *)
21862187 proc exit*(status: INT);
21872188 begin
2188- _ := SYSCALL(231, status);
2189+ _ := SYSTEM.SYSCALL(231, status);
21892190 end;
21902191
21912192 (* The test of programs: one on a pseudo-terminal of 100 by 30 prints
@@ -2339,7 +2340,7 @@
23392340 proc testShell;
23402341 var
23412342 r, w, fd, n, k, child, c, err, pty, sigs, mask, parent: INT; t: I64; st: Status; buf: [64]U8;
2342- m, raw: Mode; soft, hard, s2, h2, user, system: I64; e: []U8; ok, path: BOOL;
2343+ m, raw: Mode; soft, hard, s2, h2, user, system: I64; e: []const U8; ok, path: BOOL;
23432344 begin
23442345 r, w := pipe();
23452346 if w < 0 then exit(2); end;
@@ -2459,16 +2460,16 @@
24592460 random(x);
24602461 random(y);
24612462 if x[0..16] = y[0..16] then exit(2); end;
2462- if (inetAddr("10.0.0.255", 80, ADR(s)) # 16) or (s.port[0] # 0) or (s.port[1] # 80)
2463+ if (inetAddr("10.0.0.255", 80, SYSTEM.ADR(s)) # 16) or (s.port[0] # 0) or (s.port[1] # 80)
24632464 or (s.data[0] # 10) or (s.data[2] # 0) or (s.data[3] # 255) then
24642465 exit(2);
24652466 end;
2466- if (inetAddr("1:aBcd::ff", 258, ADR(s6)) # 28) or (s6.port[0] # 1) or (s6.port[1] # 2)
2467+ if (inetAddr("1:aBcd::ff", 258, SYSTEM.ADR(s6)) # 28) or (s6.port[0] # 1) or (s6.port[1] # 2)
24672468 or (s6.data[0] # 0) or (s6.data[5] # 1) or (s6.data[6] # 0ABH) or (s6.data[7] # 0CDH)
24682469 or (s6.data[18] # 0) or (s6.data[19] # 0FFH) then
24692470 exit(2);
24702471 end;
2471- if (inetAddr("::", 0, ADR(s6)) # 28) or (inetAddr("1:2:3:4:5:6:7:8", 0, ADR(s6)) # 28) then exit(2); end;
2472+ if (inetAddr("::", 0, SYSTEM.ADR(s6)) # 28) or (inetAddr("1:2:3:4:5:6:7:8", 0, SYSTEM.ADR(s6)) # 28) then exit(2); end;
24722473 if (connectTcp("1.2.3", 80) # -22) or (connectTcp("1.2.3.256", 80) # -22) or (connectTcp("1::2::3", 80) # -22)
24732474 or (connectTcp("1:2:3:4:5:6:7:8:9", 80) # -22) or (connectTcp("1:", 80) # -22)
24742475 or (connectTcp("12345::", 80) # -22) or (connectTcp("::1", 65536) # -22) then
@@ -2550,7 +2551,7 @@
25502551 (* The test of what a program asks of itself: a signal ignored or not,
25512552 an environment variable unset or empty, and the processors. *)
25522553 proc testProcess;
2553-var v: []U8; found: BOOL;
2554+var v: []const U8; found: BOOL;
25542555 begin
25552556 if (ignore(sigUsr1, true) # 0) or not ignored(sigUsr1) then exit(2); end;
25562557 if (ignore(sigUsr1, false) # 0) or ignored(sigUsr1) then exit(2); end;
@@ -2691,7 +2692,7 @@
26912692 directory made, listed and emptied; no terminal; a socket, sent to
26922693 after its end; programs; time and the network. *)
26932694 proc main*;
2694-var free, total: I64; fd, n, err, w, h, l, c, a, m, k, o: INT; got: [1]INT; buf: [16]U8; p, q: ^U8; i, j: Info; d: Dir; name: []U8; ok: BOOL;
2695+var free, total: I64; fd, n, err, w, h, l, c, a, m, k, o: INT; got: [1]INT; buf: [16]U8; p, q: ^U8; i, j: Info; d: Dir; name: []const U8; ok: BOOL;
26952696 begin
26962697 testPoll();
26972698 fd := create("/tmp/raz-sys-test");

lib/Sys.raz (history) modified +195 -194

@@ -16,6 +16,7 @@
1616 status holds, which every Unix encodes alike. *)
1717 module Sys;
1818 import C, CAbi;
19+import SYSTEM;
1920
2021 const
2122 stdin* = 0; (* standard input's file descriptor *)
@@ -101,11 +102,11 @@
101102
102103 (* A program for spawn to start. *)
103104 Program* = record
104- path*: []U8;
105- args*: [][]U8; (* the first is its name *)
106- env*: [][]U8; (* NAME=value, each added to this environment *)
105+ path*: []const U8;
106+ args*: [][]const U8; (* the first is its name *)
107+ env*: [][]const U8; (* NAME=value, each added to this environment *)
107108 onlyEnv*: BOOL; (* env is its whole environment *)
108- dir*: []U8; (* its working directory; "" for this program's *)
109+ dir*: []const U8; (* its working directory; "" for this program's *)
109110 fds*: [3]INT; (* stdin, stdout, stderr; 0 for this program's *)
110111 group*: INT; (* its group: 0 for this program's, -1 a new one *)
111112 foreground*: BOOL; (* its group gets the terminal on standard input *)
@@ -213,16 +214,16 @@
213214 is to see. broke is set to 0 before the call. *)
214215 proc again: BOOL;
215216 begin
216- return (failed() = -4) and (XCHG(ADR(broke), 0) = 0);
217+ return (failed() = -4) and (XCHG(broke, 0) = 0);
217218 end;
218219
219220 (* Writes s to the file descriptor fd; the number of bytes written, or
220221 minus an errno. *)
221-proc write*(fd: INT; s: []U8): INT;
222+proc write*(fd: INT; s: []const U8): INT;
222223 var r: INT;
223224 begin
224225 if LEN(s) = 0 then return 0; end;
225- r := C.write(I32(fd), ADR(s[0]), UINT(LEN(s)));
226+ r := C.write(I32(fd), SYSTEM.PTR(s), UINT(LEN(s)));
226227 if r < 0 then return failed(); end;
227228 return r;
228229 end;
@@ -233,13 +234,13 @@
233234 var r: INT;
234235 begin
235236 if LEN(buf) = 0 then return 0; end;
236- r := C.read(I32(fd), ADR(buf[0]), UINT(LEN(buf)));
237+ r := C.read(I32(fd), SYSTEM.ADR(buf[0]), UINT(LEN(buf)));
237238 if r < 0 then return failed(); end;
238239 return r;
239240 end;
240241
241242 (* path, a C string in buf, or false if it doesn't fit. *)
242-proc cstr(path, buf: []U8): BOOL;
243+proc cstr(path: []const U8; buf: []U8): BOOL;
243244 begin
244245 if LEN(path) >= LEN(buf) then return false; end;
245246 COPY(buf, path);
@@ -267,33 +268,33 @@
267268 (* The file at path, opened as how asks: its file descriptor, closed in
268269 a program exec starts, or minus an errno. A file it creates has the
269270 permission bits mode, less those the umask takes away. *)
270-proc openMode*(path: []U8; how: Accesses; mode: INT): INT;
271+proc openMode*(path: []const U8; how: Accesses; mode: INT): INT;
271272 var buf: [4096]U8; r: INT;
272273 begin
273274 if executing in how then return -22; end; (* EINVAL: access asks it, open can't *)
274275 if not cstr(path, buf) then return -36; end;
275- r := INT(C.open(ADR(buf[0]), flags(how), mode));
276+ r := INT(C.open(SYSTEM.ADR(buf[0]), flags(how), mode));
276277 if r < 0 then return failed(); end;
277278 return r;
278279 end;
279280
280281 (* openMode with 644: a file it creates is readable by all, writable
281282 by its owner. *)
282-proc open*(path: []U8; how: Accesses): INT;
283+proc open*(path: []const U8; how: Accesses): INT;
283284 begin
284285 return openMode(path, how, 1A4H); (* 644 *)
285286 end;
286287
287288 (* The file at path, opened for reading, closed in a program exec
288289 starts. *)
289-proc openRead*(path: []U8): INT;
290+proc openRead*(path: []const U8): INT;
290291 begin
291292 return open(path, {reading});
292293 end;
293294
294295 (* The file at path, made empty or new, opened for writing, closed in a
295296 program exec starts. *)
296-proc create*(path: []U8): INT;
297+proc create*(path: []const U8): INT;
297298 begin
298299 return open(path, {writing, creating, truncating});
299300 end;
@@ -458,7 +459,7 @@
458459 var name: [4]U8; fd: I32; err: INT;
459460 begin
460461 _ := cstr("raz", name); (* the name /proc shows *)
461- fd := C.memfd_create(ADR(name[0]), CAbi.mfdCloexec);
462+ fd := C.memfd_create(SYSTEM.ADR(name[0]), CAbi.mfdCloexec);
462463 if fd < 0 then return failed(); end;
463464 if C.ftruncate(fd, I64(size)) # 0 then
464465 err := failed(); (* before close can change errno *)
@@ -504,79 +505,79 @@
504505 end;
505506
506507 (* Renames old to new, replacing what new names: 0, or minus an errno. *)
507-proc rename*(old, new: []U8): INT;
508+proc rename*(old, new: []const U8): INT;
508509 var a, b: [4096]U8;
509510 begin
510511 if not cstr(old, a) or not cstr(new, b) then return -36; end;
511- if C.rename(ADR(a[0]), ADR(b[0])) # 0 then return failed(); end;
512+ if C.rename(SYSTEM.ADR(a[0]), SYSTEM.ADR(b[0])) # 0 then return failed(); end;
512513 return 0;
513514 end;
514515
515516 (* Removes the file at path; not a directory. *)
516-proc remove*(path: []U8): INT;
517+proc remove*(path: []const U8): INT;
517518 var a: [4096]U8;
518519 begin
519520 if not cstr(path, a) then return -36; end;
520- if C.unlink(ADR(a[0])) # 0 then return failed(); end;
521+ if C.unlink(SYSTEM.ADR(a[0])) # 0 then return failed(); end;
521522 return 0;
522523 end;
523524
524525 (* Makes a directory at path, readable by all, writable by its owner. *)
525-proc makeDir*(path: []U8): INT;
526+proc makeDir*(path: []const U8): INT;
526527 var a: [4096]U8;
527528 begin
528529 if not cstr(path, a) then return -36; end;
529- if C.mkdir(ADR(a[0]), 1EDH) # 0 then return failed(); end; (* mode 755 *)
530+ if C.mkdir(SYSTEM.ADR(a[0]), 1EDH) # 0 then return failed(); end; (* mode 755 *)
530531 return 0;
531532 end;
532533
533534 (* Makes a directory at path with the permission bits mode, less those
534535 the umask takes away: 1C0H (700) for one only its owner may enter. Of
535536 the bits above them Linux keeps only sticky, 200H. *)
536-proc makeDirMode*(path: []U8; mode: INT): INT;
537+proc makeDirMode*(path: []const U8; mode: INT): INT;
537538 var a: [4096]U8;
538539 begin
539540 if not cstr(path, a) then return -36; end;
540- if C.mkdir(ADR(a[0]), U32(mode)) # 0 then return failed(); end;
541+ if C.mkdir(SYSTEM.ADR(a[0]), U32(mode)) # 0 then return failed(); end;
541542 return 0;
542543 end;
543544
544545 (* Removes the directory at path, which must be empty. *)
545-proc removeDir*(path: []U8): INT;
546+proc removeDir*(path: []const U8): INT;
546547 var a: [4096]U8;
547548 begin
548549 if not cstr(path, a) then return -36; end;
549- if C.rmdir(ADR(a[0])) # 0 then return failed(); end;
550+ if C.rmdir(SYSTEM.ADR(a[0])) # 0 then return failed(); end;
550551 return 0;
551552 end;
552553
553554 (* Sets the permission bits of what path names. *)
554-proc chmod*(path: []U8; mode: INT): INT;
555+proc chmod*(path: []const U8; mode: INT): INT;
555556 var a: [4096]U8;
556557 begin
557558 if not cstr(path, a) then return -36; end;
558- if C.chmod(ADR(a[0]), U32(mode)) # 0 then return failed(); end;
559+ if C.chmod(SYSTEM.ADR(a[0]), U32(mode)) # 0 then return failed(); end;
559560 return 0;
560561 end;
561562
562563 (* Makes a fifo (a named pipe) at path with the permission bits mode,
563564 less those the umask takes away. 0, or minus an errno. *)
564-proc makeFifo*(path: []U8; mode: INT): INT;
565+proc makeFifo*(path: []const U8; mode: INT): INT;
565566 var a: [4096]U8;
566567 begin
567568 if not cstr(path, a) then return -36; end;
568- if C.mkfifo(ADR(a[0]), U32(mode & 1FFH)) # 0 then return failed(); end;
569+ if C.mkfifo(SYSTEM.ADR(a[0]), U32(mode & 1FFH)) # 0 then return failed(); end;
569570 return 0;
570571 end;
571572
572573 (* Sets the owner and group of what path names, following a symbolic
573574 link: a user or group number, or -1 to leave it as it is. Only
574575 root may give a file away. 0, or minus an errno. *)
575-proc chown*(path: []U8; uid, gid: INT): INT;
576+proc chown*(path: []const U8; uid, gid: INT): INT;
576577 var a: [4096]U8;
577578 begin
578579 if not cstr(path, a) then return -36; end;
579- if C.chown(ADR(a[0]), U32(uid & 0FFFFFFFFH), U32(gid & 0FFFFFFFFH)) # 0 then return failed(); end;
580+ if C.chown(SYSTEM.ADR(a[0]), U32(uid & 0FFFFFFFFH), U32(gid & 0FFFFFFFFH)) # 0 then return failed(); end;
580581 return 0;
581582 end;
582583
@@ -584,7 +585,7 @@
584585 was last read, to sec seconds and nsec nanoseconds since 1970, as a
585586 program copying a file keeps its time: Info.seconds gives sec back,
586587 whatever the time. *)
587-proc setTime*(path: []U8; sec: I64; nsec: INT): INT;
588+proc setTime*(path: []const U8; sec: I64; nsec: INT): INT;
588589 var a: [4096]U8; t: [2]Timespec;
589590 begin
590591 if not cstr(path, a) then return -36; end;
@@ -592,14 +593,14 @@
592593 t[0].sec := sec;
593594 t[0].nsec := nsec;
594595 t[1] := t[0];
595- if C.utimensat(CAbi.atFdcwd, ADR(a[0]), ^U8(ADR(t)), 0) # 0 then return failed(); end;
596+ if C.utimensat(CAbi.atFdcwd, SYSTEM.ADR(a[0]), ^U8(SYSTEM.ADR(t)), 0) # 0 then return failed(); end;
596597 return 0;
597598 end;
598599
599600 (* 0 if this user, by its real ids, may do with path what how asks:
600601 reading, writing and executing; minus an errno, -13 (EACCES) if not.
601602 An empty how asks only whether path is there. *)
602-proc access*(path: []U8; how: Accesses): INT;
603+proc access*(path: []const U8; how: Accesses): INT;
603604 var a: [4096]U8; m: I32;
604605 begin
605606 if not cstr(path, a) then return -36; end;
@@ -607,7 +608,7 @@
607608 if reading in how then m := m | CAbi.rOk; end;
608609 if writing in how then m := m | CAbi.wOk; end;
609610 if executing in how then m := m | CAbi.xOk; end;
610- if C.access(ADR(a[0]), m) # 0 then return failed(); end;
611+ if C.access(SYSTEM.ADR(a[0]), m) # 0 then return failed(); end;
611612 return 0;
612613 end;
613614
@@ -619,21 +620,21 @@
619620 end;
620621
621622 (* Makes path a symbolic link to target. *)
622-proc symlink*(target, path: []U8): INT;
623+proc symlink*(target, path: []const U8): INT;
623624 var a, b: [4096]U8;
624625 begin
625626 if not cstr(target, a) or not cstr(path, b) then return -36; end;
626- if C.symlink(ADR(a[0]), ADR(b[0])) # 0 then return failed(); end;
627+ if C.symlink(SYSTEM.ADR(a[0]), SYSTEM.ADR(b[0])) # 0 then return failed(); end;
627628 return 0;
628629 end;
629630
630631 (* What the symbolic link at path names, good until the next call; and
631632 0, or minus an errno. *)
632-proc readLink*(path: []U8): ([]U8, INT);
633+proc readLink*(path: []const U8): ([]const U8, INT);
633634 var a: [4096]U8; n: INT;
634635 begin
635636 if not cstr(path, a) then return "", -36; end;
636- n := C.readlink(ADR(a[0]), ADR(linked[0]), UINT(LEN(linked)));
637+ n := C.readlink(SYSTEM.ADR(a[0]), SYSTEM.ADR(linked[0]), UINT(LEN(linked)));
637638 if n < 0 then return "", failed(); end;
638639 if n = LEN(linked) then return "", -36; end; (* it may be cut short *)
639640 return linked[0..n], 0;
@@ -644,14 +645,14 @@
644645 (* The type of file a struct stat says, S_IFDIR, S_IFREG or another *)
645646 proc fileType(st: Stat): INT;
646647 begin
647- return INT(field(^U8(ADR(st)), CAbi.stModeAt, CAbi.stModeLen)) & CAbi.sIfmt;
648+ return INT(field(^U8(SYSTEM.ADR(st)), CAbi.stModeAt, CAbi.stModeLen)) & CAbi.sIfmt;
648649 end;
649650
650651 (* An Info from a struct stat, all but symlink. *)
651652 proc fromStat(st: Stat): Info;
652653 var i: Info; p: ^U8;
653654 begin
654- p := ^U8(ADR(st));
655+ p := ^U8(SYSTEM.ADR(st));
655656 i.size := field(p, CAbi.stSizeAt, CAbi.stSizeLen);
656657 i.dev := U64(field(p, CAbi.stDevAt, CAbi.stDevLen));
657658 i.ino := U64(field(p, CAbi.stInoAt, CAbi.stInoLen));
@@ -670,13 +671,13 @@
670671 (* The size of what path names, whether it is a directory or a regular
671672 file, following a symbolic link, and whether path is one; and 0, or
672673 minus an errno. *)
673-proc info*(path: []U8): (Info, INT);
674+proc info*(path: []const U8): (Info, INT);
674675 var a: [4096]U8; st: Stat; i: Info; isLink: BOOL;
675676 begin
676677 if not cstr(path, a) then return i, -36; end;
677- if C.lstat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end;
678+ if C.lstat(SYSTEM.ADR(a[0]), ^U8(SYSTEM.ADR(st))) # 0 then return i, failed(); end;
678679 isLink := fileType(st) = CAbi.sIflnk;
679- if C.stat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end;
680+ if C.stat(SYSTEM.ADR(a[0]), ^U8(SYSTEM.ADR(st))) # 0 then return i, failed(); end;
680681 i := fromStat(st);
681682 i.symlink := isLink;
682683 return i, 0;
@@ -685,11 +686,11 @@
685686 (* info of path itself: if it is a symbolic link, of the link, not of
686687 what it names, so that symlink is true, dir and file false, and the
687688 size the length of what it names. *)
688-proc linkInfo*(path: []U8): (Info, INT);
689+proc linkInfo*(path: []const U8): (Info, INT);
689690 var a: [4096]U8; st: Stat; i: Info;
690691 begin
691692 if not cstr(path, a) then return i, -36; end;
692- if C.lstat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end;
693+ if C.lstat(SYSTEM.ADR(a[0]), ^U8(SYSTEM.ADR(st))) # 0 then return i, failed(); end;
693694 i := fromStat(st);
694695 i.symlink := fileType(st) = CAbi.sIflnk;
695696 return i, 0;
@@ -699,18 +700,18 @@
699700 proc infoOf*(fd: INT): (Info, INT);
700701 var st: Stat; i: Info;
701702 begin
702- if C.fstat(I32(fd), ^U8(ADR(st))) # 0 then return i, failed(); end;
703+ if C.fstat(I32(fd), ^U8(SYSTEM.ADR(st))) # 0 then return i, failed(); end;
703704 return fromStat(st), 0;
704705 end;
705706
706707 (* The bytes free to an ordinary user on path's file system, and the
707708 bytes in all. *)
708-proc space*(path: []U8): (I64, I64, INT);
709+proc space*(path: []const U8): (I64, I64, INT);
709710 var a: [4096]U8; st: [(CAbi.statvfsLen + 7) div 8]U64; p: ^U8; unit: I64;
710711 begin
711712 if not cstr(path, a) then return 0, 0, -36; end;
712- p := ^U8(ADR(st));
713- if C.statvfs(ADR(a[0]), p) # 0 then return 0, 0, failed(); end;
713+ p := ^U8(SYSTEM.ADR(st));
714+ if C.statvfs(SYSTEM.ADR(a[0]), p) # 0 then return 0, 0, failed(); end;
714715 unit := field(p, CAbi.fFrsizeAt, CAbi.fFrsizeLen);
715716 return field(p, CAbi.fBavailAt, CAbi.fBavailLen) * unit, field(p, CAbi.fBlocksAt, CAbi.fBlocksLen) * unit, 0;
716717 end;
@@ -728,19 +729,19 @@
728729 end;
729730
730731 (* Opens the directory at path, for nextEntry. *)
731-proc openDir*(var d: Dir; path: []U8): INT;
732+proc openDir*(var d: Dir; path: []const U8): INT;
732733 var a: [4096]U8;
733734 begin
734735 d.kind := unknown;
735736 if not cstr(path, a) then return -36; end;
736- d.d := C.opendir(ADR(a[0]));
737+ d.d := C.opendir(SYSTEM.ADR(a[0]));
737738 if d.d = nil then return failed(); end;
738739 return 0;
739740 end;
740741
741742 (* The next name in the directory, good until the next call, but . and
742743 .., in no order; false at the end. *)
743-proc nextEntry*(var d: Dir): ([]U8, BOOL);
744+proc nextEntry*(var d: Dir): ([]const U8, BOOL);
744745 var e: ^U8; n: INT;
745746 begin
746747 while true do
@@ -775,16 +776,16 @@
775776 proc rawMode*(fd: INT): BOOL;
776777 var t: [256]U8;
777778 begin
778- if C.tcgetattr(I32(fd), ADR(saved[0])) # 0 then return false; end;
779+ if C.tcgetattr(I32(fd), SYSTEM.ADR(saved[0])) # 0 then return false; end;
779780 t := saved;
780- C.cfmakeraw(ADR(t[0]));
781- return C.tcsetattr(I32(fd), CAbi.tcsanow, ADR(t[0])) = 0;
781+ C.cfmakeraw(SYSTEM.ADR(t[0]));
782+ return C.tcsetattr(I32(fd), CAbi.tcsanow, SYSTEM.ADR(t[0])) = 0;
782783 end;
783784
784785 (* The terminal on fd as rawMode found it. *)
785786 proc restoreMode*(fd: INT);
786787 begin
787- _ := C.tcsetattr(I32(fd), CAbi.tcsanow, ADR(saved[0]));
788+ _ := C.tcsetattr(I32(fd), CAbi.tcsanow, SYSTEM.ADR(saved[0]));
788789 end;
789790
790791 (* The modes of the terminal on fd, as a shell keeps them for each job;
@@ -792,7 +793,7 @@
792793 proc getMode*(fd: INT): (Mode, INT);
793794 var m: Mode;
794795 begin
795- if C.tcgetattr(I32(fd), ADR(m.t[0])) # 0 then return m, failed(); end;
796+ if C.tcgetattr(I32(fd), SYSTEM.ADR(m.t[0])) # 0 then return m, failed(); end;
796797 return m, 0;
797798 end;
798799
@@ -800,7 +801,7 @@
800801 is sent: 0, or minus an errno. *)
801802 proc setMode*(fd: INT; m: Mode): INT;
802803 begin
803- if C.tcsetattr(I32(fd), CAbi.tcsadrain, ADR(m.t[0])) # 0 then return failed(); end;
804+ if C.tcsetattr(I32(fd), CAbi.tcsadrain, SYSTEM.ADR(m.t[0])) # 0 then return failed(); end;
804805 return 0;
805806 end;
806807
@@ -809,7 +810,7 @@
809810 proc termSize*(fd: INT): (INT, INT);
810811 var w: Winsize;
811812 begin
812- if (C.ioctl(I32(fd), CAbi.tiocgwinsz, ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then
813+ if (C.ioctl(I32(fd), CAbi.tiocgwinsz, SYSTEM.ADR(w)) # 0) or (w.cols = 0) or (w.rows = 0) then
813814 return 80, 24;
814815 end;
815816 return INT(w.cols), INT(w.rows);
@@ -821,8 +822,8 @@
821822 var p: Pollfd; r: I32;
822823 begin
823824 p := {fd: I32(fd), events: CAbi.pollin};
824- _ := XCHG(ADR(broke), 0);
825- repeat r := C.poll(^U8(ADR(p)), 1, I32(ms)); until (r >= 0) or not again();
825+ _ := XCHG(broke, 0);
826+ repeat r := C.poll(^U8(SYSTEM.ADR(p)), 1, I32(ms)); until (r >= 0) or not again();
826827 return r > 0;
827828 end;
828829
@@ -830,7 +831,7 @@
830831 proc time(clock: I32): I64;
831832 var t: Timespec;
832833 begin
833- _ := C.clock_gettime(clock, ^U8(ADR(t)));
834+ _ := C.clock_gettime(clock, ^U8(SYSTEM.ADR(t)));
834835 return t.sec * 1000000000 + t.nsec;
835836 end;
836837
@@ -854,7 +855,7 @@
854855 at := clock() + I64(ms) * 1000000;
855856 t := {sec: at div 1000000000, nsec: at mod 1000000000};
856857 (* until t, again after EINTR, which it returns, the C library's *)
857- repeat until C.clock_nanosleep(CAbi.clockMonotonic, CAbi.timerAbstime, ^U8(ADR(t)), nil) # CAbi.eIntr;
858+ repeat until C.clock_nanosleep(CAbi.clockMonotonic, CAbi.timerAbstime, ^U8(SYSTEM.ADR(t)), nil) # CAbi.eIntr;
858859 end;
859860
860861 (* Ends the program: random bytes can't be faked. *)
@@ -873,7 +874,7 @@
873874 begin
874875 n := 0;
875876 while n < LEN(b) do (* a signal may cut it short *)
876- r := C.getrandom(ADR(b[n]), UINT(LEN(b) - n), 0);
877+ r := C.getrandom(SYSTEM.ADR(b[n]), UINT(LEN(b) - n), 0);
877878 if r > 0 then INC(n, r);
878879 elsif (r >= 0) or (failed() # errIntr) then noRandom(); (* r = 0 can't be, and is no progress *)
879880 end;
@@ -891,7 +892,7 @@
891892 if fd < 0 then return failed(); end;
892893 if serving then
893894 one := 1; (* so that a server can start again at once *)
894- _ := C.setsockopt(fd, CAbi.solSocket, CAbi.soReuseaddr, ^U8(ADR(one)), 4);
895+ _ := C.setsockopt(fd, CAbi.solSocket, CAbi.soReuseaddr, ^U8(SYSTEM.ADR(one)), 4);
895896 r := C.bind(fd, a, U32(size));
896897 if (r = 0) and (kind = CAbi.sockStream) then (* a stream socket takes connections; *)
897898 r := C.listen(fd, 4096); (* one of datagrams only receives *)
@@ -925,7 +926,7 @@
925926 -36 (ENAMETOOLONG) if it is too long. A path that starts with a zero
926927 byte is one of Linux's abstract names, which has no file and no
927928 trailing zero: its length ends with the name's. *)
928-proc unixAddr(path: []U8; a: ^Sockaddr): INT;
929+proc unixAddr(path: []const U8; a: ^Sockaddr): INT;
929930 var p: ^U8;
930931 begin
931932 if LEN(path) >= CAbi.sunPathLen then return -36; end;
@@ -937,40 +938,40 @@
937938 end;
938939
939940 (* A stream socket connected to the Unix socket at path. *)
940-proc connect*(path: []U8): INT;
941+proc connect*(path: []const U8): INT;
941942 var a: Sockaddr; size: INT;
942943 begin
943- size := unixAddr(path, ADR(a));
944+ size := unixAddr(path, SYSTEM.ADR(a));
944945 if size < 0 then return size; end;
945- return socket(CAbi.afUnix, CAbi.sockStream, ^U8(ADR(a)), size, false);
946+ return socket(CAbi.afUnix, CAbi.sockStream, ^U8(SYSTEM.ADR(a)), size, false);
946947 end;
947948
948949 (* A stream socket made at path, which must not be there yet, taking
949950 connections. *)
950-proc listen*(path: []U8): INT;
951+proc listen*(path: []const U8): INT;
951952 var a: Sockaddr; size: INT;
952953 begin
953- size := unixAddr(path, ADR(a));
954+ size := unixAddr(path, SYSTEM.ADR(a));
954955 if size < 0 then return size; end;
955- return socket(CAbi.afUnix, CAbi.sockStream, ^U8(ADR(a)), size, true);
956+ return socket(CAbi.afUnix, CAbi.sockStream, ^U8(SYSTEM.ADR(a)), size, true);
956957 end;
957958
958959 (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size
959960 of its struct sockaddr_in or sockaddr_in6, or 0 if either is
960961 wrong. *)
961-proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT;
962+proc inetAddr(addr: []const U8; port: INT; a: ^Sockaddr): INT;
962963 var s: [64]U8; b: [16]U8; p: ^U8; at, size: INT;
963964 begin
964965 if (port < 0) or (port > 65535) or not cstr(addr, s) then return 0; end;
965966 p := ^U8(a);
966967 (* into b first, since musl's inet_pton leaves what it read of an
967968 address it refuses, and the rest of the address is to be zero *)
968- if C.inet_pton(CAbi.afInet, ADR(s[0]), ADR(b[0])) = 1 then
969+ if C.inet_pton(CAbi.afInet, SYSTEM.ADR(s[0]), SYSTEM.ADR(b[0])) = 1 then
969970 size := CAbi.sockaddrInLen;
970971 setFamily(p, CAbi.afInet, size);
971972 COPY(p[CAbi.sinAddrAt..CAbi.sinAddrAt + 4], b[0..4]);
972973 at := CAbi.sinPortAt;
973- elsif C.inet_pton(CAbi.afInet6, ADR(s[0]), ADR(b[0])) = 1 then
974+ elsif C.inet_pton(CAbi.afInet6, SYSTEM.ADR(s[0]), SYSTEM.ADR(b[0])) = 1 then
974975 size := CAbi.sockaddrIn6Len;
975976 setFamily(p, CAbi.afInet6, size);
976977 COPY(p[CAbi.sin6AddrAt..CAbi.sin6AddrAt + 16], b);
@@ -994,37 +995,37 @@
994995
995996 (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL)
996997 if they are wrong. *)
997-proc inet(addr: []U8; port, kind: INT; serving: BOOL): INT;
998+proc inet(addr: []const U8; port, kind: INT; serving: BOOL): INT;
998999 var a: Sockaddr; size: INT;
9991000 begin
1000- size := inetAddr(addr, port, ADR(a));
1001+ size := inetAddr(addr, port, SYSTEM.ADR(a));
10011002 if size = 0 then return -22; end;
1002- return socket(familyOf(^U8(ADR(a))), kind, ^U8(ADR(a)), size, serving);
1003+ return socket(familyOf(^U8(SYSTEM.ADR(a))), kind, ^U8(SYSTEM.ADR(a)), size, serving);
10031004 end;
10041005
10051006 (* A stream socket connected to port at addr, an IPv4 or IPv6 address
10061007 as numbers. *)
1007-proc connectTcp*(addr: []U8; port: INT): INT;
1008+proc connectTcp*(addr: []const U8; port: INT): INT;
10081009 begin
10091010 return inet(addr, port, CAbi.sockStream, false);
10101011 end;
10111012
10121013 (* A socket of datagrams to and from port at addr. *)
1013-proc connectUdp*(addr: []U8; port: INT): INT;
1014+proc connectUdp*(addr: []const U8; port: INT): INT;
10141015 begin
10151016 return inet(addr, port, CAbi.sockDgram, false);
10161017 end;
10171018
10181019 (* A stream socket taking connections on port at addr; "0.0.0.0" or
10191020 "::" is every address the machine has. *)
1020-proc listenTcp*(addr: []U8; port: INT): INT;
1021+proc listenTcp*(addr: []const U8; port: INT): INT;
10211022 begin
10221023 return inet(addr, port, CAbi.sockStream, true);
10231024 end;
10241025
10251026 (* A socket of datagrams on port at addr, from anyone, for receive and
10261027 reply. *)
1027-proc listenUdp*(addr: []U8; port: INT): INT;
1028+proc listenUdp*(addr: []const U8; port: INT): INT;
10281029 begin
10291030 return inet(addr, port, CAbi.sockDgram, true);
10301031 end;
@@ -1055,16 +1056,16 @@
10551056 begin
10561057 r := {unix: false, ipv6: false};
10571058 size := U32(SIZE(Sockaddr));
1058- p := ^U8(ADR(a));
1059- if C.getpeername(I32(fd), p, ADR(size)) # 0 then return r, failed(); end;
1059+ p := ^U8(SYSTEM.ADR(a));
1060+ if C.getpeername(I32(fd), p, SYSTEM.ADR(size)) # 0 then return r, failed(); end;
10601061 if familyOf(p) = CAbi.afUnix then (* ask who made the connection *)
10611062 credSize := U32(LEN(cred));
1062- if C.getsockopt(I32(fd), CAbi.solSocket, CAbi.soPeercred, ADR(cred[0]), ADR(credSize)) # 0 then
1063+ if C.getsockopt(I32(fd), CAbi.solSocket, CAbi.soPeercred, SYSTEM.ADR(cred[0]), SYSTEM.ADR(credSize)) # 0 then
10631064 return r, failed();
10641065 end;
10651066 r.unix := true;
1066- r.pid := INT(field(ADR(cred[0]), CAbi.ucPidAt, CAbi.ucPidLen));
1067- r.uid := INT(field(ADR(cred[0]), CAbi.ucUidAt, CAbi.ucUidLen));
1067+ r.pid := INT(field(SYSTEM.ADR(cred[0]), CAbi.ucPidAt, CAbi.ucPidLen));
1068+ r.uid := INT(field(SYSTEM.ADR(cred[0]), CAbi.ucUidAt, CAbi.ucUidLen));
10681069 else
10691070 r.port := portOf(p);
10701071 if familyOf(p) = CAbi.afInet6 then
@@ -1083,7 +1084,7 @@
10831084 proc socketPair*: (INT, INT, INT);
10841085 var fds: [2]I32;
10851086 begin
1086- if C.socketpair(CAbi.afUnix, CAbi.sockStream | CAbi.sockCloexec, 0, ADR(fds[0])) # 0 then
1087+ if C.socketpair(CAbi.afUnix, CAbi.sockStream | CAbi.sockCloexec, 0, SYSTEM.ADR(fds[0])) # 0 then
10871088 return -1, -1, failed();
10881089 end;
10891090 return INT(fds[0]), INT(fds[1]), 0;
@@ -1092,22 +1093,22 @@
10921093 (* Writes s to the socket fd, as write does, but returns -32 (EPIPE)
10931094 where write would stop the program with SIGPIPE: when the other end
10941095 has closed it. *)
1095-proc send*(fd: INT; s: []U8): INT;
1096+proc send*(fd: INT; s: []const U8): INT;
10961097 var r: INT;
10971098 begin
10981099 if LEN(s) = 0 then return 0; end;
1099- r := C.send(I32(fd), ADR(s[0]), UINT(LEN(s)), CAbi.msgNosignal);
1100+ r := C.send(I32(fd), SYSTEM.PTR(s), UINT(LEN(s)), CAbi.msgNosignal);
11001101 if r < 0 then return failed(); end;
11011102 return r;
11021103 end;
11031104
11041105 (* send, but never waits: returns -11 (EAGAIN) where send would wait for
11051106 room, and doesn't make reads on fd non-blocking too. *)
1106-proc sendNow*(fd: INT; s: []U8): INT;
1107+proc sendNow*(fd: INT; s: []const U8): INT;
11071108 var r: INT;
11081109 begin
11091110 if LEN(s) = 0 then return 0; end;
1110- r := C.send(I32(fd), ADR(s[0]), UINT(LEN(s)), CAbi.msgNosignal | CAbi.msgDontwait);
1111+ r := C.send(I32(fd), SYSTEM.PTR(s), UINT(LEN(s)), CAbi.msgNosignal | CAbi.msgDontwait);
11111112 if r < 0 then return failed(); end;
11121113 return r;
11131114 end;
@@ -1137,8 +1138,8 @@
11371138 if fds[i].write then events := events | CAbi.pollout; end;
11381139 list[i] := {fd: I32(fds[i].fd), events: events};
11391140 end;
1140- _ := XCHG(ADR(broke), 0);
1141- repeat r := INT(C.poll(^U8(PTR(list)), UINT(n), I32(ms))); until (r >= 0) or not again();
1141+ _ := XCHG(broke, 0);
1142+ repeat r := INT(C.poll(^U8(SYSTEM.PTR(list)), UINT(n), I32(ms))); until (r >= 0) or not again();
11421143 e := 0;
11431144 if r < 0 then e := failed(); end;
11441145 for i := 0 to n - 1 do
@@ -1154,7 +1155,7 @@
11541155 reached its end or failed, so that a read or a write won't wait; -1
11551156 if none has. ms < 0 waits as long as it takes. At most 64 fds in
11561157 all. *)
1157-proc readyFor*(reads, writes: []INT; ms: INT): INT;
1158+proc readyFor*(reads, writes: []const INT; ms: INT): INT;
11581159 var p: [64]Poll; ps: []Poll; n, i: INT;
11591160 begin
11601161 n := 0;
@@ -1181,7 +1182,7 @@
11811182 (* The first of fds that has something to read within ms milliseconds,
11821183 or that has reached its end or failed, so that a read won't wait; -1
11831184 if none has. ms < 0 waits as long as it takes. At most 64 fds. *)
1184-proc readyOf*(fds: []INT; ms: INT): INT;
1185+proc readyOf*(fds: []const INT; ms: INT): INT;
11851186 begin
11861187 return readyFor(fds, [], ms);
11871188 end;
@@ -1214,20 +1215,20 @@
12141215 or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds.
12151216 It starts to connect without waiting, then waits for the socket to
12161217 be writable, which it is once connected or refused, and asks which. *)
1217-proc connectTcpWithin*(addr: []U8; port, ms: INT): INT;
1218+proc connectTcpWithin*(addr: []const U8; port, ms: INT): INT;
12181219 var a: Sockaddr; size, r: INT; fd, err: I32; errSize: U32;
12191220 begin
1220- size := inetAddr(addr, port, ADR(a));
1221+ size := inetAddr(addr, port, SYSTEM.ADR(a));
12211222 if size = 0 then return -22; end;
1222- fd := C.socket(I32(familyOf(^U8(ADR(a)))), CAbi.sockStream | CAbi.sockCloexec | CAbi.sockNonblock, 0);
1223+ fd := C.socket(I32(familyOf(^U8(SYSTEM.ADR(a)))), CAbi.sockStream | CAbi.sockCloexec | CAbi.sockNonblock, 0);
12231224 if fd < 0 then return failed(); end;
12241225 r := 0;
1225- if C.connect(fd, ^U8(ADR(a)), U32(size)) # 0 then r := failed(); end;
1226+ if C.connect(fd, ^U8(SYSTEM.ADR(a)), U32(size)) # 0 then r := failed(); end;
12261227 if r = -115 then (* EINPROGRESS *)
12271228 r := -110;
12281229 if readyFor([], [INT(fd)], ms) = INT(fd) then
12291230 errSize := 4;
1230- if C.getsockopt(fd, CAbi.solSocket, CAbi.soError, ^U8(ADR(err)), ADR(errSize)) = 0 then
1231+ if C.getsockopt(fd, CAbi.solSocket, CAbi.soError, ^U8(SYSTEM.ADR(err)), SYSTEM.ADR(errSize)) = 0 then
12311232 r := linux(-INT(err));
12321233 else
12331234 r := failed();
@@ -1245,8 +1246,8 @@
12451246 var a: Sockaddr; size: U32;
12461247 begin
12471248 size := U32(SIZE(Sockaddr));
1248- if C.getsockname(I32(fd), ^U8(ADR(a)), ADR(size)) # 0 then return failed(); end;
1249- return portOf(^U8(ADR(a)));
1249+ if C.getsockname(I32(fd), ^U8(SYSTEM.ADR(a)), SYSTEM.ADR(size)) # 0 then return failed(); end;
1250+ return portOf(^U8(SYSTEM.ADR(a)));
12501251 end;
12511252
12521253 (* The next datagram to the socket fd, waiting for one: its first
@@ -1256,7 +1257,7 @@
12561257 var p: Peer; size: U32; n: INT;
12571258 begin
12581259 size := U32(SIZE(Sockaddr));
1259- n := C.recvfrom(I32(fd), PTR(buf), UINT(LEN(buf)), 0, ^U8(ADR(p.a)), ADR(size));
1260+ n := C.recvfrom(I32(fd), SYSTEM.PTR(buf), UINT(LEN(buf)), 0, ^U8(SYSTEM.ADR(p.a)), SYSTEM.ADR(size));
12601261 if n < 0 then n := failed(); end;
12611262 p.size := INT(size);
12621263 return n, p;
@@ -1264,10 +1265,10 @@
12641265
12651266 (* Sends s, as one datagram, from the socket fd to peer, as receive
12661267 gave it: the bytes sent, or minus an errno. *)
1267-proc reply*(fd: INT; peer: Peer; s: []U8): INT;
1268+proc reply*(fd: INT; peer: Peer; s: []const U8): INT;
12681269 var r: INT;
12691270 begin
1270- r := C.sendto(I32(fd), PTR(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(ADR(peer.a)), U32(peer.size));
1271+ r := C.sendto(I32(fd), SYSTEM.PTR(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(SYSTEM.ADR(peer.a)), U32(peer.size));
12711272 if r < 0 then return failed(); end;
12721273 return r;
12731274 end;
@@ -1275,17 +1276,17 @@
12751276 (* Sends s, at least one byte, to the Unix socket fd, as send does, and
12761277 with it the files fds, at most 16, which the program that receives
12771278 them then has open too: the bytes sent, or minus an errno. *)
1278-proc sendFds*(fd: INT; s: []U8; fds: []INT): INT;
1279+proc sendFds*(fd: INT; s: []const U8; fds: []const INT): INT;
12791280 var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; sent: ^I32; i, r, size: INT;
12801281 begin
12811282 if (LEN(s) = 0) or (LEN(fds) > 16) then return -22; end;
1282- v := {base: ADR(s[0]), size: LEN(s)};
1283- mp := ^U8(ADR(m));
1284- setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(ADR(v)));
1283+ v := {base: SYSTEM.PTR(s), size: LEN(s)};
1284+ mp := ^U8(SYSTEM.ADR(m));
1285+ setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(SYSTEM.ADR(v)));
12851286 setField(mp, CAbi.msgIovlenAt, CAbi.msgIovlenLen, 1);
12861287 if LEN(fds) > 0 then
12871288 (* a struct cmsghdr, its level and type ints, then the fds *)
1288- cp := ^U8(ADR(c));
1289+ cp := ^U8(SYSTEM.ADR(c));
12891290 size := CAbi.cmsgDataAt + 4 * LEN(fds);
12901291 setField(cp, CAbi.cmsgLenAt, CAbi.cmsgLenLen, size);
12911292 setField(cp, CAbi.cmsgLevelAt, 4, CAbi.solSocket);
@@ -1308,10 +1309,10 @@
13081309 proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT);
13091310 var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; got: ^I32; n, k, i, size: INT;
13101311 begin
1311- v := {base: PTR(buf), size: LEN(buf)};
1312- mp := ^U8(ADR(m));
1313- cp := ^U8(ADR(c));
1314- setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(ADR(v)));
1312+ v := {base: SYSTEM.PTR(buf), size: LEN(buf)};
1313+ mp := ^U8(SYSTEM.ADR(m));
1314+ cp := ^U8(SYSTEM.ADR(c));
1315+ setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(SYSTEM.ADR(v)));
13151316 setField(mp, CAbi.msgIovlenAt, CAbi.msgIovlenLen, 1);
13161317 setField(mp, CAbi.msgControlAt, SIZE(^U8), INT(cp));
13171318 setField(mp, CAbi.msgControllenAt, CAbi.msgControllenLen, SIZE(Control));
@@ -1336,7 +1337,7 @@
13361337
13371338 (* What errno err, or minus it, means, as the C library's strerror
13381339 says it. *)
1339-proc errorText*(err: INT): []U8;
1340+proc errorText*(err: INT): []const U8;
13401341 var s: ^U8; n, i: INT;
13411342 begin
13421343 if err < 0 then err := -err; end;
@@ -1353,11 +1354,11 @@
13531354
13541355 (* The value of the environment variable name and true, or "" and
13551356 false if it isn't set: "" and true if it is set to nothing. *)
1356-proc findEnv*(name: []U8): ([]U8, BOOL);
1357+proc findEnv*(name: []const U8): ([]const U8, BOOL);
13571358 var a: [4096]U8; s: ^U8; n: INT;
13581359 begin
13591360 if not cstr(name, a) then return "", false; end;
1360- s := C.getenv(ADR(a[0]));
1361+ s := C.getenv(SYSTEM.ADR(a[0]));
13611362 if s = nil then return "", false; end;
13621363 n := 0;
13631364 while s[n] # 0 do INC(n); end;
@@ -1365,8 +1366,8 @@
13651366 end;
13661367
13671368 (* The value of the environment variable name; "" if it isn't set. *)
1368-proc env*(name: []U8): []U8;
1369-var v: []U8;
1369+proc env*(name: []const U8): []const U8;
1370+var v: []const U8;
13701371 begin
13711372 v, _ := findEnv(name);
13721373 return v;
@@ -1374,7 +1375,7 @@
13741375
13751376 (* The environment's ith NAME=value, from 0, and true; "" and false
13761377 past the last. *)
1377-proc envAt*(i: INT): ([]U8, BOOL);
1378+proc envAt*(i: INT): ([]const U8, BOOL);
13781379 var e: ^^U8; s: ^U8; j, n: INT;
13791380 begin
13801381 if i < 0 then return "", false; end;
@@ -1390,21 +1391,21 @@
13901391
13911392 (* The working directory, good until the next call; and 0, or minus an
13921393 errno. *)
1393-proc workDir*: ([]U8, INT);
1394+proc workDir*: ([]const U8, INT);
13941395 var n: INT;
13951396 begin
1396- if C.getcwd(ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end;
1397+ if C.getcwd(SYSTEM.ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end;
13971398 n := 0;
13981399 while cwd[n] # 0 do INC(n); end;
13991400 return cwd[0..n], 0;
14001401 end;
14011402
14021403 (* Makes path the working directory. *)
1403-proc setWorkDir*(path: []U8): INT;
1404+proc setWorkDir*(path: []const U8): INT;
14041405 var a: [4096]U8;
14051406 begin
14061407 if not cstr(path, a) then return -36; end;
1407- if C.chdir(ADR(a[0])) # 0 then return failed(); end;
1408+ if C.chdir(SYSTEM.ADR(a[0])) # 0 then return failed(); end;
14081409 return 0;
14091410 end;
14101411
@@ -1430,12 +1431,12 @@
14301431 var w: Winsize;
14311432 begin
14321433 w := {rows: U16(rows), cols: U16(cols)};
1433- if C.ioctl(I32(fd), CAbi.tiocswinsz, ADR(w)) # 0 then return failed(); end;
1434+ if C.ioctl(I32(fd), CAbi.tiocswinsz, SYSTEM.ADR(w)) # 0 then return failed(); end;
14341435 return 0;
14351436 end;
14361437
14371438 (* Copies s and a zero to at: the byte after them. *)
1438-proc put(s: []U8; at: ^U8): ^U8;
1439+proc put(s: []const U8; at: ^U8): ^U8;
14391440 begin
14401441 COPY(at[0..LEN(s)], s);
14411442 at[LEN(s)] := 0;
@@ -1444,7 +1445,7 @@
14441445
14451446 (* Whether the NAME=value s, a C string, names a variable that one of
14461447 env gives. *)
1447-proc replaced(s: ^U8; env: [][]U8): BOOL;
1448+proc replaced(s: ^U8; env: [][]const U8): BOOL;
14481449 var i, n: INT;
14491450 begin
14501451 for i := 0 to LEN(env) - 1 do
@@ -1459,7 +1460,7 @@
14591460 strings and a nil, then the environment old with each NAME=value of
14601461 env in place of its variable or added, and a nil; or nil. The
14611462 environment follows the arguments. *)
1462-proc argsAndEnv(args, env: [][]U8; old: ^^U8): (^^U8, INT);
1463+proc argsAndEnv(args, env: [][]const U8; old: ^^U8): (^^U8, INT);
14631464 var p: ^^U8; s: ^U8; size, n, i, k: INT;
14641465 begin
14651466 n := 0;
@@ -1487,7 +1488,7 @@
14871488 or holds an = or a 0, or value a 0, and -12 if there is no memory.
14881489 The C library's setenv keeps the environment. It isn't safe while
14891490 another thread reads the environment or starts a program. *)
1490-proc setEnv*(name, value: []U8): INT;
1491+proc setEnv*(name, value: []const U8): INT;
14911492 var p: ^U8; size, i, r: INT;
14921493 begin
14931494 if LEN(name) = 0 then return -22; end; (* EINVAL *)
@@ -1514,7 +1515,7 @@
15141515 proc pipe*: (INT, INT);
15151516 var fds: [2]I32;
15161517 begin
1517- if C.pipe2(ADR(fds[0]), CAbi.oCloexec) # 0 then return failed(), -1; end;
1518+ if C.pipe2(SYSTEM.ADR(fds[0]), CAbi.oCloexec) # 0 then return failed(), -1; end;
15181519 return INT(fds[0]), INT(fds[1]);
15191520 end;
15201521
@@ -1539,10 +1540,10 @@
15391540
15401541 (* The name of this machine, good until the next call; and 0, or minus
15411542 an errno. *)
1542-proc hostName*: ([]U8, INT);
1543+proc hostName*: ([]const U8, INT);
15431544 var n: INT;
15441545 begin
1545- if C.gethostname(ADR(host[0]), LEN(host) - 1) # 0 then return "", failed(); end;
1546+ if C.gethostname(SYSTEM.ADR(host[0]), LEN(host) - 1) # 0 then return "", failed(); end;
15461547 host[LEN(host) - 1] := 0; (* POSIX doesn't promise one if it is cut *)
15471548 n := 0;
15481549 while host[n] # 0 do INC(n); end;
@@ -1554,7 +1555,7 @@
15541555 var mask: [1024]U8; i, b, count: INT;
15551556 begin
15561557 for i := 0 to LEN(mask) - 1 do mask[i] := 0; end; (* the C library fills in as many bytes as the system has processors' bits *)
1557- if C.sched_getaffinity(0, UINT(LEN(mask)), ADR(mask[0])) # 0 then return 1; end;
1558+ if C.sched_getaffinity(0, UINT(LEN(mask)), SYSTEM.ADR(mask[0])) # 0 then return 1; end;
15581559 count := 0;
15591560 for i := 0 to LEN(mask) - 1 do
15601561 for b := 0 to 7 do
@@ -1577,7 +1578,7 @@
15771578 proc cpuTime*(children: BOOL): (I64, I64);
15781579 var ru: [64]U64; p: ^U8; (* struct rusage, which cabi checks fits *)
15791580 begin
1580- p := ^U8(ADR(ru));
1581+ p := ^U8(SYSTEM.ADR(ru));
15811582 if children then _ := C.getrusage(CAbi.rusageChildren, p);
15821583 else _ := C.getrusage(CAbi.rusageSelf, p);
15831584 end;
@@ -1590,7 +1591,7 @@
15901591 proc limit*(which: INT): (I64, I64, INT);
15911592 var r: [2]I64; i: INT; (* struct rlimit *)
15921593 begin
1593- if C.getrlimit(I32(which), ^U8(ADR(r))) # 0 then return 0, 0, failed(); end;
1594+ if C.getrlimit(I32(which), ^U8(SYSTEM.ADR(r))) # 0 then return 0, 0, failed(); end;
15941595 for i := 0 to 1 do
15951596 if r[i] = CAbi.rlimInfinity then r[i] := -1; end;
15961597 end;
@@ -1606,7 +1607,7 @@
16061607 for i := 0 to 1 do
16071608 if r[i] = -1 then r[i] := CAbi.rlimInfinity; end;
16081609 end;
1609- if C.setrlimit(I32(which), ^U8(ADR(r))) # 0 then return failed(); end;
1610+ if C.setrlimit(I32(which), ^U8(SYSTEM.ADR(r))) # 0 then return failed(); end;
16101611 return 0;
16111612 end;
16121613
@@ -1649,7 +1650,7 @@
16491650 (* The ith directory of search, a list of them with : between, as PATH
16501651 is: dir, "." if it is empty, and where the next starts; -1 past the
16511652 last. *)
1652-proc pathDir(search: []U8; i: INT): ([]U8, INT);
1653+proc pathDir(search: []const U8; i: INT): ([]const U8, INT);
16531654 var j: INT;
16541655 begin
16551656 if i > LEN(search) then return "", -1; end;
@@ -1660,7 +1661,7 @@
16601661 end;
16611662
16621663 (* dir, a /, and name, a C string in buf; false if it doesn't fit. *)
1663-proc joinPath(dir, name, buf: []U8): BOOL;
1664+proc joinPath(dir, name: []const U8; buf: []U8): BOOL;
16641665 var n: INT;
16651666 begin
16661667 n := LEN(dir) + 1 + LEN(name);
@@ -1673,7 +1674,7 @@
16731674 end;
16741675
16751676 (* Whether name holds a /, and so is a path, not a name to look for. *)
1676-proc isPath(name: []U8): BOOL;
1677+proc isPath(name: []const U8): BOOL;
16771678 var i: INT;
16781679 begin
16791680 for i := 0 to LEN(name) - 1 do
@@ -1687,16 +1688,16 @@
16871688 execvp does: each in turn, an empty one being the working directory.
16881689 It returns only if none could be run. It runs in spawn's child, after
16891690 the fork, so it takes no memory: each path is made in buf. *)
1690-proc run(name, search, buf: []U8; argv, envp: ^^U8);
1691-var dir: []U8; i: INT;
1691+proc run(name, search: []const U8; buf: []U8; argv, envp: ^^U8);
1692+var dir: []const U8; i: INT;
16921693 begin
16931694 if isPath(name) or (LEN(name) = 0) then
1694- if cstr(name, buf) then _ := C.execve(ADR(buf[0]), argv, envp); end;
1695+ if cstr(name, buf) then _ := C.execve(SYSTEM.ADR(buf[0]), argv, envp); end;
16951696 return;
16961697 end;
16971698 dir, i := pathDir(search, 0);
16981699 while i >= 0 do
1699- if joinPath(dir, name, buf) then _ := C.execve(ADR(buf[0]), argv, envp); end;
1700+ if joinPath(dir, name, buf) then _ := C.execve(SYSTEM.ADR(buf[0]), argv, envp); end;
17001701 dir, i := pathDir(search, i);
17011702 end;
17021703 end;
@@ -1706,8 +1707,8 @@
17061707 directories of search that is no directory and that this user may
17071708 run. 0; or -2 (ENOENT) if there is none, or -13 (EACCES) if one is
17081709 there and can't be run. *)
1709-proc find(name, search, buf: []U8): INT;
1710-var dir: []U8; i, err, r: INT; f: Info;
1710+proc find(name, search: []const U8; buf: []U8): INT;
1711+var dir: []const U8; i, err, r: INT; f: Info;
17111712 begin
17121713 if isPath(name) then
17131714 if not cstr(name, buf) then return -36; end;
@@ -1719,7 +1720,7 @@
17191720 if joinPath(dir, name, buf) then
17201721 f, err := info(buf[0..LEN(dir) + 1 + LEN(name)]);
17211722 if (err = 0) and not f.dir then
1722- if C.access(ADR(buf[0]), 1) = 0 then return 0; end; (* X_OK *)
1723+ if C.access(SYSTEM.ADR(buf[0]), 1) = 0 then return 0; end; (* X_OK *)
17231724 r := -13; (* EACCES *)
17241725 end;
17251726 end;
@@ -1746,7 +1747,7 @@
17461747 program exec starts. It runs in spawn's child, after the fork, so it
17471748 takes no memory: it closes the runs between the fds kept, the lowest
17481749 first, each with one closeFrom. *)
1749-proc closeAllBut(keep: []INT);
1750+proc closeAllBut(keep: []const INT);
17501751 var lo, next, i: INT;
17511752 begin
17521753 lo := 3;
@@ -1770,12 +1771,12 @@
17701771 terminal's foreground; then its standard input, output and error,
17711772 each p.fds names over the terminal's; then its working directory,
17721773 the C string dir. 0, or minus an errno. *)
1773-proc takeOn(p: Program; name, dir: []U8): INT;
1774+proc takeOn(p: Program; name, dir: []const U8): INT;
17741775 var fd: I32; i: INT;
17751776 begin
17761777 if p.tty # 0 then
17771778 _ := C.setsid();
1778- fd := C.open(ADR(name[0]), CAbi.oRdwr);
1779+ fd := C.open(SYSTEM.PTR(name), CAbi.oRdwr);
17791780 if fd < 0 then return failed(); end;
17801781 if C.ioctl(fd, CAbi.tiocsctty, 0) # 0 then return failed(); end;
17811782 for i := 0 to 2 do _ := C.dup2(fd, I32(i)); end;
@@ -1792,7 +1793,7 @@
17921793 _ := C.dup2(I32(p.fds[i]), I32(i));
17931794 end;
17941795 end;
1795- if (LEN(p.dir) > 0) and (C.chdir(ADR(dir[0])) # 0) then return failed(); end;
1796+ if (LEN(p.dir) > 0) and (C.chdir(SYSTEM.PTR(dir)) # 0) then return failed(); end;
17961797 return 0;
17971798 end;
17981799
@@ -1800,7 +1801,7 @@
18001801 proc ignoredIn(var a: Sigaction): BOOL;
18011802 var h: ^UINT;
18021803 begin
1803- h := ^UINT(^U8(ADR(a)) + CAbi.saHandlerAt);
1804+ h := ^UINT(^U8(SYSTEM.ADR(a)) + CAbi.saHandlerAt);
18041805 return h^ = 1;
18051806 end;
18061807
@@ -1809,7 +1810,7 @@
18091810 proc ignored*(sig: INT): BOOL;
18101811 var a: Sigaction;
18111812 begin
1812- _ := C.sigaction(I32(sig), nil, ^U8(ADR(a)));
1813+ _ := C.sigaction(I32(sig), nil, ^U8(SYSTEM.ADR(a)));
18131814 return ignoredIn(a);
18141815 end;
18151816
@@ -1821,7 +1822,7 @@
18211822 terminal's foreground, and signals as they are at first. *)
18221823 proc spawn*(p: Program): INT;
18231824 var
1824- a, dir, name: [4096]U8; argv: ^^U8; none: ^U8; size, err, i, g: INT; search: []U8;
1825+ a, dir, name: [4096]U8; argv: ^^U8; none: ^U8; size, err, i, g: INT; search: []const U8;
18251826 all, old, empty: Sigset; dfl: Sigaction; pid: I32;
18261827 begin
18271828 if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
@@ -1831,7 +1832,7 @@
18311832 end;
18321833 none := nil;
18331834 if p.onlyEnv then
1834- argv, size := argsAndEnv(p.args, p.env, ADR(none));
1835+ argv, size := argsAndEnv(p.args, p.env, SYSTEM.ADR(none));
18351836 else
18361837 argv, size := argsAndEnv(p.args, p.env, C.environ);
18371838 end;
@@ -1841,15 +1842,15 @@
18411842 err := find(p.path, search, a);
18421843 if err < 0 then munmap(^U8(argv), size); return err; end;
18431844 for i := 0 to LEN(all) - 1 do all[i] := 0FFFFFFFFFFFFFFFFH; end;
1844- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(all)), ^U8(ADR(old)));
1845+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(all)), ^U8(SYSTEM.ADR(old)));
18451846 pid := C.fork();
18461847 if pid = 0 then
18471848 if takeOn(p, name, dir) # 0 then C._exit(127); end;
18481849 closeAllBut(p.more);
18491850 for i := 1 to CAbi.sigMax do
1850- if not (p.keepIgnored and ignored(i)) then _ := C.sigaction(I32(i), ^U8(ADR(dfl)), nil); end;
1851+ if not (p.keepIgnored and ignored(i)) then _ := C.sigaction(I32(i), ^U8(SYSTEM.ADR(dfl)), nil); end;
18511852 end;
1852- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(empty)), nil);
1853+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(empty)), nil);
18531854 run(p.path, search, a, argv, argv + (LEN(p.args) + 1));
18541855 C._exit(127);
18551856 end;
@@ -1861,7 +1862,7 @@
18611862 if p.group # 0 then _ := C.setpgid(pid, I32(g)); end;
18621863 if p.foreground then _ := C.tcsetpgrp(0, I32(g)); end;
18631864 end;
1864- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(old)), nil);
1865+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(old)), nil);
18651866 munmap(^U8(argv), size);
18661867 if pid < 0 then return err; end;
18671868 return INT(pid);
@@ -1878,7 +1879,7 @@
18781879 signals given back as they were. *)
18791880 proc exec*(p: Program): INT;
18801881 var
1881- a, dir, name: [4096]U8; argv: ^^U8; none: ^U8; size, r, i: INT; search: []U8;
1882+ a, dir, name: [4096]U8; argv: ^^U8; none: ^U8; size, r, i: INT; search: []const U8;
18821883 all, old, empty: Sigset; dfl: Sigaction; acts: [CAbi.sigMax + 1]Sigaction;
18831884 begin
18841885 if not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *)
@@ -1892,7 +1893,7 @@
18921893 if r < 0 then return r; end;
18931894 none := nil;
18941895 if p.onlyEnv then
1895- argv, size := argsAndEnv(p.args, p.env, ADR(none));
1896+ argv, size := argsAndEnv(p.args, p.env, SYSTEM.ADR(none));
18961897 else
18971898 argv, size := argsAndEnv(p.args, p.env, C.environ);
18981899 end;
@@ -1905,19 +1906,19 @@
19051906 (* every signal as it is at first and none blocked, as spawn
19061907 gives them, each kept to give back if execve fails *)
19071908 for i := 0 to LEN(all) - 1 do all[i] := 0FFFFFFFFFFFFFFFFH; end;
1908- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(all)), ^U8(ADR(old)));
1909+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(all)), ^U8(SYSTEM.ADR(old)));
19091910 for i := 1 to CAbi.sigMax do
1910- _ := C.sigaction(I32(i), nil, ^U8(ADR(acts[i]))); (* as it is *)
1911+ _ := C.sigaction(I32(i), nil, ^U8(SYSTEM.ADR(acts[i]))); (* as it is *)
19111912 if not (p.keepIgnored and ignoredIn(acts[i])) then
1912- _ := C.sigaction(I32(i), ^U8(ADR(dfl)), nil);
1913+ _ := C.sigaction(I32(i), ^U8(SYSTEM.ADR(dfl)), nil);
19131914 end;
19141915 end;
1915- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(empty)), nil);
1916- _ := C.execve(ADR(a[0]), argv, argv + (LEN(p.args) + 1));
1916+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(empty)), nil);
1917+ _ := C.execve(SYSTEM.ADR(a[0]), argv, argv + (LEN(p.args) + 1));
19171918 r := failed();
1918- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(all)), nil);
1919- for i := 1 to CAbi.sigMax do _ := C.sigaction(I32(i), ^U8(ADR(acts[i])), nil); end;
1920- _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(old)), nil);
1919+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(all)), nil);
1920+ for i := 1 to CAbi.sigMax do _ := C.sigaction(I32(i), ^U8(SYSTEM.ADR(acts[i])), nil); end;
1921+ _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(old)), nil);
19211922 end;
19221923 munmap(^U8(argv), size);
19231924 return r;
@@ -1928,14 +1929,14 @@
19281929 kernel's execve does and a shell wants: no search, and every fd and
19291930 signal as it is, but that a handled signal does what it does at
19301931 first. It returns only if it can't: minus an errno. *)
1931-proc execve*(path: []U8; args, env: [][]U8): INT;
1932+proc execve*(path: []const U8; args, env: [][]const U8): INT;
19321933 var a: [4096]U8; argv: ^^U8; none: ^U8; size, r: INT;
19331934 begin
19341935 if not cstr(path, a) then return -36; end; (* ENAMETOOLONG *)
19351936 none := nil;
1936- argv, size := argsAndEnv(args, env, ADR(none));
1937+ argv, size := argsAndEnv(args, env, SYSTEM.ADR(none));
19371938 if argv = nil then return -12; end; (* ENOMEM *)
1938- _ := C.execve(ADR(a[0]), argv, argv + (LEN(args) + 1));
1939+ _ := C.execve(SYSTEM.ADR(a[0]), argv, argv + (LEN(args) + 1));
19391940 r := failed();
19401941 munmap(^U8(argv), size);
19411942 return r;
@@ -1945,7 +1946,7 @@
19451946 proc waitFor(pid: INT; options: I32): (INT, Status, INT);
19461947 var status, r: I32;
19471948 begin
1948- r := C.waitpid(I32(pid), ADR(status), options);
1949+ r := C.waitpid(I32(pid), SYSTEM.ADR(status), options);
19491950 if r < 0 then return failed(), running, 0; end;
19501951 if r = 0 then return 0, running, 0; end;
19511952 if status & 7FH = 0 then return INT(r), exited, INT(status) shr 8 & 0FFH; end;
@@ -1991,7 +1992,7 @@
19911992 e := CAbi.errno();
19921993 saved := e^; (* as the code it stopped left it *)
19931994 b[0] := U8(sig);
1994- _ := C.write(sigWrite, ADR(b[0]), 1);
1995+ _ := C.write(sigWrite, SYSTEM.ADR(b[0]), 1);
19951996 e^ := saved;
19961997 end;
19971998
@@ -2000,9 +2001,9 @@
20002001 proc action(h: Handler; flags: INT): Sigaction;
20012002 var a: Sigaction; p: ^Handler;
20022003 begin
2003- p := ^Handler(^U8(ADR(a)) + CAbi.saHandlerAt);
2004+ p := ^Handler(^U8(SYSTEM.ADR(a)) + CAbi.saHandlerAt);
20042005 p^ := h;
2005- setField(^U8(ADR(a)), CAbi.saFlagsAt, CAbi.saFlagsLen, flags);
2006+ setField(^U8(SYSTEM.ADR(a)), CAbi.saFlagsAt, CAbi.saFlagsLen, flags);
20062007 return a;
20072008 end;
20082009
@@ -2017,20 +2018,20 @@
20172018 (* Catches the signals sigs: they don't do what they would, but give
20182019 their numbers on an fd, which a later catch adds to and gives again;
20192020 or minus an errno. *)
2020-proc catch*(sigs: []INT): INT;
2021+proc catch*(sigs: []const INT): INT;
20212022 var fds: [2]I32; act: Sigaction; i: INT;
20222023 begin
20232024 for i := 0 to LEN(sigs) - 1 do
20242025 if not takable(sigs[i]) then return -22; end; (* EINVAL *)
20252026 end;
20262027 if sigWrite = 0 then
2027- if C.pipe2(ADR(fds[0]), CAbi.oNonblock | CAbi.oCloexec) # 0 then return failed(); end;
2028+ if C.pipe2(SYSTEM.ADR(fds[0]), CAbi.oNonblock | CAbi.oCloexec) # 0 then return failed(); end;
20282029 sigRead := fds[0];
20292030 sigWrite := fds[1];
20302031 end;
20312032 act := action(onSignal, CAbi.saRestart);
20322033 for i := 0 to LEN(sigs) - 1 do
2033- if C.sigaction(I32(sigs[i]), ^U8(ADR(act)), nil) # 0 then return failed(); end;
2034+ if C.sigaction(I32(sigs[i]), ^U8(SYSTEM.ADR(act)), nil) # 0 then return failed(); end;
20342035 end;
20352036 return INT(sigRead);
20362037 end;
@@ -2050,7 +2051,7 @@
20502051 var act: Sigaction;
20512052 begin
20522053 if yes then act := action(Handler(1), 0); end; (* SIG_IGN *)
2053- if C.sigaction(I32(sig), ^U8(ADR(act)), nil) # 0 then return failed(); end;
2054+ if C.sigaction(I32(sig), ^U8(SYSTEM.ADR(act)), nil) # 0 then return failed(); end;
20542055 return 0;
20552056 end;
20562057
@@ -2065,8 +2066,8 @@
20652066 program, perhaps while Out or Heap holds its lock. *)
20662067 proc onNoted(sig: I32);
20672068 begin
2068- _ := XCHG(ADR(noted[sig]), 1);
2069- _ := XCHG(ADR(broke), 1);
2069+ _ := XCHG(noted[sig], 1);
2070+ _ := XCHG(broke, 1);
20702071 end;
20712072
20722073 (* Takes the signal sig away from what it would do: it is noted, for
@@ -2079,7 +2080,7 @@
20792080 begin
20802081 if not takable(sig) then return -22; end; (* EINVAL *)
20812082 act := action(onNoted, 0); (* no SA_RESTART *)
2082- if C.sigaction(I32(sig), ^U8(ADR(act)), nil) # 0 then return failed(); end;
2083+ if C.sigaction(I32(sig), ^U8(SYSTEM.ADR(act)), nil) # 0 then return failed(); end;
20832084 return 0;
20842085 end;
20852086
@@ -2088,7 +2089,7 @@
20882089 proc came*(sig: INT): BOOL;
20892090 begin
20902091 if (sig < 1) or (sig > CAbi.sigMax) then return false; end;
2091- return XCHG(ADR(noted[sig]), 0) = 1;
2092+ return XCHG(noted[sig], 0) = 1;
20922093 end;
20932094
20942095 (* A copy of this program, which goes on from here: 0 in the copy, its
@@ -2279,7 +2280,7 @@
22792280 proc testShell;
22802281 var
22812282 r, w, fd, n, k, child, c, err, pty, sigs, mask, parent: INT; t: I64; st: Status; buf: [64]U8;
2282- m, raw: Mode; soft, hard, s2, h2, user, system: I64; e: []U8; ok, path: BOOL;
2283+ m, raw: Mode; soft, hard, s2, h2, user, system: I64; e: []const U8; ok, path: BOOL;
22832284 begin
22842285 r, w := pipe();
22852286 if w < 0 then exit(2); end;
@@ -2399,21 +2400,21 @@
23992400 random(x);
24002401 random(y);
24012402 if x[0..16] = y[0..16] then exit(2); end;
2402- p := ^U8(ADR(s));
2403- q := ^U8(ADR(s6)) + CAbi.sin6AddrAt;
2404- if (inetAddr("10.0.0.255", 80, ADR(s)) # CAbi.sockaddrInLen) or (portOf(p) # 80)
2403+ p := ^U8(SYSTEM.ADR(s));
2404+ q := ^U8(SYSTEM.ADR(s6)) + CAbi.sin6AddrAt;
2405+ if (inetAddr("10.0.0.255", 80, SYSTEM.ADR(s)) # CAbi.sockaddrInLen) or (portOf(p) # 80)
24052406 or (p[CAbi.sinAddrAt] # 10) or (p[CAbi.sinAddrAt + 2] # 0) or (p[CAbi.sinAddrAt + 3] # 255) then
24062407 exit(2);
24072408 end;
2408- if (inetAddr("1:aBcd::ff", 258, ADR(s6)) # CAbi.sockaddrIn6Len) or (portOf(^U8(ADR(s6))) # 258)
2409+ if (inetAddr("1:aBcd::ff", 258, SYSTEM.ADR(s6)) # CAbi.sockaddrIn6Len) or (portOf(^U8(SYSTEM.ADR(s6))) # 258)
24092410 or (q[1] # 1) or (q[2] # 0ABH) or (q[3] # 0CDH) or (q[14] # 0) or (q[15] # 0FFH) then
24102411 exit(2);
24112412 end;
2412- q := ^U8(ADR(s6));
2413+ q := ^U8(SYSTEM.ADR(s6));
24132414 for i := CAbi.sin6PortAt + 2 to CAbi.sin6AddrAt - 1 do (* the flow, zero *)
24142415 if q[i] # 0 then exit(2); end;
24152416 end;
2416- if (inetAddr("::", 0, ADR(s6)) # CAbi.sockaddrIn6Len) or (inetAddr("1:2:3:4:5:6:7:8", 0, ADR(s6)) # CAbi.sockaddrIn6Len) then exit(2); end;
2417+ if (inetAddr("::", 0, SYSTEM.ADR(s6)) # CAbi.sockaddrIn6Len) or (inetAddr("1:2:3:4:5:6:7:8", 0, SYSTEM.ADR(s6)) # CAbi.sockaddrIn6Len) then exit(2); end;
24172418 if (connectTcp("1.2.3", 80) # -22) or (connectTcp("1.2.3.256", 80) # -22) or (connectTcp("1::2::3", 80) # -22)
24182419 or (connectTcp("1:2:3:4:5:6:7:8:9", 80) # -22) or (connectTcp("1:", 80) # -22)
24192420 or (connectTcp("12345::", 80) # -22) or (connectTcp("::1", 65536) # -22) then
@@ -2495,7 +2496,7 @@
24952496 (* The test of what a program asks of itself: a signal ignored or not,
24962497 an environment variable unset or empty, and the processors. *)
24972498 proc testProcess;
2498-var v: []U8; found: BOOL;
2499+var v: []const U8; found: BOOL;
24992500 begin
25002501 if (ignore(sigUsr1, true) # 0) or not ignored(sigUsr1) then exit(2); end;
25012502 if (ignore(sigUsr1, false) # 0) or ignored(sigUsr1) then exit(2); end;
@@ -2636,7 +2637,7 @@
26362637 and closed; a directory made, listed and emptied; no terminal; a
26372638 socket, sent to after its end; programs; time and the network. *)
26382639 proc main*;
2639-var free, total: I64; fd, n, err, w, h, l, c, a, m, k, o: INT; got: [1]INT; buf: [16]U8; p, q: ^U8; i, j: Info; d: Dir; name: []U8; ok: BOOL;
2640+var free, total: I64; fd, n, err, w, h, l, c, a, m, k, o: INT; got: [1]INT; buf: [16]U8; p, q: ^U8; i, j: Info; d: Dir; name: []const U8; ok: BOOL;
26402641 begin
26412642 testPoll();
26422643 fd := create("/tmp/raz-sys-test");

lib/Task.raz (history) modified +1 -0

@@ -14,6 +14,7 @@
1414 in x, and the caller reads it after Thread.join. *)
1515 module Task(T);
1616 import Heap, Mem, Thread;
17+import SYSTEM;
1718
1819 type
1920 (* What the thread is given: what to run and its copy of x. *)

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

@@ -16,6 +16,7 @@
1616 the Thread. Its test uses Check. *)
1717 module Thread;
1818 import Sys, Rt, Check;
19+import SYSTEM;
1920
2021 const
2122 Failed*: ERROR = "can't start a thread";
@@ -80,7 +81,7 @@
8081
8182 proc futex(word: ^INT; op, val: INT): INT;
8283 begin
83- return SYSCALL(202, word, op, val, 0);
84+ return SYSTEM.SYSCALL(202, word, op, val, 0);
8485 end;
8586
8687 (* Where a new thread starts: the signal handlers' stack is a thread's
@@ -90,7 +91,7 @@
9091 begin
9192 t := ^Thread(arg);
9293 alt := {sp: ^U8(t) - Alt, size: Alt};
93- _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
94+ _ := SYSTEM.SYSCALL(131, SYSTEM.ADR(alt), 0); (* sigaltstack *)
9495 t^.fn(t^.arg);
9596 end;
9697
@@ -101,9 +102,9 @@
101102 var t: ^Thread;
102103 begin
103104 t := ^Thread(arg);
104- _ := XCHG(ADR(t^.ktid), SYSCALL(186)); (* gettid *)
105+ _ := XCHG(t^.ktid, SYSTEM.SYSCALL(186)); (* gettid *)
105106 run(arg);
106- _ := XCHG(ADR(t^.ktid), -1);
107+ _ := XCHG(t^.ktid, -1);
107108 return nil;
108109 end;
109110
@@ -123,7 +124,7 @@
123124 t^.fn := p;
124125 t^.arg := arg;
125126 if cCreate # nil then
126- if cCreate(ADR(tid), nil, cRun, ^U8(t)) # 0 then
127+ if cCreate(SYSTEM.ADR(tid), nil, cRun, ^U8(t)) # 0 then
127128 Sys.munmap(base, size);
128129 return nil, Failed;
129130 end;
@@ -132,8 +133,8 @@
132133 end;
133134 (* mprotect: the guard page, no access; it fails when the process
134135 has as many mappings as it may *)
135- if (SYSCALL(10, base, Page, 0) < 0)
136- or (start(Flags, base + Page + Stack, ADR(t^.tid), ADR(t^.tid), run, ^U8(t)) < 0) then
136+ if (SYSTEM.SYSCALL(10, base, Page, 0) < 0)
137+ or (start(Flags, base + Page + Stack, SYSTEM.ADR(t^.tid), SYSTEM.ADR(t^.tid), run, ^U8(t)) < 0) then
137138 Sys.munmap(base, size);
138139 return nil, Failed;
139140 end;
@@ -147,10 +148,10 @@
147148 if cJoin # nil then
148149 _ := cJoin(UINT(t^.tid), nil);
149150 else
150- tid := ADR(t^.tid);
151+ tid := SYSTEM.ADR(t^.tid);
151152 v := tid^;
152153 while v # 0 do
153- _ := futex(ADR(t^.tid), FutexWait, v);
154+ _ := futex(SYSTEM.ADR(t^.tid), FutexWait, v);
154155 v := tid^;
155156 end;
156157 end;
@@ -169,26 +170,26 @@
169170 var tid: ^VOLATILE INT; k: INT;
170171 begin
171172 if cCreate # nil then
172- tid := ADR(t^.ktid);
173+ tid := SYSTEM.ADR(t^.ktid);
173174 k := tid^;
174175 while k = 0 do Sys.yield; k := tid^; end;
175176 else
176- tid := ADR(t^.tid);
177+ tid := SYSTEM.ADR(t^.tid);
177178 k := tid^;
178179 end;
179180 if k <= 0 then return -3; end;
180- return SYSCALL(234, Sys.pid(), k, sig); (* tgkill *)
181+ return SYSTEM.SYSCALL(234, Sys.pid(), k, sig); (* tgkill *)
181182 end;
182183
183184 (* Takes m, sleeping while another thread holds it. *)
184185 proc lock*(var m: Mutex);
185186 var c: INT;
186187 begin
187- if CAS(ADR(m.state), 0, 1) then return; end;
188- c := XCHG(ADR(m.state), 2);
188+ if CAS(m.state, 0, 1) then return; end;
189+ c := XCHG(m.state, 2);
189190 while c # 0 do
190- _ := futex(ADR(m.state), FutexWait + Private, 2);
191- c := XCHG(ADR(m.state), 2);
191+ _ := futex(SYSTEM.ADR(m.state), FutexWait + Private, 2);
192+ c := XCHG(m.state, 2);
192193 end;
193194 end;
194195
@@ -196,9 +197,9 @@
196197 for it. *)
197198 proc unlock*(var m: Mutex);
198199 begin
199- if XADD(ADR(m.state), -1) # 1 then
200- _ := XCHG(ADR(m.state), 0);
201- _ := futex(ADR(m.state), FutexWake + Private, 1);
200+ if XADD(m.state, -1) # 1 then
201+ _ := XCHG(m.state, 0);
202+ _ := futex(SYSTEM.ADR(m.state), FutexWake + Private, 1);
202203 end;
203204 end;
204205
@@ -225,7 +226,7 @@
225226 proc testArg(i: INT): INT;
226227 var s: ^U8; n, v: INT;
227228 begin
228- s := ARGV()[i];
229+ s := SYSTEM.ARGV()[i];
229230 v := 0;
230231 n := 0;
231232 while s[n] # 0 do v := v * 10 + INT(s[n]) - '0'; INC(n); end;
@@ -237,7 +238,7 @@
237238 var n, alive, started, k, i: INT; t: ^Thread; err: ERROR; fail: BOOL;
238239 begin
239240 n := 2000; alive := 50;
240- fail := (ARGC() = 2) and (ARGV()[1][0] = 'f');
241+ fail := (ARGC() = 2) and (SYSTEM.ARGV()[1][0] = 'f');
241242 if ARGC() = 3 then n := testArg(1); alive := testArg(2); end;
242243 if fail then n := LEN(wave); alive := LEN(wave); end;
243244 if (alive < 1) or (alive > LEN(wave)) then Rt.stop("Thread: alive is 1 to 1000"); end;

lib/Vec.raz (history) modified +1 -0

@@ -9,6 +9,7 @@
99 tryAdd ask and add in one call. *)
1010 module Vec(T);
1111 import Mem, Rt, Sys;
12+import SYSTEM;
1213
1314 type
1415 Vec* = record

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

@@ -161,7 +161,7 @@
161161 (* end of the tables *)
162162
163163 (* Whether c is in one of the ranges of t, by halving. *)
164-proc within(t: []I32; c: I32): BOOL;
164+proc within(t: []const I32; c: I32): BOOL;
165165 var lo, hi, m: INT;
166166 begin
167167 lo := 0;
@@ -186,7 +186,7 @@
186186 end;
187187
188188 (* The columns the UTF-8 text s takes, as Str.decode reads it. *)
189-proc columns*(s: []U8): INT;
189+proc columns*(s: []const U8): INT;
190190 var c: I32; i, n, w: INT;
191191 begin
192192 i := 0;
@@ -200,7 +200,7 @@
200200 end;
201201
202202 (* Checks that every character in cs has the width w. *)
203-proc allWidth(what: []U8; cs: []I32; w: INT);
203+proc allWidth(what: []const U8; cs: []const I32; w: INT);
204204 var i: INT;
205205 begin
206206 for i := 0 to LEN(cs) - 1 do Check.int(what, width(cs[i]), w); end;

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

@@ -288,7 +288,7 @@
288288
289289 (* The name of chunk c: its module's and its own, or literal and its
290290 number for a literal *)
291-proc chunkName*(c: INT): []U8;
291+proc chunkName*(c: INT): []const U8;
292292 begin
293293 if chunks[c].name < 0 then return Diag.say("literal{}", [Fmt.int(c)]); end;
294294 if chunks[c].home < 0 then return Scan.nameOf(chunks[c].name); end;

src/Diag.raz (history) modified +25 -25

@@ -23,10 +23,10 @@
2323 Pos* = record f*, a*, b*: INT; end;
2424
2525 File = record
26- path: []U8;
26+ path: []const U8;
2727 buf: ^U8;
2828 len: INT;
29- origin: []U8; (* a line told once, under the first message about the file; "" for none *)
29+ origin: []const U8; (* a line told once, under the first message about the file; "" for none *)
3030 end;
3131
3232 const
@@ -66,8 +66,8 @@
6666
6767 (* Paths are shown from the working directory where they are under it,
6868 so messages read the same wherever the compiler or its library is. *)
69-proc shownPath*(path: []U8): []U8;
70-var d: []U8; err: INT; c: []U8;
69+proc shownPath*(path: []const U8): []const U8;
70+var d: []const U8; err: INT; c: []const U8;
7171 begin
7272 if not cwdKnown then
7373 d, err := Sys.workDir();
@@ -82,7 +82,7 @@
8282 return path;
8383 end;
8484
85-proc fatal*(msg: []U8); forward;
85+proc fatal*(msg: []const U8); forward;
8686
8787 (* Memory, or the end of the compile when there is none *)
8888 proc grab(size: INT): ^U8;
@@ -95,8 +95,8 @@
9595
9696 (* Keeps buf, len bytes of a file, under a number, which it gives back;
9797 buf stays as it is, and its path is copied. *)
98-proc addFile*(path: []U8; buf: ^U8; len: INT): INT;
99-var more: ^File; i: INT; p: []U8; ok: BOOL;
98+proc addFile*(path: []const U8; buf: ^U8; len: INT): INT;
99+var more: ^File; i: INT; p: []const U8; ok: BOOL;
100100 begin
101101 if numFiles = cap then
102102 more := ^File(grab((2 * cap + 8) * SIZE(File)));
@@ -114,12 +114,12 @@
114114
115115 (* Gives file f a line to tell once, under the first message about it:
116116 where a library came from and the raz it was written for *)
117-proc setOrigin*(f: INT; text: []U8);
117+proc setOrigin*(f: INT; text: []const U8);
118118 begin
119119 files[f].origin := text;
120120 end;
121121
122-proc pathOf*(f: INT): []U8;
122+proc pathOf*(f: INT): []const U8;
123123 begin
124124 return files[f].path;
125125 end;
@@ -133,7 +133,7 @@
133133 return LEN(Sys.env("NO_COLOR")) > 0;
134134 end;
135135
136-proc put(s: []U8);
136+proc put(s: []const U8);
137137 begin
138138 Buf.str(out, s);
139139 end;
@@ -149,7 +149,7 @@
149149 end;
150150
151151 (* The text of a number *)
152-proc say*(f: []U8; args: []Fmt.Arg): []U8;
152+proc say*(f: []const U8; args: []const Fmt.Arg): []const U8;
153153 var b: ^Buf.Buf;
154154 begin
155155 b := ^Buf.Buf(grab(SIZE(Buf.Buf)));
@@ -159,7 +159,7 @@
159159 end;
160160
161161 (* c, when colour is on *)
162-proc paintOn(c: []U8);
162+proc paintOn(c: []const U8);
163163 begin
164164 if not colourKnown then
165165 colour := Sys.isTerminal(2) and not noColour();
@@ -169,7 +169,7 @@
169169 end;
170170
171171 (* s in colour c, when colour is on *)
172-proc paint(c, s: []U8);
172+proc paint(c, s: []const U8);
173173 begin
174174 paintOn(c);
175175 put(s);
@@ -178,7 +178,7 @@
178178
179179 (* What has been made, written to standard error *)
180180 proc flush;
181-var s: []U8; n: INT;
181+var s: []const U8; n: INT;
182182 begin
183183 s := Buf.bytes(out);
184184 while LEN(s) > 0 do
@@ -233,8 +233,8 @@
233233 (* "file:line:col: kind: msg", then the line with p underlined. A tab
234234 before p is copied into the underline, so that the two line up
235235 whatever the terminal makes of tabs. *)
236-proc show(p: Pos; kind, kindColour, msg: []U8);
237-var line, start, stop, lo, hi, i, n: INT; buf: ^U8; f: ^File; digits: []U8;
236+proc show(p: Pos; kind, kindColour, msg: []const U8);
237+var line, start, stop, lo, hi, i, n: INT; buf: ^U8; f: ^File; digits: []const U8;
238238 begin
239239 if p.f >= numFiles then
240240 (* about no place in a file, as for Rt, which the compiler
@@ -306,7 +306,7 @@
306306 end;
307307
308308 (* The text at p, at most the 255 bytes a message can hold *)
309-proc source*(p: Pos): []U8;
309+proc source*(p: Pos): []const U8;
310310 var n: INT;
311311 begin
312312 n := p.b - p.a;
@@ -317,8 +317,8 @@
317317 (* Messages *)
318318
319319 (* Line line of the file at path, as written, to at most 255 bytes *)
320-proc lineText*(path: []U8; line: INT): []U8;
321-var i, k, n, j: INT; f: ^File; want: []U8;
320+proc lineText*(path: []const U8; line: INT): []const U8;
321+var i, k, n, j: INT; f: ^File; want: []const U8;
322322 begin
323323 want := shownPath(path);
324324 for i := 0 to numFiles - 1 do
@@ -338,7 +338,7 @@
338338 return "";
339339 end;
340340
341-proc error*(p: Pos; msg: []U8);
341+proc error*(p: Pos; msg: []const U8);
342342 begin
343343 (* a second error at one place follows from the first: when a symbol
344344 ends a construct with an error, the one around it may stop there too *)
@@ -356,7 +356,7 @@
356356 end;
357357 end;
358358
359-proc warning*(p: Pos; msg: []U8);
359+proc warning*(p: Pos; msg: []const U8);
360360 begin
361361 if werror then
362362 error(p, msg);
@@ -368,12 +368,12 @@
368368 end;
369369
370370 (* Notes and help follow an error or a warning, and are shown with it *)
371-proc note*(p: Pos; msg: []U8);
371+proc note*(p: Pos; msg: []const U8);
372372 begin
373373 if shown then show(p, "note", Cyan, msg); end;
374374 end;
375375
376-proc help*(msg: []U8);
376+proc help*(msg: []const U8);
377377 begin
378378 if shown then
379379 paint(Green, "help:");
@@ -386,7 +386,7 @@
386386
387387 (* An error with no place in the source, such as a file that can't be
388388 read: it stops the compiler at once. *)
389-proc fatal*(msg: []U8);
389+proc fatal*(msg: []const U8);
390390 begin
391391 put("raz: ");
392392 put(msg);
@@ -395,7 +395,7 @@
395395 Rt.exit(1);
396396 end;
397397
398-proc count(n: INT; what: []U8): []U8;
398+proc count(n: INT; what: []const U8): []const U8;
399399 begin
400400 if n = 1 then return say("1 {}", [Fmt.str(what)]); end;
401401 return say("{} {}s", [Fmt.int(n), Fmt.str(what)]);

src/Elf.raz modified +11 -11

@@ -30,10 +30,10 @@
3030 var
3131 needed: [32]INT; (* the libraries to load, names interned *)
3232 numNeeded*: INT; (* none: a static program *)
33- mainPath: []U8; (* the main module's file, for gdb *)
33+ mainPath: []const U8; (* the main module's file, for gdb *)
3434 stripped*: BOOL; (* -s: no symbols and no line numbers; the sections are there, empty *)
35- interp: []U8; (* the loader a program that uses C names *)
36- libc*: []U8; (* and the C library it needs *)
35+ interp: []const U8; (* the loader a program that uses C names *)
36+ libc*: []const U8; (* and the C library it needs *)
3737
3838 buf: ^U8;
3939 len, cap: INT;
@@ -72,7 +72,7 @@
7272 end;
7373 end;
7474
75-proc setMainPath*(path: []U8);
75+proc setMainPath*(path: []const U8);
7676 begin
7777 mainPath := path;
7878 end;
@@ -141,7 +141,7 @@
141141
142142 (* Where in ShNames the name is: the byte after a zero that starts it and
143143 is followed by one; the empty name, found nowhere, is 0 *)
144-proc nameAt(name: []U8): INT;
144+proc nameAt(name: []const U8): INT;
145145 var i, k: INT; same: BOOL;
146146 begin
147147 for i := 1 to LEN(ShNames) - LEN(name) - 1 do
@@ -157,16 +157,16 @@
157157 end;
158158
159159 (* A section header. Its name is stored as its offset in ShNames. *)
160-proc shdr(name: []U8; typ: INT; flags, adr, off, size: INT; lnk, info: INT; align, entsize: INT);
160+proc shdr(name: []const U8; typ: INT; flags, adr, off, size: INT; lnk, info: INT; align, entsize: INT);
161161 begin
162162 putN(nameAt(name), 4); putN(typ, 4); putN(flags, 8); putN(adr, 8);
163163 putN(off, 8); putN(size, 8); putN(lnk, 4); putN(info, 4);
164164 putN(align, 8); putN(entsize, 8);
165165 end;
166166
167-proc putStr(s: []U8);
167+proc putStr(s: []const U8);
168168 begin
169- putBytes(ADR(s[0]), LEN(s));
169+ putBytes(PTR(s), LEN(s));
170170 putN(0, 1);
171171 end;
172172
@@ -184,7 +184,7 @@
184184 the table itself is in the places, in rodata (Link). Section
185185 offsets go in off, sizes in size: line, info, abbrev. *)
186186 proc putDebug(off, size: []INT);
187-var cwd: []U8; err: INT;
187+var cwd: []const U8; err: INT;
188188 begin
189189 off[0] := Chunk.chunks[Link.placesChunk].adr - Link.roAdr + Link.roOff + Link.linesOff;
190190 size[0] := Link.linesSize;
@@ -310,13 +310,13 @@
310310 putN(0, 16); (* DT_NULL *)
311311 end;
312312
313-proc writeElf*(path: []U8; entry: INT);
313+proc writeElf*(path: []const U8; entry: INT);
314314 var
315315 nph, nsh, c, nsyms, sec, strsCap: INT;
316316 roExtra, dynSize, symOff, strOff, shstrOff, shOff, strsLen: INT;
317317 dbgOff, dbgSize: [3]INT;
318318 strs: ^U8;
319- s: []U8;
319+ s: []const U8;
320320 dyn: BOOL;
321321 begin
322322 cap := 1 shl 16;

src/Gen.raz modified +3 -3

@@ -194,7 +194,7 @@
194194 end;
195195
196196 const
197- StubNames: [8][]U8 = ["check0", "check1", "check2", "check3", "check4", "check5", "check6", "check7"];
197+ StubNames: [8][]const U8 = ["check0", "check1", "check2", "check3", "check4", "check5", "check6", "check7"];
198198 (* the registers of the stack: the value at depth d is in Regs[d mod
199199 NumRegs]. rax, rdx and rcx, which division and shifts need, and rsi
200200 and rdi, which copying needs, aren't among them. *)
@@ -1573,9 +1573,9 @@
15731573 ARegister = -3; (* a Mem that is no memory but a register, its index *)
15741574
15751575 (* The name s, interned *)
1576-proc internStr(s: []U8): INT;
1576+proc internStr(s: []const U8): INT;
15771577 begin
1578- return Scan.intern(ADR(s[0]), LEN(s));
1578+ return Scan.intern(PTR(s), LEN(s));
15791579 end;
15801580
15811581 (* The program goes on if the condition cc holds, and otherwise stops

src/Item.raz (history) modified +20 -20

@@ -132,7 +132,7 @@
132132 end;
133133
134134 (* A message, from a format and the strings that fill it *)
135-proc say1(f, a: []U8): []U8;
135+proc say1(f, a: []const U8): []const U8;
136136 begin
137137 return Diag.say(f, [Fmt.str(a)]);
138138 end;
@@ -140,7 +140,7 @@
140140 (* Under -strict, what reaches memory other than through a variable,
141141 what, is refused at pos in a module that doesn't import SYSTEM
142142 (report 3) *)
143-proc needSystem*(pos: Diag.Pos; what: []U8): ERROR;
143+proc needSystem*(pos: Diag.Pos; what: []const U8): ERROR;
144144 begin
145145 if strict and not Sym.curModule^.system then
146146 return Scan.markHelp(pos, say1("{} needs import SYSTEM", what),
@@ -149,7 +149,7 @@
149149 return nil;
150150 end;
151151
152-proc say2(f, a, b: []U8): []U8;
152+proc say2(f, a, b: []const U8): []const U8;
153153 begin
154154 return Diag.say(f, [Fmt.str(a), Fmt.str(b)]);
155155 end;
@@ -232,7 +232,7 @@
232232
233233 (* An item for "found ...": a constant without a type of its own as it
234234 is written, so that "found 1.5" says what is wrong; else its type. *)
235-proc what*(x: Item): []U8;
235+proc what*(x: Item): []const U8;
236236 begin
237237 if (x.mode = mConst) and ((x.typ = Sym.tConst) or (x.typ = Sym.tRConst)) then
238238 return Diag.source(x.pos);
@@ -242,7 +242,7 @@
242242
243243 (* Two operands of different types. Numbers convert, so say how. *)
244244 proc mismatchOps(x, y: Item; xt, yt: ^Sym.Type): ERROR;
245-var text: []U8;
245+var text: []const U8;
246246 begin
247247 text := say2("{} and {} are different types", Sym.typeName(xt), Sym.typeName(yt));
248248 (* the help converts the narrower integer to the wider, which loses
@@ -602,7 +602,7 @@
602602 (* An error in x's type, with help that says what to write instead
603603 unless hint is empty; if x is an argument, a note at the parameter it
604604 goes to. *)
605-proc mismatchHelp(x: Item; text, hint: []U8): ERROR;
605+proc mismatchHelp(x: Item; text, hint: []const U8): ERROR;
606606 begin
607607 Diag.error(x.pos, text);
608608 if LEN(hint) > 0 then Diag.help(hint); end;
@@ -612,14 +612,14 @@
612612 return Scan.Failed;
613613 end;
614614
615-proc mismatch(x: Item; text: []U8): ERROR;
615+proc mismatch(x: Item; text: []const U8): ERROR;
616616 begin
617617 return mismatchHelp(x, text, "");
618618 end;
619619
620620 (* An error at x, which is a view, or part of one, and so has no
621621 address: text, and help that says what to do instead. *)
622-proc noAddress*(x: Item; text: []U8): ERROR;
622+proc noAddress*(x: Item; text: []const U8): ERROR;
623623 begin
624624 return Scan.markHelp(x.pos, text, "a view has no address, since it may be misaligned: copy it to a variable");
625625 end;
@@ -635,7 +635,7 @@
635635 end;
636636
637637 proc coerce*(var x: Item; t: ^Sym.Type): ERROR;
638-var s: ^Sym.Type; tmp: I64; inFrame: BOOL; hint: []U8;
638+var s: ^Sym.Type; tmp: I64; inFrame: BOOL; hint: []const U8;
639639 begin
640640 if x.mode = mCond then try value(x); end;
641641 s := x.typ;
@@ -753,7 +753,7 @@
753753
754754 (* t's name, ending in a zero byte, for Rt.fail *)
755755 proc nameChunk(t: ^Sym.Type): INT;
756-var s: []U8; p: ^U8; n, c: INT;
756+var s: []const U8; p: ^U8; n, c: INT;
757757 begin
758758 s := Sym.typeName(t);
759759 n := LEN(s);
@@ -984,7 +984,7 @@
984984 (* What x must be to have a view made of it, as a T: a variable, not
985985 volatile, and T a type of plain data. *)
986986 proc viewable(x: Item; t: ^Sym.Type): ERROR;
987-var u: ^Sym.Type; text: []U8;
987+var u: ^Sym.Type; text: []const U8;
988988 begin
989989 (* another module's variable, ro, is one too, read and not written *)
990990 if (x.mode # mVar) or not (x.isVar or x.ro) then
@@ -1019,7 +1019,7 @@
10191019 through the slice must still be a value of it. In a record, the help
10201020 names the field that holds it. *)
10211021 proc bytesType(x: Item; t: ^Sym.Type): ERROR;
1022-var u: ^Sym.Type; f: ^Sym.Obj; text, hint: []U8;
1022+var u: ^Sym.Type; f: ^Sym.Obj; text, hint: []const U8;
10231023 begin
10241024 u := notPlain(t);
10251025 if u = nil then return nil; end;
@@ -1041,7 +1041,7 @@
10411041 return Scan.markHelp(x.pos, text, hint);
10421042 end;
10431043
1044-(* BYTES(x), the bytes of x as a []U8 (report section 6.8), made as a
1044+(* BYTES(x), the bytes of x as a []const U8 (report section 6.8), made as a
10451045 slice of x is, refused where one is, and keeping x's frame mark, so
10461046 that returnValue refuses the bytes of a local as a slice of one:
10471047
@@ -1418,7 +1418,7 @@
14181418 integers: x is the wrong kind for op, and the message names the
14191419 operator it may have meant *)
14201420 proc wrongLogic(op: Scan.Sym; var x: Item): ERROR;
1421-var bitsOf: []U8;
1421+var bitsOf: []const U8;
14221422 begin
14231423 bitsOf := "the bits of integers take ";
14241424 if (op = Scan.sAnd) and Sym.isInt(x.typ) then
@@ -1704,7 +1704,7 @@
17041704 untyped constant hasn't (report section 6.1). It is loaded, unless a
17051705 constant, before n is read, as the left of an operator is by op1. *)
17061706 proc rotand*(var x: Item; left: BOOL): ERROR;
1707-var name, s: []U8;
1707+var name, s: []const U8;
17081708 begin
17091709 if x.mode in {mType, mBuiltin, mNone, mCase, mStr} then return notValue(x); end;
17101710 if left then name := "ROL"; else name := "ROR"; end;
@@ -1796,7 +1796,7 @@
17961796 0 counts, or for POPCOUNT a set; an untyped constant has no width.
17971797 Of a constant the count is folded. *)
17981798 proc countBits*(var x: Item; which: INT): ERROR;
1799-var name, s: []U8; ok: BOOL;
1799+var name, s: []const U8; ok: BOOL;
18001800 begin
18011801 if x.mode in {mType, mBuiltin, mNone, mCase, mStr} then return notValue(x); end;
18021802 if which = Sym.bClz then name := "CLZ"; elsif which = Sym.bCtz then name := "CTZ"; else name := "POPCOUNT"; end;
@@ -1830,7 +1830,7 @@
18301830 untyped constants end, so they keep their type, as a hexadecimal
18311831 number above it is a U64 (report section 3). *)
18321832 proc limit*(var x: Item; t: ^Sym.Type; max: BOOL; p: Diag.Pos): ERROR;
1833-var name: []U8; ones: U64; v: I64;
1833+var name: []const U8; ones: U64; v: I64;
18341834 begin
18351835 if t^.form # Sym.fInt then
18361836 if max then name := "MAX"; else name := "MIN"; end;
@@ -1936,7 +1936,7 @@
19361936 end;
19371937
19381938 (* Too many arguments or too few, at p *)
1939-proc wrongCount(var c: Gen.CallInfo; p: Diag.Pos; text: []U8): ERROR;
1939+proc wrongCount(var c: Gen.CallInfo; p: Diag.Pos; text: []const U8): ERROR;
19401940 begin
19411941 if c.obj = nil then return Scan.markAt(p, text); end;
19421942 Diag.error(p, Diag.say("{}: {} takes {}", [Fmt.str(text), Fmt.str(Scan.nameOf(c.obj^.name)), Fmt.int(c.sig^.len)]));
@@ -1976,7 +1976,7 @@
19761976 write instead, b for ADR(b) and p^ for a pointer p. Mostly met in
19771977 programs written before the library took var (report 2026-10.33). *)
19781978 proc givenAddress(const a: Item; p: ^Sym.Obj): ERROR;
1979-var s, kind: []U8;
1979+var s, kind: []const U8;
19801980 begin
19811981 if (a.typ^.form # Sym.fPtr) or (a.typ^.base = nil) or not Sym.same(a.typ^.base, p^.typ) then
19821982 return nil;
@@ -2471,7 +2471,7 @@
24712471 (* COPY(d, s) or FILL(d, x): d, an array variable or a slice, as a slice
24722472 in the frame, before s or x is read; text says what the built-in
24732473 writes into, for an error *)
2474-proc destSlice(var d: Item; text: []U8): ERROR;
2474+proc destSlice(var d: Item; text: []const U8): ERROR;
24752475 begin
24762476 if (d.typ^.form = Sym.fArray) and (d.mode = mVar) then try notReadOnly(d); end;
24772477 if (d.typ^.form = Sym.fSlice) and d.typ^.rdonly then

src/Link.raz (history) modified +4 -4

@@ -160,7 +160,7 @@
160160 (* The line program of the files paths, nfiles of them, numbered from
161161 1, as they are written in the table *)
162162 proc makeLines(paths: ^INT; nfiles: INT);
163-var i, f, c, cf, cl, cc, op, at, da, dl: INT; s: []U8;
163+var i, f, c, cf, cl, cc, op, at, da, dl: INT; s: []const U8;
164164 begin
165165 lpLen := 0;
166166 putN(0, 4); (* unit_length, patched below *)
@@ -219,7 +219,7 @@
219219 at, names, poolAt: INT; (* where the next number goes, the next name, the pool's start *)
220220
221221 (* The name s, in the pool, and its offset from the pool's start, at at *)
222-proc putName(s: []U8);
222+proc putName(s: []const U8);
223223 begin
224224 patch4(buf, at, names - poolAt);
225225 COPY(buf[names..names + LEN(s)], s);
@@ -322,8 +322,8 @@
322322 end;
323323
324324 (* The address a as raz writes it, in hexadecimal: 0FFFFFFFF80000000H *)
325-proc literal(a: INT): []U8;
326-var s: []U8;
325+proc literal(a: INT): []const U8;
326+var s: []const U8;
327327 begin
328328 s := Diag.say("{}H", [Fmt.hex(U64(a))]);
329329 if s[0] > '9' then s := Diag.say("0{}", [Fmt.str(s)]); end;

src/Parse.raz (history) modified +59 -59

@@ -80,15 +80,15 @@
8080 MaxFixes = 4096; (* addresses in one constant *)
8181 MaxPending = 64; (* modules being compiled at once *)
8282 MaxFors = 256; (* for loops of a procedure whose limit may go in a register *)
83- Suffixes: [4][]U8 = [".linux-x86_64", ".linux", ".x86_64", ""];
83+ Suffixes: [4][]const U8 = [".linux-x86_64", ".linux", ".x86_64", ""];
8484
8585 var
86- libDir*, mainDir: []U8;
87- incDirs*: [16][]U8;
86+ libDir*, mainDir: []const U8;
87+ incDirs*: [16][]const U8;
8888 numInc*: INT;
89- userDirs: [][]U8; (* RAZ_PATH, or HOME/.raz/lib; set by the driver *)
90- thisVersion: []U8; (* the compiler's version; set by the driver *)
91- originNote: []U8; (* for the module about to be opened, see libraryNote *)
89+ userDirs: [][]const U8; (* RAZ_PATH, or HOME/.raz/lib; set by the driver *)
90+ thisVersion: []const U8; (* the compiler's version; set by the driver *)
91+ originNote: []const U8; (* for the module about to be opened, see libraryNote *)
9292 firstModule*, lastModule*: PModule; (* in the order they were finished *)
9393
9494 checkMode: BOOL; (* reading a file only for its interface *)
@@ -121,7 +121,7 @@
121121 doubts: [MaxDoubts]record
122122 at: Diag.Pos; (* a place the module's end warns of *)
123123 n: INT; (* a call standing on its own that drops this many results, or *)
124- msg, hint: []U8; (* any other doubt, in words (msg is empty for a drop) *)
124+ msg, hint: []const U8; (* any other doubt, in words (msg is empty for a drop) *)
125125 end;
126126 numDoubts: INT; (* the module being compiled has those from its
127127 first one, saved by compileFile, to here *)
@@ -152,57 +152,57 @@
152152
153153 (* Little helpers *)
154154
155-proc setLibDir*(dir: []U8);
155+proc setLibDir*(dir: []const U8);
156156 begin
157157 libDir := dir;
158158 end;
159159
160-proc addIncDir*(dir: []U8);
160+proc addIncDir*(dir: []const U8);
161161 begin
162162 incDirs[numInc] := dir;
163163 INC(numInc);
164164 end;
165165
166166 (* The driver's user library directories, kept until compilation ends *)
167-proc setUserDirs*(dirs: [][]U8);
167+proc setUserDirs*(dirs: [][]const U8);
168168 begin
169169 userDirs := dirs;
170170 end;
171171
172172 (* The driver's version of the compiler, which a library's note names *)
173-proc setVersion*(v: []U8);
173+proc setVersion*(v: []const U8);
174174 begin
175175 thisVersion := v;
176176 end;
177177
178-proc nameOf(n: INT): []U8;
178+proc nameOf(n: INT): []const U8;
179179 begin
180180 return Scan.nameOf(n);
181181 end;
182182
183183 (* The name number of s, which isn't empty *)
184-proc internName(s: []U8): INT;
184+proc internName(s: []const U8): INT;
185185 begin
186- return Scan.intern(ADR(s[0]), LEN(s));
186+ return Scan.intern(PTR(s), LEN(s));
187187 end;
188188
189-proc say1(f, a: []U8): []U8;
189+proc say1(f, a: []const U8): []const U8;
190190 begin
191191 return Diag.say(f, [Fmt.str(a)]);
192192 end;
193193
194-proc say2(f, a, b: []U8): []U8;
194+proc say2(f, a, b: []const U8): []const U8;
195195 begin
196196 return Diag.say(f, [Fmt.str(a), Fmt.str(b)]);
197197 end;
198198
199-proc say3(f, a, b, c: []U8): []U8;
199+proc say3(f, a, b, c: []const U8): []const U8;
200200 begin
201201 return Diag.say(f, [Fmt.str(a), Fmt.str(b), Fmt.str(c)]);
202202 end;
203203
204204 (* More than n of what, as a message *)
205-proc tooMany(n: INT; what: []U8): []U8;
205+proc tooMany(n: INT; what: []const U8): []const U8;
206206 begin
207207 return Diag.say("more than {} {}", [Fmt.int(n), Fmt.str(what)]);
208208 end;
@@ -234,7 +234,7 @@
234234 end;
235235
236236 (* A missing symbol is reported just after the one before it. *)
237-proc expected(what: []U8): ERROR;
237+proc expected(what: []const U8): ERROR;
238238 var at: Diag.Pos;
239239 begin
240240 if Scan.tok = Scan.sBlank then
@@ -272,7 +272,7 @@
272272
273273 (* The error of a procedure or module whose own "end" isn't where it
274274 should be, with what closeEnd saw *)
275-proc endMissing(p: Diag.Pos; msg: []U8): ERROR;
275+proc endMissing(p: Diag.Pos; msg: []const U8): ERROR;
276276 begin
277277 Diag.error(p, msg);
278278 foundNotes(p);
@@ -474,10 +474,10 @@
474474 end;
475475
476476 (* Where module n is found, if it is: dir and the file in it *)
477-proc moduleFile(n: INT): ([]U8, []U8, BOOL); forward;
477+proc moduleFile(n: INT): ([]const U8, []const U8, BOOL); forward;
478478
479479 (* name in lower case, in memory that is never freed, as messages are *)
480-proc lowerCase(s: []U8): []U8;
480+proc lowerCase(s: []const U8): []const U8;
481481 var p: ^U8; i: INT;
482482 begin
483483 if LEN(s) = 0 then return ""; end;
@@ -490,7 +490,7 @@
490490
491491 (* Whether s is a hexadecimal number but for the digit it must start
492492 with, as FFFDH is: capitals A to F and digits, then H *)
493-proc hexLike(s: []U8): BOOL;
493+proc hexLike(s: []const U8): BOOL;
494494 var i: INT;
495495 begin
496496 if (LEN(s) < 2) or (s[LEN(s) - 1] # 'H') then return false; end;
@@ -502,7 +502,7 @@
502502
503503 (* Reports name n at p as not declared, with what it may have meant *)
504504 proc notDeclared(p: Diag.Pos; n: INT);
505-var found: BOOL; low: []U8;
505+var found: BOOL; low: []const U8;
506506 begin
507507 Diag.error(p, say1("{} isn't declared", nameOf(n)));
508508 commentNote(p);
@@ -538,7 +538,7 @@
538538 (* An error at at: o, a name of an enumeration, is a name of another of
539539 its scope too, so it is written with its type. *)
540540 proc twinError(o: PObj; at: Diag.Pos): ERROR;
541-var a, b: []U8;
541+var a, b: []const U8;
542542 begin
543543 a := Sym.typeName(o^.typ); b := Sym.typeName(o^.twin^.typ);
544544 return Scan.markHelp(at, Diag.say("{} is a name of {} and of {}",
@@ -1094,7 +1094,7 @@
10941094 end;
10951095
10961096 (* The name of the atomic built-in which, for a message *)
1097-proc atomicName(which: INT): []U8;
1097+proc atomicName(which: INT): []const U8;
10981098 begin
10991099 if which = Sym.bCas then return "CAS"; end;
11001100 if which = Sym.bXchg then return "XCHG"; end;
@@ -1196,7 +1196,7 @@
11961196 return nil;
11971197 end;
11981198
1199-proc incOrDec(which: INT): []U8;
1199+proc incOrDec(which: INT): []const U8;
12001200 begin
12011201 if which = Sym.bDec then return "DEC"; end;
12021202 return "INC";
@@ -1206,7 +1206,7 @@
12061206 its elements start at by Item's startOf. Anything else is an error
12071207 that says what PTR is for, and for a pointer what to write. *)
12081208 proc ptrOf(var x: TItem): ERROR;
1209-var e: PType; s: []U8;
1209+var e: PType; s: []const U8;
12101210 begin
12111211 if x.mode = Item.mStr then
12121212 e := Sym.tU8;
@@ -1231,7 +1231,7 @@
12311231 place, so have none of their own. f is one name, not a path a.b,
12321232 which would be a field of f's type, asked of that type. *)
12331233 proc typeField(t: PType; at: Diag.Pos; isOffset: BOOL): (PObj, ERROR);
1234-var f: PObj; what, s, hint, g: []U8; dot: Diag.Pos;
1234+var f: PObj; what, s, hint, g: []const U8; dot: Diag.Pos;
12351235 begin
12361236 if isOffset then what := "OFFSET"; else what := "SIZE(T.f)"; end;
12371237 if t^.form # Sym.fRecord then
@@ -1442,7 +1442,7 @@
14421442 (* x, before ".", has no fields; tok is what follows. Other languages
14431443 write p.f through a pointer and s.len for a length. *)
14441444 proc fieldOfWhat(x: TItem): ERROR;
1445-var msg, f: []U8;
1445+var msg, f: []const U8;
14461446 begin
14471447 msg := say1("expected a record, found {}", Item.what(x));
14481448 if Scan.tok = Scan.sIdent then f := nameOf(Scan.id); else f := ""; end;
@@ -1698,7 +1698,7 @@
16981698 (* A set literal: the bits of the constant names, or'd at run time with
16991699 those of the others. *)
17001700 proc setLiteral(var x: TItem; t: PType): ERROR;
1701-var e: TItem; bits, slot: I64; start: Diag.Pos; s: []U8;
1701+var e: TItem; bits, slot: I64; start: Diag.Pos; s: []const U8;
17021702 begin
17031703 start := Scan.tokPos();
17041704 Scan.next;
@@ -1859,7 +1859,7 @@
18591859
18601860 (* A doubt other than a drop, to be warned of at p with msg and hint.
18611861 Text read twice, as a while's condition is, is noted once. *)
1862-proc noteDoubt(p: Diag.Pos; msg, hint: []U8);
1862+proc noteDoubt(p: Diag.Pos; msg, hint: []const U8);
18631863 var i: INT;
18641864 begin
18651865 for i := 0 to numDoubts - 1 do
@@ -1885,7 +1885,7 @@
18851885 end;
18861886
18871887 proc factor(var x: TItem; want: PType): ERROR;
1888-var called, vol, several: BOOL; t: PType; start: INT; s: []U8;
1888+var called, vol, several: BOOL; t: PType; start: INT; s: []const U8;
18891889 begin
18901890 several := passOn;
18911891 passOn := false;
@@ -2044,7 +2044,7 @@
20442044
20452045 (* Notes x, an operand of the and or or (word) just read, if it is an
20462046 unparenthesised = or # of two BOOLs *)
2047-proc noteBoolRel(const x: TItem; word: []U8);
2047+proc noteBoolRel(const x: TItem; word: []const U8);
20482048 begin
20492049 if bareBoolRel then
20502050 noteDoubt(x.pos, say2("{} is read first: = and # bind tighter than {}", Diag.source(x.pos), word),
@@ -2404,7 +2404,7 @@
24042404 keeps each label's chunk in lo and its length in hi, for the
24052405 comparing of labels. *)
24062406 proc strArm(p: I64; var ls: Labels; var endL: INT): ERROR;
2407-var x: TItem; i, L, body: INT; last: BOOL; s: []U8;
2407+var x: TItem; i, L, body: INT; last: BOOL; s: []const U8;
24082408 begin
24092409 L := Gen.NoLabel;
24102410 body := Gen.NoLabel;
@@ -2495,7 +2495,7 @@
24952495 Xml.Kind.done, is read by qualIdent, as it is anywhere else, and must
24962496 be one of t's. *)
24972497 proc armCase(t: PType): (PObj, ERROR);
2498-var st: Scan.State; c: PObj; at: Diag.Pos; qualified: BOOL; msg: []U8;
2498+var st: Scan.State; c: PObj; at: Diag.Pos; qualified: BOOL; msg: []const U8;
24992499 begin
25002500 at := Scan.tokPos();
25012501 Scan.saveScan(st);
@@ -2651,7 +2651,7 @@
26512651
26522652 (* What a message calls x: its name n when x is just that name, else what
26532653 it is. *)
2654-proc subject(x: TItem; n: INT): []U8;
2654+proc subject(x: TItem; n: INT): []const U8;
26552655 begin
26562656 if x.pos.b - x.pos.a = LEN(nameOf(n)) then return nameOf(n); end;
26572657 if x.mode = Item.mConst then return "a constant"; end;
@@ -4091,7 +4091,7 @@
40914091 end;
40924092
40934093 (* The arguments of an instance: types, or procedures named. *)
4094-proc parseArgs(var args: Sym.Args; mname: []U8): ERROR;
4094+proc parseArgs(var args: Sym.Args; mname: []const U8): ERROR;
40954095 var o: PObj; start: Diag.Pos;
40964096 begin
40974097 Scan.next;
@@ -4211,7 +4211,7 @@
42114211 it is meant to go unused. Writing a var parameter, a match's name for
42124212 a field or C's variable is what it is for. *)
42134213 proc warn(o: PObj);
4214-var s, t: []U8;
4214+var s, t: []const U8;
42154215 begin
42164216 s := nameOf(o^.name);
42174217 if (o^.cls = Sym.oProc) and o^.openEnd then
@@ -4244,7 +4244,7 @@
42444244
42454245 (* Warns of the call at p, which drops its n results *)
42464246 proc dropped(p: Diag.Pos; n: INT);
4247-var s, blanks: []U8; i: INT;
4247+var s, blanks: []const U8; i: INT;
42484248 begin
42494249 s := Diag.source(p);
42504250 i := 0;
@@ -4297,7 +4297,7 @@
42974297 pending: [MaxPending]PModule;
42984298 numPending: INT;
42994299
4300-proc exists(path: []U8): BOOL;
4300+proc exists(path: []const U8): BOOL;
43014301 var info: Sys.Info; err: INT;
43024302 begin
43034303 info, err := Sys.info(path);
@@ -4306,7 +4306,7 @@
43064306
43074307 (* Which file path is, as its device and inode: two names of one file
43084308 have the same. Zero for a file that can't be asked about. *)
4309-proc identity(path: []U8): (INT, INT);
4309+proc identity(path: []const U8): (INT, INT);
43104310 var a: [4096]U8; st: [18]INT; (* struct stat: st_dev, then st_ino *)
43114311 begin
43124312 if LEN(path) >= 4096 then return 0, 0; end;
@@ -4317,7 +4317,7 @@
43174317 end;
43184318
43194319 (* s, in memory that is never freed, for what must outlast the buffer it is in *)
4320-proc keep(s: []U8): []U8;
4320+proc keep(s: []const U8): []const U8;
43214321 var p: ^U8;
43224322 begin
43234323 if LEN(s) = 0 then return ""; end;
@@ -4333,12 +4333,12 @@
43334333 the middle of reading another file, so it is re-entrant: it saves the
43344334 scanner's state, the open scopes, the current module and file and
43354335 whether checks are on, and puts them back at the end. *)
4336-proc compileFile(path: []U8; n: INT; args: Sym.Args; checkOnly: BOOL): (PModule, ERROR);
4336+proc compileFile(path: []const U8; n: INT; args: Sym.Args; checkOnly: BOOL): (PModule, ERROR);
43374337 var
43384338 st: Scan.State; saved: [Sym.MaxDepth]INT; d: INT;
43394339 oldMod: PModule; oldCheck, oldChecks: BOOL; m: PModule;
43404340 lib: ^Sym.Lib; start: Diag.Pos; alias, mname, line, oldPath: INT; o: PObj; bodyChunk: INT; iargs: Sym.Args;
4341- generic: BOOL; argsAt: Scan.State; why: []U8; firstDoubt: INT;
4341+ generic: BOOL; argsAt: Scan.State; why: []const U8; firstDoubt: INT;
43424342 begin
43434343 firstDoubt := numDoubts;
43444344 Scan.saveScan(st);
@@ -4544,10 +4544,10 @@
45444544
45454545 (* Reads every other file of module n in dir, and checks its interface
45464546 against m, compiled from the file named chosen. *)
4547-proc checkSiblings(dir, chosen: []U8; n: INT; m: PModule; args: Sym.Args): ERROR;
4547+proc checkSiblings(dir, chosen: []const U8; n: INT; m: PModule; args: Sym.Args): ERROR;
45484548 var
4549- dp: Sys.Dir; e, prefix: []U8; i, numOthers: INT; more: BOOL; sib: PModule;
4550- others: [32][]U8;
4549+ dp: Sys.Dir; e, prefix: []const U8; i, numOthers: INT; more: BOOL; sib: PModule;
4550+ others: [32][]const U8;
45514551 begin
45524552 prefix := say1("{}.", nameOf(n));
45534553 numOthers := 0;
@@ -4571,7 +4571,7 @@
45714571
45724572 (* The compiler's version as a library's RAZ-VERSION would say it:
45734573 "0.21" for "0.21.0-5-g38d29a8"; a name with fewer dots stays whole *)
4574-proc majorMinor(v: []U8): []U8;
4574+proc majorMinor(v: []const U8): []const U8;
45754575 var i, dots: INT;
45764576 begin
45774577 dots := 0;
@@ -4588,7 +4588,7 @@
45884588 RAZ_PATH directory: if dir holds a file RAZ-VERSION, the raz its
45894589 library was written for. The file is only read; a library with none,
45904590 or a module of the program's own directory or of lib, has no line. *)
4591-proc libraryNote(dir: []U8): []U8;
4591+proc libraryNote(dir: []const U8): []const U8;
45924592 var fd, n, i: INT; b: [32]U8;
45934593 begin
45944594 if (dir = mainDir) or (dir = libDir) then return ""; end;
@@ -4603,7 +4603,7 @@
46034603 end;
46044604
46054605 (* The directories searched for modules: main, -I, user libraries, lib *)
4606-proc searchDir(i: INT): []U8;
4606+proc searchDir(i: INT): []const U8;
46074607 begin
46084608 if i = -1 then return mainDir; end;
46094609 if i < numInc then return incDirs[i]; end;
@@ -4614,13 +4614,13 @@
46144614
46154615 (* The file of module n in dir that suffix j says: Name.linux-x86_64.raz
46164616 for a file of this target alone, and so on to Name.raz *)
4617-proc fileName(n, j: INT): []U8;
4617+proc fileName(n, j: INT): []const U8;
46184618 begin
46194619 return Diag.say("{}{}.raz", [Fmt.str(nameOf(n)), Fmt.str(Suffixes[j])]);
46204620 end;
46214621
4622-proc moduleFile(n: INT): ([]U8, []U8, BOOL);
4623-var i, j: INT; dir, f: []U8;
4622+proc moduleFile(n: INT): ([]const U8, []const U8, BOOL);
4623+var i, j: INT; dir, f: []const U8;
46244624 begin
46254625 for i := -1 to numInc + LEN(userDirs) do
46264626 dir := searchDir(i);
@@ -4635,9 +4635,9 @@
46354635 (* A program has one module of each name: module n, found as dir/f,
46364636 must have no files in a later directory, unless dir/f is a link to
46374637 one of them, which chooses it (report, section 3) *)
4638-proc checkOneModule(n: INT; dir, f: []U8; at: Diag.Pos): ERROR;
4638+proc checkOneModule(n: INT; dir, f: []const U8; at: Diag.Pos): ERROR;
46394639 var
4640- i, j, dev, ino, mineDev, mineIno: INT; past, chosen: BOOL; g, files, others: []U8;
4640+ i, j, dev, ino, mineDev, mineIno: INT; past, chosen: BOOL; g, files, others: []const U8;
46414641 begin
46424642 mineDev, mineIno := identity(say2("{}/{}", dir, f));
46434643 others := "";
@@ -4665,7 +4665,7 @@
46654665 end;
46664666
46674667 proc importModule(name: INT; args: Sym.Args): (PModule, ERROR);
4668-var m: PModule; i: INT; dir, f, where: []U8; found: BOOL;
4668+var m: PModule; i: INT; dir, f, where: []const U8; found: BOOL;
46694669 begin
46704670 m := findModule(name, args);
46714671 if m # nil then return m, nil; end;
@@ -4779,8 +4779,8 @@
47794779
47804780 (* The main module, from the file at path, and Rt, which every program
47814781 needs, first *)
4782-proc compileMain*(path: []U8): (PModule, ERROR);
4783-var base: []U8; i, n: INT; none: Sym.Args; m: PModule;
4782+proc compileMain*(path: []const U8): (PModule, ERROR);
4783+var base: []const U8; i, n: INT; none: Sym.Args; m: PModule;
47844784 begin
47854785 none.n := 0;
47864786 i := LEN(path);

src/Raz.raz (history) modified +12 -12

@@ -43,15 +43,15 @@
4343 cLinks: [3]Gen.Link; (* C's symbols the entry point gives the library, in a program that uses C *)
4444 numCLinks: INT;
4545
46-proc say1(f, a: []U8): []U8;
46+proc say1(f, a: []const U8): []const U8;
4747 begin
4848 return Diag.say(f, [Fmt.str(a)]);
4949 end;
5050
5151 (* The number of the name s *)
52-proc internStr(s: []U8): INT;
52+proc internStr(s: []const U8): INT;
5353 begin
54- return Scan.intern(ADR(s[0]), LEN(s));
54+ return Scan.intern(PTR(s), LEN(s));
5555 end;
5656
5757 (* The modules the program uses: the main module, Rt, and every module
@@ -98,7 +98,7 @@
9898 hexadecimal ones that start with a digit and end in H; and whether it
9999 is one, and fits in 64 bits. Past high(INT) it is taken as a UINT,
100100 whose bits it keeps: 0FFFFFFFF80000000H is -80000000H. *)
101-proc address(s: []U8): (INT, BOOL);
101+proc address(s: []const U8): (INT, BOOL);
102102 var i, n, d, radix: INT; v: UINT;
103103 begin
104104 n := LEN(s);
@@ -155,7 +155,7 @@
155155 end;
156156
157157 (* The module named n, or nil if the program has none *)
158-proc moduleNamed(n: []U8): ^Sym.Module;
158+proc moduleNamed(n: []const U8): ^Sym.Module;
159159 var m: ^Sym.Module;
160160 begin
161161 m := Parse.firstModule;
@@ -164,7 +164,7 @@
164164 end;
165165
166166 (* What the library module m, found by name, declares as n *)
167-proc objIn(m: ^Sym.Module; n: []U8): ^Sym.Obj;
167+proc objIn(m: ^Sym.Module; n: []const U8): ^Sym.Obj;
168168 var o: ^Sym.Obj;
169169 begin
170170 o := Sym.find(m^.scope, internStr(n));
@@ -181,7 +181,7 @@
181181 end;
182182
183183 (* The library is given C's symbol sym, in its variable v *)
184-proc addCLink(sym: []U8; v: ^Sym.Obj);
184+proc addCLink(sym: []const U8; v: ^Sym.Obj);
185185 begin
186186 cLinks[numCLinks].chunk := Chunk.externChunk(internStr(sym));
187187 cLinks[numCLinks].into := v^.chunk;
@@ -189,7 +189,7 @@
189189 end;
190190
191191 (* s as a C string, in memory that is never freed *)
192-proc cstr(s: []U8): ^U8;
192+proc cstr(s: []const U8): ^U8;
193193 var p: ^U8;
194194 begin
195195 p := Scan.grab(LEN(s) + 1);
@@ -203,7 +203,7 @@
203203 from an unset one; Sys.env alone gives "" for both. The slices and
204204 their array live until the compiler exits, as command-line paths do. *)
205205 proc userLibraries;
206-var path, s: []U8; dirs: ^[]U8; i, first, n: INT; more, found: BOOL;
206+var path, s: []const U8; dirs: ^[]const U8; i, first, n: INT; more, found: BOOL;
207207 begin
208208 i := 0;
209209 repeat
@@ -219,7 +219,7 @@
219219 if not found then
220220 s := Sys.env("HOME");
221221 if LEN(s) > 0 then
222- dirs := ^[]U8(Scan.grab(SIZE([]U8)));
222+ dirs := ^[]const U8(Scan.grab(SIZE([]const U8)));
223223 dirs[0] := say1("{}/.raz/lib", s);
224224 Parse.setUserDirs(dirs[0..1]);
225225 end;
@@ -230,7 +230,7 @@
230230 for i := 0 to LEN(path) - 1 do
231231 if path[i] = ':' then INC(n); end;
232232 end;
233- dirs := ^[]U8(Scan.grab(n * SIZE([]U8)));
233+ dirs := ^[]const U8(Scan.grab(n * SIZE([]const U8)));
234234 n := 0;
235235 first := 0;
236236 for i := 0 to LEN(path) do
@@ -247,7 +247,7 @@
247247
248248 proc main*: INT;
249249 var
250- path, outPath, s: []U8; dir: []U8;
250+ path, outPath, s: []const U8; dir: []const U8;
251251 i, first, entry, fd, last, errno, base: INT;
252252 m, rt, thread: ^Sym.Module; mainObj: ^Sym.Obj;
253253 run, noProfile, listing, dynamic, libcSaid, ok, bare: BOOL; err: ERROR;

src/Scan.raz (history) modified +16 -16

@@ -51,7 +51,7 @@
5151 MaxStr* = 65536;
5252 NumWords = 44;
5353 NumOps = 28;
54- words: [NumWords][]U8 = [
54+ words: [NumWords][]const U8 = [
5555 "and", "begin", "break", "by", "code", "const", "continue", "defer", "div", "do",
5656 "else", "elsif", "end", "extern", "for", "forward", "if", "import",
5757 "in", "link", "match", "mod", "module", "not", "of", "or", "packed",
@@ -59,7 +59,7 @@
5959 "to", "try", "type", "until", "var", "variant", "VOLATILE", "while",
6060 "xor"];
6161 (* sPlus to sBlank *)
62- ops: [NumOps][]U8 = [
62+ ops: [NumOps][]const U8 = [
6363 "+", "-", "*", "/", "=", "#", "<", "<=", ">", ">=",
6464 ":=", ":", ";", ",", ".", "..", "...",
6565 "(", ")", "[", "]", "{", "}", "^", "&", "~", "|", "_"];
@@ -107,7 +107,7 @@
107107 end;
108108
109109 (* The bytes of the string just read, without the zero after them *)
110-proc strBytes*: []U8;
110+proc strBytes*: []const U8;
111111 begin
112112 return sbuf[0..slen];
113113 end;
@@ -228,7 +228,7 @@
228228 end;
229229
230230 (* The name n, which stays as it is *)
231-proc nameOf*(n: INT): []U8;
231+proc nameOf*(n: INT): []const U8;
232232 begin
233233 return namePtr[n][0..nameLen[n]];
234234 end;
@@ -396,19 +396,19 @@
396396
397397 (* An error at p, shown: the parser returns Failed, which try passes up
398398 to where it goes on. *)
399-proc markAt*(p: Diag.Pos; msg: []U8): ERROR;
399+proc markAt*(p: Diag.Pos; msg: []const U8): ERROR;
400400 begin
401401 Diag.error(p, msg);
402402 return Failed;
403403 end;
404404
405-proc mark*(msg: []U8): ERROR;
405+proc mark*(msg: []const U8): ERROR;
406406 begin
407407 return markAt(tokPos(), msg);
408408 end;
409409
410410 (* markAt, with a line of help after the message. *)
411-proc markHelp*(p: Diag.Pos; msg, hint: []U8): ERROR;
411+proc markHelp*(p: Diag.Pos; msg, hint: []const U8): ERROR;
412412 begin
413413 Diag.error(p, msg);
414414 Diag.help(hint);
@@ -417,21 +417,21 @@
417417
418418 (* An error in the text at bytes a to b of the file being read, which
419419 stops the compiler: past it, the symbols can't be trusted. *)
420-proc markBytes(a, b: INT; msg: []U8);
420+proc markBytes(a, b: INT; msg: []const U8);
421421 begin
422422 Diag.setQuiet(false);
423423 Diag.error({f: cur.f, a: a, b: b}, msg);
424424 Diag.finish;
425425 end;
426426
427-proc lexError(msg: []U8);
427+proc lexError(msg: []const U8);
428428 begin
429429 markBytes(cur.tokPos, cur.pos, msg);
430430 end;
431431
432432 (* The n characters at the scanner are how another language writes t:
433433 an error, but reading goes on as if t were written. *)
434-proc slip(n: INT; t: Sym; msg: []U8);
434+proc slip(n: INT; t: Sym; msg: []const U8);
435435 begin
436436 if not skipping then Diag.error({f: cur.f, a: cur.pos, b: cur.pos + n}, msg); end;
437437 INC(cur.pos, n);
@@ -439,7 +439,7 @@
439439 end;
440440
441441 (* How an operator or reserved word is written, quoted, for messages. *)
442-proc symText*(s: Sym): []U8;
442+proc symText*(s: Sym): []const U8;
443443 begin
444444 if (s >= sPlus) and (s <= sBlank) then
445445 return Diag.say("\"{}\"", [Fmt.str(ops[INT(s) - INT(sPlus)])]);
@@ -449,7 +449,7 @@
449449
450450 (* The current symbol, for "expected ..., found ...": a name as it is,
451451 a literal by its kind, an operator or reserved word quoted. *)
452-proc found*: []U8;
452+proc found*: []const U8;
453453 begin
454454 match tok of
455455 | sIdent: return nameOf(id);
@@ -487,7 +487,7 @@
487487 end;
488488
489489 (* Reads the file at path to scan it; "" if it can, else why not *)
490-proc open*(path: []U8): []U8;
490+proc open*(path: []const U8): []const U8;
491491 var fd, n, got, r, err: INT; info: Sys.Info;
492492 begin
493493 info, err := Sys.info(path);
@@ -619,7 +619,7 @@
619619 end;
620620
621621 (* The text of the file from byte a up to but not including b *)
622-proc text(a, b: INT): []U8;
622+proc text(a, b: INT): []const U8;
623623 begin
624624 return Diag.source({f: cur.f, a: a, b: b});
625625 end;
@@ -817,7 +817,7 @@
817817
818818 (* s is digits, a point, digits, and maybe E, a sign and digits. False if
819819 the value is past the largest F64; one below the smallest is 0. *)
820-proc readReal(s: []U8): (F64, BOOL);
820+proc readReal(s: []const U8): (F64, BOOL);
821821 var
822822 num, den, d: Big; i, digits, e, ex: INT; neg, half, sticky: BOOL;
823823 q, b: U64; x: F64; bits: ^F64;
@@ -1165,5 +1165,5 @@
11651165 nameHash := ^INT(grab(nameCap * SIZE(INT)));
11661166 tableMask := 2 * nameCap - 1;
11671167 table := words64(tableMask + 1);
1168- for i := 0 to NumWords - 1 do _ := intern(ADR(words[i][0]), LEN(words[i])); end;
1168+ for i := 0 to NumWords - 1 do _ := intern(PTR(words[i]), LEN(words[i])); end;
11691169 end Scan.

src/Sym.raz (history) modified +10 -10

@@ -126,7 +126,7 @@
126126 sname*: INT; (* the name of its symbols: List(I64) for an instance *)
127127 args*: Args;
128128 scope*: INT;
129- path*: []U8;
129+ path*: []const U8;
130130 first*, last*: ^Obj; (* its top-level declarations, in order *)
131131 locals*, lastLocal*: ^Obj; (* its procedures' declarations, in order *)
132132 imports*: ^Import;
@@ -368,7 +368,7 @@
368368 (* How far apart two names are: the edits, a character put in, taken out,
369369 changed or swapped with the next, that make one the other, ignoring
370370 case. *)
371-proc distance(a, b: []U8): INT;
371+proc distance(a, b: []const U8): INT;
372372 var d: [Scan.MaxIdent + 2][Scan.MaxIdent + 2]INT; i, j, c: INT;
373373 begin
374374 for i := 0 to LEN(a) do d[i][0] := i; end;
@@ -392,7 +392,7 @@
392392 if none is within an edit for every three characters. Only after an
393393 error, so it looks at every object. *)
394394 proc closest*(name, s: INT): ^Obj;
395-var i, j, d, best: INT; o, found: ^Obj; n: []U8; reach: BOOL;
395+var i, j, d, best: INT; o, found: ^Obj; n: []const U8; reach: BOOL;
396396 begin
397397 n := Scan.nameOf(name);
398398 best := LEN(n) div 3 + 1;
@@ -633,7 +633,7 @@
633633 end;
634634
635635 (* A name for t, kept for good, as every message is *)
636-proc typeName*(t: ^Type): []U8;
636+proc typeName*(t: ^Type): []const U8;
637637 var b: ^Buf.Buf;
638638 begin
639639 b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf)));
@@ -700,12 +700,12 @@
700700
701701 (* The universe *)
702702
703-proc basic(name: []U8; form: Form; size: I64; signed: BOOL): ^Type;
703+proc basic(name: []const U8; form: Form; size: I64; signed: BOOL): ^Type;
704704 var t: ^Type; o: ^Obj;
705705 begin
706706 t := newType(form, size, size);
707707 t^.signed := signed;
708- o := newObj(oType, Scan.intern(ADR(name[0]), LEN(name)), t);
708+ o := newObj(oType, Scan.intern(PTR(name), LEN(name)), t);
709709 o^.exported := true;
710710 t^.obj := o;
711711 _ := insert(o, 0);
@@ -713,13 +713,13 @@
713713 end;
714714
715715 (* The name s, interned *)
716-proc internOf(s: []U8): INT;
716+proc internOf(s: []const U8): INT;
717717 begin
718- return Scan.intern(ADR(s[0]), LEN(s));
718+ return Scan.intern(PTR(s), LEN(s));
719719 end;
720720
721721 (* Declares name in the scope s, exported, as a built-in is *)
722-proc enterIn(s: INT; name: []U8; cls: Class; t: ^Type; v: I64);
722+proc enterIn(s: INT; name: []const U8; cls: Class; t: ^Type; v: I64);
723723 var o: ^Obj;
724724 begin
725725 o := newObj(cls, internOf(name), t);
@@ -730,7 +730,7 @@
730730 end;
731731
732732 (* Declares name in the universe *)
733-proc enter(name: []U8; cls: Class; t: ^Type; v: I64);
733+proc enter(name: []const U8; cls: Class; t: ^Type; v: I64);
734734 begin
735735 enterIn(0, name, cls, t, v);
736736 end;

src/X64.raz (history) modified +34 -34

@@ -50,7 +50,7 @@
5050 (* The text of the instruction that starts at at, for the listing *)
5151 Said = record
5252 at: INT;
53- text: []U8;
53+ text: []const U8;
5454 end;
5555
5656 var
@@ -226,7 +226,7 @@
226226 numSaid := n;
227227 end;
228228
229-proc sayAt*(at: INT; s: []U8);
229+proc sayAt*(at: INT; s: []const U8);
230230 begin
231231 if not listing then return; end;
232232 if numSaid = saidCap then
@@ -239,14 +239,14 @@
239239 end;
240240
241241 (* The text of the instruction about to be written *)
242-proc say*(s: []U8);
242+proc say*(s: []const U8);
243243 begin
244244 sayAt(Chunk.pc, s);
245245 end;
246246
247247 (* The text of the instruction at at, said again, as when its operand is
248248 patched *)
249-proc restate*(at: INT; s: []U8);
249+proc restate*(at: INT; s: []const U8);
250250 var i: INT;
251251 begin
252252 i := numSaid - 1;
@@ -255,7 +255,7 @@
255255 end;
256256
257257 const
258- RegNames: [4][16][]U8 = [
258+ RegNames: [4][16][]const U8 = [
259259 ["rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
260260 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"],
261261 ["eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
@@ -264,13 +264,13 @@
264264 "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"],
265265 ["al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
266266 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"]];
267- CondNames*: [16][]U8 = ["o", "no", "b", "ae", "e", "ne", "be", "a", "s", "ns", "p", "np", "l", "ge", "le", "g"];
268- AluNames: [8][]U8 = ["add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"];
269- ShiftNames: [8][]U8 = ["rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar"];
270- UnaryNames: [8][]U8 = ["", "", "not", "neg", "mul", "imul", "div", "idiv"]; (* from 2 *)
267+ CondNames*: [16][]const U8 = ["o", "no", "b", "ae", "e", "ne", "be", "a", "s", "ns", "p", "np", "l", "ge", "le", "g"];
268+ AluNames: [8][]const U8 = ["add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"];
269+ ShiftNames: [8][]const U8 = ["rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar"];
270+ UnaryNames: [8][]const U8 = ["", "", "not", "neg", "mul", "imul", "div", "idiv"]; (* from 2 *)
271271
272272 (* The name of register r, of size bytes *)
273-proc rnSized(r, size: INT): []U8;
273+proc rnSized(r, size: INT): []const U8;
274274 begin
275275 if size = 1 then return RegNames[3][r]; end;
276276 if size = 2 then return RegNames[2][r]; end;
@@ -278,19 +278,19 @@
278278 return RegNames[0][r];
279279 end;
280280
281-proc rn(r: INT): []U8;
281+proc rn(r: INT): []const U8;
282282 begin
283283 return RegNames[0][r];
284284 end;
285285
286-proc xn(x: INT): []U8;
286+proc xn(x: INT): []const U8;
287287 begin
288288 return Diag.say("xmm{}", [Fmt.int(x)]);
289289 end;
290290
291291 (* A memory operand, with the size of what it holds, as the assembler
292292 reads it *)
293-proc mnSized(m: Mem; size: INT): []U8;
293+proc mnSized(m: Mem; size: INT): []const U8;
294294 var b: ^Buf.Buf;
295295 begin
296296 b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf)));
@@ -312,24 +312,24 @@
312312 return Buf.bytes(b^);
313313 end;
314314
315-proc mn(m: Mem): []U8;
315+proc mn(m: Mem): []const U8;
316316 begin
317317 return mnSized(m, 0);
318318 end;
319319
320320 (* "op a, b" and "op a" *)
321-proc text2(op, a, b: []U8): []U8;
321+proc text2(op, a, b: []const U8): []const U8;
322322 begin
323323 return Diag.say("{} {}, {}", [Fmt.str(op), Fmt.str(a), Fmt.str(b)]);
324324 end;
325325
326-proc text1(op, a: []U8): []U8;
326+proc text1(op, a: []const U8): []const U8;
327327 begin
328328 return Diag.say("{} {}", [Fmt.str(op), Fmt.str(a)]);
329329 end;
330330
331331 (* v in decimal *)
332-proc num(v: INT): []U8;
332+proc num(v: INT): []const U8;
333333 begin
334334 return Diag.say("{}", [Fmt.int(v)]);
335335 end;
@@ -537,7 +537,7 @@
537537 lowest, one bit, 0F BD and 0F BC. ZF is set if r is 0, which has no
538538 one bit, and r is then left undefined. *)
539539 proc bitScan*(reverse: BOOL; r: INT);
540-var opc: INT; name: []U8;
540+var opc: INT; name: []const U8;
541541 begin
542542 if reverse then opc := 0BD0FH; name := "bsr"; else opc := 0BC0FH; name := "bsf"; end;
543543 if listing then say(text2(name, rn(r), rn(r))); end;
@@ -674,7 +674,7 @@
674674 long forms of nop, of up to 8 bytes, that x86 decodes as one *)
675675 proc align*(n: INT);
676676 const
677- Nops: [8][]U8 = ["\x90", "\x66\x90", "\x0F\x1F\x00", "\x0F\x1F\x40\x00",
677+ Nops: [8][]const U8 = ["\x90", "\x66\x90", "\x0F\x1F\x00", "\x0F\x1F\x40\x00",
678678 "\x0F\x1F\x44\x00\x00", "\x66\x0F\x1F\x44\x00\x00", "\x0F\x1F\x80\x00\x00\x00\x00",
679679 "\x0F\x1F\x84\x00\x00\x00\x00\x00"];
680680 var k, i: INT;
@@ -779,7 +779,7 @@
779779 return 0F2H;
780780 end;
781781
782-proc realEnd(single: BOOL): []U8;
782+proc realEnd(single: BOOL): []const U8;
783783 begin
784784 if single then return "ss"; end;
785785 return "sd";
@@ -798,7 +798,7 @@
798798 opM(realPfx(single), false, 110FH, x, m, false);
799799 end;
800800
801-proc sseName(op: INT; single: BOOL): []U8;
801+proc sseName(op: INT; single: BOOL): []const U8;
802802 begin
803803 if op = 58H then return Diag.say("add{}", [Fmt.str(realEnd(single))]); end;
804804 if op = 59H then return Diag.say("mul{}", [Fmt.str(realEnd(single))]); end;
@@ -962,7 +962,7 @@
962962
963963 (* The current symbol as a word: an identifier, or a reserved word that
964964 is also an instruction *)
965-proc asmWord: []U8;
965+proc asmWord: []const U8;
966966 begin
967967 match Scan.tok of
968968 | sIdent: return Scan.nameOf(Scan.id);
@@ -980,7 +980,7 @@
980980
981981 (* Whether w names a register: rax, eax, ax, al and so on, or xmm0 to
982982 xmm15 (size 16); r and size are set if so *)
983-proc isReg(w: []U8; r, size: ^INT): BOOL;
983+proc isReg(w: []const U8; r, size: ^INT): BOOL;
984984 const Sizes: [4]INT = [8, 4, 2, 1];
985985 var i, j, n, d: INT;
986986 begin
@@ -1005,7 +1005,7 @@
10051005
10061006 (* Which word of list, a list of words each with a space either side,
10071007 w is, from 0; -1 if none *)
1008-proc wordIndex(w: []U8; list: []U8): INT;
1008+proc wordIndex(w: []const U8; list: []const U8): INT;
10091009 var i, n, start: INT;
10101010 begin
10111011 n := 0;
@@ -1021,7 +1021,7 @@
10211021 end;
10221022
10231023 (* w from byte from on, at most n bytes of it, as copy does *)
1024-proc part(w: []U8; from, n: INT): []U8;
1024+proc part(w: []const U8; from, n: INT): []const U8;
10251025 var e: INT;
10261026 begin
10271027 e := from + n;
@@ -1031,9 +1031,9 @@
10311031 end;
10321032
10331033 (* The condition a name ends in: e of je, nz of jnz *)
1034-proc cond(w: []U8): INT;
1034+proc cond(w: []const U8): INT;
10351035 const
1036- Alias: [12][]U8 = ["c", "nae", "nc", "nb", "z", "nz", "na", "nbe", "nge", "nl", "ng", "nle"];
1036+ Alias: [12][]const U8 = ["c", "nae", "nc", "nb", "z", "nz", "na", "nbe", "nge", "nl", "ng", "nle"];
10371037 AliasCc: [12]INT = [2, 2, 3, 3, 4, 5, 6, 7, 12, 13, 14, 15];
10381038 var i: INT;
10391039 begin
@@ -1047,7 +1047,7 @@
10471047 end;
10481048
10491049 proc operand(o: ^Operand; constExpr: ConstFn): ERROR;
1050-var w: []U8; r, size, sz: INT; st: Scan.State; v: I64; isR, wasMinus: BOOL;
1050+var w: []const U8; r, size, sz: INT; st: Scan.State; v: I64; isR, wasMinus: BOOL;
10511051 begin
10521052 o^ := {};
10531053 w := asmWord();
@@ -1141,7 +1141,7 @@
11411141 BitPfx: [5]INT = [0, 0, 0F3H, 0F3H, 0F3H];
11421142 BitCodes: [5]INT = [0BC0FH, 0BD0FH, 0BC0FH, 0BD0FH, 0B80FH];
11431143 (* the instructions of no operands; the last seven are a kernel's *)
1144- Plain: [22][]U8 = ["ret", "leave", "syscall", "cpuid", "rdtsc",
1144+ Plain: [22][]const U8 = ["ret", "leave", "syscall", "cpuid", "rdtsc",
11451145 "pause", "nop", "ud2", "int3", "hlt", "cqo", "cdq", "mfence", "lfence", "sfence",
11461146 "cli", "sti", "iretq", "swapgs", "rdmsr", "wrmsr", "wbinvd"];
11471147 PlainOp: [22]INT = [0C3H, 0C9H, 050FH, 0A20FH, 310FH,
@@ -1155,7 +1155,7 @@
11551155
11561156 var
11571157 (* the instruction being assembled *)
1158- aw: []U8; (* its word *)
1158+ aw: []const U8; (* its word *)
11591159 ao: [3]Operand; (* its operands *)
11601160 an: INT; (* how many *)
11611161 asize, apfx: INT;
@@ -1448,7 +1448,7 @@
14481448 Scan.next;
14491449 if Scan.tok = Scan.sColon then
14501450 sayAt(Chunk.pc, Diag.say("{}:", [Fmt.str(aw)]));
1451- k := try lab(Scan.intern(ADR(aw[0]), LEN(aw)));
1451+ k := try lab(Scan.intern(PTR(aw), LEN(aw)));
14521452 if lplaces[k] >= 0 then
14531453 return Scan.markAt(aat, Diag.say("label {} is defined twice", [Fmt.str(aw)]));
14541454 end;
@@ -1540,7 +1540,7 @@
15401540 end;
15411541
15421542 (* Whether s holds a space *)
1543-proc hasSpace(s: []U8): BOOL;
1543+proc hasSpace(s: []const U8): BOOL;
15441544 var i: INT;
15451545 begin
15461546 for i := 0 to LEN(s) - 1 do
@@ -1551,7 +1551,7 @@
15511551
15521552 (* n, in decimal, at least w wide, as write(n: w) *)
15531553 proc padded(n, w: INT);
1554-var s: []U8; i: INT;
1554+var s: []const U8; i: INT;
15551555 begin
15561556 s := Diag.say("{}", [Fmt.int(n)]);
15571557 for i := LEN(s) to w - 1 do Out.str(" "); end;
@@ -1563,7 +1563,7 @@
15631563 instructions made for it, at their offsets in the procedure; a jump
15641564 within it says where to by its offset too. *)
15651565 proc list*(home: INT);
1566-var order: ^INT; n, i, j, k, c, t, line: INT; text: []U8;
1566+var order: ^INT; n, i, j, k, c, t, line: INT; text: []const U8;
15671567 begin
15681568 order := ^INT(Scan.grab(Chunk.numChunks * SIZE(INT)));
15691569 n := 0;

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

@@ -11,27 +11,27 @@
1111 completion for concha.
1212
1313 type Row* = variant
14- usage(scope, line: []U8); (* a synopsis, without "usage: " *)
15- sub(scope, name, help: []U8); (* a subcommand *)
16- option(scope: []U8; letter: U8; long, value, help: []U8);
14+ usage(scope, line: []const U8); (* a synopsis, without "usage: " *)
15+ sub(scope, name, help: []const U8); (* a subcommand *)
16+ option(scope: []const U8; letter: U8; long, value, help: []const U8);
1717 end;
1818
1919 type Parser* = record
2020 letter*: U8; (* the option just read *)
21- value*: []U8; (* its value; "" for a flag *)
21+ value*: []const U8; (* its value; "" for a flag *)
2222 long*: BOOL; (* it was written by its long name *)
23- spelt*: []U8; (* as it was written, no dashes: "b" or "bar"; the program's to read only *)
23+ spelt*: []const U8; (* as it was written, no dashes: "b" or "bar"; the program's to read only *)
2424 (* the rest are Opt's own *)
25- name: []U8; (* the program's, as the messages begin *)
26- table: []Row;
27- scope: []U8;
25+ name: []const U8; (* the program's, as the messages begin *)
26+ table: []const Row;
27+ scope: []const U8;
2828 at: INT; (* the next word *)
29- group: []U8; (* the letters left of a word of them, as -lw *)
29+ group: []const U8; (* the letters left of a word of them, as -lw *)
3030 ended: BOOL; (* the scope's options have ended *)
3131 help: BOOL; (* the option just read is -h or --help *)
3232 end;
3333
34-proc init*(var p: Parser; name: []U8; table: []Row);
34+proc init*(var p: Parser; name: []const U8; table: []const Row);
3535 p reads the arguments from 1 on, by table, in the program's own
3636 scope; name begins the messages.
3737
@@ -39,7 +39,7 @@
3939 The next option, in p.letter, p.value and p.long; false when the
4040 scope's options end.
4141
42-proc operand*(var p: Parser): ([]U8, BOOL);
42+proc operand*(var p: Parser): ([]const U8, BOOL);
4343 The next operand, after what options are left; false when there are
4444 no more.
4545
@@ -48,7 +48,7 @@
4848 options are left: the operands from there on are Files.arg(i), for
4949 i up to ARGC() - 1, as an interpreter hands them to its script.
5050
51-proc scope*(var p: Parser; name: []U8);
51+proc scope*(var p: Parser; name: []const U8);
5252 The options of the subcommand name, from the word after its own,
5353 which operand has given.
5454
@@ -57,16 +57,16 @@
5757 anything else is a mistake. A number with no top is given the
5858 largest I64 for hi, and the mistake says "from lo up".
5959
60-proc refuse*(const p: Parser; wants: []U8);
60+proc refuse*(const p: Parser; wants: []const U8);
6161 The value of the option just read refused, as number refuses one:
6262 "-b wants wants, not 'value'", the option as it was written, with
6363 the scope's synopsis lines, and status 2.
6464
65-proc fail*(const p: Parser; text: []U8);
65+proc fail*(const p: Parser; text: []const U8);
6666 The program's own mistake, written as Opt's are but alone, and
6767 status 2.
6868
69-proc misuse*(const p: Parser; text: []U8);
69+proc misuse*(const p: Parser; text: []const U8);
7070 The program's own mistake, written as Opt's are, with the scope's
7171 synopsis lines after it, and status 2.
7272

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

@@ -1,5 +1,5 @@
11 module Str;
2- Operations on strings, which are []U8. = and # compare them; this
2+ Operations on strings, which are []const U8. = and # compare them; this
33 module orders, searches and hashes them, trims them and takes them
44 apart, tells an ASCII character's kind and changes a letter's case,
55 joins them and replaces in them, reads and writes their UTF-8, reads
@@ -7,7 +7,7 @@
77 gives is a slice of the string it was given, with no memory of its
88 own.
99
10-proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL);
10+proc copy*(a: ^Mem.Allocator; s: []const U8): ([]U8, BOOL);
1111 s's bytes, copied into memory from a, to keep after s's own are
1212 gone; "" and false if a has no room.
1313
@@ -15,32 +15,32 @@
1515 Gives back to a a copy that copy made from it; "", which copy gives
1616 for an empty string, was never a's, and is left alone.
1717
18-proc cmp*(a, b: []U8): INT;
18+proc cmp*(a, b: []const U8): INT;
1919 -1, 0 or 1 as a sorts before, with or after b, byte by byte.
2020
21-proc eq*(a, b: []U8): BOOL;
21+proc eq*(a, b: []const U8): BOOL;
2222 Whether a and b hold the same bytes: a = b, as a procedure value.
2323
24-proc eqFold*(a, b: []U8): BOOL;
24+proc eqFold*(a, b: []const U8): BOOL;
2525 Whether a and b are the same but for the case of ASCII letters.
2626
27-proc hash*(s: []U8): U64;
27+proc hash*(s: []const U8): U64;
2828 FNV-1a, 64 bits.
2929
30-proc find*(s, sub: []U8): INT;
30+proc find*(s, sub: []const U8): INT;
3131 Where sub first starts in s, or -1.
3232
33-proc findFrom*(s, sub: []U8; from: INT): INT;
33+proc findFrom*(s, sub: []const U8; from: INT): INT;
3434 Where sub first starts in s at or after from, or -1; from is at
3535 most LEN(s).
3636
37-proc findLast*(s, sub: []U8): INT;
37+proc findLast*(s, sub: []const U8): INT;
3838 Where sub last starts in s, or -1.
3939
40-proc hasPrefix*(s, p: []U8): BOOL;
40+proc hasPrefix*(s, p: []const U8): BOOL;
4141 Whether s starts with p.
4242
43-proc hasSuffix*(s, x: []U8): BOOL;
43+proc hasSuffix*(s, x: []const U8): BOOL;
4444 Whether s ends with x.
4545
4646 proc isSpace*(c: U8): BOOL;
@@ -60,20 +60,20 @@
6060 proc hexVal*(c: U8): INT;
6161 c's value as a hexadecimal digit, capital or small; -1 if it isn't one.
6262
63-proc trimLeft*(s: []U8): []U8;
63+proc trimLeft*(s: []const U8): []const U8;
6464 s without the spaces at its start.
6565
66-proc trimRight*(s: []U8): []U8;
66+proc trimRight*(s: []const U8): []const U8;
6767 s without the spaces at its end.
6868
69-proc trim*(s: []U8): []U8;
69+proc trim*(s: []const U8): []const U8;
7070 s without the spaces at either end.
7171
72-proc cut*(s, sep: []U8): ([]U8, []U8, BOOL);
72+proc cut*(s, sep: []const U8): ([]const U8, []const U8, BOOL);
7373 What comes before the first sep in s, what comes after it, and true;
7474 or s, an empty string and false if s has no sep.
7575
76-proc field*(s: []U8): ([]U8, []U8);
76+proc field*(s: []const U8): ([]const U8, []const U8);
7777 The first word of s, the bytes after the spaces at its start up to
7878 the next space or the end, and the rest of s from there; two empty
7979 strings if s holds only spaces.
@@ -84,10 +84,10 @@
8484 proc upper*(s: []U8);
8585 s's small ASCII letters made capitals, in place.
8686
87-proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8);
87+proc join*(var b: Buf.Buf; parts: [][]const U8; sep: []const U8);
8888 The parts added to b, with sep between each two.
8989
90-proc replace*(var b: Buf.Buf; s, old, new: []U8);
90+proc replace*(var b: Buf.Buf; s, old, new: []const U8);
9191 s added to b, with new for each old in it, from the left, none
9292 overlapping another; s as it is if old is empty.
9393
@@ -96,34 +96,34 @@
9696 character, a surrogate or one past 10FFFFH, becomes FFFDH, the
9797 character that stands for a wrong one.
9898
99-proc decode*(s: []U8): (I32, INT);
99+proc decode*(s: []const U8): (I32, INT);
100100 The character s starts with, and its length in bytes: FFFDH and 1
101101 if its first byte doesn't start one rightly, being a continuation,
102102 or followed by too few continuations, or spelling a surrogate or a
103103 character in more bytes than it needs; 0 and 0 if s is empty.
104104
105-proc decodeLast*(s: []U8): (I32, INT);
105+proc decodeLast*(s: []const U8): (I32, INT);
106106 The character s ends with, and its length in bytes, read as decode
107107 reads one: FFFDH and 1 if the last byte doesn't end one rightly; 0
108108 and 0 if s is empty.
109109
110-proc next*(s: []U8; i: INT): (I32, INT);
110+proc next*(s: []const U8; i: INT): (I32, INT);
111111 The character at i in s, as decode reads it, and where the one after
112112 it starts; 0 and -1 if i is at the end or past it.
113113
114-proc chars*(s: []U8): INT;
114+proc chars*(s: []const U8): INT;
115115 The characters in s, as decode reads them, each byte that doesn't
116116 start one rightly counted as one.
117117
118-proc valid*(s: []U8): BOOL;
118+proc valid*(s: []const U8): BOOL;
119119 Whether s is UTF-8: decode finds no byte that doesn't start a
120120 character rightly.
121121
122-proc toInt*(s: []U8): (I64, BOOL);
122+proc toInt*(s: []const U8): (I64, BOOL);
123123 s as a decimal number, with a - or + before it if any, and nothing
124124 else; false if it isn't one, or an I64 can't hold it.
125125
126-proc toHex*(s: []U8): (U64, BOOL);
126+proc toHex*(s: []const U8): (U64, BOOL);
127127 s in hexadecimal, digits only, capitals or not; false if it isn't
128128 that, or a U64 can't hold it.
129129
@@ -136,18 +136,18 @@
136136 proc base64Size*(n: INT): INT;
137137 The bytes base64 makes of n bytes: 4 for each 3, or part of 3.
138138
139-proc base64With*(s, out, alphabet: []U8; pad: BOOL): INT;
139+proc base64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): INT;
140140 s in base64 into out, which holds base64Size(LEN(s)) bytes at least;
141141 a shorter out stops the program at the byte it lacks, as any slice
142142 does. alphabet holds the 64 digits (Base64 or Base64Url, or one's
143143 own). A last group of 1 or 2 bytes is padded with = to four if pad,
144144 and else has 2 or 3 digits. The bytes written.
145145
146-proc base64*(s, out: []U8): INT;
146+proc base64*(s: []const U8; out: []U8): INT;
147147 s in base64 (RFC 4648, section 4), padded, into out as base64With
148148 writes it.
149149
150-proc unbase64With*(s, out, alphabet: []U8; pad: BOOL): (INT, BOOL);
150+proc unbase64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): (INT, BOOL);
151151 s, base64 with the digits of alphabet, decoded into out, which holds
152152 (LEN(s) + 3) div 4 * 3 bytes at least; a shorter out stops the
153153 program at the byte it lacks, as any slice does. The bytes written,
@@ -161,32 +161,32 @@
161161 it (RFC 4648, section 3.5 allows a decoder to take that). Line
162162 breaks, and padding or its lack, are the caller's to mend first.
163163
164-proc unbase64*(s, out: []U8): (INT, BOOL);
164+proc unbase64*(s: []const U8; out: []U8): (INT, BOOL);
165165 s, base64 (RFC 4648, section 4), padded, decoded into out as
166166 unbase64With reads it; out holds LEN(s) div 4 * 3 bytes at least.
167167
168-proc toU64*(s: []U8): (U64, BOOL);
168+proc toU64*(s: []const U8): (U64, BOOL);
169169 s as a decimal number, digits only; false if it isn't one, or a U64
170170 can't hold it.
171171
172-proc fromC*(p: ^U8): []U8;
172+proc fromC*(p: ^U8): []const U8;
173173 The bytes at p up to its zero byte, not copied; "" for nil.
174174
175-proc toC*(s, out: []U8): ^U8;
175+proc toC*(s: []const U8; out: []U8): ^U8;
176176 s copied into out with a zero byte after it, for C: out holds
177177 LEN(s) + 1 bytes at least, or the program stops at the byte it
178- lacks, as any slice does. The pointer C is given, PTR(out).
178+ lacks, as any slice does. The pointer C is given, SYSTEM.PTR(out).
179179
180180 proc fromInt*(n: I64): ([20]U8, INT);
181181 n in decimal, as Out.int writes it: its bytes, the first of the 20,
182182 and how many.
183183
184-proc le*(s: []U8): U64;
184+proc le*(s: []const U8): U64;
185185 The bytes of s, at most 8, as an unsigned number, the first byte
186186 the lowest: how a file or a message in little-endian order is read,
187187 whatever the machine's own order.
188188
189-proc be*(s: []U8): U64;
189+proc be*(s: []const U8): U64;
190190 As le, the first byte the highest: big-endian, network order.
191191
192192 proc putLE*(s: []U8; v: U64);

test/libc/SetEnvC.raz (history) modified +1 -1

@@ -3,7 +3,7 @@
33 module SetEnvC;
44 import Out, Rt, Sys;
55
6-proc run(env: [][]U8);
6+proc run(env: [][]const U8);
77 var p: Sys.Program; pid: INT;
88 begin
99 p.path := "/bin/sh";

test/run/BufCut.stderr (history) modified +1 -1

@@ -1,3 +1,3 @@
11 Buf.cut past the end
2- in Buf.cut at lib/Buf.raz:95:9: n = 6
2+ in Buf.cut at lib/Buf.raz:96:9: n = 6
33 in BufCut.main at test/run/BufCut.raz:11:5

test/run/BufFull.stderr (history) modified +2 -2

@@ -1,4 +1,4 @@
11 Buf: out of memory
2- in Buf.need at lib/Buf.raz:50:9: n = 10000
3- in Buf.str at lib/Buf.raz:66:5
2+ in Buf.need at lib/Buf.raz:51:9: n = 10000
3+ in Buf.str at lib/Buf.raz:67:5
44 in BufFull.main at test/run/BufFull.raz:11:5

test/run/BufInit.stderr (history) modified +3 -3

@@ -1,5 +1,5 @@
11 Buf used before Buf.init
2- in Buf.room at lib/Buf.raz:31:9: n = 5, cap = 64, p = nil
3- in Buf.need at lib/Buf.raz:48:5: n = 5
4- in Buf.str at lib/Buf.raz:66:5
2+ in Buf.room at lib/Buf.raz:32:9: n = 5, cap = 64, p = nil
3+ in Buf.need at lib/Buf.raz:49:5: n = 5
4+ in Buf.str at lib/Buf.raz:67:5
55 in BufInit.main at test/run/BufInit.raz:9:5

test/run/HeapDebugEnd.stderr (history) modified +5 -5

@@ -1,7 +1,7 @@
11 Heap: a write past the block's end: block at 0x?, 20 bytes
2- in Heap.found at lib/Heap.raz:161:5: h = 0x?, i = 18, n = 0
3- in Heap.badBlock at lib/Heap.raz:170:5: h = 0x?
4- in Heap.freeDebug at lib/Heap.raz:220:31: h = 0x?, out = nil, p = nil, i = 0, size = 0, b = nil
5- in Heap.free at lib/Heap.raz:252:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0
6- in Mem.free at lib/Mem.raz:39:5: a = 0x?, p = 0x?
2+ in Heap.found at lib/Heap.raz:162:5: h = 0x?, i = 18, n = 0
3+ in Heap.badBlock at lib/Heap.raz:171:5: h = 0x?
4+ in Heap.freeDebug at lib/Heap.raz:221:31: h = 0x?, out = nil, p = nil, i = 0, size = 0, b = nil
5+ in Heap.free at lib/Heap.raz:253:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0
6+ in Mem.free at lib/Mem.raz:40:5: a = 0x?, p = 0x?
77 in HeapDebugEnd.main at test/run/HeapDebugEnd.raz:12:5: p = 0x?

test/run/HeapDebugFree.stderr (history) modified +5 -5

@@ -1,7 +1,7 @@
11 Heap: a write after free: block at 0x?, 20 bytes
2- in Heap.found at lib/Heap.raz:161:5: h = 0x?, i = 18, n = 0
3- in Heap.badBlock at lib/Heap.raz:170:5: h = 0x?
4- in Heap.freeDebug at lib/Heap.raz:234:36: h = 0x?, out = 0x?, p = 0x?, i = 0, size = 20, b = nil
5- in Heap.free at lib/Heap.raz:252:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0
6- in Mem.free at lib/Mem.raz:39:5: a = 0x?, p = 0x?
2+ in Heap.found at lib/Heap.raz:162:5: h = 0x?, i = 18, n = 0
3+ in Heap.badBlock at lib/Heap.raz:171:5: h = 0x?
4+ in Heap.freeDebug at lib/Heap.raz:235:36: h = 0x?, out = 0x?, p = 0x?, i = 0, size = 20, b = nil
5+ in Heap.free at lib/Heap.raz:253:42: _a = 0x?, p = 0x?, h = 0x?, b = nil, c = 0
6+ in Mem.free at lib/Mem.raz:40:5: a = 0x?, p = 0x?
77 in HeapDebugFree.main at test/run/HeapDebugFree.raz:15:9: p = 0x?, q = 0x?, i = 1023

test/run/HeapSure.stderr (history) modified +1 -1

@@ -1,3 +1,3 @@
11 Heap: out of memory
2- in Heap.allocSure at lib/Heap.raz:285:9: _a = 0x?, size = 9223372036854775803, align = 8, p = nil
2+ in Heap.allocSure at lib/Heap.raz:286:9: _a = 0x?, size = 9223372036854775803, align = 8, p = nil
33 in HeapSure.main at test/run/HeapSure.raz:8:5

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

@@ -1,7 +1,7 @@
11 (* Map.done: the slots given back to the allocator, through one that
22 counts its blocks; the map empty after, and used again. *)
33 module MapDone;
4-import Fmt, Heap, Mem, Str, Names := Map([]U8, INT, Str.hash, Str.eq);
4+import Fmt, Heap, Mem, Str, Names := Map([]const U8, INT, Str.hash, Str.eq);
55
66 var counting: Mem.Allocator; live: INT;
77

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

@@ -3,7 +3,7 @@
33 module SetEnv;
44 import Out, Rt, Sys;
55
6-proc run(env: [][]U8);
6+proc run(env: [][]const U8);
77 var p: Sys.Program; pid: INT;
88 begin
99 p.path := "/bin/sh";

test/run/ThreadOverflow.stderr (history) modified +1 -1

@@ -3,4 +3,4 @@
33 in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1926
44 and 1926 more the same
55 in ThreadOverflow.work at test/run/ThreadOverflow.raz:15:5: _arg = nil
6- in Thread.run at lib/Thread.linux-x86_64.raz:94:5: arg = 0x?, t = 0x?
6+ in Thread.run at lib/Thread.linux-x86_64.raz:95:5: arg = 0x?, t = 0x?

test/run/ThreadOverflowC.stderr (history) modified +2 -2

@@ -1,5 +1,5 @@
11 test/run/ThreadOverflowC.raz:7:1: stopped by a stack overflow
22 in ThreadOverflowC.big at test/run/ThreadOverflowC.raz:7:1
33 in ThreadOverflowC.work at test/run/ThreadOverflowC.raz:16:5: _arg = nil
4- in Thread.run at lib/Thread.linux-x86_64.raz:94:5: arg = 0x?, t = 0x?
5- in Thread.cRun at lib/Thread.linux-x86_64.raz:105:5: arg = 0x?, t = 0x?
4+ in Thread.run at lib/Thread.linux-x86_64.raz:95:5: arg = 0x?, t = 0x?
5+ in Thread.cRun at lib/Thread.linux-x86_64.raz:106:5: arg = 0x?, t = 0x?

test/run/VecFull.stderr (history) modified +2 -2

@@ -1,4 +1,4 @@
11 Vec: out of memory
2- in Vec(INT).need at lib/Vec.raz:56:9: n = 1
3- in Vec(INT).push at lib/Vec.raz:64:5: x = 257
2+ in Vec(INT).need at lib/Vec.raz:57:9: n = 1
3+ in Vec(INT).push at lib/Vec.raz:65:5: x = 257
44 in VecFull.main at test/run/VecFull.raz:11:28: i = 257

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

@@ -29,7 +29,7 @@
2929
3030 var
3131 sc: Scan.Scanner; (* the text being read, at the current symbol *)
32- src: []U8;
32+ src: []const U8;
3333 docStart, docEnd: INT; (* the comment just before it, or -1 *)
3434 man: BOOL; (* writing mdoc *)
3535 atStart: BOOL; (* emit is at the start of a line *)
@@ -68,7 +68,7 @@
6868 end;
6969
7070 (* a line of mdoc's own, such as .Ed *)
71-proc control(s: []U8);
71+proc control(s: []const U8);
7272 begin
7373 Out.str(s);
7474 Out.ln;
@@ -89,12 +89,12 @@
8989 shown := false;
9090 end;
9191
92-proc text: []U8;
92+proc text: []const U8;
9393 begin
9494 return Scan.text(sc);
9595 end;
9696
97-proc is(s: []U8): BOOL;
97+proc is(s: []const U8): BOOL;
9898 begin
9999 return text() = s;
100100 end;
@@ -252,7 +252,7 @@
252252 (* One declaration, from its first token, the comment before it kept.
253253 In mdoc a module's test, its main, is left out, and declarations
254254 with no comment share a display. *)
255-proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: INT);
255+proc declaration(prefix: []const U8; exported: BOOL; start, ds, de, stop: INT);
256256 begin
257257 if not exported then return; end;
258258 if (groupStart >= 0) and (LEN(prefix) > 0) then heading; end;
@@ -315,7 +315,7 @@
315315 end;
316316
317317 proc section;
318-var word: []U8; start, ds, de, stop: INT; exp: BOOL;
318+var word: []const U8; start, ds, de, stop: INT; exp: BOOL;
319319 begin
320320 word := text();
321321 groupStart := docStart; groupEnd := docEnd;
@@ -342,7 +342,7 @@
342342 next;
343343 end;
344344
345-proc document(path: []U8);
345+proc document(path: []const U8);
346346 var b: Buf.Buf; start, ds, de: INT;
347347 begin
348348 groupStart := -1;
@@ -378,7 +378,7 @@
378378 (* line, from the report or a manual page's literal block, added to b
379379 as the program has it: in a page, \e is a backslash, \(ga a
380380 backquote and \& nothing. *)
381-proc addLine(var b: Buf.Buf; line: []U8; page: BOOL);
381+proc addLine(var b: Buf.Buf; line: []const U8; page: BOOL);
382382 var i: INT;
383383 begin
384384 i := 0;
@@ -399,7 +399,7 @@
399399 end;
400400
401401 (* text written to the file dir/name and ext, its path made in out *)
402-proc write(var out: Buf.Buf; dir, name, ext, text: []U8);
402+proc write(var out: Buf.Buf; dir, name, ext, text: []const U8);
403403 begin
404404 Buf.reset(out);
405405 Buf.str(out, dir); Buf.str(out, "/"); Buf.str(out, name); Buf.str(out, ext);
@@ -411,9 +411,9 @@
411411 -literal and .Ed. In a page, a block that starts on the line after
412412 a module's is what that program prints, written to dir/Name.shown,
413413 so that the page can be checked against the program. *)
414-proc examples(path, dir: []U8);
414+proc examples(path, dir: []const U8);
415415 var
416- b, out, prog: Buf.Buf; s, line, first, last, name, shows: []U8;
416+ b, out, prog: Buf.Buf; s, line, first, last, name, shows: []const U8;
417417 i, k, n, after: INT; inBlock, whole, page, fence: BOOL;
418418 begin
419419 Buf.init(b, Heap.heap);

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

@@ -10,7 +10,7 @@
1010 import Out, Rt, Buf, Heap, Scan, Files;
1111
1212 var
13- src: []U8;
13+ src: []const U8;
1414 state: U64; (* the generator: xorshift64 *)
1515
1616 (* A number from the generator, below n. *)
@@ -23,7 +23,7 @@
2323 end;
2424
2525 (* The seed, as a nonzero state. *)
26-proc seed(s: []U8);
26+proc seed(s: []const U8);
2727 var i: INT;
2828 begin
2929 state := 88172645463325252;

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

@@ -33,7 +33,7 @@
3333
3434 var
3535 sc: Scan.Scanner; (* the source, at the symbol being written *)
36- src: []U8;
36+ src: []const U8;
3737 out: Buf.Buf;
3838 lineAt: INT; (* where the line being written starts in out *)
3939 lineDelta: INT; (* how far this line's indent moved *)
@@ -60,7 +60,7 @@
6060
6161 (* Drops the spaces at the end of the line in out. *)
6262 proc trim;
63-var s: []U8;
63+var s: []const U8;
6464 begin
6565 s := Buf.bytes(out);
6666 while (out.len > lineAt) and ((s[out.len - 1] = ' ') or (s[out.len - 1] = '\t')) do
@@ -134,7 +134,7 @@
134134 (* Whether the current symbol, first on its line, goes on with the
135135 expression of the line before. *)
136136 proc continues: BOOL;
137-var t: []U8;
137+var t: []const U8;
138138 begin
139139 if (brackets > 0) or prevBinary or Scan.is(prev, ",") then return true; end;
140140 t := Scan.text(sc);
@@ -252,7 +252,7 @@
252252 (* After a symbol that isn't a comment: the blocks and brackets it opens
253253 or closes. *)
254254 proc track(binaryNow: BOOL);
255-var t: []U8;
255+var t: []const U8;
256256 begin
257257 t := Scan.text(sc);
258258 if sc.kind = Scan.word then
@@ -285,7 +285,7 @@
285285 end;
286286
287287 (* src, formatted, into out. *)
288-proc format(text: []U8);
288+proc format(text: []const U8);
289289 var b: BOOL;
290290 begin
291291 src := text;
@@ -323,7 +323,7 @@
323323 end;
324324
325325 proc main*;
326-var b: Buf.Buf; i: INT; path: []U8;
326+var b: Buf.Buf; i: INT; path: []const U8;
327327 begin
328328 Buf.init(b, Heap.heap);
329329 Buf.init(out, Heap.heap);

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

@@ -12,7 +12,7 @@
1212 (* word is an identifier or a reserved word; literal a string or a
1313 character; symbol an operator or delimiter. *)
1414 Scanner* = record
15- src*: []U8;
15+ src*: []const U8;
1616 pos*: INT; (* where the next symbol is looked for *)
1717 kind*: Kind; (* the current symbol *)
1818 start*, stop*: INT; (* its text: src[start..stop] *)
@@ -40,7 +40,7 @@
4040
4141 (* Whether w is one of the words of list, which are separated by
4242 single spaces. *)
43-proc among*(w, list: []U8): BOOL;
43+proc among*(w, list: []const U8): BOOL;
4444 var i, j: INT;
4545 begin
4646 i := 0;
@@ -54,19 +54,19 @@
5454 end;
5555
5656 (* Whether w is one of the report's reserved words. *)
57-proc reserved*(w: []U8): BOOL;
57+proc reserved*(w: []const U8): BOOL;
5858 begin
5959 return among(w, words);
6060 end;
6161
6262 (* The scanner at the start of src; next gives the first symbol. *)
63-proc init*(var s: Scanner; src: []U8);
63+proc init*(var s: Scanner; src: []const U8);
6464 begin
6565 s := {src: src, kind: eof};
6666 end;
6767
6868 (* Past the comment that starts at p, its nested comments with it. *)
69-proc pastComment(src: []U8; p: INT): INT;
69+proc pastComment(src: []const U8; p: INT): INT;
7070 var depth: INT;
7171 begin
7272 depth := 0;
@@ -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: INT): INT;
87+proc pastNumber(src: []const 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
@@ -101,7 +101,7 @@
101101 (* Past the string or character that starts at p, or to its line's end;
102102 a raw string, between backquotes, has no escapes and may run over
103103 lines. *)
104-proc pastLiteral(src: []U8; p: INT): INT;
104+proc pastLiteral(src: []const U8; p: INT): INT;
105105 var q: U8;
106106 begin
107107 q := src[p];
@@ -115,14 +115,14 @@
115115 end;
116116
117117 (* Whether src[p..] starts with the symbol t. *)
118-proc at(src: []U8; p: INT; t: []U8): BOOL;
118+proc at(src: []const U8; p: INT; t: []const U8): BOOL;
119119 begin
120120 return (p + LEN(t) <= LEN(src)) and (src[p..p + LEN(t)] = t);
121121 end;
122122
123123 (* On to the next symbol. *)
124124 proc next*(var s: Scanner);
125-var src: []U8; p: INT; c: U8;
125+var src: []const U8; p: INT; c: U8;
126126 begin
127127 src := s.src;
128128 p := s.pos;
@@ -159,13 +159,13 @@
159159 s.pos := p;
160160 end;
161161
162-proc text*(const s: Scanner): []U8;
162+proc text*(const s: Scanner): []const U8;
163163 begin
164164 return s.src[s.start..s.stop];
165165 end;
166166
167167 (* Whether the current symbol is t. *)
168-proc is*(const s: Scanner; t: []U8): BOOL;
168+proc is*(const s: Scanner; t: []const U8): BOOL;
169169 begin
170170 return text(s) = t;
171171 end;

tools/Test.raz (history) modified +34 -34

@@ -57,7 +57,7 @@
5757 can't tell: it is 1. *)
5858 module Test;
5959 import Opt, Fmt, Out, Buf, Str, Heap, Sys, Rt, Files;
60-import Names := Vec([]U8), Jobs := Vec(Job), ByName := Sort([]U8, less);
60+import Names := Vec([]const U8), Jobs := Vec(Job), ByName := Sort([]const U8, less);
6161
6262 const
6363 TapKey = 1; (* the keys of --tap and --junit, which have no letter *)
@@ -95,10 +95,10 @@
9595
9696 (* A test and how it is going. *)
9797 Job = record
98- path: []U8; (* its file, as given *)
99- name: []U8; (* the file's name without .raz *)
100- bin: []U8; (* its program, in the out directory *)
101- log: []U8; (* its .out, beside the program *)
98+ path: []const U8; (* its file, as given *)
99+ name: []const U8; (* the file's name without .raz *)
100+ bin: []const U8; (* its program, in the out directory *)
101+ log: []const U8; (* its .out, beside the program *)
102102 phase: Phase;
103103 pid: INT; (* the compiler's or the test's, while building or running *)
104104 began: I64; (* Sys.clock when its build started *)
@@ -109,31 +109,31 @@
109109 end;
110110
111111 var
112- raz: []U8; (* the compiler: $RAZ, or raz on PATH *)
112+ raz: []const U8; (* the compiler: $RAZ, or raz on PATH *)
113113 includes: Names.Vec; (* the -I directories *)
114114 operands: Names.Vec; (* the files and directories given *)
115115 jobs: INT; (* -j: tests at once *)
116116 timeout: I64; (* -t, in nanoseconds *)
117- outDir: []U8; (* -o *)
118- only: []U8; (* -r: the text a name must hold, or "" *)
117+ outDir: []const U8; (* -o *)
118+ only: []const U8; (* -r: the text a name must hold, or "" *)
119119 tests: Jobs.Vec; (* in the order they are reported *)
120120 busy: INT; (* tests being built or run *)
121121 devNull: INT; (* /dev/null, each test's standard input *)
122122 signals: INT; (* the fd the interrupting signals come on *)
123123 colour: BOOL; (* the words of the results are coloured *)
124124 tap: BOOL; (* --tap: report in TAP *)
125- junit: []U8; (* --junit: the file for the XML, or "" *)
125+ junit: []const U8; (* --junit: the file for the XML, or "" *)
126126 watch: BOOL; (* -w: run again when a file changes *)
127127 clearing: BOOL; (* the screen is cleared before each run of -w *)
128128
129129 (* Whether a sorts before b, for sorting a directory's files. *)
130-proc less(a, b: []U8): BOOL;
130+proc less(a, b: []const U8): BOOL;
131131 begin
132132 return Str.cmp(a, b) < 0;
133133 end;
134134
135135 (* A mistake in the setup: the message, and status 2. *)
136-proc die(f: []U8; args: []Fmt.Arg);
136+proc die(f: []const U8; args: []Fmt.Arg);
137137 var b: Buf.Buf;
138138 begin
139139 Buf.init(b, Heap.heap);
@@ -144,7 +144,7 @@
144144 end;
145145
146146 (* a, b and c joined, in memory of its own that is never freed. *)
147-proc join(a, b, c: []U8): []U8;
147+proc join(a, b, c: []const U8): []const U8;
148148 var s: Buf.Buf;
149149 begin
150150 Buf.init(s, Heap.heap);
@@ -153,8 +153,8 @@
153153 end;
154154
155155 (* Whether the source at path has a line that starts proc main*. *)
156-proc hasMain(path: []U8): BOOL;
157-var b: Buf.Buf; src: []U8;
156+proc hasMain(path: []const U8): BOOL;
157+var b: Buf.Buf; src: []const U8;
158158 begin
159159 Buf.init(b, Heap.heap);
160160 defer Buf.done(b);
@@ -164,8 +164,8 @@
164164 end;
165165
166166 (* Adds the test at path, unless -r leaves it out. *)
167-proc add(path: []U8);
168-var j: ^Job; name: []U8;
167+proc add(path: []const U8);
168+var j: ^Job; name: []const U8;
169169 begin
170170 name := path[Str.findLast(path, "/") + 1..LEN(path)];
171171 if Str.hasSuffix(name, ".raz") then name := name[0..LEN(name) - 4]; end;
@@ -177,8 +177,8 @@
177177 end;
178178
179179 (* Adds the tests of the directory dir: its *.raz with a main, by name. *)
180-proc addDir(dir: []U8);
181-var d: Sys.Dir; files: Names.Vec; name, path: []U8; ok: BOOL; err, i: INT;
180+proc addDir(dir: []const U8);
181+var d: Sys.Dir; files: Names.Vec; name, path: []const U8; ok: BOOL; err, i: INT;
182182 begin
183183 err := Sys.openDir(d, dir);
184184 if err < 0 then die("can't read {}: {}", [Fmt.str(dir), Fmt.str(Sys.errorText(err))]); end;
@@ -195,7 +195,7 @@
195195 end;
196196
197197 (* Adds what an operand names: a directory's tests, or a file. *)
198-proc addOperand(path: []U8);
198+proc addOperand(path: []const U8);
199199 var f: Sys.Info; err: INT;
200200 begin
201201 f, err := Sys.info(path);
@@ -218,7 +218,7 @@
218218 end;
219219
220220 (* Sets the environment variable name to value, for the tests. *)
221-proc setProp(name, value: []U8);
221+proc setProp(name, value: []const U8);
222222 begin
223223 if Sys.setEnv(name, value) # 0 then die("can't set {}", [Fmt.str(name)]); end;
224224 end;
@@ -236,7 +236,7 @@
236236
237237 (* Reads the command line into the settings and the list of tests. *)
238238 proc readArgs;
239-var p: Opt.Parser; arg: []U8; ok, timed: BOOL; fuzz: I64;
239+var p: Opt.Parser; arg: []const U8; ok, timed: BOOL; fuzz: I64;
240240 begin
241241 jobs := 1; timeout := 60 * Second; outDir := "build/raztest";
242242 Names.init(includes, Heap.heap);
@@ -278,7 +278,7 @@
278278 end;
279279
280280 (* Makes the directory dir and those it is in, as mkdir -p does. *)
281-proc makeDirs(dir: []U8);
281+proc makeDirs(dir: []const U8);
282282 var i, err: INT; f: Sys.Info;
283283 begin
284284 for i := 1 to LEN(dir) - 1 do
@@ -326,7 +326,7 @@
326326
327327 (* Starts args[0] with its output and errors into j's log, as j's next
328328 phase, in a group of its own; false, with j failed, if it can't. *)
329-proc start(var j: Job; args: [][]U8; phase: Phase): BOOL;
329+proc start(var j: Job; args: [][]const U8; phase: Phase): BOOL;
330330 var fd: INT;
331331 begin
332332 fd := Sys.create(j.log);
@@ -368,7 +368,7 @@
368368 (* The test j's phase has ended, how and with value as Sys.wait says:
369369 on to running it, or the end. *)
370370 proc ended(var j: Job; how: Sys.Status; value: INT);
371-var args: [1][]U8;
371+var args: [1][]const U8;
372372 begin
373373 if (j.phase = building) and (how = Sys.exited) and (value = 0) then
374374 args[0] := j.bin;
@@ -409,7 +409,7 @@
409409 end;
410410
411411 (* Writes word, in colour c on a terminal, padded to a column of 8. *)
412-proc putWord(word, c: []U8);
412+proc putWord(word, c: []const U8);
413413 var i: INT;
414414 begin
415415 if colour then Out.str(c); Out.str(word); Out.str(Plain); else Out.str(word); end;
@@ -417,8 +417,8 @@
417417 end;
418418
419419 (* Writes the file at path, each line after the text lead. *)
420-proc putLog(path, lead: []U8);
421-var b: Buf.Buf; s, line, rest: []U8; more: BOOL;
420+proc putLog(path, lead: []const U8);
421+var b: Buf.Buf; s, line, rest: []const U8; more: BOOL;
422422 begin
423423 Buf.init(b, Heap.heap);
424424 defer Buf.done(b);
@@ -433,7 +433,7 @@
433433 end;
434434
435435 (* Why the test j failed: what its why says, or that it timed out. *)
436-proc reason(const j: Job): []U8;
436+proc reason(const j: Job): []const U8;
437437 begin
438438 if j.result = timedOut then return "timed out"; end;
439439 return Buf.bytes(j.why);
@@ -522,7 +522,7 @@
522522 each control byte but tab, newline and carriage return, which XML 1.0
523523 forbids, written as ?. Bytes from 128 up, valid UTF-8 or not, are
524524 passed through as they are. *)
525-proc xml(var b: Buf.Buf; s: []U8);
525+proc xml(var b: Buf.Buf; s: []const U8);
526526 var i: INT; c: U8;
527527 begin
528528 for i := 0 to LEN(s) - 1 do
@@ -605,7 +605,7 @@
605605 end;
606606
607607 (* The directory of the file path. *)
608-proc dirOf(path: []U8): []U8;
608+proc dirOf(path: []const U8): []const U8;
609609 var i: INT;
610610 begin
611611 i := Str.findLast(path, "/");
@@ -615,7 +615,7 @@
615615 end;
616616
617617 (* Adds dir to the directories to watch, unless it is there. *)
618-proc watchDir(var dirs: Names.Vec; dir: []U8);
618+proc watchDir(var dirs: Names.Vec; dir: []const U8);
619619 var i: INT;
620620 begin
621621 for i := 0 to dirs.len - 1 do
@@ -627,7 +627,7 @@
627627 (* The directories to watch: those given, those of the test files given,
628628 and the -I ones. *)
629629 proc watchDirs(var dirs: Names.Vec);
630-var i, err: INT; f: Sys.Info; path: []U8;
630+var i, err: INT; f: Sys.Info; path: []const U8;
631631 begin
632632 Names.init(dirs, Heap.heap);
633633 for i := 0 to operands.len - 1 do
@@ -641,8 +641,8 @@
641641 (* Adds to the fingerprint and the count the *.raz files of dir. It
642642 runs every few hundred milliseconds for as long as -w does, so the
643643 paths are made in one buffer, used again. *)
644-proc lookIn(dir: []U8; var print: I64; var count: INT);
645-var d: Sys.Dir; name: []U8; ok: BOOL; f: Sys.Info; err: INT; path: Buf.Buf;
644+proc lookIn(dir: []const U8; var print: I64; var count: INT);
645+var d: Sys.Dir; name: []const U8; ok: BOOL; f: Sys.Info; err: INT; path: Buf.Buf;
646646 begin
647647 if Sys.openDir(d, dir) < 0 then return; end;
648648 Buf.init(path, Heap.heap);

tools/Widths.raz (history) modified +10 -10

@@ -20,7 +20,7 @@
2020 w: [Last + 1]U8; (* each character's width, 1 unless a file says *)
2121
2222 (* The whole file at path. *)
23-proc load(path: []U8; var b: Buf.Buf): []U8;
23+proc load(path: []const U8; var b: Buf.Buf): []const U8;
2424 begin
2525 Buf.init(b, Heap.heap);
2626 if not Files.read(path, b) then
@@ -31,7 +31,7 @@
3131 end;
3232
3333 (* s in hexadecimal, a code point; stops the program if it isn't one. *)
34-proc point(s: []U8): INT;
34+proc point(s: []const U8): INT;
3535 var v: U64; ok: BOOL;
3636 begin
3737 v, ok := Str.toHex(Str.trim(s));
@@ -52,8 +52,8 @@
5252 (* EastAsianWidth.txt: lines of a code point, or a range lo..hi, ";"
5353 and the property; W and F are 2 columns. Its first line names the
5454 file, and so the version. *)
55-proc eastAsian(text: []U8): []U8;
56-var line, rest, r, p, lo, hi, version: []U8; ok: BOOL;
55+proc eastAsian(text: []const U8): []const U8;
56+var line, rest, r, p, lo, hi, version: []const U8; ok: BOOL;
5757 begin
5858 line, rest, ok := Str.cut(text, "\n");
5959 _, version, ok := Str.cut(line, "-");
@@ -77,8 +77,8 @@
7777 (* UnicodeData.txt: lines of fields between ";", the code point, the
7878 name and the general category first. A range is two lines, its
7979 first and last, named "<..., First>" and "<..., Last>". *)
80-proc categories(text: []U8);
81-var line, rest, c, name, gc: []U8; ok: BOOL; first, n: INT;
80+proc categories(text: []const U8);
81+var line, rest, c, name, gc: []const U8; ok: BOOL; first, n: INT;
8282 begin
8383 rest := text;
8484 first := -1;
@@ -100,8 +100,8 @@
100100 (* PropList.txt: lines of a code point, or a range lo..hi, ";" and a
101101 property; a Prepended_Concatenation_Mark, a sign set over the digits
102102 after it, is seen, so 1 column, though a format character. *)
103-proc concatenation(text: []U8);
104-var line, rest, r, p, lo, hi: []U8; ok: BOOL;
103+proc concatenation(text: []const U8);
104+var line, rest, r, p, lo, hi: []const U8; ok: BOOL;
105105 begin
106106 rest := text;
107107 while LEN(rest) > 0 do
@@ -127,7 +127,7 @@
127127
128128 (* The constant name, the ranges of characters whose width is width,
129129 each its first and last, four ranges to a line. *)
130-proc table(var b: Buf.Buf; name: []U8; width: U8);
130+proc table(var b: Buf.Buf; name: []const U8; width: U8);
131131 var c, lo, n: INT;
132132 begin
133133 Buf.str(b, " "); Buf.str(b, name); Buf.str(b, ": []I32 = [");
@@ -147,7 +147,7 @@
147147 end;
148148
149149 proc main*;
150-var src, eaw, ucd, props, out: Buf.Buf; s, before, after, version: []U8; ok: BOOL;
150+var src, eaw, ucd, props, out: Buf.Buf; s, before, after, version: []const U8; ok: BOOL;
151151 begin
152152 if LEN(Files.arg(4)) = 0 then
153153 Out.str("usage: Widths lib/Width.raz EastAsianWidth.txt UnicodeData.txt PropList.txt\n");

tools/cabi.c (history) modified +1 -1

@@ -103,7 +103,7 @@
103103 " its errnos beside Linux's, and errno and closeFrom.\n\n"
104104 " Written by tools/cabi.c, from the system's own headers; not to be\n"
105105 " edited, but written again. *)\n", target);
106- printf("module CAbi;\n\nconst\n");
106+ printf("module CAbi;\nimport SYSTEM;\n\nconst\n");
107107
108108 SAY("open's flags, fcntl's requests, seek, flock, mmap, access");
109109 K("oRdonly", O_RDONLY); K("oWronly", O_WRONLY); K("oRdwr", O_RDWR);