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.
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | 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), | |
| 3 | 3 | Ints := Pile(I64), More := Pile(I64), Never := Loud(I64), Ones := Loud(U8); |
| 4 | 4 | |
| 5 | 5 | type Colour = (red, green, blue); |
| @@ -11,6 +11,12 @@ | ||
| 11 | 11 | beside the new; the release notes list the old forms, and the next |
| 12 | 12 | version removes them. Nothing marks an old form in the source. |
| 13 | 13 | |
| 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 | + | |
| 14 | 20 | Modules written in raz, in the compiler's `lib` directory: |
| 15 | 21 | |
| 16 | 22 | | Module | What | |
| @@ -26,7 +32,7 @@ | ||
| 26 | 32 | | `Mem` | `Allocator`, the interface of every allocator, and pages from the system | |
| 27 | 33 | | `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 | |
| 28 | 34 | | `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 | | |
| 30 | 36 | | `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 | |
| 31 | 37 | | `Buf` | a growable byte buffer | |
| 32 | 38 | | `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 @@ | ||
| 58 | 64 | proc atExit*(p: proc): ERROR; (* p run when the program ends by exit *) |
| 59 | 65 | proc exit*(status: INT); (* the atExit procedures, the last first, then the end *) |
| 60 | 66 | 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 *) | |
| 62 | 68 | proc trace*; (* the calls under way, and their variables, on standard error *) |
| 63 | 69 | ``` |
| 64 | 70 | |
| @@ -182,7 +188,7 @@ | ||
| 182 | 188 | |
| 183 | 189 | ``` |
| 184 | 190 | module Out; |
| 185 | -proc str*(s: []U8); | |
| 191 | +proc str*(s: []const U8); | |
| 186 | 192 | proc char*(c: U8); |
| 187 | 193 | proc ln*; (* a line feed *) |
| 188 | 194 | proc int*(n: I64); (* n in decimal *) |
| @@ -276,11 +282,11 @@ | ||
| 276 | 282 | Kind* = (unknown, isFile, isDir, isLink, isOther); (* what a directory says a name in it is *) |
| 277 | 283 | Dir* = record ... end; (* an open directory; its fields are the target's *) |
| 278 | 284 | 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 *) | |
| 282 | 288 | 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 *) | |
| 284 | 290 | fds*: [3]INT; (* its standard input, output and error; 0 for this program's own *) |
| 285 | 291 | group*: INT; (* the process group it joins: 0 for this program's, -1 a new one it leads *) |
| 286 | 292 | foreground*: BOOL; (* its group takes the terminal on standard input *) |
| @@ -304,12 +310,12 @@ | ||
| 304 | 310 | ready*: BOOL; (* set by poll *) |
| 305 | 311 | end; |
| 306 | 312 | |
| 307 | -proc write*(fd: INT; s: []U8): INT; (* the bytes written *) | |
| 313 | +proc write*(fd: INT; s: []const U8): INT; (* the bytes written *) | |
| 308 | 314 | 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}) *) | |
| 313 | 319 | proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *) |
| 314 | 320 | proc position*(fd: INT): I64; (* where the next read or write is *) |
| 315 | 321 | proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *) |
| @@ -331,26 +337,26 @@ | ||
| 331 | 337 | proc yield*; (* the processor given to another thread *) |
| 332 | 338 | proc exit*(status: INT); (* the program ended at once, without Rt's atExit *) |
| 333 | 339 | |
| 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 *) | |
| 344 | 350 | 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 *) | |
| 349 | 355 | 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 *) | |
| 351 | 357 | |
| 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 *) | |
| 354 | 360 | proc entryKind*(const d: Dir): Kind; (* what the name nextEntry gave last is *) |
| 355 | 361 | proc closeDir*(var d: Dir); |
| 356 | 362 | |
| @@ -360,27 +366,27 @@ | ||
| 360 | 366 | proc setMode*(fd: INT; m: Mode): INT; (* once what was written to it is sent *) |
| 361 | 367 | proc termSize*(fd: INT): (INT, INT); (* columns and rows; 80 and 24 if unknown *) |
| 362 | 368 | 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 *) | |
| 365 | 371 | 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 *) |
| 366 | 372 | proc setBlocking*(fd: INT; yes: BOOL): INT; (* if not yes, a read or write that would wait is -11 at once *) |
| 367 | 373 | proc blocking*(fd: INT): INT; (* 1 if reads and writes wait, 0 if they are -11 at once, or minus an errno *) |
| 368 | 374 | |
| 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 *) | |
| 370 | 376 | |
| 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; | |
| 377 | 383 | |
| 378 | 384 | proc pipe*: (INT, INT); (* the fd to read and the fd to write; or minus an errno and -1 *) |
| 379 | 385 | proc openPty*: INT; (* a pseudo-terminal: the fd of its controlling side *) |
| 380 | 386 | proc setTermSize*(fd, cols, rows: INT): INT; (* the size its programs are told of *) |
| 381 | 387 | proc spawn*(p: Program): INT; (* a program started: its process id *) |
| 382 | 388 | 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 *) | |
| 384 | 390 | proc fork*: INT; (* this program copied: 0 in the copy, its process id in this one *) |
| 385 | 391 | proc setsid*: INT; (* a session of its own, led by this program: its process id, or minus an errno *) |
| 386 | 392 | proc wait*(pid: INT; block: BOOL): (INT, Status, INT); (* which program, how, and its code *) |
| @@ -393,13 +399,13 @@ | ||
| 393 | 399 | proc foregroundOf*(fd: INT): INT; (* the group the terminal on fd gives its keys to *) |
| 394 | 400 | proc uid*: INT; (* the user this program runs as *) |
| 395 | 401 | 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 *) | |
| 397 | 403 | proc processors*: INT; (* the processors this program may run on, at least 1 *) |
| 398 | 404 | proc cpuTime*(children: BOOL): (I64, I64); (* ns used in the program and in the system; or by its children *) |
| 399 | 405 | proc limit*(which: INT): (I64, I64, INT); (* the soft limit and the hard; -1 for none *) |
| 400 | 406 | proc setLimit*(which: INT; soft, hard: I64): INT; |
| 401 | 407 | |
| 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 *) | |
| 403 | 409 | proc caught*(fd: INT): INT; (* the next signal caught, or 0 if none is waiting *) |
| 404 | 410 | proc ignore*(sig: INT; yes: BOOL): INT; (* sig ignored; or, if not yes, back to what it does at first *) |
| 405 | 411 | proc ignored*(sig: INT): BOOL; (* whether sig does nothing now *) |
| @@ -411,23 +417,23 @@ | ||
| 411 | 417 | proc sleep*(ms: INT); |
| 412 | 418 | proc random*(b: []U8); (* b filled with random bytes; stops the program if it can't be *) |
| 413 | 419 | |
| 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; | |
| 419 | 425 | 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 *) | |
| 424 | 430 | 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 *) | |
| 426 | 432 | proc localPort*(fd: INT): INT; (* the port the socket fd is bound to *) |
| 427 | 433 | proc closeWrite*(fd: INT): INT; (* no more writing to the socket fd; the other end reads an end *) |
| 428 | 434 | proc peer*(fd: INT): (Remote, INT); (* who is at the other end of the connected socket fd *) |
| 429 | 435 | 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 *) | |
| 431 | 437 | proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); (* read, and the fds that came with it *) |
| 432 | 438 | |
| 433 | 439 | proc memFile*(size: INT): INT; (* a file of size zero bytes, in memory, with no name: its fd *) |
| @@ -787,22 +793,22 @@ | ||
| 787 | 793 | |
| 788 | 794 | ``` |
| 789 | 795 | 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 *) | |
| 794 | 800 | 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 *) | |
| 806 | 812 | proc isDigit*(c: U8): BOOL; (* 0 to 9 *) |
| 807 | 813 | proc isLetter*(c: U8): BOOL; (* A to Z, a to z *) |
| 808 | 814 | proc isSpace*(c: U8): BOOL; (* a space, as trim takes it *) |
| @@ -810,28 +816,28 @@ | ||
| 810 | 816 | proc hexVal*(c: U8): INT; (* c's value as a hexadecimal digit, or -1 *) |
| 811 | 817 | proc lower*(s: []U8); (* s's ASCII capitals made small, in place *) |
| 812 | 818 | 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 *) | |
| 815 | 821 | 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) *) | |
| 826 | 832 | 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 *) | |
| 829 | 835 | 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 *) | |
| 832 | 838 | 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 *) | |
| 835 | 841 | proc putLE*(s: []U8; v: U64); (* v into s, the lowest byte first *) |
| 836 | 842 | proc putBE*(s: []U8; v: U64); (* v into s, the highest byte first *) |
| 837 | 843 | |
| @@ -840,7 +846,7 @@ | ||
| 840 | 846 | proc init*(var b: Buf; a: ^Mem.Allocator); |
| 841 | 847 | proc room*(var b: Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *) |
| 842 | 848 | proc add*(var b: Buf; c: U8); |
| 843 | -proc str*(var b: Buf; s: []U8); | |
| 849 | +proc str*(var b: Buf; s: []const U8); | |
| 844 | 850 | proc spare*(var b: Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *) |
| 845 | 851 | proc bytes*(const b: Buf): []U8; (* what it holds, until it next grows *) |
| 846 | 852 | proc cut*(var b: Buf; n: INT); (* only the first n bytes kept, its memory kept *) |
| @@ -853,17 +859,17 @@ | ||
| 853 | 859 | uint(u: U64); |
| 854 | 860 | hex(h: U64); |
| 855 | 861 | lowHex(h: U64); |
| 856 | - str(s: []U8); | |
| 862 | + str(s: []const U8); | |
| 857 | 863 | char(c: U8); |
| 858 | 864 | bool(b: BOOL); |
| 859 | 865 | real(r: F64; places: INT); |
| 860 | 866 | end; |
| 861 | 867 | const ShortMost* = 24; (* the longest Fmt.short *) |
| 862 | 868 | 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 *) | |
| 867 | 873 | |
| 868 | 874 | module List(T); |
| 869 | 875 | type |
| @@ -927,7 +933,7 @@ | ||
| 927 | 933 | proc fromBits*(u: U64): F64; (* the F64 whose bits are u *) |
| 928 | 934 | proc mul*(a, b: U64): (U64, U64); (* a times b: the low 64 bits of the product, and the high *) |
| 929 | 935 | 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 *) | |
| 931 | 937 | ``` |
| 932 | 938 | |
| 933 | 939 | A `Buf`, a `List`, a `Map` and a `Vec` take their memory from the |
| @@ -946,7 +952,7 @@ | ||
| 946 | 952 | room; `room` asks first: `import Lines := Vec([]U8);`. `Fmt`'s format takes the next argument at each |
| 947 | 953 | `{}`; `{{` and `}}` stand for `{` and `}`. A `Map` hashes and |
| 948 | 954 | 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);`. | |
| 950 | 956 | |
| 951 | 957 | `Str` reads and writes UTF-8. `encode` writes a character, of at most |
| 952 | 958 | 10FFFFH, in one to four bytes; a number that isn't one becomes FFFDH, |
| @@ -1101,37 +1107,37 @@ | ||
| 1101 | 1107 | |
| 1102 | 1108 | ``` |
| 1103 | 1109 | 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 *) | |
| 1111 | 1117 | |
| 1112 | 1118 | module Opt; |
| 1113 | 1119 | type |
| 1114 | 1120 | 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); | |
| 1118 | 1124 | end; |
| 1119 | 1125 | Parser* = record |
| 1120 | 1126 | letter*: U8; (* the option just read *) |
| 1121 | - value*: []U8; (* its value; "" for a flag *) | |
| 1127 | + value*: []const U8; (* its value; "" for a flag *) | |
| 1122 | 1128 | 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 *) | |
| 1124 | 1130 | ... |
| 1125 | 1131 | 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 *) | |
| 1127 | 1133 | 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 *) | |
| 1129 | 1135 | 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 *) | |
| 1131 | 1137 | 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 *) | |
| 1135 | 1141 | ``` |
| 1136 | 1142 | |
| 1137 | 1143 | `Opt` reads a command line by the rules of the C library's `getopt`, |
| @@ -1268,7 +1274,7 @@ | ||
| 1268 | 1274 | ``` |
| 1269 | 1275 | module Width; |
| 1270 | 1276 | 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 *) | |
| 1272 | 1278 | ``` |
| 1273 | 1279 | |
| 1274 | 1280 | A combining mark, a format character, a control and Hangul's medial |
| @@ -1336,9 +1342,9 @@ | ||
| 1336 | 1342 | |
| 1337 | 1343 | ``` |
| 1338 | 1344 | 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 *) | |
| 1342 | 1348 | proc mute*(on: BOOL); (* while on, checks say nothing and are not counted *) |
| 1343 | 1349 | proc mutedFailures*(): INT; (* how many failed since mute was turned on *) |
| 1344 | 1350 | ``` |
| @@ -1384,7 +1390,7 @@ | ||
| 1384 | 1390 | proc pick*(var s: Source; n: INT): INT; (* 0 to n - 1; n at least 1 *) |
| 1385 | 1391 | proc bool*(var s: Source): BOOL; |
| 1386 | 1392 | 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 *) | |
| 1388 | 1394 | ``` |
| 1389 | 1395 | |
| 1390 | 1396 | `check` runs `p` on each case saved in the directory `$PROP_DIR/name` |
| @@ -384,7 +384,7 @@ | ||
| 384 | 384 | end; |
| 385 | 385 | |
| 386 | 386 | 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; | |
| 388 | 388 | begin |
| 389 | 389 | for i := 0 to 4 do a[i] := i * i; end; |
| 390 | 390 | Out.int(sum(a)); Out.ln; (* the array, as a slice *) |
| @@ -1224,7 +1224,7 @@ | ||
| 1224 | 1224 | .Cm Sort |
| 1225 | 1225 | are generic modules: |
| 1226 | 1226 | .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); | |
| 1228 | 1228 | .Ed |
| 1229 | 1229 | .Sh 14. TALKING TO C |
| 1230 | 1230 | .Bd -literal -offset indent |
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | .Cm "import Ints := List(INT);" |
| 160 | 160 | makes an instance of a generic module, one for each distinct list of |
| 161 | 161 | 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)" . | |
| 163 | 163 | .It |
| 164 | 164 | A module's body runs once, after those of the modules it imports, and |
| 165 | 165 | before the main module's |
| @@ -312,7 +312,7 @@ | ||
| 312 | 312 | scope there. |
| 313 | 313 | |
| 314 | 314 | ``` |
| 315 | -import Table := Map([]U8, Colour, Str.hash, Str.eq); | |
| 315 | +import Table := Map([]const U8, Colour, Str.hash, Str.eq); | |
| 316 | 316 | |
| 317 | 317 | type Colour = (red, green, blue); |
| 318 | 318 | |
| @@ -327,7 +327,7 @@ | ||
| 327 | 327 | ``` |
| 328 | 328 | |
| 329 | 329 | ``` |
| 330 | -import Names := Map([]U8, I64, Str.hash, Str.eq); | |
| 330 | +import Names := Map([]const U8, I64, Str.hash, Str.eq); | |
| 331 | 331 | ``` |
| 332 | 332 | |
| 333 | 333 | A procedure argument names a procedure, not a variable or an |
| @@ -18,12 +18,12 @@ | ||
| 18 | 18 | `; |
| 19 | 19 | |
| 20 | 20 | var |
| 21 | - title: []U8; | |
| 21 | + title: []const U8; | |
| 22 | 22 | width, height: I64; |
| 23 | 23 | scale: F64; |
| 24 | 24 | |
| 25 | 25 | (* 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; | |
| 27 | 27 | var ok: BOOL; lower: [16]U8; |
| 28 | 28 | begin |
| 29 | 29 | if LEN(name) > LEN(lower) then return false; end; |
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | end; |
| 42 | 42 | |
| 43 | 43 | 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; | |
| 45 | 45 | begin |
| 46 | 46 | rest := Text; |
| 47 | 47 | more := true; |
| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | type |
| 22 | 22 | Command = record |
| 23 | - args: [maxWords][]U8; | |
| 23 | + args: [maxWords][]const U8; | |
| 24 | 24 | 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 *) | |
| 26 | 26 | append: BOOL; (* output is >> *) |
| 27 | 27 | end; |
| 28 | 28 | Pipeline = record |
| @@ -39,12 +39,12 @@ | ||
| 39 | 39 | interactive: BOOL; (* commands come from a terminal: job control *) |
| 40 | 40 | group: INT; (* the shell's process group *) |
| 41 | 41 | 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 *) | |
| 43 | 43 | at: INT; (* where in it *) |
| 44 | - text: []U8; (* the last word read *) | |
| 44 | + text: []const U8; (* the last word read *) | |
| 45 | 45 | |
| 46 | 46 | (* "Sh: " and a message on standard error. *) |
| 47 | -proc say(f: []U8; args: []Fmt.Arg); | |
| 47 | +proc say(f: []const U8; args: []Fmt.Arg); | |
| 48 | 48 | var b: Buf.Buf; _n: INT; |
| 49 | 49 | begin |
| 50 | 50 | Buf.init(b, Heap.heap); |
| @@ -175,8 +175,8 @@ | ||
| 175 | 175 | |
| 176 | 176 | (* The program a command names: the name itself if it has a /, else the |
| 177 | 177 | 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; | |
| 180 | 180 | begin |
| 181 | 181 | if Str.find(name, "/") >= 0 then return name, true; end; |
| 182 | 182 | path := Sys.env("PATH"); |
| @@ -195,7 +195,7 @@ | ||
| 195 | 195 | end; |
| 196 | 196 | |
| 197 | 197 | (* 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; | |
| 199 | 199 | var fd: INT; |
| 200 | 200 | begin |
| 201 | 201 | fd := Sys.open(path, how); |
| @@ -206,7 +206,7 @@ | ||
| 206 | 206 | (* cd, wait and exit, which change the shell itself, so it can't start |
| 207 | 207 | them as programs; true if c is one. *) |
| 208 | 208 | 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; | |
| 210 | 210 | begin |
| 211 | 211 | match c^.args[0] of |
| 212 | 212 | | "cd": |
| @@ -231,7 +231,7 @@ | ||
| 231 | 231 | |
| 232 | 232 | (* What the shell itself says on standard output, out before any |
| 233 | 233 | program it starts writes. *) |
| 234 | -proc show(f: []U8; args: []Fmt.Arg); | |
| 234 | +proc show(f: []const U8; args: []Fmt.Arg); | |
| 235 | 235 | begin |
| 236 | 236 | Fmt.print(f, args); |
| 237 | 237 | Out.flush; |
| @@ -244,7 +244,7 @@ | ||
| 244 | 244 | proc start(p: ^Pipeline); |
| 245 | 245 | var |
| 246 | 246 | 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; | |
| 248 | 248 | begin |
| 249 | 249 | if (p^.n = 1) and not p^.background and builtin(ADR(p^.cmds[0])) then return; end; |
| 250 | 250 | leader := 0; |
| @@ -299,7 +299,7 @@ | ||
| 299 | 299 | end; |
| 300 | 300 | |
| 301 | 301 | (* Runs script: each pipeline as it is read. *) |
| 302 | -proc run(script: []U8); | |
| 302 | +proc run(script: []const U8); | |
| 303 | 303 | var p: Pipeline; t: Token; ok: BOOL; |
| 304 | 304 | begin |
| 305 | 305 | Arena.reset(arena); |
| @@ -364,7 +364,7 @@ | ||
| 364 | 364 | Opt.option("", 'c', "command", "script", "run script, not standard input")]; |
| 365 | 365 | |
| 366 | 366 | 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; | |
| 368 | 368 | begin |
| 369 | 369 | if not Arena.init(arena, 1 shl 24) then Rt.stop("Sh: no memory"); end; |
| 370 | 370 | Opt.init(p, "Sh", Options); |
| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | (* 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 | |
| 3 | 3 | 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. *) | |
| 5 | 5 | 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); | |
| 7 | 7 | |
| 8 | 8 | const Text = "the cat and the hat and the bat"; |
| 9 | 9 | |
| 10 | 10 | proc main*; |
| 11 | 11 | var |
| 12 | 12 | 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; | |
| 14 | 14 | begin |
| 15 | 15 | Count.init(counts, Heap.heap); |
| 16 | 16 | Names.init(order, Heap.heap); |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | (* An allocator that hands out memory from one block and frees it all |
| 2 | 2 | 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. *) | |
| 4 | 4 | module Arena; |
| 5 | 5 | import Mem, Rt; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | type |
| 8 | 9 | Arena* = record |
| @@ -70,7 +71,7 @@ | ||
| 70 | 71 | var ar: Arena; a: ^Mem.Allocator; p, q: ^U8; m: INT; |
| 71 | 72 | begin |
| 72 | 73 | if not init(ar, 4096) then Rt.stop("Arena.init"); end; |
| 73 | - a := ADR(ar.base); | |
| 74 | + a := SYSTEM.ADR(ar.base); | |
| 74 | 75 | p := Mem.alloc(a, 3, 1); |
| 75 | 76 | q := Mem.alloc(a, 8, 8); |
| 76 | 77 | if (p = nil) or (q # p + 8) then Rt.stop("Arena: alignment"); end; |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* A growable byte buffer, its memory from an allocator. *) |
| 2 | 2 | module Buf; |
| 3 | 3 | import Mem, Arena, Rt, Sys; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | type |
| 6 | 7 | Buf* = record |
| @@ -61,7 +62,7 @@ | ||
| 61 | 62 | end; |
| 62 | 63 | |
| 63 | 64 | (* 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); | |
| 65 | 66 | begin |
| 66 | 67 | need(b, LEN(s)); |
| 67 | 68 | COPY(b.data[b.len..b.len + LEN(s)], s); |
| @@ -73,7 +74,7 @@ | ||
| 73 | 74 | grows, as bytes is. *) |
| 74 | 75 | proc spare*(var b: Buf; n: INT): []U8; |
| 75 | 76 | 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 *) | |
| 77 | 78 | need(b, n); |
| 78 | 79 | return b.data[b.len..b.len + n]; |
| 79 | 80 | end; |
| @@ -81,7 +82,7 @@ | ||
| 81 | 82 | (* What the buffer holds, until it next grows. *) |
| 82 | 83 | proc bytes*(const b: Buf): []U8; |
| 83 | 84 | begin |
| 84 | - if b.len = 0 then return ""; end; | |
| 85 | + if b.len = 0 then return []; end; | |
| 85 | 86 | return b.data[0..b.len]; |
| 86 | 87 | end; |
| 87 | 88 | |
| @@ -118,7 +119,7 @@ | ||
| 118 | 119 | var ar: Arena.Arena; b: Buf; i: INT; s: []U8; |
| 119 | 120 | begin |
| 120 | 121 | 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)); | |
| 122 | 123 | if LEN(bytes(b)) # 0 then Rt.stop("Buf: not empty"); end; |
| 123 | 124 | for i := 0 to 9999 do add(b, U8(i mod 251)); end; |
| 124 | 125 | str(b, "end"); |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | interface is the same. *) |
| 7 | 7 | module Bytes; |
| 8 | 8 | import Rt; |
| 9 | +import SYSTEM; | |
| 9 | 10 | |
| 10 | 11 | const |
| 11 | 12 | Ones = 0101010101010101H; (* a one in each byte *) |
| @@ -42,13 +43,13 @@ | ||
| 42 | 43 | end; |
| 43 | 44 | |
| 44 | 45 | (* 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; | |
| 46 | 47 | var i: INT; m, v, bs: U64; p: ^U64; |
| 47 | 48 | begin |
| 48 | 49 | bs := U64(b) * Ones; |
| 49 | 50 | i := 0; |
| 50 | 51 | while i + 8 <= LEN(s) do |
| 51 | - p := ^U64(ADR(s[i])); | |
| 52 | + p := ^U64(SYSTEM.PTR(s[i..LEN(s)])); | |
| 52 | 53 | v := p^ xor bs; |
| 53 | 54 | m := ~(((v & Lows) + Lows) | v | Lows) & Tops; |
| 54 | 55 | if m # 0 then return i + INT((((m & (0 - m)) - 1) & Ones) * Ones shr 56) - 1; end; |
| @@ -62,13 +63,13 @@ | ||
| 62 | 63 | end; |
| 63 | 64 | |
| 64 | 65 | (* 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; | |
| 66 | 67 | var i: INT; m, v, bs: U64; p: ^U64; |
| 67 | 68 | begin |
| 68 | 69 | bs := U64(b) * Ones; |
| 69 | 70 | i := LEN(s); |
| 70 | 71 | while i >= 8 do |
| 71 | - p := ^U64(ADR(s[i - 8])); | |
| 72 | + p := ^U64(SYSTEM.PTR(s[i - 8..LEN(s)])); | |
| 72 | 73 | v := p^ xor bs; |
| 73 | 74 | m := ~(((v & Lows) + Lows) | v | Lows) & Tops; |
| 74 | 75 | if m # 0 then return i - 8 + highest(m); end; |
| @@ -82,14 +83,14 @@ | ||
| 82 | 83 | end; |
| 83 | 84 | |
| 84 | 85 | (* How many bytes of s are b. *) |
| 85 | -proc count*(s: []U8; b: U8): INT; | |
| 86 | +proc count*(s: []const U8; b: U8): INT; | |
| 86 | 87 | var i, n: INT; v, bs: U64; p: ^U64; |
| 87 | 88 | begin |
| 88 | 89 | bs := U64(b) * Ones; |
| 89 | 90 | i := 0; |
| 90 | 91 | n := 0; |
| 91 | 92 | while i + 8 <= LEN(s) do |
| 92 | - p := ^U64(ADR(s[i])); | |
| 93 | + p := ^U64(SYSTEM.PTR(s[i..LEN(s)])); | |
| 93 | 94 | v := p^ xor bs; |
| 94 | 95 | n := n + INT(((~(((v & Lows) + Lows) | v | Lows) & Tops) shr 7) * Ones shr 56); |
| 95 | 96 | i := i + 8; |
| @@ -107,7 +108,7 @@ | ||
| 107 | 108 | both agree. They are the two bytes farthest apart, so as far from |
| 108 | 109 | being the same test as two can be, and need no table of which bytes |
| 109 | 110 | are rare. *) |
| 110 | -proc find*(s, sub: []U8): INT; | |
| 111 | +proc find*(s, sub: []const U8): INT; | |
| 111 | 112 | var i, j, n, lastStart: INT; m, v, w, b0, b1: U64; p: ^U64; |
| 112 | 113 | begin |
| 113 | 114 | n := LEN(sub); |
| @@ -119,9 +120,9 @@ | ||
| 119 | 120 | b1 := U64(sub[n - 1]) * Ones; |
| 120 | 121 | i := 0; |
| 121 | 122 | while i + 7 <= lastStart do |
| 122 | - p := ^U64(ADR(s[i])); | |
| 123 | + p := ^U64(SYSTEM.PTR(s[i..LEN(s)])); | |
| 123 | 124 | v := p^ xor b0; |
| 124 | - p := ^U64(ADR(s[i + n - 1])); | |
| 125 | + p := ^U64(SYSTEM.PTR(s[i + n - 1..LEN(s)])); | |
| 125 | 126 | w := p^ xor b1; |
| 126 | 127 | m := ~(((v & Lows) + Lows) | v | Lows) & ~(((w & Lows) + Lows) | w | Lows) & Tops; |
| 127 | 128 | while m # 0 do |
| @@ -153,7 +154,7 @@ | ||
| 153 | 154 | return INT((seed shr 33) mod U64(n)); |
| 154 | 155 | end; |
| 155 | 156 | |
| 156 | -proc refIndex(s: []U8; b: U8): INT; | |
| 157 | +proc refIndex(s: []const U8; b: U8): INT; | |
| 157 | 158 | var i: INT; |
| 158 | 159 | begin |
| 159 | 160 | for i := 0 to LEN(s) - 1 do |
| @@ -162,7 +163,7 @@ | ||
| 162 | 163 | return -1; |
| 163 | 164 | end; |
| 164 | 165 | |
| 165 | -proc refLast(s: []U8; b: U8): INT; | |
| 166 | +proc refLast(s: []const U8; b: U8): INT; | |
| 166 | 167 | var i: INT; |
| 167 | 168 | begin |
| 168 | 169 | for i := LEN(s) - 1 to 0 by -1 do |
| @@ -171,7 +172,7 @@ | ||
| 171 | 172 | return -1; |
| 172 | 173 | end; |
| 173 | 174 | |
| 174 | -proc refCount(s: []U8; b: U8): INT; | |
| 175 | +proc refCount(s: []const U8; b: U8): INT; | |
| 175 | 176 | var i, n: INT; |
| 176 | 177 | begin |
| 177 | 178 | n := 0; |
| @@ -181,7 +182,7 @@ | ||
| 181 | 182 | return n; |
| 182 | 183 | end; |
| 183 | 184 | |
| 184 | -proc refFind(s, sub: []U8): INT; | |
| 185 | +proc refFind(s, sub: []const U8): INT; | |
| 185 | 186 | var i: INT; |
| 186 | 187 | begin |
| 187 | 188 | for i := 0 to LEN(s) - LEN(sub) do |
| @@ -191,14 +192,14 @@ | ||
| 191 | 192 | end; |
| 192 | 193 | |
| 193 | 194 | (* 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); | |
| 195 | 196 | begin |
| 196 | 197 | if index(s, b) # refIndex(s, b) then Rt.stop("Bytes.index"); end; |
| 197 | 198 | if last(s, b) # refLast(s, b) then Rt.stop("Bytes.last"); end; |
| 198 | 199 | if count(s, b) # refCount(s, b) then Rt.stop("Bytes.count"); end; |
| 199 | 200 | end; |
| 200 | 201 | |
| 201 | -proc checkFind(s, sub: []U8); | |
| 202 | +proc checkFind(s, sub: []const U8); | |
| 202 | 203 | begin |
| 203 | 204 | if find(s, sub) # refFind(s, sub) then Rt.stop("Bytes.find"); end; |
| 204 | 205 | end; |
| @@ -244,7 +245,7 @@ | ||
| 244 | 245 | that are almost its bytes; the slice cut short just before and just |
| 245 | 246 | after it; also subs longer than the slice, and empty ones *) |
| 246 | 247 | proc testPlanted; |
| 247 | -var n, p, i, f: INT; s: []U8; | |
| 248 | +var n, p, i, f: INT; s: []const U8; | |
| 248 | 249 | begin |
| 249 | 250 | for f := 0 to 2 do |
| 250 | 251 | for n := 1 to 24 do |
| @@ -5,13 +5,14 @@ | ||
| 5 | 5 | 64-bit target, eight at a time in a U64. *) |
| 6 | 6 | module Bytes; |
| 7 | 7 | import Rt; |
| 8 | +import SYSTEM; | |
| 8 | 9 | |
| 9 | 10 | (* The first place of b in s, or -1. Sixteen bytes at a time are |
| 10 | 11 | compared with b's sixteen copies (pcmpeqb), and pmovmskb makes of the |
| 11 | 12 | result a number with a bit set for each byte that matched. The bytes |
| 12 | 13 | left over, fewer than sixteen, are compared one by one. Where the |
| 13 | 14 | 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; | |
| 15 | 16 | code |
| 16 | 17 | movd xmm1, edx; |
| 17 | 18 | punpcklbw xmm1, xmm1; (* b in the low two bytes... *) |
| @@ -49,7 +50,7 @@ | ||
| 49 | 50 | end index; |
| 50 | 51 | |
| 51 | 52 | (* 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; | |
| 53 | 54 | code |
| 54 | 55 | movd xmm1, edx; |
| 55 | 56 | punpcklbw xmm1, xmm1; |
| @@ -82,7 +83,7 @@ | ||
| 82 | 83 | end last; |
| 83 | 84 | |
| 84 | 85 | (* 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; | |
| 86 | 87 | code |
| 87 | 88 | movd xmm1, edx; |
| 88 | 89 | punpcklbw xmm1, xmm1; |
| @@ -119,7 +120,7 @@ | ||
| 119 | 120 | once: sixteen bytes are compared with a, sixteen from gap places on |
| 120 | 121 | with b, and the two results anded. The places in rdi and rsi (s), |
| 121 | 122 | 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; | |
| 123 | 124 | code |
| 124 | 125 | mov r11, rcx; (* a, for the places one by one *) |
| 125 | 126 | movd xmm1, ecx; |
| @@ -175,7 +176,7 @@ | ||
| 175 | 176 | its place (pair), and checked whole only where both agree. They are |
| 176 | 177 | the two bytes farthest apart, so as far from being the same test as |
| 177 | 178 | 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; | |
| 179 | 180 | var i, n: INT; |
| 180 | 181 | begin |
| 181 | 182 | n := LEN(sub); |
| @@ -204,7 +205,7 @@ | ||
| 204 | 205 | return INT((seed shr 33) mod U64(n)); |
| 205 | 206 | end; |
| 206 | 207 | |
| 207 | -proc refIndex(s: []U8; b: U8): INT; | |
| 208 | +proc refIndex(s: []const U8; b: U8): INT; | |
| 208 | 209 | var i: INT; |
| 209 | 210 | begin |
| 210 | 211 | for i := 0 to LEN(s) - 1 do |
| @@ -213,7 +214,7 @@ | ||
| 213 | 214 | return -1; |
| 214 | 215 | end; |
| 215 | 216 | |
| 216 | -proc refLast(s: []U8; b: U8): INT; | |
| 217 | +proc refLast(s: []const U8; b: U8): INT; | |
| 217 | 218 | var i: INT; |
| 218 | 219 | begin |
| 219 | 220 | for i := LEN(s) - 1 to 0 by -1 do |
| @@ -222,7 +223,7 @@ | ||
| 222 | 223 | return -1; |
| 223 | 224 | end; |
| 224 | 225 | |
| 225 | -proc refCount(s: []U8; b: U8): INT; | |
| 226 | +proc refCount(s: []const U8; b: U8): INT; | |
| 226 | 227 | var i, n: INT; |
| 227 | 228 | begin |
| 228 | 229 | n := 0; |
| @@ -232,7 +233,7 @@ | ||
| 232 | 233 | return n; |
| 233 | 234 | end; |
| 234 | 235 | |
| 235 | -proc refFind(s, sub: []U8): INT; | |
| 236 | +proc refFind(s, sub: []const U8): INT; | |
| 236 | 237 | var i: INT; |
| 237 | 238 | begin |
| 238 | 239 | for i := 0 to LEN(s) - LEN(sub) do |
| @@ -242,14 +243,14 @@ | ||
| 242 | 243 | end; |
| 243 | 244 | |
| 244 | 245 | (* 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); | |
| 246 | 247 | begin |
| 247 | 248 | if index(s, b) # refIndex(s, b) then Rt.stop("Bytes.index"); end; |
| 248 | 249 | if last(s, b) # refLast(s, b) then Rt.stop("Bytes.last"); end; |
| 249 | 250 | if count(s, b) # refCount(s, b) then Rt.stop("Bytes.count"); end; |
| 250 | 251 | end; |
| 251 | 252 | |
| 252 | -proc checkFind(s, sub: []U8); | |
| 253 | +proc checkFind(s, sub: []const U8); | |
| 253 | 254 | begin |
| 254 | 255 | if find(s, sub) # refFind(s, sub) then Rt.stop("Bytes.find"); end; |
| 255 | 256 | end; |
| @@ -295,7 +296,7 @@ | ||
| 295 | 296 | that are almost its bytes; the slice cut short just before and just |
| 296 | 297 | after it; also subs longer than the slice, and empty ones *) |
| 297 | 298 | proc testPlanted; |
| 298 | -var n, p, i, f: INT; s: []U8; | |
| 299 | +var n, p, i, f: INT; s: []const U8; | |
| 299 | 300 | begin |
| 300 | 301 | for f := 0 to 2 do |
| 301 | 302 | for n := 1 to 24 do |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | programs reach for. A program that imports C uses C, and so is |
| 3 | 3 | linked dynamically and starts through the C library. *) |
| 4 | 4 | module C; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | extern proc write*(fd: I32; buf: ^U8; n: UINT): INT; |
| 7 | 8 | extern proc read*(fd: I32; buf: ^U8; n: UINT): INT; |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | Written by tools/cabi.c, from the system's own headers; not to be |
| 7 | 7 | edited, but written again. *) |
| 8 | 8 | module CAbi; |
| 9 | +import SYSTEM; | |
| 9 | 10 | |
| 10 | 11 | const |
| 11 | 12 | (* open's flags, fcntl's requests, seek, flock, mmap, access *) |
| @@ -27,7 +27,7 @@ | ||
| 27 | 27 | checks: INT; (* checks made *) |
| 28 | 28 | failures: INT; (* of them, failed *) |
| 29 | 29 | 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 *) | |
| 31 | 31 | muted: BOOL; (* checks say nothing and aren't counted, as Prop searches *) |
| 32 | 32 | mutedFails: INT; (* checks failed since mute was turned on *) |
| 33 | 33 | |
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | |
| 49 | 49 | (* Writes s to standard error, trying again after a short or interrupted |
| 50 | 50 | write; nothing while muted. *) |
| 51 | -proc put(s: []U8); | |
| 51 | +proc put(s: []const U8); | |
| 52 | 52 | var n: INT; |
| 53 | 53 | begin |
| 54 | 54 | if muted then return; end; |
| @@ -90,7 +90,7 @@ | ||
| 90 | 90 | (* Writes s between quotes, with the quote, backslash and bytes below |
| 91 | 91 | 32 or 127 as escapes; the bytes from 128 are written as they are, |
| 92 | 92 | so UTF-8 reads. *) |
| 93 | -proc putQuoted(s: []U8); | |
| 93 | +proc putQuoted(s: []const U8); | |
| 94 | 94 | var i, from: INT; c: U8; |
| 95 | 95 | begin |
| 96 | 96 | put("\""); |
| @@ -114,7 +114,7 @@ | ||
| 114 | 114 | |
| 115 | 115 | (* The index of the first byte where a and b differ, or the shorter |
| 116 | 116 | length if one is a prefix of the other. *) |
| 117 | -proc firstDiff(a, b: []U8): INT; | |
| 117 | +proc firstDiff(a, b: []const U8): INT; | |
| 118 | 118 | var i, n: INT; |
| 119 | 119 | begin |
| 120 | 120 | n := LEN(a); |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | (* Counts a failure and begins its report with the FAIL line. Standard |
| 150 | 150 | output is flushed first, so the two come in order. While muted, it |
| 151 | 151 | only counts it among the muted failures. *) |
| 152 | -proc fail(what: []U8); | |
| 152 | +proc fail(what: []const U8); | |
| 153 | 153 | begin |
| 154 | 154 | if muted then INC(mutedFails); return; end; |
| 155 | 155 | INC(failures); |
| @@ -158,7 +158,7 @@ | ||
| 158 | 158 | end; |
| 159 | 159 | |
| 160 | 160 | (* Fails, saying what, when cond is false. *) |
| 161 | -proc ok*(cond: BOOL; what: []U8); | |
| 161 | +proc ok*(cond: BOOL; what: []const U8); | |
| 162 | 162 | begin |
| 163 | 163 | count; |
| 164 | 164 | if not cond then fail(what); end; |
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | |
| 167 | 167 | (* Fails, saying what, when got is not want; shows both, escaped, and |
| 168 | 168 | where they first differ. *) |
| 169 | -proc str*(what, got, want: []U8); | |
| 169 | +proc str*(what, got, want: []const U8); | |
| 170 | 170 | var at: INT; |
| 171 | 171 | begin |
| 172 | 172 | count; |
| @@ -179,7 +179,7 @@ | ||
| 179 | 179 | end; |
| 180 | 180 | |
| 181 | 181 | (* 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); | |
| 183 | 183 | begin |
| 184 | 184 | count; |
| 185 | 185 | if got = want then return; end; |
| @@ -193,14 +193,14 @@ | ||
| 193 | 193 | capN: INT; (* bytes in cap *) |
| 194 | 194 | |
| 195 | 195 | (* The test's sink: appends s to cap. *) |
| 196 | -proc capture(s: []U8); | |
| 196 | +proc capture(s: []const U8); | |
| 197 | 197 | var i: INT; |
| 198 | 198 | begin |
| 199 | 199 | for i := 0 to LEN(s) - 1 do cap[capN] := s[i]; INC(capN); end; |
| 200 | 200 | end; |
| 201 | 201 | |
| 202 | 202 | (* 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); | |
| 204 | 204 | begin |
| 205 | 205 | capN := 0; |
| 206 | 206 | f; |
| @@ -5,14 +5,15 @@ | ||
| 5 | 5 | (a program makes its own with Sys.openDir). *) |
| 6 | 6 | module Files; |
| 7 | 7 | import Sys, Buf, Heap, Rt; |
| 8 | +import SYSTEM; | |
| 8 | 9 | |
| 9 | 10 | (* Argument i, a C string, as a slice; empty if there is no argument i, |
| 10 | 11 | as for i below 0 or from ARGC() on. *) |
| 11 | -proc arg*(i: INT): []U8; | |
| 12 | +proc arg*(i: INT): []const U8; | |
| 12 | 13 | var s: ^U8; n: INT; |
| 13 | 14 | begin |
| 14 | 15 | if (i < 0) or (i >= ARGC()) then return ""; end; |
| 15 | - s := ARGV()[i]; | |
| 16 | + s := SYSTEM.ARGV()[i]; | |
| 16 | 17 | n := 0; |
| 17 | 18 | while s[n] # 0 do INC(n); end; |
| 18 | 19 | return s[0..n]; |
| @@ -22,7 +23,7 @@ | ||
| 22 | 23 | the read that failed, as Sys gives them: -2 (ENOENT) for no such |
| 23 | 24 | file, -13 (EACCES) for one not allowed, -21 (EISDIR) for a |
| 24 | 25 | 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; | |
| 26 | 27 | var fd, n: INT; |
| 27 | 28 | begin |
| 28 | 29 | fd := Sys.openRead(path); |
| @@ -36,14 +37,14 @@ | ||
| 36 | 37 | end; |
| 37 | 38 | |
| 38 | 39 | (* 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; | |
| 40 | 41 | begin |
| 41 | 42 | return load(path, b) = 0; |
| 42 | 43 | end; |
| 43 | 44 | |
| 44 | 45 | (* Writes all of s to fd, again after a short write (a pipe, a socket) |
| 45 | 46 | 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; | |
| 47 | 48 | var n, at: INT; |
| 48 | 49 | begin |
| 49 | 50 | at := 0; |
| @@ -58,7 +59,7 @@ | ||
| 58 | 59 | |
| 59 | 60 | (* Makes the file at path hold data; false if it can't be written, or |
| 60 | 61 | the close, where a late write error shows, fails. *) |
| 61 | -proc write*(path, data: []U8): BOOL; | |
| 62 | +proc write*(path, data: []const U8): BOOL; | |
| 62 | 63 | var fd, r: INT; |
| 63 | 64 | begin |
| 64 | 65 | fd := Sys.create(path); |
| @@ -100,7 +101,7 @@ | ||
| 100 | 101 | rest, from at. A relative target is read from the link's directory, |
| 101 | 102 | which res keeps; an absolute one starts again from the root. *) |
| 102 | 103 | 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; | |
| 104 | 105 | begin |
| 105 | 106 | INC(links); |
| 106 | 107 | if links > MaxLinks then return -40; end; (* ELOOP *) |
| @@ -121,7 +122,7 @@ | ||
| 121 | 122 | (* Adds one name of a path to res: nothing for ".", the parent for |
| 122 | 123 | "..", the name itself for a file or directory, and for a link what |
| 123 | 124 | 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; | |
| 125 | 126 | var info: Sys.Info; mark, r: INT; |
| 126 | 127 | begin |
| 127 | 128 | if (name = ".") or (name = "..") then |
| @@ -147,8 +148,8 @@ | ||
| 147 | 148 | or symbolic link in it: 0, or minus an errno, -2 (ENOENT) if a part |
| 148 | 149 | of it isn't there, -40 (ELOOP) after 40 links. The working |
| 149 | 150 | 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; | |
| 152 | 153 | begin |
| 153 | 154 | if LEN(path) = 0 then return Sys.errNoEntry; end; |
| 154 | 155 | Buf.init(res, Heap.heap); |
| @@ -174,12 +175,12 @@ | ||
| 174 | 175 | return r; |
| 175 | 176 | end; |
| 176 | 177 | |
| 177 | -proc removeTree*(path: []U8): INT; forward; | |
| 178 | +proc removeTree*(path: []const U8): INT; forward; | |
| 178 | 179 | |
| 179 | 180 | (* Removes what is in the directory at path: 0, or minus the first |
| 180 | 181 | 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; | |
| 183 | 184 | begin |
| 184 | 185 | r := Sys.openDir(d, path); |
| 185 | 186 | if r < 0 then return r; end; |
| @@ -204,7 +205,7 @@ | ||
| 204 | 205 | (* Removes the file at path and, if it is a directory, all within it, |
| 205 | 206 | without following a symbolic link (the link goes, not what it |
| 206 | 207 | names): 0, or minus the first errno. *) |
| 207 | -proc removeTree*(path: []U8): INT; | |
| 208 | +proc removeTree*(path: []const U8): INT; | |
| 208 | 209 | var info: Sys.Info; r: INT; |
| 209 | 210 | begin |
| 210 | 211 | info, r := Sys.linkInfo(path); |
| @@ -216,7 +217,7 @@ | ||
| 216 | 217 | end; |
| 217 | 218 | |
| 218 | 219 | (* 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; | |
| 220 | 221 | begin |
| 221 | 222 | Buf.cut(b, 0); |
| 222 | 223 | Buf.str(b, base); |
| @@ -226,7 +227,7 @@ | ||
| 226 | 227 | |
| 227 | 228 | (* Stops the test, saying what, unless realPath of path gives err and |
| 228 | 229 | 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); | |
| 230 | 231 | var b: Buf.Buf; r: INT; |
| 231 | 232 | begin |
| 232 | 233 | Buf.init(b, Heap.heap); |
| @@ -265,7 +266,7 @@ | ||
| 265 | 266 | out of it. *) |
| 266 | 267 | proc testTree; |
| 267 | 268 | 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; | |
| 269 | 270 | begin |
| 270 | 271 | Buf.init(p, Heap.heap); |
| 271 | 272 | Buf.init(q, Heap.heap); |
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | Left out: precision, other fills, argument numbers and names. *) |
| 10 | 10 | module Fmt; |
| 11 | 11 | import Out, Buf, Arena, Rt, Sys; |
| 12 | +import SYSTEM; | |
| 12 | 13 | |
| 13 | 14 | const |
| 14 | 15 | Limb = 1000000000; (* a Big's base, 10^9 *) |
| @@ -33,7 +34,7 @@ | ||
| 33 | 34 | uint(u: U64); (* in decimal *) |
| 34 | 35 | hex(h: U64); (* in hexadecimal, capitals, no 0x *) |
| 35 | 36 | lowHex(h: U64); (* in hexadecimal, lower case, no 0x *) |
| 36 | - str(s: []U8); | |
| 37 | + str(s: []const U8); | |
| 37 | 38 | char(c: U8); (* the one byte *) |
| 38 | 39 | bool(b: BOOL); (* true or false *) |
| 39 | 40 | real(r: F64; places: INT); |
| @@ -102,7 +103,7 @@ | ||
| 102 | 103 | end; |
| 103 | 104 | |
| 104 | 105 | (* s to k. *) |
| 105 | -proc put(var k: Sink; s: []U8); | |
| 106 | +proc put(var k: Sink; s: []const U8); | |
| 106 | 107 | var at, room: INT; |
| 107 | 108 | begin |
| 108 | 109 | at := k.n; |
| @@ -188,7 +189,7 @@ | ||
| 188 | 189 | proc bits(x: F64): U64; |
| 189 | 190 | var p: ^U64; |
| 190 | 191 | begin |
| 191 | - p := ^U64(ADR(x)); | |
| 192 | + p := ^U64(SYSTEM.ADR(x)); | |
| 192 | 193 | return p^; |
| 193 | 194 | end; |
| 194 | 195 | |
| @@ -254,7 +255,7 @@ | ||
| 254 | 255 | |
| 255 | 256 | (* -1, 0 or 1 as 0.d times 10^e, d's first digit not 0, is below, at or |
| 256 | 257 | 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; | |
| 258 | 259 | var i, n: INT; a, c: U8; |
| 259 | 260 | begin |
| 260 | 261 | if e # w.e then |
| @@ -306,7 +307,7 @@ | ||
| 306 | 307 | (* Whether x, cut where rest begins, is nearer the number one more in |
| 307 | 308 | the last place than to the cut one: rest is above a half, or a half |
| 308 | 309 | 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; | |
| 310 | 311 | var i: INT; |
| 311 | 312 | begin |
| 312 | 313 | if rest[0] # '5' then return rest[0] > '5'; end; |
| @@ -357,7 +358,7 @@ | ||
| 357 | 358 | end; |
| 358 | 359 | |
| 359 | 360 | (* 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); | |
| 361 | 362 | begin |
| 362 | 363 | COPY(out[n..n + LEN(s)], s); |
| 363 | 364 | INC(n, LEN(s)); |
| @@ -465,7 +466,7 @@ | ||
| 465 | 466 | |
| 466 | 467 | (* If f[i], a {, starts a width, {2}, {02} or {-10}: it is read into s |
| 467 | 468 | 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; | |
| 469 | 470 | var count: INT; |
| 470 | 471 | begin |
| 471 | 472 | s.width := 0; s.zero := false; s.left := false; |
| @@ -481,7 +482,7 @@ | ||
| 481 | 482 | end; |
| 482 | 483 | |
| 483 | 484 | (* 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); | |
| 485 | 486 | var i, start, n, close: INT; s: Spec; |
| 486 | 487 | begin |
| 487 | 488 | i := 0; start := 0; n := 0; |
| @@ -510,7 +511,7 @@ | ||
| 510 | 511 | end; |
| 511 | 512 | |
| 512 | 513 | (* 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); | |
| 514 | 515 | var k: Sink; |
| 515 | 516 | begin |
| 516 | 517 | k := sink(nil); |
| @@ -524,13 +525,13 @@ | ||
| 524 | 525 | program that doesn't call eprint carries no heap for it; its pages |
| 525 | 526 | are mapped as they are written, and a text of more than a megabyte |
| 526 | 527 | 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); | |
| 528 | 529 | var ar: Arena.Arena; b: Buf.Buf; k: Sink; s: []U8; n: INT; |
| 529 | 530 | begin |
| 530 | 531 | Out.flush; |
| 531 | 532 | 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)); | |
| 534 | 535 | format(k, f, args); |
| 535 | 536 | s := Buf.bytes(b); |
| 536 | 537 | while LEN(s) > 0 do |
| @@ -543,17 +544,17 @@ | ||
| 543 | 544 | end; |
| 544 | 545 | |
| 545 | 546 | (* 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); | |
| 547 | 548 | var k: Sink; |
| 548 | 549 | 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 *) | |
| 550 | 551 | format(k, f, args); |
| 551 | 552 | end; |
| 552 | 553 | |
| 553 | 554 | (* Formats f into out as write formats it: the bytes written, and false |
| 554 | 555 | if out was too short and the text is cut there. It needs no memory |
| 555 | 556 | 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); | |
| 557 | 558 | var k: Sink; |
| 558 | 559 | begin |
| 559 | 560 | k := sink(nil); |
| @@ -564,7 +565,7 @@ | ||
| 564 | 565 | end; |
| 565 | 566 | |
| 566 | 567 | (* 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); | |
| 568 | 569 | var d: [ShortMost]U8; i: INT; |
| 569 | 570 | begin |
| 570 | 571 | for i := 0 to LEN(xs) - 1 do |
| @@ -578,7 +579,7 @@ | ||
| 578 | 579 | var ar: Arena.Arena; b: Buf.Buf; zero: F64; small: [8]U8; d: [ShortMost]U8; n: INT; whole: BOOL; |
| 579 | 580 | begin |
| 580 | 581 | 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)); | |
| 582 | 583 | write(b, "{} {} {} {}|{}{}{} {{}}", [int(-42), uint(0FFFFFFFFFFFFFFFFH), hex(48879), |
| 583 | 584 | str("s"), char('c'), bool(true), int(0)]); |
| 584 | 585 | if Buf.bytes(b) # "-42 18446744073709551615 BEEF s|ctrue0 {}" then Rt.stop("Fmt.write"); end; |
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | the block has left the quarantine. *) |
| 28 | 28 | module Heap; |
| 29 | 29 | import Mem, Lock, Rt, Sys; |
| 30 | +import SYSTEM; | |
| 30 | 31 | |
| 31 | 32 | const |
| 32 | 33 | Classes = 9; |
| @@ -134,7 +135,7 @@ | ||
| 134 | 135 | |
| 135 | 136 | (* Stops the program, saying what was found of the debug block with |
| 136 | 137 | 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); | |
| 138 | 139 | var d: [20]U8; i, n: INT; |
| 139 | 140 | begin |
| 140 | 141 | _ := Sys.write(Sys.stderr, "Heap: "); |
| @@ -164,7 +165,7 @@ | ||
| 164 | 165 | |
| 165 | 166 | (* found, with the heap's lock held, which is let go first, so that |
| 166 | 167 | 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); | |
| 168 | 169 | begin |
| 169 | 170 | Lock.give(lock); |
| 170 | 171 | found(what, h); |
| @@ -279,7 +280,7 @@ | ||
| 279 | 280 | proc allocSure(_a: ^Mem.Allocator; size, align: INT): ^U8; |
| 280 | 281 | var p: ^U8; |
| 281 | 282 | begin |
| 282 | - p := std.alloc(ADR(std), size, align); | |
| 283 | + p := std.alloc(SYSTEM.ADR(std), size, align); | |
| 283 | 284 | if p = nil then |
| 284 | 285 | _ := Sys.write(Sys.stderr, "Heap: out of memory\n"); |
| 285 | 286 | Rt.trace; |
| @@ -357,8 +358,8 @@ | ||
| 357 | 358 | |
| 358 | 359 | begin |
| 359 | 360 | std := {alloc: alloc, free: free}; |
| 360 | - heap := ADR(std); | |
| 361 | + heap := SYSTEM.ADR(std); | |
| 361 | 362 | surer := {alloc: allocSure, free: free}; |
| 362 | - sure := ADR(surer); | |
| 363 | + sure := SYSTEM.ADR(surer); | |
| 363 | 364 | if Sys.env("RAZ_HEAP") = "debug" then debug(true); end; |
| 364 | 365 | end Heap. |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* A singly linked list of T, its nodes from an allocator. *) |
| 2 | 2 | module List(T); |
| 3 | 3 | import Mem; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | type |
| 6 | 7 | Node* = record |
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | var tries: INT; |
| 14 | 14 | begin |
| 15 | 15 | tries := 0; |
| 16 | - while not CAS(ADR(l.held), 0, 1) do | |
| 16 | + while not CAS(l.held, 0, 1) do | |
| 17 | 17 | INC(tries); |
| 18 | 18 | if tries = 64 then Sys.yield; tries := 0; end; |
| 19 | 19 | end; |
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | (* Gives up l, which the caller holds. *) |
| 23 | 23 | proc give*(var l: Lock); |
| 24 | 24 | begin |
| 25 | - _ := XCHG(ADR(l.held), 0); | |
| 25 | + _ := XCHG(l.held, 0); | |
| 26 | 26 | end; |
| 27 | 27 | |
| 28 | 28 | (* The module's test, in one thread: taken, given, taken again. *) |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | (* A hash map from K to V, by open addressing; it hashes and compares |
| 2 | 2 | keys with the procedures it is given: |
| 3 | - import Count := Map([]U8, INT, Str.hash, Str.eq); *) | |
| 3 | + import Count := Map([]const U8, INT, Str.hash, Str.eq); *) | |
| 4 | 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL); |
| 5 | 5 | import Mem; |
| 6 | +import SYSTEM; | |
| 6 | 7 | |
| 7 | 8 | type |
| 8 | 9 | Entry = record |
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | Left out: sinh, cosh, fmod and hypot, until a program needs them. *) |
| 9 | 9 | module Math; |
| 10 | 10 | import Check, Rt; |
| 11 | +import SYSTEM; | |
| 11 | 12 | |
| 12 | 13 | const |
| 13 | 14 | pi* = 3.141592653589793; (* the F64 nearest to pi *) |
| @@ -461,7 +462,7 @@ | ||
| 461 | 462 | end divMod; |
| 462 | 463 | |
| 463 | 464 | (* 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; | |
| 465 | 466 | var q, r: INT; |
| 466 | 467 | begin |
| 467 | 468 | q := s div 64; |
| @@ -905,7 +906,7 @@ | ||
| 905 | 906 | end; |
| 906 | 907 | |
| 907 | 908 | (* Whether s[i] is a decimal digit. *) |
| 908 | -proc digitAt(s: []U8; i: INT): BOOL; | |
| 909 | +proc digitAt(s: []const U8; i: INT): BOOL; | |
| 909 | 910 | begin |
| 910 | 911 | return (i < LEN(s)) and (s[i] >= '0') and (s[i] <= '9'); |
| 911 | 912 | end; |
| @@ -914,7 +915,7 @@ | ||
| 914 | 915 | or e, a sign if any and digits if any; nothing else. The F64 nearest |
| 915 | 916 | it, ties to the even one, and false if s isn't one, or is past the |
| 916 | 917 | largest F64; one below the smallest is 0. *) |
| 917 | -proc toReal*(s: []U8): (F64, BOOL); | |
| 918 | +proc toReal*(s: []const U8): (F64, BOOL); | |
| 918 | 919 | var |
| 919 | 920 | num, den, d: Big; i, digits, e, ex: INT; neg, eneg, point, half, sticky: BOOL; |
| 920 | 921 | q, b: U64; x: F64; |
| @@ -1011,7 +1012,7 @@ | ||
| 1011 | 1012 | end; |
| 1012 | 1013 | |
| 1013 | 1014 | (* 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; | |
| 1015 | 1016 | var x: F64; o: BOOL; |
| 1016 | 1017 | begin |
| 1017 | 1018 | x, o := toReal(s); |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | from the system. NEW(p, a) calls a^.alloc. *) |
| 3 | 3 | module Mem; |
| 4 | 4 | import Sys, Rt; |
| 5 | +import SYSTEM; | |
| 5 | 6 | |
| 6 | 7 | type |
| 7 | 8 | Allocator* = record |
| @@ -13,21 +13,21 @@ | ||
| 13 | 13 | |
| 14 | 14 | type |
| 15 | 15 | 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); | |
| 19 | 19 | end; |
| 20 | 20 | Parser* = record |
| 21 | 21 | letter*: U8; (* the option just read *) |
| 22 | - value*: []U8; (* its value; "" for a flag *) | |
| 22 | + value*: []const U8; (* its value; "" for a flag *) | |
| 23 | 23 | 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 *) | |
| 25 | 25 | (* 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; | |
| 29 | 29 | 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 *) | |
| 31 | 31 | ended: BOOL; (* the scope's options have ended *) |
| 32 | 32 | help: BOOL; (* the option just read is -h or --help *) |
| 33 | 33 | end; |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | |
| 40 | 40 | (* b written whole to fd, then freed. *) |
| 41 | 41 | proc say(fd: INT; var b: Buf.Buf); |
| 42 | -var s: []U8; n: INT; | |
| 42 | +var s: []const U8; n: INT; | |
| 43 | 43 | begin |
| 44 | 44 | s := Buf.bytes(b); |
| 45 | 45 | while LEN(s) > 0 do |
| @@ -90,7 +90,7 @@ | ||
| 90 | 90 | |
| 91 | 91 | (* A mistake on the command line: the sentence f, the scope's synopsis |
| 92 | 92 | 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); | |
| 94 | 94 | var b: Buf.Buf; |
| 95 | 95 | begin |
| 96 | 96 | Buf.init(b, Heap.heap); |
| @@ -102,7 +102,7 @@ | ||
| 102 | 102 | Rt.exit(2); |
| 103 | 103 | end; |
| 104 | 104 | |
| 105 | -proc dashes(const p: Parser): []U8; | |
| 105 | +proc dashes(const p: Parser): []const U8; | |
| 106 | 106 | begin |
| 107 | 107 | if p.long then return "--"; end; |
| 108 | 108 | return "-"; |
| @@ -111,7 +111,7 @@ | ||
| 111 | 111 | (* Whether an option's value may be left out, written [name] in its |
| 112 | 112 | row: given only in the option's own word, --color=when or -cwhen, |
| 113 | 113 | never as the next word, as getopt's :: has it. *) |
| 114 | -proc optional(value: []U8): BOOL; | |
| 114 | +proc optional(value: []const U8): BOOL; | |
| 115 | 115 | begin |
| 116 | 116 | return (LEN(value) > 2) and (value[0] = '[') and (value[LEN(value) - 1] = ']'); |
| 117 | 117 | end; |
| @@ -119,9 +119,9 @@ | ||
| 119 | 119 | (* The left column of a row in the help, as "-b, --bar label", or, for |
| 120 | 120 | a value that may be left out, "-c, --color[=when]", as grep's help |
| 121 | 121 | has it. *) |
| 122 | -proc left(var b: Buf.Buf; r: ^Row); | |
| 122 | +proc left(var b: Buf.Buf; const r: Row); | |
| 123 | 123 | begin |
| 124 | - match r^ of | |
| 124 | + match r of | |
| 125 | 125 | | sub(_s, name, _help): Buf.str(b, name); |
| 126 | 126 | | option(_s, letter, long, value, _help): |
| 127 | 127 | if letter >= '!' then Fmt.write(b, "-{}", [Fmt.char(letter)]); else Buf.str(b, " "); end; |
| @@ -137,7 +137,7 @@ | ||
| 137 | 137 | end; |
| 138 | 138 | end; |
| 139 | 139 | |
| 140 | -proc leftWidth(r: ^Row): INT; | |
| 140 | +proc leftWidth(const r: Row): INT; | |
| 141 | 141 | var b: Buf.Buf; n: INT; |
| 142 | 142 | begin |
| 143 | 143 | Buf.init(b, Heap.heap); |
| @@ -149,13 +149,13 @@ | ||
| 149 | 149 | |
| 150 | 150 | (* A line of the list: the left column, padded to width and three |
| 151 | 151 | 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); | |
| 153 | 153 | var i: INT; |
| 154 | 154 | begin |
| 155 | 155 | Buf.str(b, " "); |
| 156 | 156 | left(b, r); |
| 157 | 157 | for i := leftWidth(r) to width + 2 do Buf.add(b, ' '); end; |
| 158 | - match r^ of | |
| 158 | + match r of | |
| 159 | 159 | | sub(_s, _name, help): Fmt.write(b, "{}\n", [Fmt.str(help)]); |
| 160 | 160 | | option(_s, _l, _long, _v, help): Fmt.write(b, "{}\n", [Fmt.str(help)]); |
| 161 | 161 | | else: |
| @@ -164,7 +164,7 @@ | ||
| 164 | 164 | |
| 165 | 165 | (* The scope's option with the letter c, or with the long name long: |
| 166 | 166 | 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); | |
| 168 | 168 | var i: INT; |
| 169 | 169 | begin |
| 170 | 170 | for i := 0 to LEN(p.table) - 1 do |
| @@ -182,7 +182,7 @@ | ||
| 182 | 182 | (* Whether the scope has an option -h of its own, so that help is |
| 183 | 183 | --help alone there, as it is for grep, whose -h is "no file names". *) |
| 184 | 184 | proc ownsH(const p: Parser): BOOL; |
| 185 | -var r: INT; _l: U8; _v: []U8; | |
| 185 | +var r: INT; _l: U8; _v: []const U8; | |
| 186 | 186 | begin |
| 187 | 187 | r, _l, _v := find(p, 'h', ""); |
| 188 | 188 | return r >= 0; |
| @@ -193,7 +193,7 @@ | ||
| 193 | 193 | help's own row is made as the table's are, with no letter if the |
| 194 | 194 | scope has -h. *) |
| 195 | 195 | 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; | |
| 197 | 197 | begin |
| 198 | 198 | h := 'h'; |
| 199 | 199 | if ownsH(p) then h := 0; end; |
| @@ -201,26 +201,23 @@ | ||
| 201 | 201 | Buf.init(b, Heap.heap); |
| 202 | 202 | usageOf(p, b); |
| 203 | 203 | Buf.add(b, 10); |
| 204 | - width := leftWidth(ADR(own)); | |
| 204 | + width := leftWidth(own); | |
| 205 | 205 | 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; | |
| 208 | 207 | end; |
| 209 | 208 | 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; | |
| 213 | 211 | | else: |
| 214 | 212 | end; |
| 215 | 213 | end; |
| 216 | 214 | 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; | |
| 220 | 217 | | else: |
| 221 | 218 | end; |
| 222 | 219 | end; |
| 223 | - item(b, ADR(own), width); | |
| 220 | + item(b, own, width); | |
| 224 | 221 | say(Sys.stdout, b); |
| 225 | 222 | Rt.exit(0); |
| 226 | 223 | end; |
| @@ -244,7 +241,7 @@ | ||
| 244 | 241 | readEnd at the end of the options. A mistake is refused, or, if |
| 245 | 242 | quiet, passed over, as readSkip. *) |
| 246 | 243 | 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; | |
| 248 | 245 | begin |
| 249 | 246 | p.help := false; |
| 250 | 247 | p.value := ""; |
| @@ -331,7 +328,7 @@ | ||
| 331 | 328 | end; |
| 332 | 329 | |
| 333 | 330 | (* 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); | |
| 335 | 332 | var b: Buf.Buf; |
| 336 | 333 | begin |
| 337 | 334 | Buf.init(b, Heap.heap); |
| @@ -373,7 +370,7 @@ | ||
| 373 | 370 | |
| 374 | 371 | (* p reads the arguments from 1 on, by table, in the program's own |
| 375 | 372 | 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); | |
| 377 | 374 | begin |
| 378 | 375 | p := {name: name, table: table, at: 1}; |
| 379 | 376 | check(p); |
| @@ -391,7 +388,7 @@ | ||
| 391 | 388 | |
| 392 | 389 | (* The next operand, after what options are left; false when there are |
| 393 | 390 | no more. *) |
| 394 | -proc operand*(var p: Parser): ([]U8, BOOL); | |
| 391 | +proc operand*(var p: Parser): ([]const U8, BOOL); | |
| 395 | 392 | begin |
| 396 | 393 | while next(p) do end; |
| 397 | 394 | if p.at >= ARGC() then return "", false; end; |
| @@ -410,7 +407,7 @@ | ||
| 410 | 407 | |
| 411 | 408 | (* The options of the subcommand name, from the word after its own, |
| 412 | 409 | which operand has given. *) |
| 413 | -proc scope*(var p: Parser; name: []U8); | |
| 410 | +proc scope*(var p: Parser; name: []const U8); | |
| 414 | 411 | begin |
| 415 | 412 | p.scope := name; |
| 416 | 413 | p.ended := false; |
| @@ -439,7 +436,7 @@ | ||
| 439 | 436 | (* The value of the option just read refused, as number refuses one: |
| 440 | 437 | "-b wants wants, not 'value'", the option as it was written, with |
| 441 | 438 | 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); | |
| 443 | 440 | begin |
| 444 | 441 | mistake(p, "{}{} wants {}, not '{}'", |
| 445 | 442 | [Fmt.str(dashes(p)), Fmt.str(p.spelt), Fmt.str(wants), Fmt.str(p.value)]); |
| @@ -447,7 +444,7 @@ | ||
| 447 | 444 | |
| 448 | 445 | (* The program's own mistake, written as Opt's are but alone, and |
| 449 | 446 | status 2. *) |
| 450 | -proc fail*(const p: Parser; text: []U8); | |
| 447 | +proc fail*(const p: Parser; text: []const U8); | |
| 451 | 448 | var b: Buf.Buf; |
| 452 | 449 | begin |
| 453 | 450 | Buf.init(b, Heap.heap); |
| @@ -458,7 +455,7 @@ | ||
| 458 | 455 | |
| 459 | 456 | (* The program's own mistake, written as Opt's are, with the scope's |
| 460 | 457 | synopsis lines after it, and status 2. *) |
| 461 | -proc misuse*(const p: Parser; text: []U8); | |
| 458 | +proc misuse*(const p: Parser; text: []const U8); | |
| 462 | 459 | begin |
| 463 | 460 | mistake(p, "{}", [Fmt.str(text)]); |
| 464 | 461 | end; |
| @@ -478,7 +475,7 @@ | ||
| 478 | 475 | option("", jobs, "jobs", "n", "keep n jobs at most"), |
| 479 | 476 | usage("start", "keep start [-b label] name command [argument ...]"), |
| 480 | 477 | 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; | |
| 482 | 479 | begin |
| 483 | 480 | secs := 10; |
| 484 | 481 | init(p, "keep", Rows); |
| @@ -516,7 +513,7 @@ | ||
| 516 | 513 | |
| 517 | 514 | (* A scope with no digit option, and one with -5. *) |
| 518 | 515 | proc digits; |
| 519 | -var p: Parser; w: []U8; ok: BOOL; n: INT; | |
| 516 | +var p: Parser; w: []const U8; ok: BOOL; n: INT; | |
| 520 | 517 | begin |
| 521 | 518 | init(p, "digits", [ |
| 522 | 519 | usage("", "digits [-v] x y"), |
| @@ -550,7 +547,7 @@ | ||
| 550 | 547 | (* Subcommands of subcommands, no synopsis lines, and a -h of the |
| 551 | 548 | program's own. *) |
| 552 | 549 | proc plain; |
| 553 | -var p: Parser; _w: []U8; _ok: BOOL; | |
| 550 | +var p: Parser; _w: []const U8; _ok: BOOL; | |
| 554 | 551 | begin |
| 555 | 552 | init(p, "plain", [ |
| 556 | 553 | sub("", "remote", "the remotes"), |
| @@ -566,9 +563,9 @@ | ||
| 566 | 563 | end; |
| 567 | 564 | |
| 568 | 565 | 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; | |
| 572 | 569 | status: INT; |
| 573 | 570 | end; |
| 574 | 571 | |
| @@ -611,7 +608,7 @@ | ||
| 611 | 608 | 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"; |
| 612 | 609 | 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"; |
| 613 | 610 | k = "OPTTEST=keep"; |
| 614 | -var cases: []Case; i: INT; mode: []U8; | |
| 611 | +var cases: []Case; i: INT; mode: []const U8; | |
| 615 | 612 | begin |
| 616 | 613 | mode := Sys.env("OPTTEST"); |
| 617 | 614 | if mode = "keep" then keep; return; |
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | end; |
| 51 | 51 | |
| 52 | 52 | (* Writes the bytes of s. *) |
| 53 | -proc str*(s: []U8); | |
| 53 | +proc str*(s: []const U8); | |
| 54 | 54 | var i: INT; |
| 55 | 55 | begin |
| 56 | 56 | Lock.take(lock); |
| @@ -54,7 +54,7 @@ | ||
| 54 | 54 | cand: Buf.Buf; (* a case to try: a shrink of best, or a saved one *) |
| 55 | 55 | runs: INT; (* runs the shrink under way has made *) |
| 56 | 56 | 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 *) | |
| 58 | 58 | dir: Buf.Buf; (* where its cases are saved *) |
| 59 | 59 | path: Buf.Buf; (* the file of a saved case *) |
| 60 | 60 | seed: U64; (* the seed of the fresh cases *) |
| @@ -132,7 +132,7 @@ | ||
| 132 | 132 | end; |
| 133 | 133 | |
| 134 | 134 | (* 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); | |
| 136 | 136 | begin |
| 137 | 137 | Buf.reset(s.data); |
| 138 | 138 | Buf.str(s.data, data); |
| @@ -152,7 +152,7 @@ | ||
| 152 | 152 | |
| 153 | 153 | (* Runs p on data once more, with Check heard, so that it shows the |
| 154 | 154 | failure and counts it. *) |
| 155 | -proc aloud(p: Property; data: []U8); | |
| 155 | +proc aloud(p: Property; data: []const U8); | |
| 156 | 156 | begin |
| 157 | 157 | Check.mute(false); |
| 158 | 158 | replay(src, data); |
| @@ -161,7 +161,7 @@ | ||
| 161 | 161 | |
| 162 | 162 | (* Whether case a is simpler than b: shorter, or as long and smaller |
| 163 | 163 | byte by byte. *) |
| 164 | -proc simpler(a, b: []U8): BOOL; | |
| 164 | +proc simpler(a, b: []const U8): BOOL; | |
| 165 | 165 | begin |
| 166 | 166 | return (LEN(a) < LEN(b)) or ((LEN(a) = LEN(b)) and (Str.cmp(a, b) < 0)); |
| 167 | 167 | end; |
| @@ -169,7 +169,7 @@ | ||
| 169 | 169 | (* Runs p on cand, within the budget; if it fails and the bytes it drew |
| 170 | 170 | are simpler than best, they become best, and the result is true. *) |
| 171 | 171 | proc improves(p: Property): BOOL; |
| 172 | -var drawn: []U8; | |
| 172 | +var drawn: []const U8; | |
| 173 | 173 | begin |
| 174 | 174 | if runs >= Budget then return false; end; |
| 175 | 175 | INC(runs); |
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | |
| 191 | 191 | (* Makes cand best without its w bytes from i. *) |
| 192 | 192 | proc without(i, w: INT); |
| 193 | -var b: []U8; | |
| 193 | +var b: []const U8; | |
| 194 | 194 | begin |
| 195 | 195 | b := Buf.bytes(best); |
| 196 | 196 | Buf.reset(cand); |
| @@ -290,7 +290,7 @@ | ||
| 290 | 290 | |
| 291 | 291 | (* Stops the program: the environment variable called key is not a |
| 292 | 292 | number, as it must be. *) |
| 293 | -proc badEnv(key: []U8); | |
| 293 | +proc badEnv(key: []const U8); | |
| 294 | 294 | begin |
| 295 | 295 | Fmt.eprint("Prop: ${} is not a whole number\n", [Fmt.str(key)]); |
| 296 | 296 | Rt.exit(2); |
| @@ -298,7 +298,7 @@ | ||
| 298 | 298 | |
| 299 | 299 | (* The environment variable called key, a number from 0; otherwise |
| 300 | 300 | unset, and 0. *) |
| 301 | -proc envNumber(key: []U8): I64; | |
| 301 | +proc envNumber(key: []const U8): I64; | |
| 302 | 302 | var n: I64; ok: BOOL; |
| 303 | 303 | begin |
| 304 | 304 | if LEN(Sys.env(key)) = 0 then return 0; end; |
| @@ -355,7 +355,7 @@ | ||
| 355 | 355 | end; |
| 356 | 356 | |
| 357 | 357 | (* Makes path the file called file in dir. *) |
| 358 | -proc caseFile(file: []U8); | |
| 358 | +proc caseFile(file: []const U8); | |
| 359 | 359 | begin |
| 360 | 360 | Buf.reset(path); |
| 361 | 361 | Buf.str(path, Buf.bytes(dir)); |
| @@ -366,8 +366,8 @@ | ||
| 366 | 366 | (* Saves data in dir, made with the directories it needs, in a file |
| 367 | 367 | named by the hash of data, so that a case is saved once; whether it |
| 368 | 368 | 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; | |
| 371 | 371 | begin |
| 372 | 372 | d := Buf.bytes(dir); |
| 373 | 373 | for i := 1 to LEN(d) - 1 do |
| @@ -380,7 +380,7 @@ | ||
| 380 | 380 | end; |
| 381 | 381 | |
| 382 | 382 | (* 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; | |
| 384 | 384 | begin |
| 385 | 385 | if ok then return "saved"; end; |
| 386 | 386 | return "could not save"; |
| @@ -389,7 +389,7 @@ | ||
| 389 | 389 | (* Runs each case saved in dir; if one fails, it is in cand, its file |
| 390 | 390 | in path, and the result is true. *) |
| 391 | 391 | proc savedFailing(p: Property): BOOL; |
| 392 | -var d: Sys.Dir; file: []U8; more: BOOL; | |
| 392 | +var d: Sys.Dir; file: []const U8; more: BOOL; | |
| 393 | 393 | begin |
| 394 | 394 | if Sys.openDir(d, Buf.bytes(dir)) < 0 then return false; end; (* none saved yet *) |
| 395 | 395 | file, more := Sys.nextEntry(d); |
| @@ -420,8 +420,8 @@ | ||
| 420 | 420 | |
| 421 | 421 | (* Makes the buffers and registers crashed, the first time; then sets |
| 422 | 422 | 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; | |
| 425 | 425 | begin |
| 426 | 426 | if not ready then |
| 427 | 427 | Buf.init(src.data, Heap.heap); |
| @@ -443,7 +443,7 @@ | ||
| 443 | 443 | |
| 444 | 444 | (* Checks the property p, called name: the saved cases, then fresh |
| 445 | 445 | 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); | |
| 447 | 447 | var ok: BOOL; |
| 448 | 448 | begin |
| 449 | 449 | prepare(name); |
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | handlers and no profiler. *) |
| 23 | 23 | module Rt; |
| 24 | 24 | import Sys; |
| 25 | +import SYSTEM; | |
| 25 | 26 | |
| 26 | 27 | const |
| 27 | 28 | Full*: ERROR = "too many procedures to run at exit"; (* atExit's *) |
| @@ -144,7 +145,7 @@ | ||
| 144 | 145 | |
| 145 | 146 | (* Stops the program: says msg, and then a line feed, on standard |
| 146 | 147 | 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); | |
| 148 | 149 | begin |
| 149 | 150 | _ := Sys.write(Sys.stderr, msg); |
| 150 | 151 | _ := Sys.write(Sys.stderr, "\n"); |
| @@ -153,7 +154,7 @@ | ||
| 153 | 154 | |
| 154 | 155 | (* Messages, made in line, one byte kept for the line feed, and |
| 155 | 156 | written by say in one piece *) |
| 156 | -proc put(s: []U8); | |
| 157 | +proc put(s: []const U8); | |
| 157 | 158 | var i: INT; |
| 158 | 159 | begin |
| 159 | 160 | for i := 0 to LEN(s) - 1 do |
| @@ -408,7 +409,7 @@ | ||
| 408 | 409 | var a: ^U8; w: ^UINT; h: ^U16; s: ^U32; f: ^F32; d: ^F64; v: UINT; bits: INT; |
| 409 | 410 | begin |
| 410 | 411 | 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; | |
| 412 | 413 | w := ^UINT(a); |
| 413 | 414 | if l^.kind & 256 # 0 then a := ^U8(w^); w := ^UINT(a); end; |
| 414 | 415 | h := ^U16(a); s := ^U32(a); f := ^F32(a); d := ^F64(a); |
| @@ -486,7 +487,7 @@ | ||
| 486 | 487 | begin |
| 487 | 488 | (* the registers as they are, then as each frame from this one out |
| 488 | 489 | to bp's found them *) |
| 489 | - liveRegs(ADR(regs[0])); | |
| 490 | + liveRegs(SYSTEM.ADR(regs[0])); | |
| 490 | 491 | x := framePtr(); |
| 491 | 492 | xip := here(); |
| 492 | 493 | while (x # bp) and (x & 7 = 0) and (x # 0) do |
| @@ -613,7 +614,7 @@ | ||
| 613 | 614 | error, then ends the program by exit with status 2, as a failed |
| 614 | 615 | check does. info and ctx are the kernel's siginfo and ucontext. *) |
| 615 | 616 | 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; | |
| 617 | 618 | begin |
| 618 | 619 | q := ^UINT(ctx + 104); (* uc_mcontext's rdi, then rsi, then rbp *) |
| 619 | 620 | regs[5] := q[0]; |
| @@ -655,7 +656,7 @@ | ||
| 655 | 656 | proc onProf(_sig: INT; _info, ctx: ^U8); |
| 656 | 657 | var n, k: INT; q, f, row: ^UINT; ip, bp: UINT; |
| 657 | 658 | begin |
| 658 | - n := XADD(ADR(numSamples), 1); | |
| 659 | + n := XADD(numSamples, 1); | |
| 659 | 660 | if n >= MaxSamples then return; end; |
| 660 | 661 | q := ^UINT(ctx + 120); (* uc_mcontext's rbp *) |
| 661 | 662 | bp := q^; |
| @@ -707,7 +708,7 @@ | ||
| 707 | 708 | |
| 708 | 709 | (* Says the ten that took most of count's n samples, by name, with |
| 709 | 710 | 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); | |
| 711 | 712 | var i, k, best: INT; p: ^Proc; r: Row; |
| 712 | 713 | begin |
| 713 | 714 | p := ^Proc(places + 5); |
| @@ -739,9 +740,9 @@ | ||
| 739 | 740 | chains := ^UINT(Sys.mmap(MaxSamples * Depth * SIZE(UINT))); |
| 740 | 741 | if chains = nil then return; end; |
| 741 | 742 | 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); | |
| 743 | 744 | 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) *) | |
| 745 | 746 | _ := atExit(profile); |
| 746 | 747 | end; |
| 747 | 748 | |
| @@ -751,7 +752,7 @@ | ||
| 751 | 752 | var t: [4]INT; i, n, k, j, m, s: INT; seen: [Depth + 1]INT; row: ^UINT; |
| 752 | 753 | begin |
| 753 | 754 | 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 *) | |
| 755 | 756 | n := numSamples; |
| 756 | 757 | if n > MaxSamples then n := MaxSamples; end; |
| 757 | 758 | if (places = nil) or (n = 0) then return; end; |
| @@ -787,10 +788,10 @@ | ||
| 787 | 788 | end; |
| 788 | 789 | |
| 789 | 790 | 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 *) | |
| 792 | 793 | 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); | |
| 795 | 796 | if profiler # nil then profiler(); end; |
| 796 | 797 | end Rt. |
| @@ -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 | |
| 2 | 2 | module orders, searches and hashes them, trims them and takes them |
| 3 | 3 | apart, tells an ASCII character's kind and changes a letter's case, |
| 4 | 4 | joins them and replaces in them, reads and writes their UTF-8, reads |
| @@ -7,17 +7,18 @@ | ||
| 7 | 7 | own. *) |
| 8 | 8 | module Str; |
| 9 | 9 | import Mem, Heap, Rt, Bytes, Buf; |
| 10 | +import SYSTEM; | |
| 10 | 11 | |
| 11 | 12 | const least = -9223372036854775807 - 1; (* the smallest I64 *) |
| 12 | 13 | |
| 13 | 14 | (* s's bytes, copied into memory from a, to keep after s's own are |
| 14 | 15 | 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); | |
| 16 | 17 | var p: ^U8; |
| 17 | 18 | begin |
| 18 | - if LEN(s) = 0 then return "", true; end; | |
| 19 | + if LEN(s) = 0 then return [], true; end; | |
| 19 | 20 | p := Mem.alloc(a, LEN(s), 1); |
| 20 | - if p = nil then return "", false; end; | |
| 21 | + if p = nil then return [], false; end; | |
| 21 | 22 | COPY(p[0..LEN(s)], s); |
| 22 | 23 | return p[0..LEN(s)], true; |
| 23 | 24 | end; |
| @@ -26,11 +27,11 @@ | ||
| 26 | 27 | for an empty string, was never a's, and is left alone. *) |
| 27 | 28 | proc free*(a: ^Mem.Allocator; s: []U8); |
| 28 | 29 | 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; | |
| 30 | 31 | end; |
| 31 | 32 | |
| 32 | 33 | (* -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; | |
| 34 | 35 | var i, n: INT; |
| 35 | 36 | begin |
| 36 | 37 | n := LEN(a); |
| @@ -47,7 +48,7 @@ | ||
| 47 | 48 | end; |
| 48 | 49 | |
| 49 | 50 | (* 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; | |
| 51 | 52 | begin |
| 52 | 53 | return a = b; |
| 53 | 54 | end; |
| @@ -60,7 +61,7 @@ | ||
| 60 | 61 | end; |
| 61 | 62 | |
| 62 | 63 | (* 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; | |
| 64 | 65 | var i: INT; |
| 65 | 66 | begin |
| 66 | 67 | if LEN(a) # LEN(b) then return false; end; |
| @@ -71,7 +72,7 @@ | ||
| 71 | 72 | end; |
| 72 | 73 | |
| 73 | 74 | (* FNV-1a, 64 bits. *) |
| 74 | -proc hash*(s: []U8): U64; | |
| 75 | +proc hash*(s: []const U8): U64; | |
| 75 | 76 | var h: U64; i: INT; |
| 76 | 77 | begin |
| 77 | 78 | h := 0CBF29CE484222325H; |
| @@ -82,14 +83,14 @@ | ||
| 82 | 83 | end; |
| 83 | 84 | |
| 84 | 85 | (* Where sub first starts in s, or -1. *) |
| 85 | -proc find*(s, sub: []U8): INT; | |
| 86 | +proc find*(s, sub: []const U8): INT; | |
| 86 | 87 | begin |
| 87 | 88 | return Bytes.find(s, sub); |
| 88 | 89 | end; |
| 89 | 90 | |
| 90 | 91 | (* Where sub first starts in s at or after from, or -1; from is at |
| 91 | 92 | most LEN(s). *) |
| 92 | -proc findFrom*(s, sub: []U8; from: INT): INT; | |
| 93 | +proc findFrom*(s, sub: []const U8; from: INT): INT; | |
| 93 | 94 | var i: INT; |
| 94 | 95 | begin |
| 95 | 96 | i := Bytes.find(s[from..LEN(s)], sub); |
| @@ -98,7 +99,7 @@ | ||
| 98 | 99 | end; |
| 99 | 100 | |
| 100 | 101 | (* Where sub last starts in s, or -1. *) |
| 101 | -proc findLast*(s, sub: []U8): INT; | |
| 102 | +proc findLast*(s, sub: []const U8): INT; | |
| 102 | 103 | var i: INT; |
| 103 | 104 | begin |
| 104 | 105 | for i := LEN(s) - LEN(sub) to 0 by -1 do |
| @@ -108,13 +109,13 @@ | ||
| 108 | 109 | end; |
| 109 | 110 | |
| 110 | 111 | (* Whether s starts with p. *) |
| 111 | -proc hasPrefix*(s, p: []U8): BOOL; | |
| 112 | +proc hasPrefix*(s, p: []const U8): BOOL; | |
| 112 | 113 | begin |
| 113 | 114 | return (LEN(s) >= LEN(p)) and (s[0..LEN(p)] = p); |
| 114 | 115 | end; |
| 115 | 116 | |
| 116 | 117 | (* Whether s ends with x. *) |
| 117 | -proc hasSuffix*(s, x: []U8): BOOL; | |
| 118 | +proc hasSuffix*(s, x: []const U8): BOOL; | |
| 118 | 119 | begin |
| 119 | 120 | return (LEN(s) >= LEN(x)) and (s[LEN(s) - LEN(x)..LEN(s)] = x); |
| 120 | 121 | end; |
| @@ -157,7 +158,7 @@ | ||
| 157 | 158 | end; |
| 158 | 159 | |
| 159 | 160 | (* s without the spaces at its start. *) |
| 160 | -proc trimLeft*(s: []U8): []U8; | |
| 161 | +proc trimLeft*(s: []const U8): []const U8; | |
| 161 | 162 | var i: INT; |
| 162 | 163 | begin |
| 163 | 164 | i := 0; |
| @@ -166,7 +167,7 @@ | ||
| 166 | 167 | end; |
| 167 | 168 | |
| 168 | 169 | (* s without the spaces at its end. *) |
| 169 | -proc trimRight*(s: []U8): []U8; | |
| 170 | +proc trimRight*(s: []const U8): []const U8; | |
| 170 | 171 | var n: INT; |
| 171 | 172 | begin |
| 172 | 173 | n := LEN(s); |
| @@ -175,14 +176,14 @@ | ||
| 175 | 176 | end; |
| 176 | 177 | |
| 177 | 178 | (* s without the spaces at either end. *) |
| 178 | -proc trim*(s: []U8): []U8; | |
| 179 | +proc trim*(s: []const U8): []const U8; | |
| 179 | 180 | begin |
| 180 | 181 | return trimRight(trimLeft(s)); |
| 181 | 182 | end; |
| 182 | 183 | |
| 183 | 184 | (* What comes before the first sep in s, what comes after it, and true; |
| 184 | 185 | 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); | |
| 186 | 187 | var i: INT; |
| 187 | 188 | begin |
| 188 | 189 | i := find(s, sep); |
| @@ -193,7 +194,7 @@ | ||
| 193 | 194 | (* The first word of s, the bytes after the spaces at its start up to |
| 194 | 195 | the next space or the end, and the rest of s from there; two empty |
| 195 | 196 | strings if s holds only spaces. *) |
| 196 | -proc field*(s: []U8): ([]U8, []U8); | |
| 197 | +proc field*(s: []const U8): ([]const U8, []const U8); | |
| 197 | 198 | var i: INT; |
| 198 | 199 | begin |
| 199 | 200 | s := trimLeft(s); |
| @@ -219,7 +220,7 @@ | ||
| 219 | 220 | end; |
| 220 | 221 | |
| 221 | 222 | (* 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); | |
| 223 | 224 | var i: INT; |
| 224 | 225 | begin |
| 225 | 226 | for i := 0 to LEN(parts) - 1 do |
| @@ -230,7 +231,7 @@ | ||
| 230 | 231 | |
| 231 | 232 | (* s added to b, with new for each old in it, from the left, none |
| 232 | 233 | 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); | |
| 234 | 235 | var i: INT; |
| 235 | 236 | begin |
| 236 | 237 | i := -1; |
| @@ -275,7 +276,7 @@ | ||
| 275 | 276 | if its first byte doesn't start one rightly, being a continuation, |
| 276 | 277 | or followed by too few continuations, or spelling a surrogate or a |
| 277 | 278 | 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); | |
| 279 | 280 | var c, least: I32; n, i: INT; |
| 280 | 281 | begin |
| 281 | 282 | if LEN(s) = 0 then return 0, 0; end; |
| @@ -299,7 +300,7 @@ | ||
| 299 | 300 | (* The character s ends with, and its length in bytes, read as decode |
| 300 | 301 | reads one: FFFDH and 1 if the last byte doesn't end one rightly; 0 |
| 301 | 302 | and 0 if s is empty. *) |
| 302 | -proc decodeLast*(s: []U8): (I32, INT); | |
| 303 | +proc decodeLast*(s: []const U8): (I32, INT); | |
| 303 | 304 | var c: I32; i, n: INT; |
| 304 | 305 | begin |
| 305 | 306 | if LEN(s) = 0 then return 0, 0; end; |
| @@ -313,7 +314,7 @@ | ||
| 313 | 314 | |
| 314 | 315 | (* The character at i in s, as decode reads it, and where the one after |
| 315 | 316 | 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); | |
| 317 | 318 | var c: I32; n: INT; |
| 318 | 319 | begin |
| 319 | 320 | if i >= LEN(s) then return 0, -1; end; |
| @@ -323,7 +324,7 @@ | ||
| 323 | 324 | |
| 324 | 325 | (* The characters in s, as decode reads them, each byte that doesn't |
| 325 | 326 | start one rightly counted as one. *) |
| 326 | -proc chars*(s: []U8): INT; | |
| 327 | +proc chars*(s: []const U8): INT; | |
| 327 | 328 | var i, n: INT; |
| 328 | 329 | begin |
| 329 | 330 | _, i := next(s, 0); |
| @@ -336,7 +337,7 @@ | ||
| 336 | 337 | |
| 337 | 338 | (* Whether s is UTF-8: decode finds no byte that doesn't start a |
| 338 | 339 | character rightly. *) |
| 339 | -proc valid*(s: []U8): BOOL; | |
| 340 | +proc valid*(s: []const U8): BOOL; | |
| 340 | 341 | var c: I32; i, n: INT; |
| 341 | 342 | begin |
| 342 | 343 | while i < LEN(s) do |
| @@ -349,7 +350,7 @@ | ||
| 349 | 350 | |
| 350 | 351 | (* s as a decimal number, with a - or + before it if any, and nothing |
| 351 | 352 | 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); | |
| 353 | 354 | var n, d: I64; i: INT; neg: BOOL; |
| 354 | 355 | begin |
| 355 | 356 | neg := (LEN(s) > 0) and (s[0] = '-'); |
| @@ -372,7 +373,7 @@ | ||
| 372 | 373 | |
| 373 | 374 | (* s in hexadecimal, digits only, capitals or not; false if it isn't |
| 374 | 375 | that, or a U64 can't hold it. *) |
| 375 | -proc toHex*(s: []U8): (U64, BOOL); | |
| 376 | +proc toHex*(s: []const U8): (U64, BOOL); | |
| 376 | 377 | var v: U64; d, i: INT; |
| 377 | 378 | begin |
| 378 | 379 | if LEN(s) = 0 then return 0, false; end; |
| @@ -402,7 +403,7 @@ | ||
| 402 | 403 | does. alphabet holds the 64 digits (Base64 or Base64Url, or one's |
| 403 | 404 | own). A last group of 1 or 2 bytes is padded with = to four if pad, |
| 404 | 405 | 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; | |
| 406 | 407 | var i, k, v, left: INT; |
| 407 | 408 | begin |
| 408 | 409 | k := 0; |
| @@ -436,13 +437,13 @@ | ||
| 436 | 437 | |
| 437 | 438 | (* s in base64 (RFC 4648, section 4), padded, into out as base64With |
| 438 | 439 | writes it. *) |
| 439 | -proc base64*(s, out: []U8): INT; | |
| 440 | +proc base64*(s: []const U8; out: []U8): INT; | |
| 440 | 441 | begin |
| 441 | 442 | return base64With(s, out, Base64, true); |
| 442 | 443 | end; |
| 443 | 444 | |
| 444 | 445 | (* 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; | |
| 446 | 447 | var i: INT; |
| 447 | 448 | begin |
| 448 | 449 | for i := 0 to 63 do |
| @@ -454,7 +455,7 @@ | ||
| 454 | 455 | (* The last 2 or 3 digits of an unpadded s, at s, decoded into out: |
| 455 | 456 | the bytes written, 1 or 2; or -1 if a digit isn't one, or the bits |
| 456 | 457 | 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; | |
| 458 | 459 | var a, b, c: INT; |
| 459 | 460 | begin |
| 460 | 461 | a := base64Val(s[0], alphabet); |
| @@ -483,7 +484,7 @@ | ||
| 483 | 484 | uses are 0, so a byte string has the one spelling that base64 gives |
| 484 | 485 | it (RFC 4648, section 3.5 allows a decoder to take that). Line |
| 485 | 486 | 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); | |
| 487 | 488 | var i, k, a, b, c, d, v, whole, n: INT; last: BOOL; |
| 488 | 489 | begin |
| 489 | 490 | whole := LEN(s); (* the bytes in groups of 4 *) |
| @@ -532,14 +533,14 @@ | ||
| 532 | 533 | |
| 533 | 534 | (* s, base64 (RFC 4648, section 4), padded, decoded into out as |
| 534 | 535 | 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); | |
| 536 | 537 | begin |
| 537 | 538 | return unbase64With(s, out, Base64, true); |
| 538 | 539 | end; |
| 539 | 540 | |
| 540 | 541 | (* s as a decimal number, digits only; false if it isn't one, or a U64 |
| 541 | 542 | can't hold it. *) |
| 542 | -proc toU64*(s: []U8): (U64, BOOL); | |
| 543 | +proc toU64*(s: []const U8): (U64, BOOL); | |
| 543 | 544 | var v, d: U64; i: INT; |
| 544 | 545 | begin |
| 545 | 546 | if LEN(s) = 0 then return 0, false; end; |
| @@ -553,7 +554,7 @@ | ||
| 553 | 554 | end; |
| 554 | 555 | |
| 555 | 556 | (* 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; | |
| 557 | 558 | var n: INT; |
| 558 | 559 | begin |
| 559 | 560 | if p = nil then return ""; end; |
| @@ -563,13 +564,13 @@ | ||
| 563 | 564 | |
| 564 | 565 | (* s copied into out with a zero byte after it, for C: out holds |
| 565 | 566 | 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; | |
| 568 | 569 | var i: INT; |
| 569 | 570 | begin |
| 570 | 571 | for i := 0 to LEN(s) - 1 do out[i] := s[i]; end; |
| 571 | 572 | out[LEN(s)] := 0; |
| 572 | - return PTR(out); | |
| 573 | + return SYSTEM.PTR(out); | |
| 573 | 574 | end; |
| 574 | 575 | |
| 575 | 576 | (* n in decimal, as Out.int writes it: its bytes, the first of the 20, |
| @@ -593,7 +594,7 @@ | ||
| 593 | 594 | (* The bytes of s, at most 8, as an unsigned number, the first byte |
| 594 | 595 | the lowest: how a file or a message in little-endian order is read, |
| 595 | 596 | whatever the machine's own order. *) |
| 596 | -proc le*(s: []U8): U64; | |
| 597 | +proc le*(s: []const U8): U64; | |
| 597 | 598 | var v: U64; i: INT; |
| 598 | 599 | begin |
| 599 | 600 | if LEN(s) > 8 then Rt.stop("Str.le: more than 8 bytes"); end; |
| @@ -602,7 +603,7 @@ | ||
| 602 | 603 | end; |
| 603 | 604 | |
| 604 | 605 | (* As le, the first byte the highest: big-endian, network order. *) |
| 605 | -proc be*(s: []U8): U64; | |
| 606 | +proc be*(s: []const U8): U64; | |
| 606 | 607 | var v: U64; i: INT; |
| 607 | 608 | begin |
| 608 | 609 | if LEN(s) > 8 then Rt.stop("Str.be: more than 8 bytes"); end; |
| @@ -708,7 +709,7 @@ | ||
| 708 | 709 | end; |
| 709 | 710 | |
| 710 | 711 | 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; | |
| 712 | 713 | begin |
| 713 | 714 | if not eqFold("Hello", "hELLO") or eqFold("a", "b") or eqFold("a", "ab") or not eqFold("", "") |
| 714 | 715 | or eqFold("@", "`") then Rt.stop("Str.eqFold"); end; |
| @@ -834,18 +835,18 @@ | ||
| 834 | 835 | begin |
| 835 | 836 | if LEN(fromC(nil)) # 0 then Rt.stop("Str.fromC: nil"); end; |
| 836 | 837 | 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; | |
| 838 | 839 | 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; | |
| 840 | 841 | room := "xxxx"; |
| 841 | 842 | 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; | |
| 843 | 844 | p := toC("", room); |
| 844 | 845 | if room[0] # 0 then Rt.stop("Str.toC: empty"); end; |
| 845 | 846 | end; |
| 846 | 847 | |
| 847 | 848 | (* 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); | |
| 849 | 850 | var buf: [16]U8; n: INT; ok: BOOL; |
| 850 | 851 | begin |
| 851 | 852 | if base64Size(LEN(plain)) # LEN(coded) then Rt.stop("Str.base64Size"); end; |
| @@ -856,7 +857,7 @@ | ||
| 856 | 857 | end; |
| 857 | 858 | |
| 858 | 859 | (* s must not decode. *) |
| 859 | -proc testBad(s: []U8); | |
| 860 | +proc testBad(s: []const U8); | |
| 860 | 861 | var buf: [16]U8; ok: BOOL; |
| 861 | 862 | begin |
| 862 | 863 | _, ok := unbase64(s, buf[0..LEN(s) div 4 * 3]); |
| @@ -878,7 +879,7 @@ | ||
| 878 | 879 | |
| 879 | 880 | (* plain in the other alphabet and unpadded, and back; in the padded |
| 880 | 881 | form too, with the - and _ of base64url. *) |
| 881 | -proc testUrlVector(plain, bare, padded: []U8); | |
| 882 | +proc testUrlVector(plain, bare, padded: []const U8); | |
| 882 | 883 | var buf: [16]U8; n: INT; ok: BOOL; |
| 883 | 884 | begin |
| 884 | 885 | n := base64With(plain, buf[0..base64Size(LEN(plain))], Base64Url, false); |
| @@ -892,7 +893,7 @@ | ||
| 892 | 893 | end; |
| 893 | 894 | |
| 894 | 895 | (* s must not decode, unpadded, in base64url's alphabet. *) |
| 895 | -proc testUrlBad(s: []U8); | |
| 896 | +proc testUrlBad(s: []const U8); | |
| 896 | 897 | var buf: [16]U8; ok: BOOL; |
| 897 | 898 | begin |
| 898 | 899 | _, ok := unbase64With(s, buf[0..(LEN(s) + 3) div 4 * 3], Base64Url, false); |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | (* System calls on Linux for x86-64. Other targets supply their own |
| 2 | 2 | Sys, with the same exports. *) |
| 3 | 3 | module Sys; |
| 4 | +import SYSTEM; | |
| 4 | 5 | |
| 5 | 6 | const |
| 6 | 7 | stdin* = 0; (* standard input's file descriptor *) |
| @@ -85,11 +86,11 @@ | ||
| 85 | 86 | |
| 86 | 87 | (* A program for spawn to start. *) |
| 87 | 88 | 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 *) | |
| 91 | 92 | 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 *) | |
| 93 | 94 | fds*: [3]INT; (* stdin, stdout, stderr; 0 for this program's *) |
| 94 | 95 | group*: INT; (* its group: 0 for this program's, -1 a new one *) |
| 95 | 96 | foreground*: BOOL; (* its group gets the terminal on standard input *) |
| @@ -183,10 +184,10 @@ | ||
| 183 | 184 | |
| 184 | 185 | (* Writes s to the file descriptor fd; the number of bytes written, or |
| 185 | 186 | minus an errno. *) |
| 186 | -proc write*(fd: INT; s: []U8): INT; | |
| 187 | +proc write*(fd: INT; s: []const U8): INT; | |
| 187 | 188 | begin |
| 188 | 189 | 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)); | |
| 190 | 191 | end; |
| 191 | 192 | |
| 192 | 193 | (* Reads into buf from fd; the number of bytes read, 0 at the end, or |
| @@ -194,11 +195,11 @@ | ||
| 194 | 195 | proc read*(fd: INT; buf: []U8): INT; |
| 195 | 196 | begin |
| 196 | 197 | 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)); | |
| 198 | 199 | end; |
| 199 | 200 | |
| 200 | 201 | (* 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; | |
| 202 | 203 | begin |
| 203 | 204 | if LEN(path) >= LEN(buf) then return false; end; |
| 204 | 205 | COPY(buf, path); |
| @@ -226,31 +227,31 @@ | ||
| 226 | 227 | (* The file at path, opened as how asks: its file descriptor, closed in |
| 227 | 228 | a program exec starts, or minus an errno. A file it creates has the |
| 228 | 229 | 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; | |
| 230 | 231 | var buf: [4096]U8; |
| 231 | 232 | begin |
| 232 | 233 | if executing in how then return -22; end; (* EINVAL: access asks it, open can't *) |
| 233 | 234 | 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); | |
| 235 | 236 | end; |
| 236 | 237 | |
| 237 | 238 | (* openMode with 644: a file it creates is readable by all, writable |
| 238 | 239 | by its owner. *) |
| 239 | -proc open*(path: []U8; how: Accesses): INT; | |
| 240 | +proc open*(path: []const U8; how: Accesses): INT; | |
| 240 | 241 | begin |
| 241 | 242 | return openMode(path, how, 1A4H); (* 644 *) |
| 242 | 243 | end; |
| 243 | 244 | |
| 244 | 245 | (* The file at path, opened for reading, closed in a program exec |
| 245 | 246 | starts. *) |
| 246 | -proc openRead*(path: []U8): INT; | |
| 247 | +proc openRead*(path: []const U8): INT; | |
| 247 | 248 | begin |
| 248 | 249 | return open(path, {reading}); |
| 249 | 250 | end; |
| 250 | 251 | |
| 251 | 252 | (* The file at path, made empty or new, opened for writing, closed in a |
| 252 | 253 | program exec starts. *) |
| 253 | -proc create*(path: []U8): INT; | |
| 254 | +proc create*(path: []const U8): INT; | |
| 254 | 255 | begin |
| 255 | 256 | return open(path, {writing, creating, truncating}); |
| 256 | 257 | end; |
| @@ -259,29 +260,29 @@ | ||
| 259 | 260 | fromEnd: the new position, or minus an errno. *) |
| 260 | 261 | proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; |
| 261 | 262 | 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 *) | |
| 264 | 265 | end; |
| 265 | 266 | |
| 266 | 267 | (* Where in its file fd is, without moving: the next read or write's |
| 267 | 268 | position, or minus an errno. *) |
| 268 | 269 | proc position*(fd: INT): I64; |
| 269 | 270 | begin |
| 270 | - return SYSCALL(8, fd, 0, 1); (* lseek, SEEK_CUR *) | |
| 271 | + return SYSTEM.SYSCALL(8, fd, 0, 1); (* lseek, SEEK_CUR *) | |
| 271 | 272 | end; |
| 272 | 273 | |
| 273 | 274 | (* The file fd makes size bytes long, cut or filled with zeros; its |
| 274 | 275 | position stays. 0, or minus an errno. *) |
| 275 | 276 | proc truncate*(fd: INT; size: I64): INT; |
| 276 | 277 | begin |
| 277 | - return SYSCALL(77, fd, size); (* ftruncate *) | |
| 278 | + return SYSTEM.SYSCALL(77, fd, size); (* ftruncate *) | |
| 278 | 279 | end; |
| 279 | 280 | |
| 280 | 281 | (* Returns once what was written to fd is on the disk: 0, or minus an |
| 281 | 282 | errno. *) |
| 282 | 283 | proc sync*(fd: INT): INT; |
| 283 | 284 | begin |
| 284 | - return SYSCALL(74, fd); (* fsync *) | |
| 285 | + return SYSTEM.SYSCALL(74, fd); (* fsync *) | |
| 285 | 286 | end; |
| 286 | 287 | |
| 287 | 288 | (* Returns once everything written to the file system that holds fd |
| @@ -289,7 +290,7 @@ | ||
| 289 | 290 | minus an errno. *) |
| 290 | 291 | proc syncAll*(fd: INT): INT; |
| 291 | 292 | begin |
| 292 | - return SYSCALL(306, fd); (* syncfs *) | |
| 293 | + return SYSTEM.SYSCALL(306, fd); (* syncfs *) | |
| 293 | 294 | end; |
| 294 | 295 | |
| 295 | 296 | (* Takes the lock on the open file fd, which only one program holds at |
| @@ -298,8 +299,8 @@ | ||
| 298 | 299 | and otherwise returns -11 (EAGAIN). 0, or minus an errno. *) |
| 299 | 300 | proc lock*(fd: INT; wait: BOOL): INT; |
| 300 | 301 | 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 *) | |
| 303 | 304 | end; |
| 304 | 305 | |
| 305 | 306 | (* Takes the lock on the open file fd as lock does, but shared: any |
| @@ -307,14 +308,14 @@ | ||
| 307 | 308 | holds it as lock takes it. 0, or minus an errno. *) |
| 308 | 309 | proc lockShared*(fd: INT; wait: BOOL): INT; |
| 309 | 310 | 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 *) | |
| 312 | 313 | end; |
| 313 | 314 | |
| 314 | 315 | (* Closes the file descriptor fd. *) |
| 315 | 316 | proc close*(fd: INT); |
| 316 | 317 | begin |
| 317 | - _ := SYSCALL(3, fd); | |
| 318 | + _ := SYSTEM.SYSCALL(3, fd); | |
| 318 | 319 | end; |
| 319 | 320 | |
| 320 | 321 | (* Closes the file descriptor fd, as close does, and says whether that |
| @@ -325,21 +326,21 @@ | ||
| 325 | 326 | closed again, after -4 (EINTR) too. *) |
| 326 | 327 | proc closeChecked*(fd: INT): INT; |
| 327 | 328 | begin |
| 328 | - return SYSCALL(3, fd); | |
| 329 | + return SYSTEM.SYSCALL(3, fd); | |
| 329 | 330 | end; |
| 330 | 331 | |
| 331 | 332 | (* A new file descriptor for the file fd is open on, the lowest free: |
| 332 | 333 | it, or minus an errno. *) |
| 333 | 334 | proc dup*(fd: INT): INT; |
| 334 | 335 | begin |
| 335 | - return SYSCALL(32, fd); (* dup *) | |
| 336 | + return SYSTEM.SYSCALL(32, fd); (* dup *) | |
| 336 | 337 | end; |
| 337 | 338 | |
| 338 | 339 | (* Makes the file descriptor into stand for the file fd is open on, |
| 339 | 340 | closing what into was first: into, or minus an errno. *) |
| 340 | 341 | proc dupTo*(fd, into: INT): INT; |
| 341 | 342 | begin |
| 342 | - return SYSCALL(33, fd, into); (* dup2 *) | |
| 343 | + return SYSTEM.SYSCALL(33, fd, into); (* dup2 *) | |
| 343 | 344 | end; |
| 344 | 345 | |
| 345 | 346 | (* A new file descriptor for the file fd is open on, the lowest free |
| @@ -348,7 +349,7 @@ | ||
| 348 | 349 | names. *) |
| 349 | 350 | proc dupAbove*(fd, least: INT): INT; |
| 350 | 351 | begin |
| 351 | - return SYSCALL(72, fd, 1030, least); (* fcntl: F_DUPFD_CLOEXEC *) | |
| 352 | + return SYSTEM.SYSCALL(72, fd, 1030, least); (* fcntl: F_DUPFD_CLOEXEC *) | |
| 352 | 353 | end; |
| 353 | 354 | |
| 354 | 355 | (* Whether fd stays open in the program exec runs in this one's place: |
| @@ -358,10 +359,10 @@ | ||
| 358 | 359 | proc keepOnExec*(fd: INT; yes: BOOL): INT; |
| 359 | 360 | var f: INT; |
| 360 | 361 | begin |
| 361 | - f := SYSCALL(72, fd, 1); (* fcntl: F_GETFD *) | |
| 362 | + f := SYSTEM.SYSCALL(72, fd, 1); (* fcntl: F_GETFD *) | |
| 362 | 363 | if f < 0 then return f; end; |
| 363 | 364 | 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 *) | |
| 365 | 366 | end; |
| 366 | 367 | |
| 367 | 368 | (* size bytes of fresh, zeroed memory from the system, a multiple of |
| @@ -369,7 +370,7 @@ | ||
| 369 | 370 | proc mmap*(size: INT): ^U8; |
| 370 | 371 | var p: INT; |
| 371 | 372 | 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 *) | |
| 373 | 374 | if p < 0 then return nil; end; |
| 374 | 375 | return ^U8(p); |
| 375 | 376 | end; |
| @@ -377,7 +378,7 @@ | ||
| 377 | 378 | (* Gives back to the system the size bytes at p that mmap gave. *) |
| 378 | 379 | proc munmap*(p: ^U8; size: INT); |
| 379 | 380 | begin |
| 380 | - _ := SYSCALL(11, p, size); | |
| 381 | + _ := SYSTEM.SYSCALL(11, p, size); | |
| 381 | 382 | end; |
| 382 | 383 | |
| 383 | 384 | (* A file in memory, with no name, of size zeroed bytes: its fd, or |
| @@ -386,9 +387,9 @@ | ||
| 386 | 387 | var name: [4]U8; fd, r: INT; |
| 387 | 388 | begin |
| 388 | 389 | _ := 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 *) | |
| 390 | 391 | if fd < 0 then return fd; end; |
| 391 | - r := SYSCALL(77, fd, size); (* ftruncate *) | |
| 392 | + r := SYSTEM.SYSCALL(77, fd, size); (* ftruncate *) | |
| 392 | 393 | if r < 0 then close(fd); return r; end; |
| 393 | 394 | return fd; |
| 394 | 395 | end; |
| @@ -399,7 +400,7 @@ | ||
| 399 | 400 | proc mapFile*(fd, size: INT): ^U8; |
| 400 | 401 | var p: INT; |
| 401 | 402 | 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 *) | |
| 403 | 404 | if p < 0 then return nil; end; |
| 404 | 405 | return ^U8(p); |
| 405 | 406 | end; |
| @@ -410,7 +411,7 @@ | ||
| 410 | 411 | proc mapRead*(fd, size: INT): ^U8; |
| 411 | 412 | var p: INT; |
| 412 | 413 | 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 *) | |
| 414 | 415 | if p < 0 then return nil; end; |
| 415 | 416 | return ^U8(p); |
| 416 | 417 | end; |
| @@ -424,7 +425,7 @@ | ||
| 424 | 425 | prot := 0; (* PROT_NONE *) |
| 425 | 426 | if read then prot := 1; end; |
| 426 | 427 | if write then prot := prot | 2; end; |
| 427 | - return SYSCALL(10, p, size, prot); (* mprotect *) | |
| 428 | + return SYSTEM.SYSCALL(10, p, size, prot); (* mprotect *) | |
| 428 | 429 | end; |
| 429 | 430 | |
| 430 | 431 | (* Whether the file descriptor fd is a terminal: whether it has a |
| @@ -432,85 +433,85 @@ | ||
| 432 | 433 | proc isTerminal*(fd: INT): BOOL; |
| 433 | 434 | var t: [8]INT; (* struct termios: 60 bytes *) |
| 434 | 435 | begin |
| 435 | - return SYSCALL(16, fd, 5401H, ADR(t)) = 0; | |
| 436 | + return SYSTEM.SYSCALL(16, fd, 5401H, SYSTEM.ADR(t)) = 0; | |
| 436 | 437 | end; |
| 437 | 438 | |
| 438 | 439 | (* 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; | |
| 440 | 441 | var a, b: [4096]U8; |
| 441 | 442 | begin |
| 442 | 443 | 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)); | |
| 444 | 445 | end; |
| 445 | 446 | |
| 446 | 447 | (* Removes the file at path; not a directory. *) |
| 447 | -proc remove*(path: []U8): INT; | |
| 448 | +proc remove*(path: []const U8): INT; | |
| 448 | 449 | var a: [4096]U8; |
| 449 | 450 | begin |
| 450 | 451 | 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 *) | |
| 452 | 453 | end; |
| 453 | 454 | |
| 454 | 455 | (* 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; | |
| 456 | 457 | var a: [4096]U8; |
| 457 | 458 | begin |
| 458 | 459 | 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 *) | |
| 460 | 461 | end; |
| 461 | 462 | |
| 462 | 463 | (* Makes a directory at path with the permission bits mode, less those |
| 463 | 464 | the umask takes away: 1C0H (700) for one only its owner may enter. Of |
| 464 | 465 | 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; | |
| 466 | 467 | var a: [4096]U8; |
| 467 | 468 | begin |
| 468 | 469 | 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 *) | |
| 470 | 471 | end; |
| 471 | 472 | |
| 472 | 473 | (* Makes a fifo (a named pipe) at path with the permission bits mode, |
| 473 | 474 | 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; | |
| 475 | 476 | var a: [4096]U8; |
| 476 | 477 | begin |
| 477 | 478 | 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 *) | |
| 479 | 480 | end; |
| 480 | 481 | |
| 481 | 482 | |
| 482 | 483 | (* Sets the owner and group of what path names, following a symbolic |
| 483 | 484 | link: a user or group number, or -1 to leave it as it is. Only |
| 484 | 485 | 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; | |
| 486 | 487 | var a: [4096]U8; |
| 487 | 488 | begin |
| 488 | 489 | 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 *) | |
| 490 | 491 | end; |
| 491 | 492 | |
| 492 | 493 | |
| 493 | 494 | (* Removes the directory at path, which must be empty. *) |
| 494 | -proc removeDir*(path: []U8): INT; | |
| 495 | +proc removeDir*(path: []const U8): INT; | |
| 495 | 496 | var a: [4096]U8; |
| 496 | 497 | begin |
| 497 | 498 | 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 *) | |
| 499 | 500 | end; |
| 500 | 501 | |
| 501 | 502 | (* 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; | |
| 503 | 504 | var a: [4096]U8; |
| 504 | 505 | begin |
| 505 | 506 | 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); | |
| 507 | 508 | end; |
| 508 | 509 | |
| 509 | 510 | (* Sets when the contents of what path names last changed, and when it |
| 510 | 511 | was last read, to sec seconds and nsec nanoseconds since 1970, as a |
| 511 | 512 | program copying a file keeps its time: Info.seconds gives sec back, |
| 512 | 513 | whatever the time. *) |
| 513 | -proc setTime*(path: []U8; sec: I64; nsec: INT): INT; | |
| 514 | +proc setTime*(path: []const U8; sec: I64; nsec: INT): INT; | |
| 514 | 515 | var a: [4096]U8; t: [2]Timespec; |
| 515 | 516 | begin |
| 516 | 517 | if not cstr(path, a) then return -36; end; |
| @@ -518,13 +519,13 @@ | ||
| 518 | 519 | t[0].sec := sec; |
| 519 | 520 | t[0].nsec := nsec; |
| 520 | 521 | 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 *) | |
| 522 | 523 | end; |
| 523 | 524 | |
| 524 | 525 | (* 0 if this user, by its real ids, may do with path what how asks: |
| 525 | 526 | reading, writing and executing; minus an errno, -13 (EACCES) if not. |
| 526 | 527 | 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; | |
| 528 | 529 | var a: [4096]U8; m: INT; |
| 529 | 530 | begin |
| 530 | 531 | if not cstr(path, a) then return -36; end; |
| @@ -532,31 +533,31 @@ | ||
| 532 | 533 | if reading in how then m := m | 4; end; (* R_OK *) |
| 533 | 534 | if writing in how then m := m | 2; end; (* W_OK *) |
| 534 | 535 | 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 *) | |
| 536 | 537 | end; |
| 537 | 538 | |
| 538 | 539 | (* Sets the bits taken from every file this program, and the programs |
| 539 | 540 | it starts, make: the mask it was. *) |
| 540 | 541 | proc umask*(mask: INT): INT; |
| 541 | 542 | begin |
| 542 | - return SYSCALL(95, mask & 1FFH); (* umask *) | |
| 543 | + return SYSTEM.SYSCALL(95, mask & 1FFH); (* umask *) | |
| 543 | 544 | end; |
| 544 | 545 | |
| 545 | 546 | (* Makes path a symbolic link to target. *) |
| 546 | -proc symlink*(target, path: []U8): INT; | |
| 547 | +proc symlink*(target, path: []const U8): INT; | |
| 547 | 548 | var a, b: [4096]U8; |
| 548 | 549 | begin |
| 549 | 550 | 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)); | |
| 551 | 552 | end; |
| 552 | 553 | |
| 553 | 554 | (* What the symbolic link at path names, good until the next call; and |
| 554 | 555 | 0, or minus an errno. *) |
| 555 | -proc readLink*(path: []U8): ([]U8, INT); | |
| 556 | +proc readLink*(path: []const U8): ([]const U8, INT); | |
| 556 | 557 | var a: [4096]U8; n: INT; |
| 557 | 558 | begin |
| 558 | 559 | 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 *) | |
| 560 | 561 | if n < 0 then return "", n; end; |
| 561 | 562 | if n = LEN(linked) then return "", -36; end; (* it may be cut short *) |
| 562 | 563 | return linked[0..n], 0; |
| @@ -584,14 +585,14 @@ | ||
| 584 | 585 | (* The size of what path names, whether it is a directory or a regular |
| 585 | 586 | file, following a symbolic link, and whether path is one; and 0, or |
| 586 | 587 | minus an errno. *) |
| 587 | -proc info*(path: []U8): (Info, INT); | |
| 588 | +proc info*(path: []const U8): (Info, INT); | |
| 588 | 589 | var a: [4096]U8; st: [18]INT; i: Info; r: INT; isLink: BOOL; (* struct stat: 144 bytes *) |
| 589 | 590 | begin |
| 590 | 591 | 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 *) | |
| 592 | 593 | if r # 0 then return i, r; end; |
| 593 | 594 | 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 *) | |
| 595 | 596 | if r # 0 then return i, r; end; |
| 596 | 597 | i := fromStat(st); |
| 597 | 598 | i.symlink := isLink; |
| @@ -601,11 +602,11 @@ | ||
| 601 | 602 | (* info of path itself: if it is a symbolic link, of the link, not of |
| 602 | 603 | what it names, so that symlink is true, dir and file false, and the |
| 603 | 604 | size the length of what it names. *) |
| 604 | -proc linkInfo*(path: []U8): (Info, INT); | |
| 605 | +proc linkInfo*(path: []const U8): (Info, INT); | |
| 605 | 606 | var a: [4096]U8; st: [18]INT; i: Info; r: INT; |
| 606 | 607 | begin |
| 607 | 608 | 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 *) | |
| 609 | 610 | if r # 0 then return i, r; end; |
| 610 | 611 | i := fromStat(st); |
| 611 | 612 | i.symlink := st[3] & 0F000H = 0A000H; (* S_IFLNK *) |
| @@ -616,18 +617,18 @@ | ||
| 616 | 617 | proc infoOf*(fd: INT): (Info, INT); |
| 617 | 618 | var st: [18]INT; i: Info; r: INT; |
| 618 | 619 | begin |
| 619 | - r := SYSCALL(5, fd, ADR(st)); (* fstat *) | |
| 620 | + r := SYSTEM.SYSCALL(5, fd, SYSTEM.ADR(st)); (* fstat *) | |
| 620 | 621 | if r # 0 then return i, r; end; |
| 621 | 622 | return fromStat(st), 0; |
| 622 | 623 | end; |
| 623 | 624 | |
| 624 | 625 | (* The bytes free to an ordinary user on path's file system, and the |
| 625 | 626 | bytes in all. *) |
| 626 | -proc space*(path: []U8): (I64, I64, INT); | |
| 627 | +proc space*(path: []const U8): (I64, I64, INT); | |
| 627 | 628 | var a: [4096]U8; st: [15]INT; r, unit: INT; (* struct statfs: 120 bytes *) |
| 628 | 629 | begin |
| 629 | 630 | 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 *) | |
| 631 | 632 | if r # 0 then return 0, 0, r; end; |
| 632 | 633 | unit := st[9]; (* f_frsize, the unit blocks are counted in *) |
| 633 | 634 | if unit = 0 then unit := st[1]; end; (* f_bsize *) |
| @@ -648,26 +649,26 @@ | ||
| 648 | 649 | end; |
| 649 | 650 | |
| 650 | 651 | (* 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; | |
| 652 | 653 | var a: [4096]U8; |
| 653 | 654 | begin |
| 654 | 655 | d.kind := unknown; |
| 655 | 656 | d.pos := 0; |
| 656 | 657 | d.len := 0; |
| 657 | 658 | 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 *) | |
| 659 | 660 | if d.fd < 0 then return d.fd; end; |
| 660 | 661 | return 0; |
| 661 | 662 | end; |
| 662 | 663 | |
| 663 | 664 | (* The next name in the directory, good until the next call, but . and |
| 664 | 665 | .., in no order; false at the end. *) |
| 665 | -proc nextEntry*(var d: Dir): ([]U8, BOOL); | |
| 666 | +proc nextEntry*(var d: Dir): ([]const U8, BOOL); | |
| 666 | 667 | var n, at: INT; |
| 667 | 668 | begin |
| 668 | 669 | while true do |
| 669 | 670 | 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 *) | |
| 671 | 672 | d.pos := 0; |
| 672 | 673 | if d.len <= 0 then return "", false; end; |
| 673 | 674 | end; |
| @@ -696,7 +697,7 @@ | ||
| 696 | 697 | (* Closes the directory d that openDir opened. *) |
| 697 | 698 | proc closeDir*(var d: Dir); |
| 698 | 699 | begin |
| 699 | - _ := SYSCALL(3, d.fd); | |
| 700 | + _ := SYSTEM.SYSCALL(3, d.fd); | |
| 700 | 701 | end; |
| 701 | 702 | |
| 702 | 703 | (* Puts the terminal on fd into raw mode: no echo, no lines, no signals, |
| @@ -705,7 +706,7 @@ | ||
| 705 | 706 | proc rawMode*(fd: INT): BOOL; |
| 706 | 707 | var t: Termios; |
| 707 | 708 | 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 *) | |
| 709 | 710 | t := saved; |
| 710 | 711 | t.iflag := t.iflag & ~U32(5EBH); (* IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON *) |
| 711 | 712 | t.oflag := t.oflag & ~U32(1); (* OPOST *) |
| @@ -713,13 +714,13 @@ | ||
| 713 | 714 | t.lflag := t.lflag & ~U32(804BH); (* ISIG ICANON ECHO ECHONL IEXTEN *) |
| 714 | 715 | t.cc[5] := 0; (* VTIME: no time limit *) |
| 715 | 716 | 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 *) | |
| 717 | 718 | end; |
| 718 | 719 | |
| 719 | 720 | (* The terminal on fd as rawMode found it. *) |
| 720 | 721 | proc restoreMode*(fd: INT); |
| 721 | 722 | begin |
| 722 | - _ := SYSCALL(16, fd, 5402H, ADR(saved)); | |
| 723 | + _ := SYSTEM.SYSCALL(16, fd, 5402H, SYSTEM.ADR(saved)); | |
| 723 | 724 | end; |
| 724 | 725 | |
| 725 | 726 | (* The modes of the terminal on fd, as a shell keeps them for each job; |
| @@ -727,7 +728,7 @@ | ||
| 727 | 728 | proc getMode*(fd: INT): (Mode, INT); |
| 728 | 729 | var m: Mode; r: INT; |
| 729 | 730 | begin |
| 730 | - r := SYSCALL(16, fd, 5401H, ADR(m.t)); (* TCGETS *) | |
| 731 | + r := SYSTEM.SYSCALL(16, fd, 5401H, SYSTEM.ADR(m.t)); (* TCGETS *) | |
| 731 | 732 | return m, r; |
| 732 | 733 | end; |
| 733 | 734 | |
| @@ -735,7 +736,7 @@ | ||
| 735 | 736 | is sent: 0, or minus an errno. *) |
| 736 | 737 | proc setMode*(fd: INT; m: Mode): INT; |
| 737 | 738 | begin |
| 738 | - return SYSCALL(16, fd, 5403H, ADR(m.t)); (* TCSETSW *) | |
| 739 | + return SYSTEM.SYSCALL(16, fd, 5403H, SYSTEM.ADR(m.t)); (* TCSETSW *) | |
| 739 | 740 | end; |
| 740 | 741 | |
| 741 | 742 | (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't |
| @@ -743,7 +744,7 @@ | ||
| 743 | 744 | proc termSize*(fd: INT): (INT, INT); |
| 744 | 745 | var w: Winsize; |
| 745 | 746 | 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 *) | |
| 747 | 748 | return 80, 24; |
| 748 | 749 | end; |
| 749 | 750 | return INT(w.cols), INT(w.rows); |
| @@ -755,7 +756,7 @@ | ||
| 755 | 756 | var p: Pollfd; |
| 756 | 757 | begin |
| 757 | 758 | 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 *) | |
| 759 | 760 | end; |
| 760 | 761 | |
| 761 | 762 | (* The clock that only goes forward, in nanoseconds: for how long |
| @@ -763,7 +764,7 @@ | ||
| 763 | 764 | proc clock*: I64; |
| 764 | 765 | var t: Timespec; |
| 765 | 766 | begin |
| 766 | - _ := SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *) | |
| 767 | + _ := SYSTEM.SYSCALL(228, 1, SYSTEM.ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *) | |
| 767 | 768 | return t.sec * 1000000000 + t.nsec; |
| 768 | 769 | end; |
| 769 | 770 | |
| @@ -771,7 +772,7 @@ | ||
| 771 | 772 | proc now*: I64; |
| 772 | 773 | var t: Timespec; |
| 773 | 774 | begin |
| 774 | - _ := SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *) | |
| 775 | + _ := SYSTEM.SYSCALL(228, 0, SYSTEM.ADR(t)); (* clock_gettime: CLOCK_REALTIME *) | |
| 775 | 776 | return t.sec * 1000000000 + t.nsec; |
| 776 | 777 | end; |
| 777 | 778 | |
| @@ -781,14 +782,14 @@ | ||
| 781 | 782 | begin |
| 782 | 783 | at := clock() + I64(ms) * 1000000; |
| 783 | 784 | 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 *) | |
| 785 | 786 | end; |
| 786 | 787 | |
| 787 | 788 | (* Ends the program: random bytes can't be faked. *) |
| 788 | 789 | proc noRandom; |
| 789 | 790 | begin |
| 790 | 791 | _ := write(stderr, "Sys.random: the kernel gave no random bytes\n"); |
| 791 | - _ := SYSCALL(231, 2); (* exit *) | |
| 792 | + _ := SYSTEM.SYSCALL(231, 2); (* exit *) | |
| 792 | 793 | end; |
| 793 | 794 | |
| 794 | 795 | (* Fills b with random bytes, from the kernel. Random bytes can't be |
| @@ -800,7 +801,7 @@ | ||
| 800 | 801 | begin |
| 801 | 802 | n := 0; |
| 802 | 803 | 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 *) | |
| 804 | 805 | if r > 0 then INC(n, r); |
| 805 | 806 | elsif r # errIntr then noRandom(); |
| 806 | 807 | end; |
| @@ -814,17 +815,17 @@ | ||
| 814 | 815 | proc socket(family, kind: INT; a: ^U8; size: INT; serving: BOOL): INT; |
| 815 | 816 | var fd, r, one: INT; |
| 816 | 817 | begin |
| 817 | - fd := SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *) | |
| 818 | + fd := SYSTEM.SYSCALL(41, family, kind | 80000H, 0); (* socket, SOCK_CLOEXEC *) | |
| 818 | 819 | if fd < 0 then return fd; end; |
| 819 | 820 | if serving then |
| 820 | 821 | 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 *) | |
| 823 | 824 | 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 *) | |
| 825 | 826 | end; |
| 826 | 827 | else |
| 827 | - r := SYSCALL(42, fd, a, size); (* connect *) | |
| 828 | + r := SYSTEM.SYSCALL(42, fd, a, size); (* connect *) | |
| 828 | 829 | end; |
| 829 | 830 | if r < 0 then close(fd); return r; end; |
| 830 | 831 | return fd; |
| @@ -834,7 +835,7 @@ | ||
| 834 | 835 | -36 (ENAMETOOLONG) if it is too long. A path that starts with a zero |
| 835 | 836 | byte is one of Linux's abstract names, which has no file and no |
| 836 | 837 | 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; | |
| 838 | 839 | begin |
| 839 | 840 | if LEN(path) >= LEN(a^.path) then return -36; end; |
| 840 | 841 | a^.family := 1; (* AF_UNIX *) |
| @@ -844,22 +845,22 @@ | ||
| 844 | 845 | end; |
| 845 | 846 | |
| 846 | 847 | (* A stream socket connected to the Unix socket at path. *) |
| 847 | -proc connect*(path: []U8): INT; | |
| 848 | +proc connect*(path: []const U8): INT; | |
| 848 | 849 | var a: SockaddrUn; size: INT; |
| 849 | 850 | begin |
| 850 | - size := unixAddr(path, ADR(a)); | |
| 851 | + size := unixAddr(path, SYSTEM.ADR(a)); | |
| 851 | 852 | 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 *) | |
| 853 | 854 | end; |
| 854 | 855 | |
| 855 | 856 | (* A stream socket made at path, which must not be there yet, taking |
| 856 | 857 | connections. *) |
| 857 | -proc listen*(path: []U8): INT; | |
| 858 | +proc listen*(path: []const U8): INT; | |
| 858 | 859 | var a: SockaddrUn; size: INT; |
| 859 | 860 | begin |
| 860 | - size := unixAddr(path, ADR(a)); | |
| 861 | + size := unixAddr(path, SYSTEM.ADR(a)); | |
| 861 | 862 | 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); | |
| 863 | 864 | end; |
| 864 | 865 | |
| 865 | 866 | (* The value of the hexadecimal digit c, or -1 if it isn't one. *) |
| @@ -873,7 +874,7 @@ | ||
| 873 | 874 | |
| 874 | 875 | (* The IPv4 address s, four numbers and dots, in out's 4 bytes, or false |
| 875 | 876 | if it isn't one. *) |
| 876 | -proc ipv4(s, out: []U8): BOOL; | |
| 877 | +proc ipv4(s: []const U8; out: []U8): BOOL; | |
| 877 | 878 | var b: [4]U8; n, i, v, d: INT; |
| 878 | 879 | begin |
| 879 | 880 | i := 0; |
| @@ -900,7 +901,7 @@ | ||
| 900 | 901 | (* The IPv6 address s, groups of hexadecimal digits and colons, one :: |
| 901 | 902 | standing for groups of zeros, in out's 16 bytes, or false if it isn't |
| 902 | 903 | one. *) |
| 903 | -proc ipv6(s, out: []U8): BOOL; | |
| 904 | +proc ipv6(s: []const U8; out: []U8): BOOL; | |
| 904 | 905 | var g: [8]INT; n, gap, i, v, d, k: INT; |
| 905 | 906 | begin |
| 906 | 907 | n := 0; |
| @@ -944,7 +945,7 @@ | ||
| 944 | 945 | (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size |
| 945 | 946 | of its struct sockaddr_in or sockaddr_in6, or 0 if either is |
| 946 | 947 | wrong. *) |
| 947 | -proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT; | |
| 948 | +proc inetAddr(addr: []const U8; port: INT; a: ^Sockaddr): INT; | |
| 948 | 949 | begin |
| 949 | 950 | if (port < 0) or (port > 65535) then return 0; end; |
| 950 | 951 | a^.port[0] := U8(port shr 8); (* in the network's order, the high byte first *) |
| @@ -956,37 +957,37 @@ | ||
| 956 | 957 | |
| 957 | 958 | (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL) |
| 958 | 959 | 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; | |
| 960 | 961 | var a: Sockaddr; size: INT; |
| 961 | 962 | begin |
| 962 | - size := inetAddr(addr, port, ADR(a)); | |
| 963 | + size := inetAddr(addr, port, SYSTEM.ADR(a)); | |
| 963 | 964 | 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); | |
| 965 | 966 | end; |
| 966 | 967 | |
| 967 | 968 | (* A stream socket connected to port at addr, an IPv4 or IPv6 address |
| 968 | 969 | as numbers. *) |
| 969 | -proc connectTcp*(addr: []U8; port: INT): INT; | |
| 970 | +proc connectTcp*(addr: []const U8; port: INT): INT; | |
| 970 | 971 | begin |
| 971 | 972 | return inet(addr, port, 1, false); (* SOCK_STREAM *) |
| 972 | 973 | end; |
| 973 | 974 | |
| 974 | 975 | (* 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; | |
| 976 | 977 | begin |
| 977 | 978 | return inet(addr, port, 2, false); (* SOCK_DGRAM *) |
| 978 | 979 | end; |
| 979 | 980 | |
| 980 | 981 | (* A stream socket taking connections on port at addr; "0.0.0.0" or |
| 981 | 982 | "::" is every address the machine has. *) |
| 982 | -proc listenTcp*(addr: []U8; port: INT): INT; | |
| 983 | +proc listenTcp*(addr: []const U8; port: INT): INT; | |
| 983 | 984 | begin |
| 984 | 985 | return inet(addr, port, 1, true); |
| 985 | 986 | end; |
| 986 | 987 | |
| 987 | 988 | (* A socket of datagrams on port at addr, from anyone, for receive and |
| 988 | 989 | reply. *) |
| 989 | -proc listenUdp*(addr: []U8; port: INT): INT; | |
| 990 | +proc listenUdp*(addr: []const U8; port: INT): INT; | |
| 990 | 991 | begin |
| 991 | 992 | return inet(addr, port, 2, true); |
| 992 | 993 | end; |
| @@ -995,7 +996,7 @@ | ||
| 995 | 996 | its own, closed in a program exec starts; or minus an errno. *) |
| 996 | 997 | proc accept*(fd: INT): INT; |
| 997 | 998 | begin |
| 998 | - return SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *) | |
| 999 | + return SYSTEM.SYSCALL(288, fd, 0, 0, 80000H); (* accept4, SOCK_CLOEXEC *) | |
| 999 | 1000 | end; |
| 1000 | 1001 | |
| 1001 | 1002 | (* Ends this side's writing to the socket fd, so that the other end |
| @@ -1003,7 +1004,7 @@ | ||
| 1003 | 1004 | errno. *) |
| 1004 | 1005 | proc closeWrite*(fd: INT): INT; |
| 1005 | 1006 | begin |
| 1006 | - return SYSCALL(48, fd, 1); (* shutdown, SHUT_WR *) | |
| 1007 | + return SYSTEM.SYSCALL(48, fd, 1); (* shutdown, SHUT_WR *) | |
| 1007 | 1008 | end; |
| 1008 | 1009 | |
| 1009 | 1010 | (* Who is at the other end of the connected socket fd, and 0; or minus |
| @@ -1013,11 +1014,11 @@ | ||
| 1013 | 1014 | begin |
| 1014 | 1015 | r := {unix: false, ipv6: false}; |
| 1015 | 1016 | 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 *) | |
| 1017 | 1018 | if e < 0 then return r, e; end; |
| 1018 | 1019 | if a.family = 1 then (* AF_UNIX: ask who made the connection *) |
| 1019 | 1020 | 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 *) | |
| 1021 | 1022 | if e < 0 then return r, e; end; |
| 1022 | 1023 | r.unix := true; |
| 1023 | 1024 | r.pid := INT(cred[0]); |
| @@ -1040,7 +1041,7 @@ | ||
| 1040 | 1041 | proc socketPair*: (INT, INT, INT); |
| 1041 | 1042 | var fds: [2]I32; r: INT; |
| 1042 | 1043 | 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 *) | |
| 1044 | 1045 | if r < 0 then return -1, -1, r; end; |
| 1045 | 1046 | return INT(fds[0]), INT(fds[1]), 0; |
| 1046 | 1047 | end; |
| @@ -1048,18 +1049,18 @@ | ||
| 1048 | 1049 | (* Writes s to the socket fd, as write does, but returns -32 (EPIPE) |
| 1049 | 1050 | where write would stop the program with SIGPIPE: when the other end |
| 1050 | 1051 | has closed it. *) |
| 1051 | -proc send*(fd: INT; s: []U8): INT; | |
| 1052 | +proc send*(fd: INT; s: []const U8): INT; | |
| 1052 | 1053 | begin |
| 1053 | 1054 | 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 *) | |
| 1055 | 1056 | end; |
| 1056 | 1057 | |
| 1057 | 1058 | (* send, but never waits: returns -11 (EAGAIN) where send would wait for |
| 1058 | 1059 | 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; | |
| 1060 | 1061 | begin |
| 1061 | 1062 | 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 *) | |
| 1063 | 1064 | end; |
| 1064 | 1065 | |
| 1065 | 1066 | |
| @@ -1087,7 +1088,7 @@ | ||
| 1087 | 1088 | if fds[i].write then events := events | 4; end; (* POLLOUT *) |
| 1088 | 1089 | list[i] := {fd: I32(fds[i].fd), events: events}; |
| 1089 | 1090 | end; |
| 1090 | - r := SYSCALL(7, PTR(list), n, ms); (* poll *) | |
| 1091 | + r := SYSTEM.SYSCALL(7, SYSTEM.PTR(list), n, ms); (* poll *) | |
| 1091 | 1092 | for i := 0 to n - 1 do |
| 1092 | 1093 | fds[i].ready := (r > 0) and (list[i].revents # 0); |
| 1093 | 1094 | end; |
| @@ -1100,7 +1101,7 @@ | ||
| 1100 | 1101 | reached its end or failed, so that a read or a write won't wait; -1 |
| 1101 | 1102 | if none has. ms < 0 waits as long as it takes. At most 64 fds in |
| 1102 | 1103 | all. *) |
| 1103 | -proc readyFor*(reads, writes: []INT; ms: INT): INT; | |
| 1104 | +proc readyFor*(reads, writes: []const INT; ms: INT): INT; | |
| 1104 | 1105 | var p: [64]Poll; ps: []Poll; n, i: INT; |
| 1105 | 1106 | begin |
| 1106 | 1107 | n := 0; |
| @@ -1127,7 +1128,7 @@ | ||
| 1127 | 1128 | (* The first of fds that has something to read within ms milliseconds, |
| 1128 | 1129 | or that has reached its end or failed, so that a read won't wait; -1 |
| 1129 | 1130 | 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; | |
| 1131 | 1132 | begin |
| 1132 | 1133 | return readyFor(fds, [], ms); |
| 1133 | 1134 | end; |
| @@ -1138,10 +1139,10 @@ | ||
| 1138 | 1139 | proc setBlocking*(fd: INT; yes: BOOL): INT; |
| 1139 | 1140 | var flags: INT; |
| 1140 | 1141 | begin |
| 1141 | - flags := SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *) | |
| 1142 | + flags := SYSTEM.SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *) | |
| 1142 | 1143 | if flags < 0 then return flags; end; |
| 1143 | 1144 | 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 *) | |
| 1145 | 1146 | end; |
| 1146 | 1147 | |
| 1147 | 1148 | (* Whether reads and writes on fd wait, as they do at first: 1 if they |
| @@ -1149,7 +1150,7 @@ | ||
| 1149 | 1150 | proc blocking*(fd: INT): INT; |
| 1150 | 1151 | var flags: INT; |
| 1151 | 1152 | begin |
| 1152 | - flags := SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *) | |
| 1153 | + flags := SYSTEM.SYSCALL(72, fd, 3, 0); (* fcntl F_GETFL *) | |
| 1153 | 1154 | if flags < 0 then return flags; end; |
| 1154 | 1155 | if flags & 800H # 0 then return 0; end; (* O_NONBLOCK *) |
| 1155 | 1156 | return 1; |
| @@ -1159,19 +1160,19 @@ | ||
| 1159 | 1160 | or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. |
| 1160 | 1161 | It starts to connect without waiting, then waits for the socket to |
| 1161 | 1162 | 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; | |
| 1163 | 1164 | var a: Sockaddr; size, fd, r: INT; err, errSize: I32; |
| 1164 | 1165 | begin |
| 1165 | - size := inetAddr(addr, port, ADR(a)); | |
| 1166 | + size := inetAddr(addr, port, SYSTEM.ADR(a)); | |
| 1166 | 1167 | 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 *) | |
| 1168 | 1169 | 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 *) | |
| 1170 | 1171 | if r = -115 then (* EINPROGRESS *) |
| 1171 | 1172 | r := -110; |
| 1172 | 1173 | if readyFor([], [fd], ms) = fd then |
| 1173 | 1174 | 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 *) | |
| 1175 | 1176 | if r = 0 then r := -INT(err); end; |
| 1176 | 1177 | end; |
| 1177 | 1178 | end; |
| @@ -1186,7 +1187,7 @@ | ||
| 1186 | 1187 | var a: Sockaddr; size: I32; r: INT; |
| 1187 | 1188 | begin |
| 1188 | 1189 | 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 *) | |
| 1190 | 1191 | if r < 0 then return r; end; |
| 1191 | 1192 | return (INT(a.port[0]) shl 8) | INT(a.port[1]); |
| 1192 | 1193 | end; |
| @@ -1198,34 +1199,34 @@ | ||
| 1198 | 1199 | var p: Peer; size: I32; n: INT; |
| 1199 | 1200 | begin |
| 1200 | 1201 | 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 *) | |
| 1202 | 1203 | p.size := INT(size); |
| 1203 | 1204 | return n, p; |
| 1204 | 1205 | end; |
| 1205 | 1206 | |
| 1206 | 1207 | (* Sends s, as one datagram, from the socket fd to peer, as receive |
| 1207 | 1208 | 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; | |
| 1209 | 1210 | 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 *) | |
| 1211 | 1212 | end; |
| 1212 | 1213 | |
| 1213 | 1214 | (* Sends s, at least one byte, to the Unix socket fd, as send does, and |
| 1214 | 1215 | with it the files fds, at most 16, which the program that receives |
| 1215 | 1216 | 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; | |
| 1217 | 1218 | var m: Msghdr; v: Iovec; c: Rights; i: INT; |
| 1218 | 1219 | begin |
| 1219 | 1220 | 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}; | |
| 1222 | 1223 | if LEN(fds) > 0 then |
| 1223 | 1224 | c := {size: 16 + 4 * LEN(fds), level: 1, kind: 1}; (* SOL_SOCKET, SCM_RIGHTS *) |
| 1224 | 1225 | 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)); | |
| 1226 | 1227 | m.controlSize := (c.size + 7) & ~7; (* CMSG_SPACE: whole quadwords *) |
| 1227 | 1228 | 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 *) | |
| 1229 | 1230 | end; |
| 1230 | 1231 | |
| 1231 | 1232 | (* Reads into buf from the Unix socket fd, as read does, and puts the |
| @@ -1235,9 +1236,9 @@ | ||
| 1235 | 1236 | proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); |
| 1236 | 1237 | var m: Msghdr; v: Iovec; c: Rights; n, k, i: INT; |
| 1237 | 1238 | 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 *) | |
| 1241 | 1242 | if n < 0 then return n, 0; end; |
| 1242 | 1243 | k := 0; |
| 1243 | 1244 | if (m.controlSize >= 16) and (c.level = 1) and (c.kind = 1) then |
| @@ -1256,7 +1257,7 @@ | ||
| 1256 | 1257 | const |
| 1257 | 1258 | (* what each errno means, as glibc's strerror says it; 41 and 58 |
| 1258 | 1259 | are none *) |
| 1259 | - errorTexts: [134][]U8 = [ | |
| 1260 | + errorTexts: [134][]const U8 = [ | |
| 1260 | 1261 | "Success", (* 0 *) |
| 1261 | 1262 | "Operation not permitted", (* 1, EPERM *) |
| 1262 | 1263 | "No such file or directory", (* 2, ENOENT *) |
| @@ -1394,7 +1395,7 @@ | ||
| 1394 | 1395 | |
| 1395 | 1396 | (* What errno err, or minus it, means, as C's strerror says it; |
| 1396 | 1397 | "unknown error" for a number that is no errno. *) |
| 1397 | -proc errorText*(err: INT): []U8; | |
| 1398 | +proc errorText*(err: INT): []const U8; | |
| 1398 | 1399 | begin |
| 1399 | 1400 | if (err < 0) and (err > -LEN(errorTexts)) then err := -err; end; |
| 1400 | 1401 | if (err < 0) or (err >= LEN(errorTexts)) then return "unknown error"; end; |
| @@ -1407,11 +1408,11 @@ | ||
| 1407 | 1408 | proc environment: ^^U8; |
| 1408 | 1409 | begin |
| 1409 | 1410 | if envp # nil then return envp; end; |
| 1410 | - return ARGV() + (ARGC() + 1); | |
| 1411 | + return SYSTEM.ARGV() + (ARGC() + 1); | |
| 1411 | 1412 | end; |
| 1412 | 1413 | |
| 1413 | 1414 | (* 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; | |
| 1415 | 1416 | var n: INT; |
| 1416 | 1417 | begin |
| 1417 | 1418 | n := 0; |
| @@ -1424,11 +1425,11 @@ | ||
| 1424 | 1425 | program calls env, from Rt, so this reads the environment itself |
| 1425 | 1426 | rather than through environment and named, which would add their |
| 1426 | 1427 | code to every executable. *) |
| 1427 | -proc findEnv*(name: []U8): ([]U8, BOOL); | |
| 1428 | +proc findEnv*(name: []const U8): ([]const U8, BOOL); | |
| 1428 | 1429 | var e: ^^U8; s: ^U8; i, n, m: INT; |
| 1429 | 1430 | begin |
| 1430 | 1431 | e := envp; |
| 1431 | - if e = nil then e := ARGV() + (ARGC() + 1); end; | |
| 1432 | + if e = nil then e := SYSTEM.ARGV() + (ARGC() + 1); end; | |
| 1432 | 1433 | i := 0; |
| 1433 | 1434 | while e[i] # nil do |
| 1434 | 1435 | s := e[i]; |
| @@ -1445,8 +1446,8 @@ | ||
| 1445 | 1446 | end; |
| 1446 | 1447 | |
| 1447 | 1448 | (* 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; | |
| 1450 | 1451 | begin |
| 1451 | 1452 | v, _ := findEnv(name); |
| 1452 | 1453 | return v; |
| @@ -1454,7 +1455,7 @@ | ||
| 1454 | 1455 | |
| 1455 | 1456 | (* The environment's ith NAME=value, from 0, and true; "" and false |
| 1456 | 1457 | past the last. *) |
| 1457 | -proc envAt*(i: INT): ([]U8, BOOL); | |
| 1458 | +proc envAt*(i: INT): ([]const U8, BOOL); | |
| 1458 | 1459 | var e: ^^U8; s: ^U8; j, n: INT; |
| 1459 | 1460 | begin |
| 1460 | 1461 | if i < 0 then return "", false; end; |
| @@ -1470,20 +1471,20 @@ | ||
| 1470 | 1471 | |
| 1471 | 1472 | (* The working directory, good until the next call; and 0, or minus an |
| 1472 | 1473 | errno. *) |
| 1473 | -proc workDir*: ([]U8, INT); | |
| 1474 | +proc workDir*: ([]const U8, INT); | |
| 1474 | 1475 | var r: INT; |
| 1475 | 1476 | 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 *) | |
| 1477 | 1478 | if r < 0 then return "", r; end; |
| 1478 | 1479 | return cwd[0..r - 1], 0; |
| 1479 | 1480 | end; |
| 1480 | 1481 | |
| 1481 | 1482 | (* Makes path the working directory. *) |
| 1482 | -proc setWorkDir*(path: []U8): INT; | |
| 1483 | +proc setWorkDir*(path: []const U8): INT; | |
| 1483 | 1484 | var a: [4096]U8; |
| 1484 | 1485 | begin |
| 1485 | 1486 | 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 *) | |
| 1487 | 1488 | end; |
| 1488 | 1489 | |
| 1489 | 1490 | (* A pseudo-terminal: the file descriptor of its controlling side, or |
| @@ -1493,10 +1494,10 @@ | ||
| 1493 | 1494 | var a: [4096]U8; fd, unlock: INT; |
| 1494 | 1495 | begin |
| 1495 | 1496 | _ := 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 *) | |
| 1497 | 1498 | if fd < 0 then return fd; end; |
| 1498 | 1499 | 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 *) | |
| 1500 | 1501 | close(fd); |
| 1501 | 1502 | return -5; (* EIO *) |
| 1502 | 1503 | end; |
| @@ -1509,11 +1510,11 @@ | ||
| 1509 | 1510 | var w: Winsize; |
| 1510 | 1511 | begin |
| 1511 | 1512 | 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 *) | |
| 1513 | 1514 | end; |
| 1514 | 1515 | |
| 1515 | 1516 | (* 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; | |
| 1517 | 1518 | begin |
| 1518 | 1519 | COPY(at[0..LEN(s)], s); |
| 1519 | 1520 | at[LEN(s)] := 0; |
| @@ -1522,7 +1523,7 @@ | ||
| 1522 | 1523 | |
| 1523 | 1524 | (* Whether the NAME=value s, a C string, names a variable that one of |
| 1524 | 1525 | env gives. *) |
| 1525 | -proc replaced(s: ^U8; env: [][]U8): BOOL; | |
| 1526 | +proc replaced(s: ^U8; env: [][]const U8): BOOL; | |
| 1526 | 1527 | var i, n: INT; |
| 1527 | 1528 | begin |
| 1528 | 1529 | for i := 0 to LEN(env) - 1 do |
| @@ -1537,7 +1538,7 @@ | ||
| 1537 | 1538 | strings and a nil, then the environment old with each NAME=value of |
| 1538 | 1539 | env in place of its variable or added, and a nil; or nil. The |
| 1539 | 1540 | 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); | |
| 1541 | 1542 | var p: ^^U8; s: ^U8; size, n, i, k: INT; |
| 1542 | 1543 | begin |
| 1543 | 1544 | n := 0; |
| @@ -1570,7 +1571,7 @@ | ||
| 1570 | 1571 | stays good for the rest of the run; they are taken in turn from |
| 1571 | 1572 | blocks of 64 KB. It isn't safe while another thread reads the |
| 1572 | 1573 | 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; | |
| 1574 | 1575 | var e, p: ^^U8; s: ^U8; size, cap, n, i: INT; |
| 1575 | 1576 | begin |
| 1576 | 1577 | if LEN(name) = 0 then return -22; end; (* EINVAL *) |
| @@ -1630,7 +1631,7 @@ | ||
| 1630 | 1631 | proc pipe*: (INT, INT); |
| 1631 | 1632 | var fds: [2]I32; r: INT; |
| 1632 | 1633 | begin |
| 1633 | - r := SYSCALL(293, ADR(fds), 80000H); (* pipe2, O_CLOEXEC *) | |
| 1634 | + r := SYSTEM.SYSCALL(293, SYSTEM.ADR(fds), 80000H); (* pipe2, O_CLOEXEC *) | |
| 1634 | 1635 | if r < 0 then return r, -1; end; |
| 1635 | 1636 | return INT(fds[0]), INT(fds[1]); |
| 1636 | 1637 | end; |
| @@ -1638,28 +1639,28 @@ | ||
| 1638 | 1639 | (* This program's process id. *) |
| 1639 | 1640 | proc pid*: INT; |
| 1640 | 1641 | begin |
| 1641 | - return SYSCALL(39); (* getpid *) | |
| 1642 | + return SYSTEM.SYSCALL(39); (* getpid *) | |
| 1642 | 1643 | end; |
| 1643 | 1644 | |
| 1644 | 1645 | (* The user this program runs as: its real id. *) |
| 1645 | 1646 | proc uid*: INT; |
| 1646 | 1647 | begin |
| 1647 | - return SYSCALL(102); (* getuid *) | |
| 1648 | + return SYSTEM.SYSCALL(102); (* getuid *) | |
| 1648 | 1649 | end; |
| 1649 | 1650 | |
| 1650 | 1651 | (* The user whose rights this program has, its effective id: 0 is |
| 1651 | 1652 | root. *) |
| 1652 | 1653 | proc euid*: INT; |
| 1653 | 1654 | begin |
| 1654 | - return SYSCALL(107); (* geteuid *) | |
| 1655 | + return SYSTEM.SYSCALL(107); (* geteuid *) | |
| 1655 | 1656 | end; |
| 1656 | 1657 | |
| 1657 | 1658 | (* The name of this machine, good until the next call; and 0, or minus |
| 1658 | 1659 | an errno. *) |
| 1659 | -proc hostName*: ([]U8, INT); | |
| 1660 | +proc hostName*: ([]const U8, INT); | |
| 1660 | 1661 | var r, n: INT; |
| 1661 | 1662 | begin |
| 1662 | - r := SYSCALL(63, ADR(uts)); (* uname *) | |
| 1663 | + r := SYSTEM.SYSCALL(63, SYSTEM.ADR(uts)); (* uname *) | |
| 1663 | 1664 | if r < 0 then return "", r; end; |
| 1664 | 1665 | n := 0; |
| 1665 | 1666 | while (n < 64) and (uts[65 + n] # 0) do INC(n); end; (* the nodename, at 65 *) |
| @@ -1670,7 +1671,7 @@ | ||
| 1670 | 1671 | proc processors*: INT; |
| 1671 | 1672 | var mask: [1024]U8; n, i, b, count: INT; |
| 1672 | 1673 | 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 *) | |
| 1674 | 1675 | count := 0; |
| 1675 | 1676 | for i := 0 to n - 1 do |
| 1676 | 1677 | for b := 0 to 7 do |
| @@ -1687,8 +1688,8 @@ | ||
| 1687 | 1688 | proc cpuTime*(children: BOOL): (I64, I64); |
| 1688 | 1689 | var ru: [18]I64; (* struct rusage: two struct timeval first *) |
| 1689 | 1690 | 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 *) | |
| 1692 | 1693 | end; |
| 1693 | 1694 | return ru[0] * 1000000000 + ru[1] * 1000, ru[2] * 1000000000 + ru[3] * 1000; |
| 1694 | 1695 | end; |
| @@ -1699,7 +1700,7 @@ | ||
| 1699 | 1700 | proc limit*(which: INT): (I64, I64, INT); |
| 1700 | 1701 | var r: [2]I64; err: INT; |
| 1701 | 1702 | 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 *) | |
| 1703 | 1704 | return r[0], r[1], err; |
| 1704 | 1705 | end; |
| 1705 | 1706 | |
| @@ -1709,20 +1710,20 @@ | ||
| 1709 | 1710 | var r: [2]I64; |
| 1710 | 1711 | begin |
| 1711 | 1712 | r := [soft, hard]; |
| 1712 | - return SYSCALL(160, which, ADR(r)); (* setrlimit *) | |
| 1713 | + return SYSTEM.SYSCALL(160, which, SYSTEM.ADR(r)); (* setrlimit *) | |
| 1713 | 1714 | end; |
| 1714 | 1715 | |
| 1715 | 1716 | (* Moves the program pid, or this one if pid is 0, to the process group |
| 1716 | 1717 | group, or to a new one it leads if group is 0. *) |
| 1717 | 1718 | proc setGroup*(pid, group: INT): INT; |
| 1718 | 1719 | begin |
| 1719 | - return SYSCALL(109, pid, group); (* setpgid *) | |
| 1720 | + return SYSTEM.SYSCALL(109, pid, group); (* setpgid *) | |
| 1720 | 1721 | end; |
| 1721 | 1722 | |
| 1722 | 1723 | (* The process group this program is in. *) |
| 1723 | 1724 | proc group*: INT; |
| 1724 | 1725 | begin |
| 1725 | - return SYSCALL(111); (* getpgrp *) | |
| 1726 | + return SYSTEM.SYSCALL(111); (* getpgrp *) | |
| 1726 | 1727 | end; |
| 1727 | 1728 | |
| 1728 | 1729 | (* Gives the keys of the terminal on fd, and its signals, to the process |
| @@ -1731,7 +1732,7 @@ | ||
| 1731 | 1732 | var g: I32; |
| 1732 | 1733 | begin |
| 1733 | 1734 | g := I32(group); |
| 1734 | - return SYSCALL(16, fd, 5410H, ADR(g)); (* TIOCSPGRP *) | |
| 1735 | + return SYSTEM.SYSCALL(16, fd, 5410H, SYSTEM.ADR(g)); (* TIOCSPGRP *) | |
| 1735 | 1736 | end; |
| 1736 | 1737 | |
| 1737 | 1738 | (* The process group the terminal on fd gives its keys to, or minus an |
| @@ -1739,7 +1740,7 @@ | ||
| 1739 | 1740 | proc foregroundOf*(fd: INT): INT; |
| 1740 | 1741 | var g: I32; r: INT; |
| 1741 | 1742 | begin |
| 1742 | - r := SYSCALL(16, fd, 540FH, ADR(g)); (* TIOCGPGRP *) | |
| 1743 | + r := SYSTEM.SYSCALL(16, fd, 540FH, SYSTEM.ADR(g)); (* TIOCGPGRP *) | |
| 1743 | 1744 | if r < 0 then return r; end; |
| 1744 | 1745 | return INT(g); |
| 1745 | 1746 | end; |
| @@ -1751,7 +1752,7 @@ | ||
| 1751 | 1752 | (* The ith directory of search, a list of them with : between, as PATH |
| 1752 | 1753 | is: dir, "." if it is empty, and where the next starts; -1 past the |
| 1753 | 1754 | last. *) |
| 1754 | -proc pathDir(search: []U8; i: INT): ([]U8, INT); | |
| 1755 | +proc pathDir(search: []const U8; i: INT): ([]const U8, INT); | |
| 1755 | 1756 | var j: INT; |
| 1756 | 1757 | begin |
| 1757 | 1758 | if i > LEN(search) then return "", -1; end; |
| @@ -1762,7 +1763,7 @@ | ||
| 1762 | 1763 | end; |
| 1763 | 1764 | |
| 1764 | 1765 | (* 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; | |
| 1766 | 1767 | var n: INT; |
| 1767 | 1768 | begin |
| 1768 | 1769 | n := LEN(dir) + 1 + LEN(name); |
| @@ -1775,7 +1776,7 @@ | ||
| 1775 | 1776 | end; |
| 1776 | 1777 | |
| 1777 | 1778 | (* 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; | |
| 1779 | 1780 | var i: INT; |
| 1780 | 1781 | begin |
| 1781 | 1782 | for i := 0 to LEN(name) - 1 do |
| @@ -1789,16 +1790,16 @@ | ||
| 1789 | 1790 | execvp does: each in turn, an empty one being the working directory. |
| 1790 | 1791 | It returns only if none could be run. It runs in spawn's child, after |
| 1791 | 1792 | 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; | |
| 1794 | 1795 | begin |
| 1795 | 1796 | 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 *) | |
| 1797 | 1798 | return; |
| 1798 | 1799 | end; |
| 1799 | 1800 | dir, i := pathDir(search, 0); |
| 1800 | 1801 | 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 *) | |
| 1802 | 1803 | dir, i := pathDir(search, i); |
| 1803 | 1804 | end; |
| 1804 | 1805 | end; |
| @@ -1808,8 +1809,8 @@ | ||
| 1808 | 1809 | directories of search that is no directory and that this user may |
| 1809 | 1810 | run. 0; or -2 (ENOENT) if there is none, or -13 (EACCES) if one is |
| 1810 | 1811 | 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; | |
| 1813 | 1814 | begin |
| 1814 | 1815 | if isPath(name) then |
| 1815 | 1816 | if not cstr(name, buf) then return -36; end; |
| @@ -1821,7 +1822,7 @@ | ||
| 1821 | 1822 | if joinPath(dir, name, buf) then |
| 1822 | 1823 | f, err := info(buf[0..LEN(dir) + 1 + LEN(name)]); |
| 1823 | 1824 | 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 *) | |
| 1825 | 1826 | r := -13; (* EACCES *) |
| 1826 | 1827 | end; |
| 1827 | 1828 | end; |
| @@ -1837,8 +1838,8 @@ | ||
| 1837 | 1838 | var n, i, size: INT; |
| 1838 | 1839 | begin |
| 1839 | 1840 | 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 *) | |
| 1842 | 1843 | size := n; |
| 1843 | 1844 | repeat INC(i); size := size div 10; until size = 0; |
| 1844 | 1845 | name[i] := 0; |
| @@ -1850,7 +1851,7 @@ | ||
| 1850 | 1851 | program exec starts. It runs in spawn's child, after the fork, so it |
| 1851 | 1852 | takes no memory: it closes the runs between the fds kept, the lowest |
| 1852 | 1853 | first, each with one close_range. *) |
| 1853 | -proc closeAllBut(keep: []INT); | |
| 1854 | +proc closeAllBut(keep: []const INT); | |
| 1854 | 1855 | var lo, next, i: INT; |
| 1855 | 1856 | begin |
| 1856 | 1857 | lo := 3; |
| @@ -1860,10 +1861,10 @@ | ||
| 1860 | 1861 | if (keep[i] >= lo) and ((next < 0) or (keep[i] < next)) then next := keep[i]; end; |
| 1861 | 1862 | end; |
| 1862 | 1863 | 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 *) | |
| 1864 | 1865 | 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 *) | |
| 1867 | 1868 | lo := next + 1; |
| 1868 | 1869 | end; |
| 1869 | 1870 | until next < 0; |
| @@ -1874,30 +1875,30 @@ | ||
| 1874 | 1875 | terminal's foreground; then its standard input, output and error, |
| 1875 | 1876 | each p.fds names over the terminal's; then its working directory, |
| 1876 | 1877 | 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; | |
| 1878 | 1879 | var fd, i, r: INT; |
| 1879 | 1880 | begin |
| 1880 | 1881 | 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 *) | |
| 1883 | 1884 | if fd < 0 then return fd; end; |
| 1884 | - r := SYSCALL(16, fd, 540EH, 0); (* TIOCSCTTY *) | |
| 1885 | + r := SYSTEM.SYSCALL(16, fd, 540EH, 0); (* TIOCSCTTY *) | |
| 1885 | 1886 | 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 *) | |
| 1887 | 1888 | 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); | |
| 1890 | 1891 | end; |
| 1891 | - if p.foreground then _ := foreground(0, SYSCALL(111)); end; (* getpgrp *) | |
| 1892 | + if p.foreground then _ := foreground(0, SYSTEM.SYSCALL(111)); end; (* getpgrp *) | |
| 1892 | 1893 | end; |
| 1893 | 1894 | for i := 0 to 2 do |
| 1894 | 1895 | if p.fds[i] = i then |
| 1895 | 1896 | _ := keepOnExec(i, true); (* dup2 of a file onto itself would leave it closed on exec *) |
| 1896 | 1897 | elsif p.fds[i] # 0 then |
| 1897 | - _ := SYSCALL(33, p.fds[i], i); (* dup2 *) | |
| 1898 | + _ := SYSTEM.SYSCALL(33, p.fds[i], i); (* dup2 *) | |
| 1898 | 1899 | end; |
| 1899 | 1900 | 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 *) | |
| 1901 | 1902 | return 0; |
| 1902 | 1903 | end; |
| 1903 | 1904 | |
| @@ -1906,7 +1907,7 @@ | ||
| 1906 | 1907 | proc ignored*(sig: INT): BOOL; |
| 1907 | 1908 | var act: [4]U64; (* struct sigaction *) |
| 1908 | 1909 | begin |
| 1909 | - _ := SYSCALL(13, sig, 0, ADR(act), 8); (* rt_sigaction *) | |
| 1910 | + _ := SYSTEM.SYSCALL(13, sig, 0, SYSTEM.ADR(act), 8); (* rt_sigaction *) | |
| 1910 | 1911 | return act[0] = 1; |
| 1911 | 1912 | end; |
| 1912 | 1913 | |
| @@ -1919,13 +1920,13 @@ | ||
| 1919 | 1920 | proc spawn*(p: Program): INT; |
| 1920 | 1921 | var |
| 1921 | 1922 | 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; | |
| 1923 | 1924 | begin |
| 1924 | 1925 | if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| 1925 | 1926 | if (p.tty # 0) and (ptyName(p.tty, name) # 0) then return -25; end; (* ENOTTY *) |
| 1926 | 1927 | none := nil; |
| 1927 | 1928 | 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)); | |
| 1929 | 1930 | else |
| 1930 | 1931 | argv, size := argsAndEnv(p.args, p.env, environment()); |
| 1931 | 1932 | end; |
| @@ -1935,26 +1936,26 @@ | ||
| 1935 | 1936 | r := find(p.path, search, a); |
| 1936 | 1937 | if r < 0 then munmap(^U8(argv), size); return r; end; |
| 1937 | 1938 | 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 *) | |
| 1940 | 1941 | 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 *) | |
| 1942 | 1943 | closeAllBut(p.more); |
| 1943 | 1944 | 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 *) | |
| 1945 | 1946 | 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 *) | |
| 1947 | 1948 | run(p.path, search, a, argv, argv + (LEN(p.args) + 1)); |
| 1948 | - _ := SYSCALL(231, 127); (* exit *) | |
| 1949 | + _ := SYSTEM.SYSCALL(231, 127); (* exit *) | |
| 1949 | 1950 | end; |
| 1950 | 1951 | if (pid > 0) and (p.tty = 0) then |
| 1951 | 1952 | (* as the program does, for whichever of the two runs first *) |
| 1952 | 1953 | 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; | |
| 1955 | 1956 | if p.foreground then _ := foreground(0, g); end; |
| 1956 | 1957 | end; |
| 1957 | - _ := SYSCALL(14, 2, ADR(old), 0, 8); | |
| 1958 | + _ := SYSTEM.SYSCALL(14, 2, SYSTEM.ADR(old), 0, 8); | |
| 1958 | 1959 | munmap(^U8(argv), size); |
| 1959 | 1960 | return pid; |
| 1960 | 1961 | end; |
| @@ -1971,7 +1972,7 @@ | ||
| 1971 | 1972 | proc exec*(p: Program): INT; |
| 1972 | 1973 | var |
| 1973 | 1974 | 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; | |
| 1975 | 1976 | begin |
| 1976 | 1977 | if not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| 1977 | 1978 | if (p.tty # 0) and (ptyName(p.tty, name) # 0) then return -25; end; (* ENOTTY *) |
| @@ -1981,7 +1982,7 @@ | ||
| 1981 | 1982 | if r < 0 then return r; end; |
| 1982 | 1983 | none := nil; |
| 1983 | 1984 | 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)); | |
| 1985 | 1986 | else |
| 1986 | 1987 | argv, size := argsAndEnv(p.args, p.env, environment()); |
| 1987 | 1988 | end; |
| @@ -1994,16 +1995,16 @@ | ||
| 1994 | 1995 | (* every signal as it is at first and none blocked, as spawn |
| 1995 | 1996 | gives them, each kept to give back if execve fails *) |
| 1996 | 1997 | 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 *) | |
| 1998 | 1999 | 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; | |
| 2001 | 2002 | 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); | |
| 2007 | 2008 | end; |
| 2008 | 2009 | munmap(^U8(argv), size); |
| 2009 | 2010 | return r; |
| @@ -2014,14 +2015,14 @@ | ||
| 2014 | 2015 | kernel's execve does and a shell wants: no search, and every fd and |
| 2015 | 2016 | signal as it is, but that a handled signal does what it does at |
| 2016 | 2017 | 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; | |
| 2018 | 2019 | var a: [4096]U8; argv: ^^U8; none: ^U8; size, r: INT; |
| 2019 | 2020 | begin |
| 2020 | 2021 | if not cstr(path, a) then return -36; end; (* ENAMETOOLONG *) |
| 2021 | 2022 | none := nil; |
| 2022 | - argv, size := argsAndEnv(args, env, ADR(none)); | |
| 2023 | + argv, size := argsAndEnv(args, env, SYSTEM.ADR(none)); | |
| 2023 | 2024 | 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 *) | |
| 2025 | 2026 | munmap(^U8(argv), size); |
| 2026 | 2027 | return r; |
| 2027 | 2028 | end; |
| @@ -2030,7 +2031,7 @@ | ||
| 2030 | 2031 | proc waitFor(pid, options: INT): (INT, Status, INT); |
| 2031 | 2032 | var status: I32; r: INT; |
| 2032 | 2033 | begin |
| 2033 | - r := SYSCALL(61, pid, ADR(status), options, 0); (* wait4 *) | |
| 2034 | + r := SYSTEM.SYSCALL(61, pid, SYSTEM.ADR(status), options, 0); (* wait4 *) | |
| 2034 | 2035 | if r <= 0 then return r, running, 0; end; |
| 2035 | 2036 | if status & 7FH = 0 then return r, exited, INT(status) shr 8 & 0FFH; end; |
| 2036 | 2037 | if status & 0FFH = 7FH then return r, stopped, INT(status) shr 8 & 0FFH; end; |
| @@ -2062,14 +2063,14 @@ | ||
| 2062 | 2063 | errno. *) |
| 2063 | 2064 | proc kill*(pid, signal: INT): INT; |
| 2064 | 2065 | begin |
| 2065 | - return SYSCALL(62, pid, signal); | |
| 2066 | + return SYSTEM.SYSCALL(62, pid, signal); | |
| 2066 | 2067 | end; |
| 2067 | 2068 | |
| 2068 | 2069 | (* Catches the signals sigs: blocks them, so that they don't do what |
| 2069 | 2070 | they would, and gives them on an fd, which a later catch adds to and |
| 2070 | 2071 | gives again; or minus an errno. Only the thread that catches them |
| 2071 | 2072 | 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; | |
| 2073 | 2074 | var m: U64; i, fd: INT; |
| 2074 | 2075 | begin |
| 2075 | 2076 | m := caughtSigs; |
| @@ -2082,8 +2083,8 @@ | ||
| 2082 | 2083 | end; |
| 2083 | 2084 | fd := -1; |
| 2084 | 2085 | 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 *) | |
| 2087 | 2088 | if fd < 0 then return fd; end; |
| 2088 | 2089 | caughtSigs := m; |
| 2089 | 2090 | sigFd := fd; |
| @@ -2110,11 +2111,11 @@ | ||
| 2110 | 2111 | if caughtSigs & bit # 0 then |
| 2111 | 2112 | caughtSigs := caughtSigs & ~bit; |
| 2112 | 2113 | 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 *) | |
| 2115 | 2116 | end; |
| 2116 | 2117 | 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 *) | |
| 2118 | 2119 | end; |
| 2119 | 2120 | |
| 2120 | 2121 | (* Returns from a signal handler, as the kernel asks: rt_sigreturn, |
| @@ -2130,7 +2131,7 @@ | ||
| 2130 | 2131 | program, perhaps while Out or Heap holds its lock. *) |
| 2131 | 2132 | proc onNoted(sig: INT); |
| 2132 | 2133 | begin |
| 2133 | - _ := XCHG(ADR(noted[sig]), 1); | |
| 2134 | + _ := XCHG(noted[sig], 1); | |
| 2134 | 2135 | end; |
| 2135 | 2136 | |
| 2136 | 2137 | (* Takes the signal sig away from what it would do: it is noted, for |
| @@ -2146,7 +2147,7 @@ | ||
| 2146 | 2147 | return -22; (* EINVAL *) |
| 2147 | 2148 | end; |
| 2148 | 2149 | 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 *) | |
| 2150 | 2151 | end; |
| 2151 | 2152 | |
| 2152 | 2153 | (* Whether the signal sig, which handle took, came since the last time |
| @@ -2154,7 +2155,7 @@ | ||
| 2154 | 2155 | proc came*(sig: INT): BOOL; |
| 2155 | 2156 | begin |
| 2156 | 2157 | 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; | |
| 2158 | 2159 | end; |
| 2159 | 2160 | |
| 2160 | 2161 | (* A copy of this program, which goes on from here: 0 in the copy, its |
| @@ -2164,7 +2165,7 @@ | ||
| 2164 | 2165 | first. *) |
| 2165 | 2166 | proc fork*: INT; |
| 2166 | 2167 | begin |
| 2167 | - return SYSCALL(57); (* fork *) | |
| 2168 | + return SYSTEM.SYSCALL(57); (* fork *) | |
| 2168 | 2169 | end; |
| 2169 | 2170 | |
| 2170 | 2171 | (* A new session and process group, led by this program, with no |
| @@ -2173,19 +2174,19 @@ | ||
| 2173 | 2174 | doesn't). *) |
| 2174 | 2175 | proc setsid*: INT; |
| 2175 | 2176 | begin |
| 2176 | - return SYSCALL(112); (* setsid *) | |
| 2177 | + return SYSTEM.SYSCALL(112); (* setsid *) | |
| 2177 | 2178 | end; |
| 2178 | 2179 | |
| 2179 | 2180 | (* Gives the processor to another thread. *) |
| 2180 | 2181 | proc yield*; |
| 2181 | 2182 | begin |
| 2182 | - _ := SYSCALL(24); | |
| 2183 | + _ := SYSTEM.SYSCALL(24); | |
| 2183 | 2184 | end; |
| 2184 | 2185 | |
| 2185 | 2186 | (* Ends the program, at once, with status. *) |
| 2186 | 2187 | proc exit*(status: INT); |
| 2187 | 2188 | begin |
| 2188 | - _ := SYSCALL(231, status); | |
| 2189 | + _ := SYSTEM.SYSCALL(231, status); | |
| 2189 | 2190 | end; |
| 2190 | 2191 | |
| 2191 | 2192 | (* The test of programs: one on a pseudo-terminal of 100 by 30 prints |
| @@ -2339,7 +2340,7 @@ | ||
| 2339 | 2340 | proc testShell; |
| 2340 | 2341 | var |
| 2341 | 2342 | 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; | |
| 2343 | 2344 | begin |
| 2344 | 2345 | r, w := pipe(); |
| 2345 | 2346 | if w < 0 then exit(2); end; |
| @@ -2459,16 +2460,16 @@ | ||
| 2459 | 2460 | random(x); |
| 2460 | 2461 | random(y); |
| 2461 | 2462 | 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) | |
| 2463 | 2464 | or (s.data[0] # 10) or (s.data[2] # 0) or (s.data[3] # 255) then |
| 2464 | 2465 | exit(2); |
| 2465 | 2466 | 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) | |
| 2467 | 2468 | or (s6.data[0] # 0) or (s6.data[5] # 1) or (s6.data[6] # 0ABH) or (s6.data[7] # 0CDH) |
| 2468 | 2469 | or (s6.data[18] # 0) or (s6.data[19] # 0FFH) then |
| 2469 | 2470 | exit(2); |
| 2470 | 2471 | 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; | |
| 2472 | 2473 | if (connectTcp("1.2.3", 80) # -22) or (connectTcp("1.2.3.256", 80) # -22) or (connectTcp("1::2::3", 80) # -22) |
| 2473 | 2474 | or (connectTcp("1:2:3:4:5:6:7:8:9", 80) # -22) or (connectTcp("1:", 80) # -22) |
| 2474 | 2475 | or (connectTcp("12345::", 80) # -22) or (connectTcp("::1", 65536) # -22) then |
| @@ -2550,7 +2551,7 @@ | ||
| 2550 | 2551 | (* The test of what a program asks of itself: a signal ignored or not, |
| 2551 | 2552 | an environment variable unset or empty, and the processors. *) |
| 2552 | 2553 | proc testProcess; |
| 2553 | -var v: []U8; found: BOOL; | |
| 2554 | +var v: []const U8; found: BOOL; | |
| 2554 | 2555 | begin |
| 2555 | 2556 | if (ignore(sigUsr1, true) # 0) or not ignored(sigUsr1) then exit(2); end; |
| 2556 | 2557 | if (ignore(sigUsr1, false) # 0) or ignored(sigUsr1) then exit(2); end; |
| @@ -2691,7 +2692,7 @@ | ||
| 2691 | 2692 | directory made, listed and emptied; no terminal; a socket, sent to |
| 2692 | 2693 | after its end; programs; time and the network. *) |
| 2693 | 2694 | 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; | |
| 2695 | 2696 | begin |
| 2696 | 2697 | testPoll(); |
| 2697 | 2698 | fd := create("/tmp/raz-sys-test"); |
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | status holds, which every Unix encodes alike. *) |
| 17 | 17 | module Sys; |
| 18 | 18 | import C, CAbi; |
| 19 | +import SYSTEM; | |
| 19 | 20 | |
| 20 | 21 | const |
| 21 | 22 | stdin* = 0; (* standard input's file descriptor *) |
| @@ -101,11 +102,11 @@ | ||
| 101 | 102 | |
| 102 | 103 | (* A program for spawn to start. *) |
| 103 | 104 | 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 *) | |
| 107 | 108 | 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 *) | |
| 109 | 110 | fds*: [3]INT; (* stdin, stdout, stderr; 0 for this program's *) |
| 110 | 111 | group*: INT; (* its group: 0 for this program's, -1 a new one *) |
| 111 | 112 | foreground*: BOOL; (* its group gets the terminal on standard input *) |
| @@ -213,16 +214,16 @@ | ||
| 213 | 214 | is to see. broke is set to 0 before the call. *) |
| 214 | 215 | proc again: BOOL; |
| 215 | 216 | begin |
| 216 | - return (failed() = -4) and (XCHG(ADR(broke), 0) = 0); | |
| 217 | + return (failed() = -4) and (XCHG(broke, 0) = 0); | |
| 217 | 218 | end; |
| 218 | 219 | |
| 219 | 220 | (* Writes s to the file descriptor fd; the number of bytes written, or |
| 220 | 221 | minus an errno. *) |
| 221 | -proc write*(fd: INT; s: []U8): INT; | |
| 222 | +proc write*(fd: INT; s: []const U8): INT; | |
| 222 | 223 | var r: INT; |
| 223 | 224 | begin |
| 224 | 225 | 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))); | |
| 226 | 227 | if r < 0 then return failed(); end; |
| 227 | 228 | return r; |
| 228 | 229 | end; |
| @@ -233,13 +234,13 @@ | ||
| 233 | 234 | var r: INT; |
| 234 | 235 | begin |
| 235 | 236 | 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))); | |
| 237 | 238 | if r < 0 then return failed(); end; |
| 238 | 239 | return r; |
| 239 | 240 | end; |
| 240 | 241 | |
| 241 | 242 | (* 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; | |
| 243 | 244 | begin |
| 244 | 245 | if LEN(path) >= LEN(buf) then return false; end; |
| 245 | 246 | COPY(buf, path); |
| @@ -267,33 +268,33 @@ | ||
| 267 | 268 | (* The file at path, opened as how asks: its file descriptor, closed in |
| 268 | 269 | a program exec starts, or minus an errno. A file it creates has the |
| 269 | 270 | 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; | |
| 271 | 272 | var buf: [4096]U8; r: INT; |
| 272 | 273 | begin |
| 273 | 274 | if executing in how then return -22; end; (* EINVAL: access asks it, open can't *) |
| 274 | 275 | 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)); | |
| 276 | 277 | if r < 0 then return failed(); end; |
| 277 | 278 | return r; |
| 278 | 279 | end; |
| 279 | 280 | |
| 280 | 281 | (* openMode with 644: a file it creates is readable by all, writable |
| 281 | 282 | by its owner. *) |
| 282 | -proc open*(path: []U8; how: Accesses): INT; | |
| 283 | +proc open*(path: []const U8; how: Accesses): INT; | |
| 283 | 284 | begin |
| 284 | 285 | return openMode(path, how, 1A4H); (* 644 *) |
| 285 | 286 | end; |
| 286 | 287 | |
| 287 | 288 | (* The file at path, opened for reading, closed in a program exec |
| 288 | 289 | starts. *) |
| 289 | -proc openRead*(path: []U8): INT; | |
| 290 | +proc openRead*(path: []const U8): INT; | |
| 290 | 291 | begin |
| 291 | 292 | return open(path, {reading}); |
| 292 | 293 | end; |
| 293 | 294 | |
| 294 | 295 | (* The file at path, made empty or new, opened for writing, closed in a |
| 295 | 296 | program exec starts. *) |
| 296 | -proc create*(path: []U8): INT; | |
| 297 | +proc create*(path: []const U8): INT; | |
| 297 | 298 | begin |
| 298 | 299 | return open(path, {writing, creating, truncating}); |
| 299 | 300 | end; |
| @@ -458,7 +459,7 @@ | ||
| 458 | 459 | var name: [4]U8; fd: I32; err: INT; |
| 459 | 460 | begin |
| 460 | 461 | _ := 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); | |
| 462 | 463 | if fd < 0 then return failed(); end; |
| 463 | 464 | if C.ftruncate(fd, I64(size)) # 0 then |
| 464 | 465 | err := failed(); (* before close can change errno *) |
| @@ -504,79 +505,79 @@ | ||
| 504 | 505 | end; |
| 505 | 506 | |
| 506 | 507 | (* 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; | |
| 508 | 509 | var a, b: [4096]U8; |
| 509 | 510 | begin |
| 510 | 511 | 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; | |
| 512 | 513 | return 0; |
| 513 | 514 | end; |
| 514 | 515 | |
| 515 | 516 | (* Removes the file at path; not a directory. *) |
| 516 | -proc remove*(path: []U8): INT; | |
| 517 | +proc remove*(path: []const U8): INT; | |
| 517 | 518 | var a: [4096]U8; |
| 518 | 519 | begin |
| 519 | 520 | 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; | |
| 521 | 522 | return 0; |
| 522 | 523 | end; |
| 523 | 524 | |
| 524 | 525 | (* 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; | |
| 526 | 527 | var a: [4096]U8; |
| 527 | 528 | begin |
| 528 | 529 | 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 *) | |
| 530 | 531 | return 0; |
| 531 | 532 | end; |
| 532 | 533 | |
| 533 | 534 | (* Makes a directory at path with the permission bits mode, less those |
| 534 | 535 | the umask takes away: 1C0H (700) for one only its owner may enter. Of |
| 535 | 536 | 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; | |
| 537 | 538 | var a: [4096]U8; |
| 538 | 539 | begin |
| 539 | 540 | 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; | |
| 541 | 542 | return 0; |
| 542 | 543 | end; |
| 543 | 544 | |
| 544 | 545 | (* Removes the directory at path, which must be empty. *) |
| 545 | -proc removeDir*(path: []U8): INT; | |
| 546 | +proc removeDir*(path: []const U8): INT; | |
| 546 | 547 | var a: [4096]U8; |
| 547 | 548 | begin |
| 548 | 549 | 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; | |
| 550 | 551 | return 0; |
| 551 | 552 | end; |
| 552 | 553 | |
| 553 | 554 | (* 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; | |
| 555 | 556 | var a: [4096]U8; |
| 556 | 557 | begin |
| 557 | 558 | 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; | |
| 559 | 560 | return 0; |
| 560 | 561 | end; |
| 561 | 562 | |
| 562 | 563 | (* Makes a fifo (a named pipe) at path with the permission bits mode, |
| 563 | 564 | 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; | |
| 565 | 566 | var a: [4096]U8; |
| 566 | 567 | begin |
| 567 | 568 | 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; | |
| 569 | 570 | return 0; |
| 570 | 571 | end; |
| 571 | 572 | |
| 572 | 573 | (* Sets the owner and group of what path names, following a symbolic |
| 573 | 574 | link: a user or group number, or -1 to leave it as it is. Only |
| 574 | 575 | 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; | |
| 576 | 577 | var a: [4096]U8; |
| 577 | 578 | begin |
| 578 | 579 | 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; | |
| 580 | 581 | return 0; |
| 581 | 582 | end; |
| 582 | 583 | |
| @@ -584,7 +585,7 @@ | ||
| 584 | 585 | was last read, to sec seconds and nsec nanoseconds since 1970, as a |
| 585 | 586 | program copying a file keeps its time: Info.seconds gives sec back, |
| 586 | 587 | whatever the time. *) |
| 587 | -proc setTime*(path: []U8; sec: I64; nsec: INT): INT; | |
| 588 | +proc setTime*(path: []const U8; sec: I64; nsec: INT): INT; | |
| 588 | 589 | var a: [4096]U8; t: [2]Timespec; |
| 589 | 590 | begin |
| 590 | 591 | if not cstr(path, a) then return -36; end; |
| @@ -592,14 +593,14 @@ | ||
| 592 | 593 | t[0].sec := sec; |
| 593 | 594 | t[0].nsec := nsec; |
| 594 | 595 | 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; | |
| 596 | 597 | return 0; |
| 597 | 598 | end; |
| 598 | 599 | |
| 599 | 600 | (* 0 if this user, by its real ids, may do with path what how asks: |
| 600 | 601 | reading, writing and executing; minus an errno, -13 (EACCES) if not. |
| 601 | 602 | 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; | |
| 603 | 604 | var a: [4096]U8; m: I32; |
| 604 | 605 | begin |
| 605 | 606 | if not cstr(path, a) then return -36; end; |
| @@ -607,7 +608,7 @@ | ||
| 607 | 608 | if reading in how then m := m | CAbi.rOk; end; |
| 608 | 609 | if writing in how then m := m | CAbi.wOk; end; |
| 609 | 610 | 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; | |
| 611 | 612 | return 0; |
| 612 | 613 | end; |
| 613 | 614 | |
| @@ -619,21 +620,21 @@ | ||
| 619 | 620 | end; |
| 620 | 621 | |
| 621 | 622 | (* Makes path a symbolic link to target. *) |
| 622 | -proc symlink*(target, path: []U8): INT; | |
| 623 | +proc symlink*(target, path: []const U8): INT; | |
| 623 | 624 | var a, b: [4096]U8; |
| 624 | 625 | begin |
| 625 | 626 | 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; | |
| 627 | 628 | return 0; |
| 628 | 629 | end; |
| 629 | 630 | |
| 630 | 631 | (* What the symbolic link at path names, good until the next call; and |
| 631 | 632 | 0, or minus an errno. *) |
| 632 | -proc readLink*(path: []U8): ([]U8, INT); | |
| 633 | +proc readLink*(path: []const U8): ([]const U8, INT); | |
| 633 | 634 | var a: [4096]U8; n: INT; |
| 634 | 635 | begin |
| 635 | 636 | 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))); | |
| 637 | 638 | if n < 0 then return "", failed(); end; |
| 638 | 639 | if n = LEN(linked) then return "", -36; end; (* it may be cut short *) |
| 639 | 640 | return linked[0..n], 0; |
| @@ -644,14 +645,14 @@ | ||
| 644 | 645 | (* The type of file a struct stat says, S_IFDIR, S_IFREG or another *) |
| 645 | 646 | proc fileType(st: Stat): INT; |
| 646 | 647 | 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; | |
| 648 | 649 | end; |
| 649 | 650 | |
| 650 | 651 | (* An Info from a struct stat, all but symlink. *) |
| 651 | 652 | proc fromStat(st: Stat): Info; |
| 652 | 653 | var i: Info; p: ^U8; |
| 653 | 654 | begin |
| 654 | - p := ^U8(ADR(st)); | |
| 655 | + p := ^U8(SYSTEM.ADR(st)); | |
| 655 | 656 | i.size := field(p, CAbi.stSizeAt, CAbi.stSizeLen); |
| 656 | 657 | i.dev := U64(field(p, CAbi.stDevAt, CAbi.stDevLen)); |
| 657 | 658 | i.ino := U64(field(p, CAbi.stInoAt, CAbi.stInoLen)); |
| @@ -670,13 +671,13 @@ | ||
| 670 | 671 | (* The size of what path names, whether it is a directory or a regular |
| 671 | 672 | file, following a symbolic link, and whether path is one; and 0, or |
| 672 | 673 | minus an errno. *) |
| 673 | -proc info*(path: []U8): (Info, INT); | |
| 674 | +proc info*(path: []const U8): (Info, INT); | |
| 674 | 675 | var a: [4096]U8; st: Stat; i: Info; isLink: BOOL; |
| 675 | 676 | begin |
| 676 | 677 | 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; | |
| 678 | 679 | 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; | |
| 680 | 681 | i := fromStat(st); |
| 681 | 682 | i.symlink := isLink; |
| 682 | 683 | return i, 0; |
| @@ -685,11 +686,11 @@ | ||
| 685 | 686 | (* info of path itself: if it is a symbolic link, of the link, not of |
| 686 | 687 | what it names, so that symlink is true, dir and file false, and the |
| 687 | 688 | size the length of what it names. *) |
| 688 | -proc linkInfo*(path: []U8): (Info, INT); | |
| 689 | +proc linkInfo*(path: []const U8): (Info, INT); | |
| 689 | 690 | var a: [4096]U8; st: Stat; i: Info; |
| 690 | 691 | begin |
| 691 | 692 | 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; | |
| 693 | 694 | i := fromStat(st); |
| 694 | 695 | i.symlink := fileType(st) = CAbi.sIflnk; |
| 695 | 696 | return i, 0; |
| @@ -699,18 +700,18 @@ | ||
| 699 | 700 | proc infoOf*(fd: INT): (Info, INT); |
| 700 | 701 | var st: Stat; i: Info; |
| 701 | 702 | 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; | |
| 703 | 704 | return fromStat(st), 0; |
| 704 | 705 | end; |
| 705 | 706 | |
| 706 | 707 | (* The bytes free to an ordinary user on path's file system, and the |
| 707 | 708 | bytes in all. *) |
| 708 | -proc space*(path: []U8): (I64, I64, INT); | |
| 709 | +proc space*(path: []const U8): (I64, I64, INT); | |
| 709 | 710 | var a: [4096]U8; st: [(CAbi.statvfsLen + 7) div 8]U64; p: ^U8; unit: I64; |
| 710 | 711 | begin |
| 711 | 712 | 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; | |
| 714 | 715 | unit := field(p, CAbi.fFrsizeAt, CAbi.fFrsizeLen); |
| 715 | 716 | return field(p, CAbi.fBavailAt, CAbi.fBavailLen) * unit, field(p, CAbi.fBlocksAt, CAbi.fBlocksLen) * unit, 0; |
| 716 | 717 | end; |
| @@ -728,19 +729,19 @@ | ||
| 728 | 729 | end; |
| 729 | 730 | |
| 730 | 731 | (* 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; | |
| 732 | 733 | var a: [4096]U8; |
| 733 | 734 | begin |
| 734 | 735 | d.kind := unknown; |
| 735 | 736 | 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])); | |
| 737 | 738 | if d.d = nil then return failed(); end; |
| 738 | 739 | return 0; |
| 739 | 740 | end; |
| 740 | 741 | |
| 741 | 742 | (* The next name in the directory, good until the next call, but . and |
| 742 | 743 | .., in no order; false at the end. *) |
| 743 | -proc nextEntry*(var d: Dir): ([]U8, BOOL); | |
| 744 | +proc nextEntry*(var d: Dir): ([]const U8, BOOL); | |
| 744 | 745 | var e: ^U8; n: INT; |
| 745 | 746 | begin |
| 746 | 747 | while true do |
| @@ -775,16 +776,16 @@ | ||
| 775 | 776 | proc rawMode*(fd: INT): BOOL; |
| 776 | 777 | var t: [256]U8; |
| 777 | 778 | 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; | |
| 779 | 780 | 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; | |
| 782 | 783 | end; |
| 783 | 784 | |
| 784 | 785 | (* The terminal on fd as rawMode found it. *) |
| 785 | 786 | proc restoreMode*(fd: INT); |
| 786 | 787 | begin |
| 787 | - _ := C.tcsetattr(I32(fd), CAbi.tcsanow, ADR(saved[0])); | |
| 788 | + _ := C.tcsetattr(I32(fd), CAbi.tcsanow, SYSTEM.ADR(saved[0])); | |
| 788 | 789 | end; |
| 789 | 790 | |
| 790 | 791 | (* The modes of the terminal on fd, as a shell keeps them for each job; |
| @@ -792,7 +793,7 @@ | ||
| 792 | 793 | proc getMode*(fd: INT): (Mode, INT); |
| 793 | 794 | var m: Mode; |
| 794 | 795 | 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; | |
| 796 | 797 | return m, 0; |
| 797 | 798 | end; |
| 798 | 799 | |
| @@ -800,7 +801,7 @@ | ||
| 800 | 801 | is sent: 0, or minus an errno. *) |
| 801 | 802 | proc setMode*(fd: INT; m: Mode): INT; |
| 802 | 803 | 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; | |
| 804 | 805 | return 0; |
| 805 | 806 | end; |
| 806 | 807 | |
| @@ -809,7 +810,7 @@ | ||
| 809 | 810 | proc termSize*(fd: INT): (INT, INT); |
| 810 | 811 | var w: Winsize; |
| 811 | 812 | 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 | |
| 813 | 814 | return 80, 24; |
| 814 | 815 | end; |
| 815 | 816 | return INT(w.cols), INT(w.rows); |
| @@ -821,8 +822,8 @@ | ||
| 821 | 822 | var p: Pollfd; r: I32; |
| 822 | 823 | begin |
| 823 | 824 | 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(); | |
| 826 | 827 | return r > 0; |
| 827 | 828 | end; |
| 828 | 829 | |
| @@ -830,7 +831,7 @@ | ||
| 830 | 831 | proc time(clock: I32): I64; |
| 831 | 832 | var t: Timespec; |
| 832 | 833 | begin |
| 833 | - _ := C.clock_gettime(clock, ^U8(ADR(t))); | |
| 834 | + _ := C.clock_gettime(clock, ^U8(SYSTEM.ADR(t))); | |
| 834 | 835 | return t.sec * 1000000000 + t.nsec; |
| 835 | 836 | end; |
| 836 | 837 | |
| @@ -854,7 +855,7 @@ | ||
| 854 | 855 | at := clock() + I64(ms) * 1000000; |
| 855 | 856 | t := {sec: at div 1000000000, nsec: at mod 1000000000}; |
| 856 | 857 | (* 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; | |
| 858 | 859 | end; |
| 859 | 860 | |
| 860 | 861 | (* Ends the program: random bytes can't be faked. *) |
| @@ -873,7 +874,7 @@ | ||
| 873 | 874 | begin |
| 874 | 875 | n := 0; |
| 875 | 876 | 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); | |
| 877 | 878 | if r > 0 then INC(n, r); |
| 878 | 879 | elsif (r >= 0) or (failed() # errIntr) then noRandom(); (* r = 0 can't be, and is no progress *) |
| 879 | 880 | end; |
| @@ -891,7 +892,7 @@ | ||
| 891 | 892 | if fd < 0 then return failed(); end; |
| 892 | 893 | if serving then |
| 893 | 894 | 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); | |
| 895 | 896 | r := C.bind(fd, a, U32(size)); |
| 896 | 897 | if (r = 0) and (kind = CAbi.sockStream) then (* a stream socket takes connections; *) |
| 897 | 898 | r := C.listen(fd, 4096); (* one of datagrams only receives *) |
| @@ -925,7 +926,7 @@ | ||
| 925 | 926 | -36 (ENAMETOOLONG) if it is too long. A path that starts with a zero |
| 926 | 927 | byte is one of Linux's abstract names, which has no file and no |
| 927 | 928 | 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; | |
| 929 | 930 | var p: ^U8; |
| 930 | 931 | begin |
| 931 | 932 | if LEN(path) >= CAbi.sunPathLen then return -36; end; |
| @@ -937,40 +938,40 @@ | ||
| 937 | 938 | end; |
| 938 | 939 | |
| 939 | 940 | (* A stream socket connected to the Unix socket at path. *) |
| 940 | -proc connect*(path: []U8): INT; | |
| 941 | +proc connect*(path: []const U8): INT; | |
| 941 | 942 | var a: Sockaddr; size: INT; |
| 942 | 943 | begin |
| 943 | - size := unixAddr(path, ADR(a)); | |
| 944 | + size := unixAddr(path, SYSTEM.ADR(a)); | |
| 944 | 945 | 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); | |
| 946 | 947 | end; |
| 947 | 948 | |
| 948 | 949 | (* A stream socket made at path, which must not be there yet, taking |
| 949 | 950 | connections. *) |
| 950 | -proc listen*(path: []U8): INT; | |
| 951 | +proc listen*(path: []const U8): INT; | |
| 951 | 952 | var a: Sockaddr; size: INT; |
| 952 | 953 | begin |
| 953 | - size := unixAddr(path, ADR(a)); | |
| 954 | + size := unixAddr(path, SYSTEM.ADR(a)); | |
| 954 | 955 | 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); | |
| 956 | 957 | end; |
| 957 | 958 | |
| 958 | 959 | (* addr, an IPv4 or IPv6 address as numbers, and port, in a: the size |
| 959 | 960 | of its struct sockaddr_in or sockaddr_in6, or 0 if either is |
| 960 | 961 | wrong. *) |
| 961 | -proc inetAddr(addr: []U8; port: INT; a: ^Sockaddr): INT; | |
| 962 | +proc inetAddr(addr: []const U8; port: INT; a: ^Sockaddr): INT; | |
| 962 | 963 | var s: [64]U8; b: [16]U8; p: ^U8; at, size: INT; |
| 963 | 964 | begin |
| 964 | 965 | if (port < 0) or (port > 65535) or not cstr(addr, s) then return 0; end; |
| 965 | 966 | p := ^U8(a); |
| 966 | 967 | (* into b first, since musl's inet_pton leaves what it read of an |
| 967 | 968 | 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 | |
| 969 | 970 | size := CAbi.sockaddrInLen; |
| 970 | 971 | setFamily(p, CAbi.afInet, size); |
| 971 | 972 | COPY(p[CAbi.sinAddrAt..CAbi.sinAddrAt + 4], b[0..4]); |
| 972 | 973 | 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 | |
| 974 | 975 | size := CAbi.sockaddrIn6Len; |
| 975 | 976 | setFamily(p, CAbi.afInet6, size); |
| 976 | 977 | COPY(p[CAbi.sin6AddrAt..CAbi.sin6AddrAt + 16], b); |
| @@ -994,37 +995,37 @@ | ||
| 994 | 995 | |
| 995 | 996 | (* A socket of kind at addr and port, as socket makes it; -22 (EINVAL) |
| 996 | 997 | 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; | |
| 998 | 999 | var a: Sockaddr; size: INT; |
| 999 | 1000 | begin |
| 1000 | - size := inetAddr(addr, port, ADR(a)); | |
| 1001 | + size := inetAddr(addr, port, SYSTEM.ADR(a)); | |
| 1001 | 1002 | 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); | |
| 1003 | 1004 | end; |
| 1004 | 1005 | |
| 1005 | 1006 | (* A stream socket connected to port at addr, an IPv4 or IPv6 address |
| 1006 | 1007 | as numbers. *) |
| 1007 | -proc connectTcp*(addr: []U8; port: INT): INT; | |
| 1008 | +proc connectTcp*(addr: []const U8; port: INT): INT; | |
| 1008 | 1009 | begin |
| 1009 | 1010 | return inet(addr, port, CAbi.sockStream, false); |
| 1010 | 1011 | end; |
| 1011 | 1012 | |
| 1012 | 1013 | (* 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; | |
| 1014 | 1015 | begin |
| 1015 | 1016 | return inet(addr, port, CAbi.sockDgram, false); |
| 1016 | 1017 | end; |
| 1017 | 1018 | |
| 1018 | 1019 | (* A stream socket taking connections on port at addr; "0.0.0.0" or |
| 1019 | 1020 | "::" is every address the machine has. *) |
| 1020 | -proc listenTcp*(addr: []U8; port: INT): INT; | |
| 1021 | +proc listenTcp*(addr: []const U8; port: INT): INT; | |
| 1021 | 1022 | begin |
| 1022 | 1023 | return inet(addr, port, CAbi.sockStream, true); |
| 1023 | 1024 | end; |
| 1024 | 1025 | |
| 1025 | 1026 | (* A socket of datagrams on port at addr, from anyone, for receive and |
| 1026 | 1027 | reply. *) |
| 1027 | -proc listenUdp*(addr: []U8; port: INT): INT; | |
| 1028 | +proc listenUdp*(addr: []const U8; port: INT): INT; | |
| 1028 | 1029 | begin |
| 1029 | 1030 | return inet(addr, port, CAbi.sockDgram, true); |
| 1030 | 1031 | end; |
| @@ -1055,16 +1056,16 @@ | ||
| 1055 | 1056 | begin |
| 1056 | 1057 | r := {unix: false, ipv6: false}; |
| 1057 | 1058 | 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; | |
| 1060 | 1061 | if familyOf(p) = CAbi.afUnix then (* ask who made the connection *) |
| 1061 | 1062 | 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 | |
| 1063 | 1064 | return r, failed(); |
| 1064 | 1065 | end; |
| 1065 | 1066 | 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)); | |
| 1068 | 1069 | else |
| 1069 | 1070 | r.port := portOf(p); |
| 1070 | 1071 | if familyOf(p) = CAbi.afInet6 then |
| @@ -1083,7 +1084,7 @@ | ||
| 1083 | 1084 | proc socketPair*: (INT, INT, INT); |
| 1084 | 1085 | var fds: [2]I32; |
| 1085 | 1086 | 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 | |
| 1087 | 1088 | return -1, -1, failed(); |
| 1088 | 1089 | end; |
| 1089 | 1090 | return INT(fds[0]), INT(fds[1]), 0; |
| @@ -1092,22 +1093,22 @@ | ||
| 1092 | 1093 | (* Writes s to the socket fd, as write does, but returns -32 (EPIPE) |
| 1093 | 1094 | where write would stop the program with SIGPIPE: when the other end |
| 1094 | 1095 | has closed it. *) |
| 1095 | -proc send*(fd: INT; s: []U8): INT; | |
| 1096 | +proc send*(fd: INT; s: []const U8): INT; | |
| 1096 | 1097 | var r: INT; |
| 1097 | 1098 | begin |
| 1098 | 1099 | 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); | |
| 1100 | 1101 | if r < 0 then return failed(); end; |
| 1101 | 1102 | return r; |
| 1102 | 1103 | end; |
| 1103 | 1104 | |
| 1104 | 1105 | (* send, but never waits: returns -11 (EAGAIN) where send would wait for |
| 1105 | 1106 | 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; | |
| 1107 | 1108 | var r: INT; |
| 1108 | 1109 | begin |
| 1109 | 1110 | 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); | |
| 1111 | 1112 | if r < 0 then return failed(); end; |
| 1112 | 1113 | return r; |
| 1113 | 1114 | end; |
| @@ -1137,8 +1138,8 @@ | ||
| 1137 | 1138 | if fds[i].write then events := events | CAbi.pollout; end; |
| 1138 | 1139 | list[i] := {fd: I32(fds[i].fd), events: events}; |
| 1139 | 1140 | 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(); | |
| 1142 | 1143 | e := 0; |
| 1143 | 1144 | if r < 0 then e := failed(); end; |
| 1144 | 1145 | for i := 0 to n - 1 do |
| @@ -1154,7 +1155,7 @@ | ||
| 1154 | 1155 | reached its end or failed, so that a read or a write won't wait; -1 |
| 1155 | 1156 | if none has. ms < 0 waits as long as it takes. At most 64 fds in |
| 1156 | 1157 | all. *) |
| 1157 | -proc readyFor*(reads, writes: []INT; ms: INT): INT; | |
| 1158 | +proc readyFor*(reads, writes: []const INT; ms: INT): INT; | |
| 1158 | 1159 | var p: [64]Poll; ps: []Poll; n, i: INT; |
| 1159 | 1160 | begin |
| 1160 | 1161 | n := 0; |
| @@ -1181,7 +1182,7 @@ | ||
| 1181 | 1182 | (* The first of fds that has something to read within ms milliseconds, |
| 1182 | 1183 | or that has reached its end or failed, so that a read won't wait; -1 |
| 1183 | 1184 | 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; | |
| 1185 | 1186 | begin |
| 1186 | 1187 | return readyFor(fds, [], ms); |
| 1187 | 1188 | end; |
| @@ -1214,20 +1215,20 @@ | ||
| 1214 | 1215 | or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. |
| 1215 | 1216 | It starts to connect without waiting, then waits for the socket to |
| 1216 | 1217 | 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; | |
| 1218 | 1219 | var a: Sockaddr; size, r: INT; fd, err: I32; errSize: U32; |
| 1219 | 1220 | begin |
| 1220 | - size := inetAddr(addr, port, ADR(a)); | |
| 1221 | + size := inetAddr(addr, port, SYSTEM.ADR(a)); | |
| 1221 | 1222 | 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); | |
| 1223 | 1224 | if fd < 0 then return failed(); end; |
| 1224 | 1225 | 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; | |
| 1226 | 1227 | if r = -115 then (* EINPROGRESS *) |
| 1227 | 1228 | r := -110; |
| 1228 | 1229 | if readyFor([], [INT(fd)], ms) = INT(fd) then |
| 1229 | 1230 | 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 | |
| 1231 | 1232 | r := linux(-INT(err)); |
| 1232 | 1233 | else |
| 1233 | 1234 | r := failed(); |
| @@ -1245,8 +1246,8 @@ | ||
| 1245 | 1246 | var a: Sockaddr; size: U32; |
| 1246 | 1247 | begin |
| 1247 | 1248 | 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))); | |
| 1250 | 1251 | end; |
| 1251 | 1252 | |
| 1252 | 1253 | (* The next datagram to the socket fd, waiting for one: its first |
| @@ -1256,7 +1257,7 @@ | ||
| 1256 | 1257 | var p: Peer; size: U32; n: INT; |
| 1257 | 1258 | begin |
| 1258 | 1259 | 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)); | |
| 1260 | 1261 | if n < 0 then n := failed(); end; |
| 1261 | 1262 | p.size := INT(size); |
| 1262 | 1263 | return n, p; |
| @@ -1264,10 +1265,10 @@ | ||
| 1264 | 1265 | |
| 1265 | 1266 | (* Sends s, as one datagram, from the socket fd to peer, as receive |
| 1266 | 1267 | 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; | |
| 1268 | 1269 | var r: INT; |
| 1269 | 1270 | 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)); | |
| 1271 | 1272 | if r < 0 then return failed(); end; |
| 1272 | 1273 | return r; |
| 1273 | 1274 | end; |
| @@ -1275,17 +1276,17 @@ | ||
| 1275 | 1276 | (* Sends s, at least one byte, to the Unix socket fd, as send does, and |
| 1276 | 1277 | with it the files fds, at most 16, which the program that receives |
| 1277 | 1278 | 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; | |
| 1279 | 1280 | var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; sent: ^I32; i, r, size: INT; |
| 1280 | 1281 | begin |
| 1281 | 1282 | 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))); | |
| 1285 | 1286 | setField(mp, CAbi.msgIovlenAt, CAbi.msgIovlenLen, 1); |
| 1286 | 1287 | if LEN(fds) > 0 then |
| 1287 | 1288 | (* a struct cmsghdr, its level and type ints, then the fds *) |
| 1288 | - cp := ^U8(ADR(c)); | |
| 1289 | + cp := ^U8(SYSTEM.ADR(c)); | |
| 1289 | 1290 | size := CAbi.cmsgDataAt + 4 * LEN(fds); |
| 1290 | 1291 | setField(cp, CAbi.cmsgLenAt, CAbi.cmsgLenLen, size); |
| 1291 | 1292 | setField(cp, CAbi.cmsgLevelAt, 4, CAbi.solSocket); |
| @@ -1308,10 +1309,10 @@ | ||
| 1308 | 1309 | proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); |
| 1309 | 1310 | var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; got: ^I32; n, k, i, size: INT; |
| 1310 | 1311 | 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))); | |
| 1315 | 1316 | setField(mp, CAbi.msgIovlenAt, CAbi.msgIovlenLen, 1); |
| 1316 | 1317 | setField(mp, CAbi.msgControlAt, SIZE(^U8), INT(cp)); |
| 1317 | 1318 | setField(mp, CAbi.msgControllenAt, CAbi.msgControllenLen, SIZE(Control)); |
| @@ -1336,7 +1337,7 @@ | ||
| 1336 | 1337 | |
| 1337 | 1338 | (* What errno err, or minus it, means, as the C library's strerror |
| 1338 | 1339 | says it. *) |
| 1339 | -proc errorText*(err: INT): []U8; | |
| 1340 | +proc errorText*(err: INT): []const U8; | |
| 1340 | 1341 | var s: ^U8; n, i: INT; |
| 1341 | 1342 | begin |
| 1342 | 1343 | if err < 0 then err := -err; end; |
| @@ -1353,11 +1354,11 @@ | ||
| 1353 | 1354 | |
| 1354 | 1355 | (* The value of the environment variable name and true, or "" and |
| 1355 | 1356 | 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); | |
| 1357 | 1358 | var a: [4096]U8; s: ^U8; n: INT; |
| 1358 | 1359 | begin |
| 1359 | 1360 | if not cstr(name, a) then return "", false; end; |
| 1360 | - s := C.getenv(ADR(a[0])); | |
| 1361 | + s := C.getenv(SYSTEM.ADR(a[0])); | |
| 1361 | 1362 | if s = nil then return "", false; end; |
| 1362 | 1363 | n := 0; |
| 1363 | 1364 | while s[n] # 0 do INC(n); end; |
| @@ -1365,8 +1366,8 @@ | ||
| 1365 | 1366 | end; |
| 1366 | 1367 | |
| 1367 | 1368 | (* 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; | |
| 1370 | 1371 | begin |
| 1371 | 1372 | v, _ := findEnv(name); |
| 1372 | 1373 | return v; |
| @@ -1374,7 +1375,7 @@ | ||
| 1374 | 1375 | |
| 1375 | 1376 | (* The environment's ith NAME=value, from 0, and true; "" and false |
| 1376 | 1377 | past the last. *) |
| 1377 | -proc envAt*(i: INT): ([]U8, BOOL); | |
| 1378 | +proc envAt*(i: INT): ([]const U8, BOOL); | |
| 1378 | 1379 | var e: ^^U8; s: ^U8; j, n: INT; |
| 1379 | 1380 | begin |
| 1380 | 1381 | if i < 0 then return "", false; end; |
| @@ -1390,21 +1391,21 @@ | ||
| 1390 | 1391 | |
| 1391 | 1392 | (* The working directory, good until the next call; and 0, or minus an |
| 1392 | 1393 | errno. *) |
| 1393 | -proc workDir*: ([]U8, INT); | |
| 1394 | +proc workDir*: ([]const U8, INT); | |
| 1394 | 1395 | var n: INT; |
| 1395 | 1396 | 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; | |
| 1397 | 1398 | n := 0; |
| 1398 | 1399 | while cwd[n] # 0 do INC(n); end; |
| 1399 | 1400 | return cwd[0..n], 0; |
| 1400 | 1401 | end; |
| 1401 | 1402 | |
| 1402 | 1403 | (* Makes path the working directory. *) |
| 1403 | -proc setWorkDir*(path: []U8): INT; | |
| 1404 | +proc setWorkDir*(path: []const U8): INT; | |
| 1404 | 1405 | var a: [4096]U8; |
| 1405 | 1406 | begin |
| 1406 | 1407 | 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; | |
| 1408 | 1409 | return 0; |
| 1409 | 1410 | end; |
| 1410 | 1411 | |
| @@ -1430,12 +1431,12 @@ | ||
| 1430 | 1431 | var w: Winsize; |
| 1431 | 1432 | begin |
| 1432 | 1433 | 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; | |
| 1434 | 1435 | return 0; |
| 1435 | 1436 | end; |
| 1436 | 1437 | |
| 1437 | 1438 | (* 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; | |
| 1439 | 1440 | begin |
| 1440 | 1441 | COPY(at[0..LEN(s)], s); |
| 1441 | 1442 | at[LEN(s)] := 0; |
| @@ -1444,7 +1445,7 @@ | ||
| 1444 | 1445 | |
| 1445 | 1446 | (* Whether the NAME=value s, a C string, names a variable that one of |
| 1446 | 1447 | env gives. *) |
| 1447 | -proc replaced(s: ^U8; env: [][]U8): BOOL; | |
| 1448 | +proc replaced(s: ^U8; env: [][]const U8): BOOL; | |
| 1448 | 1449 | var i, n: INT; |
| 1449 | 1450 | begin |
| 1450 | 1451 | for i := 0 to LEN(env) - 1 do |
| @@ -1459,7 +1460,7 @@ | ||
| 1459 | 1460 | strings and a nil, then the environment old with each NAME=value of |
| 1460 | 1461 | env in place of its variable or added, and a nil; or nil. The |
| 1461 | 1462 | 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); | |
| 1463 | 1464 | var p: ^^U8; s: ^U8; size, n, i, k: INT; |
| 1464 | 1465 | begin |
| 1465 | 1466 | n := 0; |
| @@ -1487,7 +1488,7 @@ | ||
| 1487 | 1488 | or holds an = or a 0, or value a 0, and -12 if there is no memory. |
| 1488 | 1489 | The C library's setenv keeps the environment. It isn't safe while |
| 1489 | 1490 | another thread reads the environment or starts a program. *) |
| 1490 | -proc setEnv*(name, value: []U8): INT; | |
| 1491 | +proc setEnv*(name, value: []const U8): INT; | |
| 1491 | 1492 | var p: ^U8; size, i, r: INT; |
| 1492 | 1493 | begin |
| 1493 | 1494 | if LEN(name) = 0 then return -22; end; (* EINVAL *) |
| @@ -1514,7 +1515,7 @@ | ||
| 1514 | 1515 | proc pipe*: (INT, INT); |
| 1515 | 1516 | var fds: [2]I32; |
| 1516 | 1517 | 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; | |
| 1518 | 1519 | return INT(fds[0]), INT(fds[1]); |
| 1519 | 1520 | end; |
| 1520 | 1521 | |
| @@ -1539,10 +1540,10 @@ | ||
| 1539 | 1540 | |
| 1540 | 1541 | (* The name of this machine, good until the next call; and 0, or minus |
| 1541 | 1542 | an errno. *) |
| 1542 | -proc hostName*: ([]U8, INT); | |
| 1543 | +proc hostName*: ([]const U8, INT); | |
| 1543 | 1544 | var n: INT; |
| 1544 | 1545 | 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; | |
| 1546 | 1547 | host[LEN(host) - 1] := 0; (* POSIX doesn't promise one if it is cut *) |
| 1547 | 1548 | n := 0; |
| 1548 | 1549 | while host[n] # 0 do INC(n); end; |
| @@ -1554,7 +1555,7 @@ | ||
| 1554 | 1555 | var mask: [1024]U8; i, b, count: INT; |
| 1555 | 1556 | begin |
| 1556 | 1557 | 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; | |
| 1558 | 1559 | count := 0; |
| 1559 | 1560 | for i := 0 to LEN(mask) - 1 do |
| 1560 | 1561 | for b := 0 to 7 do |
| @@ -1577,7 +1578,7 @@ | ||
| 1577 | 1578 | proc cpuTime*(children: BOOL): (I64, I64); |
| 1578 | 1579 | var ru: [64]U64; p: ^U8; (* struct rusage, which cabi checks fits *) |
| 1579 | 1580 | begin |
| 1580 | - p := ^U8(ADR(ru)); | |
| 1581 | + p := ^U8(SYSTEM.ADR(ru)); | |
| 1581 | 1582 | if children then _ := C.getrusage(CAbi.rusageChildren, p); |
| 1582 | 1583 | else _ := C.getrusage(CAbi.rusageSelf, p); |
| 1583 | 1584 | end; |
| @@ -1590,7 +1591,7 @@ | ||
| 1590 | 1591 | proc limit*(which: INT): (I64, I64, INT); |
| 1591 | 1592 | var r: [2]I64; i: INT; (* struct rlimit *) |
| 1592 | 1593 | 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; | |
| 1594 | 1595 | for i := 0 to 1 do |
| 1595 | 1596 | if r[i] = CAbi.rlimInfinity then r[i] := -1; end; |
| 1596 | 1597 | end; |
| @@ -1606,7 +1607,7 @@ | ||
| 1606 | 1607 | for i := 0 to 1 do |
| 1607 | 1608 | if r[i] = -1 then r[i] := CAbi.rlimInfinity; end; |
| 1608 | 1609 | 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; | |
| 1610 | 1611 | return 0; |
| 1611 | 1612 | end; |
| 1612 | 1613 | |
| @@ -1649,7 +1650,7 @@ | ||
| 1649 | 1650 | (* The ith directory of search, a list of them with : between, as PATH |
| 1650 | 1651 | is: dir, "." if it is empty, and where the next starts; -1 past the |
| 1651 | 1652 | last. *) |
| 1652 | -proc pathDir(search: []U8; i: INT): ([]U8, INT); | |
| 1653 | +proc pathDir(search: []const U8; i: INT): ([]const U8, INT); | |
| 1653 | 1654 | var j: INT; |
| 1654 | 1655 | begin |
| 1655 | 1656 | if i > LEN(search) then return "", -1; end; |
| @@ -1660,7 +1661,7 @@ | ||
| 1660 | 1661 | end; |
| 1661 | 1662 | |
| 1662 | 1663 | (* 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; | |
| 1664 | 1665 | var n: INT; |
| 1665 | 1666 | begin |
| 1666 | 1667 | n := LEN(dir) + 1 + LEN(name); |
| @@ -1673,7 +1674,7 @@ | ||
| 1673 | 1674 | end; |
| 1674 | 1675 | |
| 1675 | 1676 | (* 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; | |
| 1677 | 1678 | var i: INT; |
| 1678 | 1679 | begin |
| 1679 | 1680 | for i := 0 to LEN(name) - 1 do |
| @@ -1687,16 +1688,16 @@ | ||
| 1687 | 1688 | execvp does: each in turn, an empty one being the working directory. |
| 1688 | 1689 | It returns only if none could be run. It runs in spawn's child, after |
| 1689 | 1690 | 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; | |
| 1692 | 1693 | begin |
| 1693 | 1694 | 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; | |
| 1695 | 1696 | return; |
| 1696 | 1697 | end; |
| 1697 | 1698 | dir, i := pathDir(search, 0); |
| 1698 | 1699 | 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; | |
| 1700 | 1701 | dir, i := pathDir(search, i); |
| 1701 | 1702 | end; |
| 1702 | 1703 | end; |
| @@ -1706,8 +1707,8 @@ | ||
| 1706 | 1707 | directories of search that is no directory and that this user may |
| 1707 | 1708 | run. 0; or -2 (ENOENT) if there is none, or -13 (EACCES) if one is |
| 1708 | 1709 | 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; | |
| 1711 | 1712 | begin |
| 1712 | 1713 | if isPath(name) then |
| 1713 | 1714 | if not cstr(name, buf) then return -36; end; |
| @@ -1719,7 +1720,7 @@ | ||
| 1719 | 1720 | if joinPath(dir, name, buf) then |
| 1720 | 1721 | f, err := info(buf[0..LEN(dir) + 1 + LEN(name)]); |
| 1721 | 1722 | 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 *) | |
| 1723 | 1724 | r := -13; (* EACCES *) |
| 1724 | 1725 | end; |
| 1725 | 1726 | end; |
| @@ -1746,7 +1747,7 @@ | ||
| 1746 | 1747 | program exec starts. It runs in spawn's child, after the fork, so it |
| 1747 | 1748 | takes no memory: it closes the runs between the fds kept, the lowest |
| 1748 | 1749 | first, each with one closeFrom. *) |
| 1749 | -proc closeAllBut(keep: []INT); | |
| 1750 | +proc closeAllBut(keep: []const INT); | |
| 1750 | 1751 | var lo, next, i: INT; |
| 1751 | 1752 | begin |
| 1752 | 1753 | lo := 3; |
| @@ -1770,12 +1771,12 @@ | ||
| 1770 | 1771 | terminal's foreground; then its standard input, output and error, |
| 1771 | 1772 | each p.fds names over the terminal's; then its working directory, |
| 1772 | 1773 | 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; | |
| 1774 | 1775 | var fd: I32; i: INT; |
| 1775 | 1776 | begin |
| 1776 | 1777 | if p.tty # 0 then |
| 1777 | 1778 | _ := C.setsid(); |
| 1778 | - fd := C.open(ADR(name[0]), CAbi.oRdwr); | |
| 1779 | + fd := C.open(SYSTEM.PTR(name), CAbi.oRdwr); | |
| 1779 | 1780 | if fd < 0 then return failed(); end; |
| 1780 | 1781 | if C.ioctl(fd, CAbi.tiocsctty, 0) # 0 then return failed(); end; |
| 1781 | 1782 | for i := 0 to 2 do _ := C.dup2(fd, I32(i)); end; |
| @@ -1792,7 +1793,7 @@ | ||
| 1792 | 1793 | _ := C.dup2(I32(p.fds[i]), I32(i)); |
| 1793 | 1794 | end; |
| 1794 | 1795 | 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; | |
| 1796 | 1797 | return 0; |
| 1797 | 1798 | end; |
| 1798 | 1799 | |
| @@ -1800,7 +1801,7 @@ | ||
| 1800 | 1801 | proc ignoredIn(var a: Sigaction): BOOL; |
| 1801 | 1802 | var h: ^UINT; |
| 1802 | 1803 | begin |
| 1803 | - h := ^UINT(^U8(ADR(a)) + CAbi.saHandlerAt); | |
| 1804 | + h := ^UINT(^U8(SYSTEM.ADR(a)) + CAbi.saHandlerAt); | |
| 1804 | 1805 | return h^ = 1; |
| 1805 | 1806 | end; |
| 1806 | 1807 | |
| @@ -1809,7 +1810,7 @@ | ||
| 1809 | 1810 | proc ignored*(sig: INT): BOOL; |
| 1810 | 1811 | var a: Sigaction; |
| 1811 | 1812 | begin |
| 1812 | - _ := C.sigaction(I32(sig), nil, ^U8(ADR(a))); | |
| 1813 | + _ := C.sigaction(I32(sig), nil, ^U8(SYSTEM.ADR(a))); | |
| 1813 | 1814 | return ignoredIn(a); |
| 1814 | 1815 | end; |
| 1815 | 1816 | |
| @@ -1821,7 +1822,7 @@ | ||
| 1821 | 1822 | terminal's foreground, and signals as they are at first. *) |
| 1822 | 1823 | proc spawn*(p: Program): INT; |
| 1823 | 1824 | 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; | |
| 1825 | 1826 | all, old, empty: Sigset; dfl: Sigaction; pid: I32; |
| 1826 | 1827 | begin |
| 1827 | 1828 | if not cstr(p.path, a) or not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| @@ -1831,7 +1832,7 @@ | ||
| 1831 | 1832 | end; |
| 1832 | 1833 | none := nil; |
| 1833 | 1834 | 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)); | |
| 1835 | 1836 | else |
| 1836 | 1837 | argv, size := argsAndEnv(p.args, p.env, C.environ); |
| 1837 | 1838 | end; |
| @@ -1841,15 +1842,15 @@ | ||
| 1841 | 1842 | err := find(p.path, search, a); |
| 1842 | 1843 | if err < 0 then munmap(^U8(argv), size); return err; end; |
| 1843 | 1844 | 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))); | |
| 1845 | 1846 | pid := C.fork(); |
| 1846 | 1847 | if pid = 0 then |
| 1847 | 1848 | if takeOn(p, name, dir) # 0 then C._exit(127); end; |
| 1848 | 1849 | closeAllBut(p.more); |
| 1849 | 1850 | 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; | |
| 1851 | 1852 | end; |
| 1852 | - _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(empty)), nil); | |
| 1853 | + _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(empty)), nil); | |
| 1853 | 1854 | run(p.path, search, a, argv, argv + (LEN(p.args) + 1)); |
| 1854 | 1855 | C._exit(127); |
| 1855 | 1856 | end; |
| @@ -1861,7 +1862,7 @@ | ||
| 1861 | 1862 | if p.group # 0 then _ := C.setpgid(pid, I32(g)); end; |
| 1862 | 1863 | if p.foreground then _ := C.tcsetpgrp(0, I32(g)); end; |
| 1863 | 1864 | end; |
| 1864 | - _ := C.sigprocmask(CAbi.sigSetmask, ^U8(ADR(old)), nil); | |
| 1865 | + _ := C.sigprocmask(CAbi.sigSetmask, ^U8(SYSTEM.ADR(old)), nil); | |
| 1865 | 1866 | munmap(^U8(argv), size); |
| 1866 | 1867 | if pid < 0 then return err; end; |
| 1867 | 1868 | return INT(pid); |
| @@ -1878,7 +1879,7 @@ | ||
| 1878 | 1879 | signals given back as they were. *) |
| 1879 | 1880 | proc exec*(p: Program): INT; |
| 1880 | 1881 | 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; | |
| 1882 | 1883 | all, old, empty: Sigset; dfl: Sigaction; acts: [CAbi.sigMax + 1]Sigaction; |
| 1883 | 1884 | begin |
| 1884 | 1885 | if not cstr(p.dir, dir) then return -36; end; (* ENAMETOOLONG *) |
| @@ -1892,7 +1893,7 @@ | ||
| 1892 | 1893 | if r < 0 then return r; end; |
| 1893 | 1894 | none := nil; |
| 1894 | 1895 | 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)); | |
| 1896 | 1897 | else |
| 1897 | 1898 | argv, size := argsAndEnv(p.args, p.env, C.environ); |
| 1898 | 1899 | end; |
| @@ -1905,19 +1906,19 @@ | ||
| 1905 | 1906 | (* every signal as it is at first and none blocked, as spawn |
| 1906 | 1907 | gives them, each kept to give back if execve fails *) |
| 1907 | 1908 | 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))); | |
| 1909 | 1910 | 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 *) | |
| 1911 | 1912 | 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); | |
| 1913 | 1914 | end; |
| 1914 | 1915 | 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)); | |
| 1917 | 1918 | 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); | |
| 1921 | 1922 | end; |
| 1922 | 1923 | munmap(^U8(argv), size); |
| 1923 | 1924 | return r; |
| @@ -1928,14 +1929,14 @@ | ||
| 1928 | 1929 | kernel's execve does and a shell wants: no search, and every fd and |
| 1929 | 1930 | signal as it is, but that a handled signal does what it does at |
| 1930 | 1931 | 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; | |
| 1932 | 1933 | var a: [4096]U8; argv: ^^U8; none: ^U8; size, r: INT; |
| 1933 | 1934 | begin |
| 1934 | 1935 | if not cstr(path, a) then return -36; end; (* ENAMETOOLONG *) |
| 1935 | 1936 | none := nil; |
| 1936 | - argv, size := argsAndEnv(args, env, ADR(none)); | |
| 1937 | + argv, size := argsAndEnv(args, env, SYSTEM.ADR(none)); | |
| 1937 | 1938 | 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)); | |
| 1939 | 1940 | r := failed(); |
| 1940 | 1941 | munmap(^U8(argv), size); |
| 1941 | 1942 | return r; |
| @@ -1945,7 +1946,7 @@ | ||
| 1945 | 1946 | proc waitFor(pid: INT; options: I32): (INT, Status, INT); |
| 1946 | 1947 | var status, r: I32; |
| 1947 | 1948 | begin |
| 1948 | - r := C.waitpid(I32(pid), ADR(status), options); | |
| 1949 | + r := C.waitpid(I32(pid), SYSTEM.ADR(status), options); | |
| 1949 | 1950 | if r < 0 then return failed(), running, 0; end; |
| 1950 | 1951 | if r = 0 then return 0, running, 0; end; |
| 1951 | 1952 | if status & 7FH = 0 then return INT(r), exited, INT(status) shr 8 & 0FFH; end; |
| @@ -1991,7 +1992,7 @@ | ||
| 1991 | 1992 | e := CAbi.errno(); |
| 1992 | 1993 | saved := e^; (* as the code it stopped left it *) |
| 1993 | 1994 | b[0] := U8(sig); |
| 1994 | - _ := C.write(sigWrite, ADR(b[0]), 1); | |
| 1995 | + _ := C.write(sigWrite, SYSTEM.ADR(b[0]), 1); | |
| 1995 | 1996 | e^ := saved; |
| 1996 | 1997 | end; |
| 1997 | 1998 | |
| @@ -2000,9 +2001,9 @@ | ||
| 2000 | 2001 | proc action(h: Handler; flags: INT): Sigaction; |
| 2001 | 2002 | var a: Sigaction; p: ^Handler; |
| 2002 | 2003 | begin |
| 2003 | - p := ^Handler(^U8(ADR(a)) + CAbi.saHandlerAt); | |
| 2004 | + p := ^Handler(^U8(SYSTEM.ADR(a)) + CAbi.saHandlerAt); | |
| 2004 | 2005 | p^ := h; |
| 2005 | - setField(^U8(ADR(a)), CAbi.saFlagsAt, CAbi.saFlagsLen, flags); | |
| 2006 | + setField(^U8(SYSTEM.ADR(a)), CAbi.saFlagsAt, CAbi.saFlagsLen, flags); | |
| 2006 | 2007 | return a; |
| 2007 | 2008 | end; |
| 2008 | 2009 | |
| @@ -2017,20 +2018,20 @@ | ||
| 2017 | 2018 | (* Catches the signals sigs: they don't do what they would, but give |
| 2018 | 2019 | their numbers on an fd, which a later catch adds to and gives again; |
| 2019 | 2020 | or minus an errno. *) |
| 2020 | -proc catch*(sigs: []INT): INT; | |
| 2021 | +proc catch*(sigs: []const INT): INT; | |
| 2021 | 2022 | var fds: [2]I32; act: Sigaction; i: INT; |
| 2022 | 2023 | begin |
| 2023 | 2024 | for i := 0 to LEN(sigs) - 1 do |
| 2024 | 2025 | if not takable(sigs[i]) then return -22; end; (* EINVAL *) |
| 2025 | 2026 | end; |
| 2026 | 2027 | 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; | |
| 2028 | 2029 | sigRead := fds[0]; |
| 2029 | 2030 | sigWrite := fds[1]; |
| 2030 | 2031 | end; |
| 2031 | 2032 | act := action(onSignal, CAbi.saRestart); |
| 2032 | 2033 | 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; | |
| 2034 | 2035 | end; |
| 2035 | 2036 | return INT(sigRead); |
| 2036 | 2037 | end; |
| @@ -2050,7 +2051,7 @@ | ||
| 2050 | 2051 | var act: Sigaction; |
| 2051 | 2052 | begin |
| 2052 | 2053 | 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; | |
| 2054 | 2055 | return 0; |
| 2055 | 2056 | end; |
| 2056 | 2057 | |
| @@ -2065,8 +2066,8 @@ | ||
| 2065 | 2066 | program, perhaps while Out or Heap holds its lock. *) |
| 2066 | 2067 | proc onNoted(sig: I32); |
| 2067 | 2068 | begin |
| 2068 | - _ := XCHG(ADR(noted[sig]), 1); | |
| 2069 | - _ := XCHG(ADR(broke), 1); | |
| 2069 | + _ := XCHG(noted[sig], 1); | |
| 2070 | + _ := XCHG(broke, 1); | |
| 2070 | 2071 | end; |
| 2071 | 2072 | |
| 2072 | 2073 | (* Takes the signal sig away from what it would do: it is noted, for |
| @@ -2079,7 +2080,7 @@ | ||
| 2079 | 2080 | begin |
| 2080 | 2081 | if not takable(sig) then return -22; end; (* EINVAL *) |
| 2081 | 2082 | 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; | |
| 2083 | 2084 | return 0; |
| 2084 | 2085 | end; |
| 2085 | 2086 | |
| @@ -2088,7 +2089,7 @@ | ||
| 2088 | 2089 | proc came*(sig: INT): BOOL; |
| 2089 | 2090 | begin |
| 2090 | 2091 | 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; | |
| 2092 | 2093 | end; |
| 2093 | 2094 | |
| 2094 | 2095 | (* A copy of this program, which goes on from here: 0 in the copy, its |
| @@ -2279,7 +2280,7 @@ | ||
| 2279 | 2280 | proc testShell; |
| 2280 | 2281 | var |
| 2281 | 2282 | 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; | |
| 2283 | 2284 | begin |
| 2284 | 2285 | r, w := pipe(); |
| 2285 | 2286 | if w < 0 then exit(2); end; |
| @@ -2399,21 +2400,21 @@ | ||
| 2399 | 2400 | random(x); |
| 2400 | 2401 | random(y); |
| 2401 | 2402 | 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) | |
| 2405 | 2406 | or (p[CAbi.sinAddrAt] # 10) or (p[CAbi.sinAddrAt + 2] # 0) or (p[CAbi.sinAddrAt + 3] # 255) then |
| 2406 | 2407 | exit(2); |
| 2407 | 2408 | 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) | |
| 2409 | 2410 | or (q[1] # 1) or (q[2] # 0ABH) or (q[3] # 0CDH) or (q[14] # 0) or (q[15] # 0FFH) then |
| 2410 | 2411 | exit(2); |
| 2411 | 2412 | end; |
| 2412 | - q := ^U8(ADR(s6)); | |
| 2413 | + q := ^U8(SYSTEM.ADR(s6)); | |
| 2413 | 2414 | for i := CAbi.sin6PortAt + 2 to CAbi.sin6AddrAt - 1 do (* the flow, zero *) |
| 2414 | 2415 | if q[i] # 0 then exit(2); end; |
| 2415 | 2416 | 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; | |
| 2417 | 2418 | if (connectTcp("1.2.3", 80) # -22) or (connectTcp("1.2.3.256", 80) # -22) or (connectTcp("1::2::3", 80) # -22) |
| 2418 | 2419 | or (connectTcp("1:2:3:4:5:6:7:8:9", 80) # -22) or (connectTcp("1:", 80) # -22) |
| 2419 | 2420 | or (connectTcp("12345::", 80) # -22) or (connectTcp("::1", 65536) # -22) then |
| @@ -2495,7 +2496,7 @@ | ||
| 2495 | 2496 | (* The test of what a program asks of itself: a signal ignored or not, |
| 2496 | 2497 | an environment variable unset or empty, and the processors. *) |
| 2497 | 2498 | proc testProcess; |
| 2498 | -var v: []U8; found: BOOL; | |
| 2499 | +var v: []const U8; found: BOOL; | |
| 2499 | 2500 | begin |
| 2500 | 2501 | if (ignore(sigUsr1, true) # 0) or not ignored(sigUsr1) then exit(2); end; |
| 2501 | 2502 | if (ignore(sigUsr1, false) # 0) or ignored(sigUsr1) then exit(2); end; |
| @@ -2636,7 +2637,7 @@ | ||
| 2636 | 2637 | and closed; a directory made, listed and emptied; no terminal; a |
| 2637 | 2638 | socket, sent to after its end; programs; time and the network. *) |
| 2638 | 2639 | 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; | |
| 2640 | 2641 | begin |
| 2641 | 2642 | testPoll(); |
| 2642 | 2643 | fd := create("/tmp/raz-sys-test"); |
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | in x, and the caller reads it after Thread.join. *) |
| 15 | 15 | module Task(T); |
| 16 | 16 | import Heap, Mem, Thread; |
| 17 | +import SYSTEM; | |
| 17 | 18 | |
| 18 | 19 | type |
| 19 | 20 | (* What the thread is given: what to run and its copy of x. *) |
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | the Thread. Its test uses Check. *) |
| 17 | 17 | module Thread; |
| 18 | 18 | import Sys, Rt, Check; |
| 19 | +import SYSTEM; | |
| 19 | 20 | |
| 20 | 21 | const |
| 21 | 22 | Failed*: ERROR = "can't start a thread"; |
| @@ -80,7 +81,7 @@ | ||
| 80 | 81 | |
| 81 | 82 | proc futex(word: ^INT; op, val: INT): INT; |
| 82 | 83 | begin |
| 83 | - return SYSCALL(202, word, op, val, 0); | |
| 84 | + return SYSTEM.SYSCALL(202, word, op, val, 0); | |
| 84 | 85 | end; |
| 85 | 86 | |
| 86 | 87 | (* Where a new thread starts: the signal handlers' stack is a thread's |
| @@ -90,7 +91,7 @@ | ||
| 90 | 91 | begin |
| 91 | 92 | t := ^Thread(arg); |
| 92 | 93 | alt := {sp: ^U8(t) - Alt, size: Alt}; |
| 93 | - _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *) | |
| 94 | + _ := SYSTEM.SYSCALL(131, SYSTEM.ADR(alt), 0); (* sigaltstack *) | |
| 94 | 95 | t^.fn(t^.arg); |
| 95 | 96 | end; |
| 96 | 97 | |
| @@ -101,9 +102,9 @@ | ||
| 101 | 102 | var t: ^Thread; |
| 102 | 103 | begin |
| 103 | 104 | t := ^Thread(arg); |
| 104 | - _ := XCHG(ADR(t^.ktid), SYSCALL(186)); (* gettid *) | |
| 105 | + _ := XCHG(t^.ktid, SYSTEM.SYSCALL(186)); (* gettid *) | |
| 105 | 106 | run(arg); |
| 106 | - _ := XCHG(ADR(t^.ktid), -1); | |
| 107 | + _ := XCHG(t^.ktid, -1); | |
| 107 | 108 | return nil; |
| 108 | 109 | end; |
| 109 | 110 | |
| @@ -123,7 +124,7 @@ | ||
| 123 | 124 | t^.fn := p; |
| 124 | 125 | t^.arg := arg; |
| 125 | 126 | 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 | |
| 127 | 128 | Sys.munmap(base, size); |
| 128 | 129 | return nil, Failed; |
| 129 | 130 | end; |
| @@ -132,8 +133,8 @@ | ||
| 132 | 133 | end; |
| 133 | 134 | (* mprotect: the guard page, no access; it fails when the process |
| 134 | 135 | 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 | |
| 137 | 138 | Sys.munmap(base, size); |
| 138 | 139 | return nil, Failed; |
| 139 | 140 | end; |
| @@ -147,10 +148,10 @@ | ||
| 147 | 148 | if cJoin # nil then |
| 148 | 149 | _ := cJoin(UINT(t^.tid), nil); |
| 149 | 150 | else |
| 150 | - tid := ADR(t^.tid); | |
| 151 | + tid := SYSTEM.ADR(t^.tid); | |
| 151 | 152 | v := tid^; |
| 152 | 153 | while v # 0 do |
| 153 | - _ := futex(ADR(t^.tid), FutexWait, v); | |
| 154 | + _ := futex(SYSTEM.ADR(t^.tid), FutexWait, v); | |
| 154 | 155 | v := tid^; |
| 155 | 156 | end; |
| 156 | 157 | end; |
| @@ -169,26 +170,26 @@ | ||
| 169 | 170 | var tid: ^VOLATILE INT; k: INT; |
| 170 | 171 | begin |
| 171 | 172 | if cCreate # nil then |
| 172 | - tid := ADR(t^.ktid); | |
| 173 | + tid := SYSTEM.ADR(t^.ktid); | |
| 173 | 174 | k := tid^; |
| 174 | 175 | while k = 0 do Sys.yield; k := tid^; end; |
| 175 | 176 | else |
| 176 | - tid := ADR(t^.tid); | |
| 177 | + tid := SYSTEM.ADR(t^.tid); | |
| 177 | 178 | k := tid^; |
| 178 | 179 | end; |
| 179 | 180 | 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 *) | |
| 181 | 182 | end; |
| 182 | 183 | |
| 183 | 184 | (* Takes m, sleeping while another thread holds it. *) |
| 184 | 185 | proc lock*(var m: Mutex); |
| 185 | 186 | var c: INT; |
| 186 | 187 | 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); | |
| 189 | 190 | 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); | |
| 192 | 193 | end; |
| 193 | 194 | end; |
| 194 | 195 | |
| @@ -196,9 +197,9 @@ | ||
| 196 | 197 | for it. *) |
| 197 | 198 | proc unlock*(var m: Mutex); |
| 198 | 199 | 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); | |
| 202 | 203 | end; |
| 203 | 204 | end; |
| 204 | 205 | |
| @@ -225,7 +226,7 @@ | ||
| 225 | 226 | proc testArg(i: INT): INT; |
| 226 | 227 | var s: ^U8; n, v: INT; |
| 227 | 228 | begin |
| 228 | - s := ARGV()[i]; | |
| 229 | + s := SYSTEM.ARGV()[i]; | |
| 229 | 230 | v := 0; |
| 230 | 231 | n := 0; |
| 231 | 232 | while s[n] # 0 do v := v * 10 + INT(s[n]) - '0'; INC(n); end; |
| @@ -237,7 +238,7 @@ | ||
| 237 | 238 | var n, alive, started, k, i: INT; t: ^Thread; err: ERROR; fail: BOOL; |
| 238 | 239 | begin |
| 239 | 240 | n := 2000; alive := 50; |
| 240 | - fail := (ARGC() = 2) and (ARGV()[1][0] = 'f'); | |
| 241 | + fail := (ARGC() = 2) and (SYSTEM.ARGV()[1][0] = 'f'); | |
| 241 | 242 | if ARGC() = 3 then n := testArg(1); alive := testArg(2); end; |
| 242 | 243 | if fail then n := LEN(wave); alive := LEN(wave); end; |
| 243 | 244 | if (alive < 1) or (alive > LEN(wave)) then Rt.stop("Thread: alive is 1 to 1000"); end; |
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | tryAdd ask and add in one call. *) |
| 10 | 10 | module Vec(T); |
| 11 | 11 | import Mem, Rt, Sys; |
| 12 | +import SYSTEM; | |
| 12 | 13 | |
| 13 | 14 | type |
| 14 | 15 | Vec* = record |
| @@ -161,7 +161,7 @@ | ||
| 161 | 161 | (* end of the tables *) |
| 162 | 162 | |
| 163 | 163 | (* 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; | |
| 165 | 165 | var lo, hi, m: INT; |
| 166 | 166 | begin |
| 167 | 167 | lo := 0; |
| @@ -186,7 +186,7 @@ | ||
| 186 | 186 | end; |
| 187 | 187 | |
| 188 | 188 | (* 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; | |
| 190 | 190 | var c: I32; i, n, w: INT; |
| 191 | 191 | begin |
| 192 | 192 | i := 0; |
| @@ -200,7 +200,7 @@ | ||
| 200 | 200 | end; |
| 201 | 201 | |
| 202 | 202 | (* 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); | |
| 204 | 204 | var i: INT; |
| 205 | 205 | begin |
| 206 | 206 | for i := 0 to LEN(cs) - 1 do Check.int(what, width(cs[i]), w); end; |
| @@ -288,7 +288,7 @@ | ||
| 288 | 288 | |
| 289 | 289 | (* The name of chunk c: its module's and its own, or literal and its |
| 290 | 290 | number for a literal *) |
| 291 | -proc chunkName*(c: INT): []U8; | |
| 291 | +proc chunkName*(c: INT): []const U8; | |
| 292 | 292 | begin |
| 293 | 293 | if chunks[c].name < 0 then return Diag.say("literal{}", [Fmt.int(c)]); end; |
| 294 | 294 | if chunks[c].home < 0 then return Scan.nameOf(chunks[c].name); end; |
| @@ -23,10 +23,10 @@ | ||
| 23 | 23 | Pos* = record f*, a*, b*: INT; end; |
| 24 | 24 | |
| 25 | 25 | File = record |
| 26 | - path: []U8; | |
| 26 | + path: []const U8; | |
| 27 | 27 | buf: ^U8; |
| 28 | 28 | 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 *) | |
| 30 | 30 | end; |
| 31 | 31 | |
| 32 | 32 | const |
| @@ -66,8 +66,8 @@ | ||
| 66 | 66 | |
| 67 | 67 | (* Paths are shown from the working directory where they are under it, |
| 68 | 68 | 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; | |
| 71 | 71 | begin |
| 72 | 72 | if not cwdKnown then |
| 73 | 73 | d, err := Sys.workDir(); |
| @@ -82,7 +82,7 @@ | ||
| 82 | 82 | return path; |
| 83 | 83 | end; |
| 84 | 84 | |
| 85 | -proc fatal*(msg: []U8); forward; | |
| 85 | +proc fatal*(msg: []const U8); forward; | |
| 86 | 86 | |
| 87 | 87 | (* Memory, or the end of the compile when there is none *) |
| 88 | 88 | proc grab(size: INT): ^U8; |
| @@ -95,8 +95,8 @@ | ||
| 95 | 95 | |
| 96 | 96 | (* Keeps buf, len bytes of a file, under a number, which it gives back; |
| 97 | 97 | 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; | |
| 100 | 100 | begin |
| 101 | 101 | if numFiles = cap then |
| 102 | 102 | more := ^File(grab((2 * cap + 8) * SIZE(File))); |
| @@ -114,12 +114,12 @@ | ||
| 114 | 114 | |
| 115 | 115 | (* Gives file f a line to tell once, under the first message about it: |
| 116 | 116 | 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); | |
| 118 | 118 | begin |
| 119 | 119 | files[f].origin := text; |
| 120 | 120 | end; |
| 121 | 121 | |
| 122 | -proc pathOf*(f: INT): []U8; | |
| 122 | +proc pathOf*(f: INT): []const U8; | |
| 123 | 123 | begin |
| 124 | 124 | return files[f].path; |
| 125 | 125 | end; |
| @@ -133,7 +133,7 @@ | ||
| 133 | 133 | return LEN(Sys.env("NO_COLOR")) > 0; |
| 134 | 134 | end; |
| 135 | 135 | |
| 136 | -proc put(s: []U8); | |
| 136 | +proc put(s: []const U8); | |
| 137 | 137 | begin |
| 138 | 138 | Buf.str(out, s); |
| 139 | 139 | end; |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | end; |
| 150 | 150 | |
| 151 | 151 | (* 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; | |
| 153 | 153 | var b: ^Buf.Buf; |
| 154 | 154 | begin |
| 155 | 155 | b := ^Buf.Buf(grab(SIZE(Buf.Buf))); |
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | end; |
| 160 | 160 | |
| 161 | 161 | (* c, when colour is on *) |
| 162 | -proc paintOn(c: []U8); | |
| 162 | +proc paintOn(c: []const U8); | |
| 163 | 163 | begin |
| 164 | 164 | if not colourKnown then |
| 165 | 165 | colour := Sys.isTerminal(2) and not noColour(); |
| @@ -169,7 +169,7 @@ | ||
| 169 | 169 | end; |
| 170 | 170 | |
| 171 | 171 | (* s in colour c, when colour is on *) |
| 172 | -proc paint(c, s: []U8); | |
| 172 | +proc paint(c, s: []const U8); | |
| 173 | 173 | begin |
| 174 | 174 | paintOn(c); |
| 175 | 175 | put(s); |
| @@ -178,7 +178,7 @@ | ||
| 178 | 178 | |
| 179 | 179 | (* What has been made, written to standard error *) |
| 180 | 180 | proc flush; |
| 181 | -var s: []U8; n: INT; | |
| 181 | +var s: []const U8; n: INT; | |
| 182 | 182 | begin |
| 183 | 183 | s := Buf.bytes(out); |
| 184 | 184 | while LEN(s) > 0 do |
| @@ -233,8 +233,8 @@ | ||
| 233 | 233 | (* "file:line:col: kind: msg", then the line with p underlined. A tab |
| 234 | 234 | before p is copied into the underline, so that the two line up |
| 235 | 235 | 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; | |
| 238 | 238 | begin |
| 239 | 239 | if p.f >= numFiles then |
| 240 | 240 | (* about no place in a file, as for Rt, which the compiler |
| @@ -306,7 +306,7 @@ | ||
| 306 | 306 | end; |
| 307 | 307 | |
| 308 | 308 | (* 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; | |
| 310 | 310 | var n: INT; |
| 311 | 311 | begin |
| 312 | 312 | n := p.b - p.a; |
| @@ -317,8 +317,8 @@ | ||
| 317 | 317 | (* Messages *) |
| 318 | 318 | |
| 319 | 319 | (* 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; | |
| 322 | 322 | begin |
| 323 | 323 | want := shownPath(path); |
| 324 | 324 | for i := 0 to numFiles - 1 do |
| @@ -338,7 +338,7 @@ | ||
| 338 | 338 | return ""; |
| 339 | 339 | end; |
| 340 | 340 | |
| 341 | -proc error*(p: Pos; msg: []U8); | |
| 341 | +proc error*(p: Pos; msg: []const U8); | |
| 342 | 342 | begin |
| 343 | 343 | (* a second error at one place follows from the first: when a symbol |
| 344 | 344 | ends a construct with an error, the one around it may stop there too *) |
| @@ -356,7 +356,7 @@ | ||
| 356 | 356 | end; |
| 357 | 357 | end; |
| 358 | 358 | |
| 359 | -proc warning*(p: Pos; msg: []U8); | |
| 359 | +proc warning*(p: Pos; msg: []const U8); | |
| 360 | 360 | begin |
| 361 | 361 | if werror then |
| 362 | 362 | error(p, msg); |
| @@ -368,12 +368,12 @@ | ||
| 368 | 368 | end; |
| 369 | 369 | |
| 370 | 370 | (* 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); | |
| 372 | 372 | begin |
| 373 | 373 | if shown then show(p, "note", Cyan, msg); end; |
| 374 | 374 | end; |
| 375 | 375 | |
| 376 | -proc help*(msg: []U8); | |
| 376 | +proc help*(msg: []const U8); | |
| 377 | 377 | begin |
| 378 | 378 | if shown then |
| 379 | 379 | paint(Green, "help:"); |
| @@ -386,7 +386,7 @@ | ||
| 386 | 386 | |
| 387 | 387 | (* An error with no place in the source, such as a file that can't be |
| 388 | 388 | read: it stops the compiler at once. *) |
| 389 | -proc fatal*(msg: []U8); | |
| 389 | +proc fatal*(msg: []const U8); | |
| 390 | 390 | begin |
| 391 | 391 | put("raz: "); |
| 392 | 392 | put(msg); |
| @@ -395,7 +395,7 @@ | ||
| 395 | 395 | Rt.exit(1); |
| 396 | 396 | end; |
| 397 | 397 | |
| 398 | -proc count(n: INT; what: []U8): []U8; | |
| 398 | +proc count(n: INT; what: []const U8): []const U8; | |
| 399 | 399 | begin |
| 400 | 400 | if n = 1 then return say("1 {}", [Fmt.str(what)]); end; |
| 401 | 401 | return say("{} {}s", [Fmt.int(n), Fmt.str(what)]); |
| @@ -30,10 +30,10 @@ | ||
| 30 | 30 | var |
| 31 | 31 | needed: [32]INT; (* the libraries to load, names interned *) |
| 32 | 32 | 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 *) | |
| 34 | 34 | 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 *) | |
| 37 | 37 | |
| 38 | 38 | buf: ^U8; |
| 39 | 39 | len, cap: INT; |
| @@ -72,7 +72,7 @@ | ||
| 72 | 72 | end; |
| 73 | 73 | end; |
| 74 | 74 | |
| 75 | -proc setMainPath*(path: []U8); | |
| 75 | +proc setMainPath*(path: []const U8); | |
| 76 | 76 | begin |
| 77 | 77 | mainPath := path; |
| 78 | 78 | end; |
| @@ -141,7 +141,7 @@ | ||
| 141 | 141 | |
| 142 | 142 | (* Where in ShNames the name is: the byte after a zero that starts it and |
| 143 | 143 | is followed by one; the empty name, found nowhere, is 0 *) |
| 144 | -proc nameAt(name: []U8): INT; | |
| 144 | +proc nameAt(name: []const U8): INT; | |
| 145 | 145 | var i, k: INT; same: BOOL; |
| 146 | 146 | begin |
| 147 | 147 | for i := 1 to LEN(ShNames) - LEN(name) - 1 do |
| @@ -157,16 +157,16 @@ | ||
| 157 | 157 | end; |
| 158 | 158 | |
| 159 | 159 | (* 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); | |
| 161 | 161 | begin |
| 162 | 162 | putN(nameAt(name), 4); putN(typ, 4); putN(flags, 8); putN(adr, 8); |
| 163 | 163 | putN(off, 8); putN(size, 8); putN(lnk, 4); putN(info, 4); |
| 164 | 164 | putN(align, 8); putN(entsize, 8); |
| 165 | 165 | end; |
| 166 | 166 | |
| 167 | -proc putStr(s: []U8); | |
| 167 | +proc putStr(s: []const U8); | |
| 168 | 168 | begin |
| 169 | - putBytes(ADR(s[0]), LEN(s)); | |
| 169 | + putBytes(PTR(s), LEN(s)); | |
| 170 | 170 | putN(0, 1); |
| 171 | 171 | end; |
| 172 | 172 | |
| @@ -184,7 +184,7 @@ | ||
| 184 | 184 | the table itself is in the places, in rodata (Link). Section |
| 185 | 185 | offsets go in off, sizes in size: line, info, abbrev. *) |
| 186 | 186 | proc putDebug(off, size: []INT); |
| 187 | -var cwd: []U8; err: INT; | |
| 187 | +var cwd: []const U8; err: INT; | |
| 188 | 188 | begin |
| 189 | 189 | off[0] := Chunk.chunks[Link.placesChunk].adr - Link.roAdr + Link.roOff + Link.linesOff; |
| 190 | 190 | size[0] := Link.linesSize; |
| @@ -310,13 +310,13 @@ | ||
| 310 | 310 | putN(0, 16); (* DT_NULL *) |
| 311 | 311 | end; |
| 312 | 312 | |
| 313 | -proc writeElf*(path: []U8; entry: INT); | |
| 313 | +proc writeElf*(path: []const U8; entry: INT); | |
| 314 | 314 | var |
| 315 | 315 | nph, nsh, c, nsyms, sec, strsCap: INT; |
| 316 | 316 | roExtra, dynSize, symOff, strOff, shstrOff, shOff, strsLen: INT; |
| 317 | 317 | dbgOff, dbgSize: [3]INT; |
| 318 | 318 | strs: ^U8; |
| 319 | - s: []U8; | |
| 319 | + s: []const U8; | |
| 320 | 320 | dyn: BOOL; |
| 321 | 321 | begin |
| 322 | 322 | cap := 1 shl 16; |
| @@ -194,7 +194,7 @@ | ||
| 194 | 194 | end; |
| 195 | 195 | |
| 196 | 196 | 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"]; | |
| 198 | 198 | (* the registers of the stack: the value at depth d is in Regs[d mod |
| 199 | 199 | NumRegs]. rax, rdx and rcx, which division and shifts need, and rsi |
| 200 | 200 | and rdi, which copying needs, aren't among them. *) |
| @@ -1573,9 +1573,9 @@ | ||
| 1573 | 1573 | ARegister = -3; (* a Mem that is no memory but a register, its index *) |
| 1574 | 1574 | |
| 1575 | 1575 | (* The name s, interned *) |
| 1576 | -proc internStr(s: []U8): INT; | |
| 1576 | +proc internStr(s: []const U8): INT; | |
| 1577 | 1577 | begin |
| 1578 | - return Scan.intern(ADR(s[0]), LEN(s)); | |
| 1578 | + return Scan.intern(PTR(s), LEN(s)); | |
| 1579 | 1579 | end; |
| 1580 | 1580 | |
| 1581 | 1581 | (* The program goes on if the condition cc holds, and otherwise stops |
| @@ -132,7 +132,7 @@ | ||
| 132 | 132 | end; |
| 133 | 133 | |
| 134 | 134 | (* 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; | |
| 136 | 136 | begin |
| 137 | 137 | return Diag.say(f, [Fmt.str(a)]); |
| 138 | 138 | end; |
| @@ -140,7 +140,7 @@ | ||
| 140 | 140 | (* Under -strict, what reaches memory other than through a variable, |
| 141 | 141 | what, is refused at pos in a module that doesn't import SYSTEM |
| 142 | 142 | (report 3) *) |
| 143 | -proc needSystem*(pos: Diag.Pos; what: []U8): ERROR; | |
| 143 | +proc needSystem*(pos: Diag.Pos; what: []const U8): ERROR; | |
| 144 | 144 | begin |
| 145 | 145 | if strict and not Sym.curModule^.system then |
| 146 | 146 | return Scan.markHelp(pos, say1("{} needs import SYSTEM", what), |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | return nil; |
| 150 | 150 | end; |
| 151 | 151 | |
| 152 | -proc say2(f, a, b: []U8): []U8; | |
| 152 | +proc say2(f, a, b: []const U8): []const U8; | |
| 153 | 153 | begin |
| 154 | 154 | return Diag.say(f, [Fmt.str(a), Fmt.str(b)]); |
| 155 | 155 | end; |
| @@ -232,7 +232,7 @@ | ||
| 232 | 232 | |
| 233 | 233 | (* An item for "found ...": a constant without a type of its own as it |
| 234 | 234 | 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; | |
| 236 | 236 | begin |
| 237 | 237 | if (x.mode = mConst) and ((x.typ = Sym.tConst) or (x.typ = Sym.tRConst)) then |
| 238 | 238 | return Diag.source(x.pos); |
| @@ -242,7 +242,7 @@ | ||
| 242 | 242 | |
| 243 | 243 | (* Two operands of different types. Numbers convert, so say how. *) |
| 244 | 244 | proc mismatchOps(x, y: Item; xt, yt: ^Sym.Type): ERROR; |
| 245 | -var text: []U8; | |
| 245 | +var text: []const U8; | |
| 246 | 246 | begin |
| 247 | 247 | text := say2("{} and {} are different types", Sym.typeName(xt), Sym.typeName(yt)); |
| 248 | 248 | (* the help converts the narrower integer to the wider, which loses |
| @@ -602,7 +602,7 @@ | ||
| 602 | 602 | (* An error in x's type, with help that says what to write instead |
| 603 | 603 | unless hint is empty; if x is an argument, a note at the parameter it |
| 604 | 604 | goes to. *) |
| 605 | -proc mismatchHelp(x: Item; text, hint: []U8): ERROR; | |
| 605 | +proc mismatchHelp(x: Item; text, hint: []const U8): ERROR; | |
| 606 | 606 | begin |
| 607 | 607 | Diag.error(x.pos, text); |
| 608 | 608 | if LEN(hint) > 0 then Diag.help(hint); end; |
| @@ -612,14 +612,14 @@ | ||
| 612 | 612 | return Scan.Failed; |
| 613 | 613 | end; |
| 614 | 614 | |
| 615 | -proc mismatch(x: Item; text: []U8): ERROR; | |
| 615 | +proc mismatch(x: Item; text: []const U8): ERROR; | |
| 616 | 616 | begin |
| 617 | 617 | return mismatchHelp(x, text, ""); |
| 618 | 618 | end; |
| 619 | 619 | |
| 620 | 620 | (* An error at x, which is a view, or part of one, and so has no |
| 621 | 621 | 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; | |
| 623 | 623 | begin |
| 624 | 624 | return Scan.markHelp(x.pos, text, "a view has no address, since it may be misaligned: copy it to a variable"); |
| 625 | 625 | end; |
| @@ -635,7 +635,7 @@ | ||
| 635 | 635 | end; |
| 636 | 636 | |
| 637 | 637 | 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; | |
| 639 | 639 | begin |
| 640 | 640 | if x.mode = mCond then try value(x); end; |
| 641 | 641 | s := x.typ; |
| @@ -753,7 +753,7 @@ | ||
| 753 | 753 | |
| 754 | 754 | (* t's name, ending in a zero byte, for Rt.fail *) |
| 755 | 755 | 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; | |
| 757 | 757 | begin |
| 758 | 758 | s := Sym.typeName(t); |
| 759 | 759 | n := LEN(s); |
| @@ -984,7 +984,7 @@ | ||
| 984 | 984 | (* What x must be to have a view made of it, as a T: a variable, not |
| 985 | 985 | volatile, and T a type of plain data. *) |
| 986 | 986 | proc viewable(x: Item; t: ^Sym.Type): ERROR; |
| 987 | -var u: ^Sym.Type; text: []U8; | |
| 987 | +var u: ^Sym.Type; text: []const U8; | |
| 988 | 988 | begin |
| 989 | 989 | (* another module's variable, ro, is one too, read and not written *) |
| 990 | 990 | if (x.mode # mVar) or not (x.isVar or x.ro) then |
| @@ -1019,7 +1019,7 @@ | ||
| 1019 | 1019 | through the slice must still be a value of it. In a record, the help |
| 1020 | 1020 | names the field that holds it. *) |
| 1021 | 1021 | 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; | |
| 1023 | 1023 | begin |
| 1024 | 1024 | u := notPlain(t); |
| 1025 | 1025 | if u = nil then return nil; end; |
| @@ -1041,7 +1041,7 @@ | ||
| 1041 | 1041 | return Scan.markHelp(x.pos, text, hint); |
| 1042 | 1042 | end; |
| 1043 | 1043 | |
| 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 | |
| 1045 | 1045 | slice of x is, refused where one is, and keeping x's frame mark, so |
| 1046 | 1046 | that returnValue refuses the bytes of a local as a slice of one: |
| 1047 | 1047 | |
| @@ -1418,7 +1418,7 @@ | ||
| 1418 | 1418 | integers: x is the wrong kind for op, and the message names the |
| 1419 | 1419 | operator it may have meant *) |
| 1420 | 1420 | proc wrongLogic(op: Scan.Sym; var x: Item): ERROR; |
| 1421 | -var bitsOf: []U8; | |
| 1421 | +var bitsOf: []const U8; | |
| 1422 | 1422 | begin |
| 1423 | 1423 | bitsOf := "the bits of integers take "; |
| 1424 | 1424 | if (op = Scan.sAnd) and Sym.isInt(x.typ) then |
| @@ -1704,7 +1704,7 @@ | ||
| 1704 | 1704 | untyped constant hasn't (report section 6.1). It is loaded, unless a |
| 1705 | 1705 | constant, before n is read, as the left of an operator is by op1. *) |
| 1706 | 1706 | proc rotand*(var x: Item; left: BOOL): ERROR; |
| 1707 | -var name, s: []U8; | |
| 1707 | +var name, s: []const U8; | |
| 1708 | 1708 | begin |
| 1709 | 1709 | if x.mode in {mType, mBuiltin, mNone, mCase, mStr} then return notValue(x); end; |
| 1710 | 1710 | if left then name := "ROL"; else name := "ROR"; end; |
| @@ -1796,7 +1796,7 @@ | ||
| 1796 | 1796 | 0 counts, or for POPCOUNT a set; an untyped constant has no width. |
| 1797 | 1797 | Of a constant the count is folded. *) |
| 1798 | 1798 | proc countBits*(var x: Item; which: INT): ERROR; |
| 1799 | -var name, s: []U8; ok: BOOL; | |
| 1799 | +var name, s: []const U8; ok: BOOL; | |
| 1800 | 1800 | begin |
| 1801 | 1801 | if x.mode in {mType, mBuiltin, mNone, mCase, mStr} then return notValue(x); end; |
| 1802 | 1802 | if which = Sym.bClz then name := "CLZ"; elsif which = Sym.bCtz then name := "CTZ"; else name := "POPCOUNT"; end; |
| @@ -1830,7 +1830,7 @@ | ||
| 1830 | 1830 | untyped constants end, so they keep their type, as a hexadecimal |
| 1831 | 1831 | number above it is a U64 (report section 3). *) |
| 1832 | 1832 | 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; | |
| 1834 | 1834 | begin |
| 1835 | 1835 | if t^.form # Sym.fInt then |
| 1836 | 1836 | if max then name := "MAX"; else name := "MIN"; end; |
| @@ -1936,7 +1936,7 @@ | ||
| 1936 | 1936 | end; |
| 1937 | 1937 | |
| 1938 | 1938 | (* 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; | |
| 1940 | 1940 | begin |
| 1941 | 1941 | if c.obj = nil then return Scan.markAt(p, text); end; |
| 1942 | 1942 | 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 @@ | ||
| 1976 | 1976 | write instead, b for ADR(b) and p^ for a pointer p. Mostly met in |
| 1977 | 1977 | programs written before the library took var (report 2026-10.33). *) |
| 1978 | 1978 | proc givenAddress(const a: Item; p: ^Sym.Obj): ERROR; |
| 1979 | -var s, kind: []U8; | |
| 1979 | +var s, kind: []const U8; | |
| 1980 | 1980 | begin |
| 1981 | 1981 | if (a.typ^.form # Sym.fPtr) or (a.typ^.base = nil) or not Sym.same(a.typ^.base, p^.typ) then |
| 1982 | 1982 | return nil; |
| @@ -2471,7 +2471,7 @@ | ||
| 2471 | 2471 | (* COPY(d, s) or FILL(d, x): d, an array variable or a slice, as a slice |
| 2472 | 2472 | in the frame, before s or x is read; text says what the built-in |
| 2473 | 2473 | writes into, for an error *) |
| 2474 | -proc destSlice(var d: Item; text: []U8): ERROR; | |
| 2474 | +proc destSlice(var d: Item; text: []const U8): ERROR; | |
| 2475 | 2475 | begin |
| 2476 | 2476 | if (d.typ^.form = Sym.fArray) and (d.mode = mVar) then try notReadOnly(d); end; |
| 2477 | 2477 | if (d.typ^.form = Sym.fSlice) and d.typ^.rdonly then |
| @@ -160,7 +160,7 @@ | ||
| 160 | 160 | (* The line program of the files paths, nfiles of them, numbered from |
| 161 | 161 | 1, as they are written in the table *) |
| 162 | 162 | 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; | |
| 164 | 164 | begin |
| 165 | 165 | lpLen := 0; |
| 166 | 166 | putN(0, 4); (* unit_length, patched below *) |
| @@ -219,7 +219,7 @@ | ||
| 219 | 219 | at, names, poolAt: INT; (* where the next number goes, the next name, the pool's start *) |
| 220 | 220 | |
| 221 | 221 | (* 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); | |
| 223 | 223 | begin |
| 224 | 224 | patch4(buf, at, names - poolAt); |
| 225 | 225 | COPY(buf[names..names + LEN(s)], s); |
| @@ -322,8 +322,8 @@ | ||
| 322 | 322 | end; |
| 323 | 323 | |
| 324 | 324 | (* 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; | |
| 327 | 327 | begin |
| 328 | 328 | s := Diag.say("{}H", [Fmt.hex(U64(a))]); |
| 329 | 329 | if s[0] > '9' then s := Diag.say("0{}", [Fmt.str(s)]); end; |
| @@ -80,15 +80,15 @@ | ||
| 80 | 80 | MaxFixes = 4096; (* addresses in one constant *) |
| 81 | 81 | MaxPending = 64; (* modules being compiled at once *) |
| 82 | 82 | 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", ""]; | |
| 84 | 84 | |
| 85 | 85 | var |
| 86 | - libDir*, mainDir: []U8; | |
| 87 | - incDirs*: [16][]U8; | |
| 86 | + libDir*, mainDir: []const U8; | |
| 87 | + incDirs*: [16][]const U8; | |
| 88 | 88 | 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 *) | |
| 92 | 92 | firstModule*, lastModule*: PModule; (* in the order they were finished *) |
| 93 | 93 | |
| 94 | 94 | checkMode: BOOL; (* reading a file only for its interface *) |
| @@ -121,7 +121,7 @@ | ||
| 121 | 121 | doubts: [MaxDoubts]record |
| 122 | 122 | at: Diag.Pos; (* a place the module's end warns of *) |
| 123 | 123 | 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) *) | |
| 125 | 125 | end; |
| 126 | 126 | numDoubts: INT; (* the module being compiled has those from its |
| 127 | 127 | first one, saved by compileFile, to here *) |
| @@ -152,57 +152,57 @@ | ||
| 152 | 152 | |
| 153 | 153 | (* Little helpers *) |
| 154 | 154 | |
| 155 | -proc setLibDir*(dir: []U8); | |
| 155 | +proc setLibDir*(dir: []const U8); | |
| 156 | 156 | begin |
| 157 | 157 | libDir := dir; |
| 158 | 158 | end; |
| 159 | 159 | |
| 160 | -proc addIncDir*(dir: []U8); | |
| 160 | +proc addIncDir*(dir: []const U8); | |
| 161 | 161 | begin |
| 162 | 162 | incDirs[numInc] := dir; |
| 163 | 163 | INC(numInc); |
| 164 | 164 | end; |
| 165 | 165 | |
| 166 | 166 | (* The driver's user library directories, kept until compilation ends *) |
| 167 | -proc setUserDirs*(dirs: [][]U8); | |
| 167 | +proc setUserDirs*(dirs: [][]const U8); | |
| 168 | 168 | begin |
| 169 | 169 | userDirs := dirs; |
| 170 | 170 | end; |
| 171 | 171 | |
| 172 | 172 | (* The driver's version of the compiler, which a library's note names *) |
| 173 | -proc setVersion*(v: []U8); | |
| 173 | +proc setVersion*(v: []const U8); | |
| 174 | 174 | begin |
| 175 | 175 | thisVersion := v; |
| 176 | 176 | end; |
| 177 | 177 | |
| 178 | -proc nameOf(n: INT): []U8; | |
| 178 | +proc nameOf(n: INT): []const U8; | |
| 179 | 179 | begin |
| 180 | 180 | return Scan.nameOf(n); |
| 181 | 181 | end; |
| 182 | 182 | |
| 183 | 183 | (* The name number of s, which isn't empty *) |
| 184 | -proc internName(s: []U8): INT; | |
| 184 | +proc internName(s: []const U8): INT; | |
| 185 | 185 | begin |
| 186 | - return Scan.intern(ADR(s[0]), LEN(s)); | |
| 186 | + return Scan.intern(PTR(s), LEN(s)); | |
| 187 | 187 | end; |
| 188 | 188 | |
| 189 | -proc say1(f, a: []U8): []U8; | |
| 189 | +proc say1(f, a: []const U8): []const U8; | |
| 190 | 190 | begin |
| 191 | 191 | return Diag.say(f, [Fmt.str(a)]); |
| 192 | 192 | end; |
| 193 | 193 | |
| 194 | -proc say2(f, a, b: []U8): []U8; | |
| 194 | +proc say2(f, a, b: []const U8): []const U8; | |
| 195 | 195 | begin |
| 196 | 196 | return Diag.say(f, [Fmt.str(a), Fmt.str(b)]); |
| 197 | 197 | end; |
| 198 | 198 | |
| 199 | -proc say3(f, a, b, c: []U8): []U8; | |
| 199 | +proc say3(f, a, b, c: []const U8): []const U8; | |
| 200 | 200 | begin |
| 201 | 201 | return Diag.say(f, [Fmt.str(a), Fmt.str(b), Fmt.str(c)]); |
| 202 | 202 | end; |
| 203 | 203 | |
| 204 | 204 | (* 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; | |
| 206 | 206 | begin |
| 207 | 207 | return Diag.say("more than {} {}", [Fmt.int(n), Fmt.str(what)]); |
| 208 | 208 | end; |
| @@ -234,7 +234,7 @@ | ||
| 234 | 234 | end; |
| 235 | 235 | |
| 236 | 236 | (* A missing symbol is reported just after the one before it. *) |
| 237 | -proc expected(what: []U8): ERROR; | |
| 237 | +proc expected(what: []const U8): ERROR; | |
| 238 | 238 | var at: Diag.Pos; |
| 239 | 239 | begin |
| 240 | 240 | if Scan.tok = Scan.sBlank then |
| @@ -272,7 +272,7 @@ | ||
| 272 | 272 | |
| 273 | 273 | (* The error of a procedure or module whose own "end" isn't where it |
| 274 | 274 | 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; | |
| 276 | 276 | begin |
| 277 | 277 | Diag.error(p, msg); |
| 278 | 278 | foundNotes(p); |
| @@ -474,10 +474,10 @@ | ||
| 474 | 474 | end; |
| 475 | 475 | |
| 476 | 476 | (* 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; | |
| 478 | 478 | |
| 479 | 479 | (* 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; | |
| 481 | 481 | var p: ^U8; i: INT; |
| 482 | 482 | begin |
| 483 | 483 | if LEN(s) = 0 then return ""; end; |
| @@ -490,7 +490,7 @@ | ||
| 490 | 490 | |
| 491 | 491 | (* Whether s is a hexadecimal number but for the digit it must start |
| 492 | 492 | 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; | |
| 494 | 494 | var i: INT; |
| 495 | 495 | begin |
| 496 | 496 | if (LEN(s) < 2) or (s[LEN(s) - 1] # 'H') then return false; end; |
| @@ -502,7 +502,7 @@ | ||
| 502 | 502 | |
| 503 | 503 | (* Reports name n at p as not declared, with what it may have meant *) |
| 504 | 504 | proc notDeclared(p: Diag.Pos; n: INT); |
| 505 | -var found: BOOL; low: []U8; | |
| 505 | +var found: BOOL; low: []const U8; | |
| 506 | 506 | begin |
| 507 | 507 | Diag.error(p, say1("{} isn't declared", nameOf(n))); |
| 508 | 508 | commentNote(p); |
| @@ -538,7 +538,7 @@ | ||
| 538 | 538 | (* An error at at: o, a name of an enumeration, is a name of another of |
| 539 | 539 | its scope too, so it is written with its type. *) |
| 540 | 540 | proc twinError(o: PObj; at: Diag.Pos): ERROR; |
| 541 | -var a, b: []U8; | |
| 541 | +var a, b: []const U8; | |
| 542 | 542 | begin |
| 543 | 543 | a := Sym.typeName(o^.typ); b := Sym.typeName(o^.twin^.typ); |
| 544 | 544 | return Scan.markHelp(at, Diag.say("{} is a name of {} and of {}", |
| @@ -1094,7 +1094,7 @@ | ||
| 1094 | 1094 | end; |
| 1095 | 1095 | |
| 1096 | 1096 | (* The name of the atomic built-in which, for a message *) |
| 1097 | -proc atomicName(which: INT): []U8; | |
| 1097 | +proc atomicName(which: INT): []const U8; | |
| 1098 | 1098 | begin |
| 1099 | 1099 | if which = Sym.bCas then return "CAS"; end; |
| 1100 | 1100 | if which = Sym.bXchg then return "XCHG"; end; |
| @@ -1196,7 +1196,7 @@ | ||
| 1196 | 1196 | return nil; |
| 1197 | 1197 | end; |
| 1198 | 1198 | |
| 1199 | -proc incOrDec(which: INT): []U8; | |
| 1199 | +proc incOrDec(which: INT): []const U8; | |
| 1200 | 1200 | begin |
| 1201 | 1201 | if which = Sym.bDec then return "DEC"; end; |
| 1202 | 1202 | return "INC"; |
| @@ -1206,7 +1206,7 @@ | ||
| 1206 | 1206 | its elements start at by Item's startOf. Anything else is an error |
| 1207 | 1207 | that says what PTR is for, and for a pointer what to write. *) |
| 1208 | 1208 | proc ptrOf(var x: TItem): ERROR; |
| 1209 | -var e: PType; s: []U8; | |
| 1209 | +var e: PType; s: []const U8; | |
| 1210 | 1210 | begin |
| 1211 | 1211 | if x.mode = Item.mStr then |
| 1212 | 1212 | e := Sym.tU8; |
| @@ -1231,7 +1231,7 @@ | ||
| 1231 | 1231 | place, so have none of their own. f is one name, not a path a.b, |
| 1232 | 1232 | which would be a field of f's type, asked of that type. *) |
| 1233 | 1233 | 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; | |
| 1235 | 1235 | begin |
| 1236 | 1236 | if isOffset then what := "OFFSET"; else what := "SIZE(T.f)"; end; |
| 1237 | 1237 | if t^.form # Sym.fRecord then |
| @@ -1442,7 +1442,7 @@ | ||
| 1442 | 1442 | (* x, before ".", has no fields; tok is what follows. Other languages |
| 1443 | 1443 | write p.f through a pointer and s.len for a length. *) |
| 1444 | 1444 | proc fieldOfWhat(x: TItem): ERROR; |
| 1445 | -var msg, f: []U8; | |
| 1445 | +var msg, f: []const U8; | |
| 1446 | 1446 | begin |
| 1447 | 1447 | msg := say1("expected a record, found {}", Item.what(x)); |
| 1448 | 1448 | if Scan.tok = Scan.sIdent then f := nameOf(Scan.id); else f := ""; end; |
| @@ -1698,7 +1698,7 @@ | ||
| 1698 | 1698 | (* A set literal: the bits of the constant names, or'd at run time with |
| 1699 | 1699 | those of the others. *) |
| 1700 | 1700 | 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; | |
| 1702 | 1702 | begin |
| 1703 | 1703 | start := Scan.tokPos(); |
| 1704 | 1704 | Scan.next; |
| @@ -1859,7 +1859,7 @@ | ||
| 1859 | 1859 | |
| 1860 | 1860 | (* A doubt other than a drop, to be warned of at p with msg and hint. |
| 1861 | 1861 | 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); | |
| 1863 | 1863 | var i: INT; |
| 1864 | 1864 | begin |
| 1865 | 1865 | for i := 0 to numDoubts - 1 do |
| @@ -1885,7 +1885,7 @@ | ||
| 1885 | 1885 | end; |
| 1886 | 1886 | |
| 1887 | 1887 | 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; | |
| 1889 | 1889 | begin |
| 1890 | 1890 | several := passOn; |
| 1891 | 1891 | passOn := false; |
| @@ -2044,7 +2044,7 @@ | ||
| 2044 | 2044 | |
| 2045 | 2045 | (* Notes x, an operand of the and or or (word) just read, if it is an |
| 2046 | 2046 | unparenthesised = or # of two BOOLs *) |
| 2047 | -proc noteBoolRel(const x: TItem; word: []U8); | |
| 2047 | +proc noteBoolRel(const x: TItem; word: []const U8); | |
| 2048 | 2048 | begin |
| 2049 | 2049 | if bareBoolRel then |
| 2050 | 2050 | noteDoubt(x.pos, say2("{} is read first: = and # bind tighter than {}", Diag.source(x.pos), word), |
| @@ -2404,7 +2404,7 @@ | ||
| 2404 | 2404 | keeps each label's chunk in lo and its length in hi, for the |
| 2405 | 2405 | comparing of labels. *) |
| 2406 | 2406 | 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; | |
| 2408 | 2408 | begin |
| 2409 | 2409 | L := Gen.NoLabel; |
| 2410 | 2410 | body := Gen.NoLabel; |
| @@ -2495,7 +2495,7 @@ | ||
| 2495 | 2495 | Xml.Kind.done, is read by qualIdent, as it is anywhere else, and must |
| 2496 | 2496 | be one of t's. *) |
| 2497 | 2497 | 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; | |
| 2499 | 2499 | begin |
| 2500 | 2500 | at := Scan.tokPos(); |
| 2501 | 2501 | Scan.saveScan(st); |
| @@ -2651,7 +2651,7 @@ | ||
| 2651 | 2651 | |
| 2652 | 2652 | (* What a message calls x: its name n when x is just that name, else what |
| 2653 | 2653 | it is. *) |
| 2654 | -proc subject(x: TItem; n: INT): []U8; | |
| 2654 | +proc subject(x: TItem; n: INT): []const U8; | |
| 2655 | 2655 | begin |
| 2656 | 2656 | if x.pos.b - x.pos.a = LEN(nameOf(n)) then return nameOf(n); end; |
| 2657 | 2657 | if x.mode = Item.mConst then return "a constant"; end; |
| @@ -4091,7 +4091,7 @@ | ||
| 4091 | 4091 | end; |
| 4092 | 4092 | |
| 4093 | 4093 | (* 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; | |
| 4095 | 4095 | var o: PObj; start: Diag.Pos; |
| 4096 | 4096 | begin |
| 4097 | 4097 | Scan.next; |
| @@ -4211,7 +4211,7 @@ | ||
| 4211 | 4211 | it is meant to go unused. Writing a var parameter, a match's name for |
| 4212 | 4212 | a field or C's variable is what it is for. *) |
| 4213 | 4213 | proc warn(o: PObj); |
| 4214 | -var s, t: []U8; | |
| 4214 | +var s, t: []const U8; | |
| 4215 | 4215 | begin |
| 4216 | 4216 | s := nameOf(o^.name); |
| 4217 | 4217 | if (o^.cls = Sym.oProc) and o^.openEnd then |
| @@ -4244,7 +4244,7 @@ | ||
| 4244 | 4244 | |
| 4245 | 4245 | (* Warns of the call at p, which drops its n results *) |
| 4246 | 4246 | proc dropped(p: Diag.Pos; n: INT); |
| 4247 | -var s, blanks: []U8; i: INT; | |
| 4247 | +var s, blanks: []const U8; i: INT; | |
| 4248 | 4248 | begin |
| 4249 | 4249 | s := Diag.source(p); |
| 4250 | 4250 | i := 0; |
| @@ -4297,7 +4297,7 @@ | ||
| 4297 | 4297 | pending: [MaxPending]PModule; |
| 4298 | 4298 | numPending: INT; |
| 4299 | 4299 | |
| 4300 | -proc exists(path: []U8): BOOL; | |
| 4300 | +proc exists(path: []const U8): BOOL; | |
| 4301 | 4301 | var info: Sys.Info; err: INT; |
| 4302 | 4302 | begin |
| 4303 | 4303 | info, err := Sys.info(path); |
| @@ -4306,7 +4306,7 @@ | ||
| 4306 | 4306 | |
| 4307 | 4307 | (* Which file path is, as its device and inode: two names of one file |
| 4308 | 4308 | 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); | |
| 4310 | 4310 | var a: [4096]U8; st: [18]INT; (* struct stat: st_dev, then st_ino *) |
| 4311 | 4311 | begin |
| 4312 | 4312 | if LEN(path) >= 4096 then return 0, 0; end; |
| @@ -4317,7 +4317,7 @@ | ||
| 4317 | 4317 | end; |
| 4318 | 4318 | |
| 4319 | 4319 | (* 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; | |
| 4321 | 4321 | var p: ^U8; |
| 4322 | 4322 | begin |
| 4323 | 4323 | if LEN(s) = 0 then return ""; end; |
| @@ -4333,12 +4333,12 @@ | ||
| 4333 | 4333 | the middle of reading another file, so it is re-entrant: it saves the |
| 4334 | 4334 | scanner's state, the open scopes, the current module and file and |
| 4335 | 4335 | 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); | |
| 4337 | 4337 | var |
| 4338 | 4338 | st: Scan.State; saved: [Sym.MaxDepth]INT; d: INT; |
| 4339 | 4339 | oldMod: PModule; oldCheck, oldChecks: BOOL; m: PModule; |
| 4340 | 4340 | 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; | |
| 4342 | 4342 | begin |
| 4343 | 4343 | firstDoubt := numDoubts; |
| 4344 | 4344 | Scan.saveScan(st); |
| @@ -4544,10 +4544,10 @@ | ||
| 4544 | 4544 | |
| 4545 | 4545 | (* Reads every other file of module n in dir, and checks its interface |
| 4546 | 4546 | 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; | |
| 4548 | 4548 | 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; | |
| 4551 | 4551 | begin |
| 4552 | 4552 | prefix := say1("{}.", nameOf(n)); |
| 4553 | 4553 | numOthers := 0; |
| @@ -4571,7 +4571,7 @@ | ||
| 4571 | 4571 | |
| 4572 | 4572 | (* The compiler's version as a library's RAZ-VERSION would say it: |
| 4573 | 4573 | "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; | |
| 4575 | 4575 | var i, dots: INT; |
| 4576 | 4576 | begin |
| 4577 | 4577 | dots := 0; |
| @@ -4588,7 +4588,7 @@ | ||
| 4588 | 4588 | RAZ_PATH directory: if dir holds a file RAZ-VERSION, the raz its |
| 4589 | 4589 | library was written for. The file is only read; a library with none, |
| 4590 | 4590 | 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; | |
| 4592 | 4592 | var fd, n, i: INT; b: [32]U8; |
| 4593 | 4593 | begin |
| 4594 | 4594 | if (dir = mainDir) or (dir = libDir) then return ""; end; |
| @@ -4603,7 +4603,7 @@ | ||
| 4603 | 4603 | end; |
| 4604 | 4604 | |
| 4605 | 4605 | (* The directories searched for modules: main, -I, user libraries, lib *) |
| 4606 | -proc searchDir(i: INT): []U8; | |
| 4606 | +proc searchDir(i: INT): []const U8; | |
| 4607 | 4607 | begin |
| 4608 | 4608 | if i = -1 then return mainDir; end; |
| 4609 | 4609 | if i < numInc then return incDirs[i]; end; |
| @@ -4614,13 +4614,13 @@ | ||
| 4614 | 4614 | |
| 4615 | 4615 | (* The file of module n in dir that suffix j says: Name.linux-x86_64.raz |
| 4616 | 4616 | 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; | |
| 4618 | 4618 | begin |
| 4619 | 4619 | return Diag.say("{}{}.raz", [Fmt.str(nameOf(n)), Fmt.str(Suffixes[j])]); |
| 4620 | 4620 | end; |
| 4621 | 4621 | |
| 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; | |
| 4624 | 4624 | begin |
| 4625 | 4625 | for i := -1 to numInc + LEN(userDirs) do |
| 4626 | 4626 | dir := searchDir(i); |
| @@ -4635,9 +4635,9 @@ | ||
| 4635 | 4635 | (* A program has one module of each name: module n, found as dir/f, |
| 4636 | 4636 | must have no files in a later directory, unless dir/f is a link to |
| 4637 | 4637 | 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; | |
| 4639 | 4639 | 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; | |
| 4641 | 4641 | begin |
| 4642 | 4642 | mineDev, mineIno := identity(say2("{}/{}", dir, f)); |
| 4643 | 4643 | others := ""; |
| @@ -4665,7 +4665,7 @@ | ||
| 4665 | 4665 | end; |
| 4666 | 4666 | |
| 4667 | 4667 | 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; | |
| 4669 | 4669 | begin |
| 4670 | 4670 | m := findModule(name, args); |
| 4671 | 4671 | if m # nil then return m, nil; end; |
| @@ -4779,8 +4779,8 @@ | ||
| 4779 | 4779 | |
| 4780 | 4780 | (* The main module, from the file at path, and Rt, which every program |
| 4781 | 4781 | 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; | |
| 4784 | 4784 | begin |
| 4785 | 4785 | none.n := 0; |
| 4786 | 4786 | i := LEN(path); |
| @@ -43,15 +43,15 @@ | ||
| 43 | 43 | cLinks: [3]Gen.Link; (* C's symbols the entry point gives the library, in a program that uses C *) |
| 44 | 44 | numCLinks: INT; |
| 45 | 45 | |
| 46 | -proc say1(f, a: []U8): []U8; | |
| 46 | +proc say1(f, a: []const U8): []const U8; | |
| 47 | 47 | begin |
| 48 | 48 | return Diag.say(f, [Fmt.str(a)]); |
| 49 | 49 | end; |
| 50 | 50 | |
| 51 | 51 | (* The number of the name s *) |
| 52 | -proc internStr(s: []U8): INT; | |
| 52 | +proc internStr(s: []const U8): INT; | |
| 53 | 53 | begin |
| 54 | - return Scan.intern(ADR(s[0]), LEN(s)); | |
| 54 | + return Scan.intern(PTR(s), LEN(s)); | |
| 55 | 55 | end; |
| 56 | 56 | |
| 57 | 57 | (* The modules the program uses: the main module, Rt, and every module |
| @@ -98,7 +98,7 @@ | ||
| 98 | 98 | hexadecimal ones that start with a digit and end in H; and whether it |
| 99 | 99 | is one, and fits in 64 bits. Past high(INT) it is taken as a UINT, |
| 100 | 100 | whose bits it keeps: 0FFFFFFFF80000000H is -80000000H. *) |
| 101 | -proc address(s: []U8): (INT, BOOL); | |
| 101 | +proc address(s: []const U8): (INT, BOOL); | |
| 102 | 102 | var i, n, d, radix: INT; v: UINT; |
| 103 | 103 | begin |
| 104 | 104 | n := LEN(s); |
| @@ -155,7 +155,7 @@ | ||
| 155 | 155 | end; |
| 156 | 156 | |
| 157 | 157 | (* 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; | |
| 159 | 159 | var m: ^Sym.Module; |
| 160 | 160 | begin |
| 161 | 161 | m := Parse.firstModule; |
| @@ -164,7 +164,7 @@ | ||
| 164 | 164 | end; |
| 165 | 165 | |
| 166 | 166 | (* 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; | |
| 168 | 168 | var o: ^Sym.Obj; |
| 169 | 169 | begin |
| 170 | 170 | o := Sym.find(m^.scope, internStr(n)); |
| @@ -181,7 +181,7 @@ | ||
| 181 | 181 | end; |
| 182 | 182 | |
| 183 | 183 | (* 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); | |
| 185 | 185 | begin |
| 186 | 186 | cLinks[numCLinks].chunk := Chunk.externChunk(internStr(sym)); |
| 187 | 187 | cLinks[numCLinks].into := v^.chunk; |
| @@ -189,7 +189,7 @@ | ||
| 189 | 189 | end; |
| 190 | 190 | |
| 191 | 191 | (* s as a C string, in memory that is never freed *) |
| 192 | -proc cstr(s: []U8): ^U8; | |
| 192 | +proc cstr(s: []const U8): ^U8; | |
| 193 | 193 | var p: ^U8; |
| 194 | 194 | begin |
| 195 | 195 | p := Scan.grab(LEN(s) + 1); |
| @@ -203,7 +203,7 @@ | ||
| 203 | 203 | from an unset one; Sys.env alone gives "" for both. The slices and |
| 204 | 204 | their array live until the compiler exits, as command-line paths do. *) |
| 205 | 205 | 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; | |
| 207 | 207 | begin |
| 208 | 208 | i := 0; |
| 209 | 209 | repeat |
| @@ -219,7 +219,7 @@ | ||
| 219 | 219 | if not found then |
| 220 | 220 | s := Sys.env("HOME"); |
| 221 | 221 | if LEN(s) > 0 then |
| 222 | - dirs := ^[]U8(Scan.grab(SIZE([]U8))); | |
| 222 | + dirs := ^[]const U8(Scan.grab(SIZE([]const U8))); | |
| 223 | 223 | dirs[0] := say1("{}/.raz/lib", s); |
| 224 | 224 | Parse.setUserDirs(dirs[0..1]); |
| 225 | 225 | end; |
| @@ -230,7 +230,7 @@ | ||
| 230 | 230 | for i := 0 to LEN(path) - 1 do |
| 231 | 231 | if path[i] = ':' then INC(n); end; |
| 232 | 232 | end; |
| 233 | - dirs := ^[]U8(Scan.grab(n * SIZE([]U8))); | |
| 233 | + dirs := ^[]const U8(Scan.grab(n * SIZE([]const U8))); | |
| 234 | 234 | n := 0; |
| 235 | 235 | first := 0; |
| 236 | 236 | for i := 0 to LEN(path) do |
| @@ -247,7 +247,7 @@ | ||
| 247 | 247 | |
| 248 | 248 | proc main*: INT; |
| 249 | 249 | var |
| 250 | - path, outPath, s: []U8; dir: []U8; | |
| 250 | + path, outPath, s: []const U8; dir: []const U8; | |
| 251 | 251 | i, first, entry, fd, last, errno, base: INT; |
| 252 | 252 | m, rt, thread: ^Sym.Module; mainObj: ^Sym.Obj; |
| 253 | 253 | run, noProfile, listing, dynamic, libcSaid, ok, bare: BOOL; err: ERROR; |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | MaxStr* = 65536; |
| 52 | 52 | NumWords = 44; |
| 53 | 53 | NumOps = 28; |
| 54 | - words: [NumWords][]U8 = [ | |
| 54 | + words: [NumWords][]const U8 = [ | |
| 55 | 55 | "and", "begin", "break", "by", "code", "const", "continue", "defer", "div", "do", |
| 56 | 56 | "else", "elsif", "end", "extern", "for", "forward", "if", "import", |
| 57 | 57 | "in", "link", "match", "mod", "module", "not", "of", "or", "packed", |
| @@ -59,7 +59,7 @@ | ||
| 59 | 59 | "to", "try", "type", "until", "var", "variant", "VOLATILE", "while", |
| 60 | 60 | "xor"]; |
| 61 | 61 | (* sPlus to sBlank *) |
| 62 | - ops: [NumOps][]U8 = [ | |
| 62 | + ops: [NumOps][]const U8 = [ | |
| 63 | 63 | "+", "-", "*", "/", "=", "#", "<", "<=", ">", ">=", |
| 64 | 64 | ":=", ":", ";", ",", ".", "..", "...", |
| 65 | 65 | "(", ")", "[", "]", "{", "}", "^", "&", "~", "|", "_"]; |
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | end; |
| 108 | 108 | |
| 109 | 109 | (* The bytes of the string just read, without the zero after them *) |
| 110 | -proc strBytes*: []U8; | |
| 110 | +proc strBytes*: []const U8; | |
| 111 | 111 | begin |
| 112 | 112 | return sbuf[0..slen]; |
| 113 | 113 | end; |
| @@ -228,7 +228,7 @@ | ||
| 228 | 228 | end; |
| 229 | 229 | |
| 230 | 230 | (* The name n, which stays as it is *) |
| 231 | -proc nameOf*(n: INT): []U8; | |
| 231 | +proc nameOf*(n: INT): []const U8; | |
| 232 | 232 | begin |
| 233 | 233 | return namePtr[n][0..nameLen[n]]; |
| 234 | 234 | end; |
| @@ -396,19 +396,19 @@ | ||
| 396 | 396 | |
| 397 | 397 | (* An error at p, shown: the parser returns Failed, which try passes up |
| 398 | 398 | to where it goes on. *) |
| 399 | -proc markAt*(p: Diag.Pos; msg: []U8): ERROR; | |
| 399 | +proc markAt*(p: Diag.Pos; msg: []const U8): ERROR; | |
| 400 | 400 | begin |
| 401 | 401 | Diag.error(p, msg); |
| 402 | 402 | return Failed; |
| 403 | 403 | end; |
| 404 | 404 | |
| 405 | -proc mark*(msg: []U8): ERROR; | |
| 405 | +proc mark*(msg: []const U8): ERROR; | |
| 406 | 406 | begin |
| 407 | 407 | return markAt(tokPos(), msg); |
| 408 | 408 | end; |
| 409 | 409 | |
| 410 | 410 | (* 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; | |
| 412 | 412 | begin |
| 413 | 413 | Diag.error(p, msg); |
| 414 | 414 | Diag.help(hint); |
| @@ -417,21 +417,21 @@ | ||
| 417 | 417 | |
| 418 | 418 | (* An error in the text at bytes a to b of the file being read, which |
| 419 | 419 | 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); | |
| 421 | 421 | begin |
| 422 | 422 | Diag.setQuiet(false); |
| 423 | 423 | Diag.error({f: cur.f, a: a, b: b}, msg); |
| 424 | 424 | Diag.finish; |
| 425 | 425 | end; |
| 426 | 426 | |
| 427 | -proc lexError(msg: []U8); | |
| 427 | +proc lexError(msg: []const U8); | |
| 428 | 428 | begin |
| 429 | 429 | markBytes(cur.tokPos, cur.pos, msg); |
| 430 | 430 | end; |
| 431 | 431 | |
| 432 | 432 | (* The n characters at the scanner are how another language writes t: |
| 433 | 433 | 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); | |
| 435 | 435 | begin |
| 436 | 436 | if not skipping then Diag.error({f: cur.f, a: cur.pos, b: cur.pos + n}, msg); end; |
| 437 | 437 | INC(cur.pos, n); |
| @@ -439,7 +439,7 @@ | ||
| 439 | 439 | end; |
| 440 | 440 | |
| 441 | 441 | (* How an operator or reserved word is written, quoted, for messages. *) |
| 442 | -proc symText*(s: Sym): []U8; | |
| 442 | +proc symText*(s: Sym): []const U8; | |
| 443 | 443 | begin |
| 444 | 444 | if (s >= sPlus) and (s <= sBlank) then |
| 445 | 445 | return Diag.say("\"{}\"", [Fmt.str(ops[INT(s) - INT(sPlus)])]); |
| @@ -449,7 +449,7 @@ | ||
| 449 | 449 | |
| 450 | 450 | (* The current symbol, for "expected ..., found ...": a name as it is, |
| 451 | 451 | a literal by its kind, an operator or reserved word quoted. *) |
| 452 | -proc found*: []U8; | |
| 452 | +proc found*: []const U8; | |
| 453 | 453 | begin |
| 454 | 454 | match tok of |
| 455 | 455 | | sIdent: return nameOf(id); |
| @@ -487,7 +487,7 @@ | ||
| 487 | 487 | end; |
| 488 | 488 | |
| 489 | 489 | (* 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; | |
| 491 | 491 | var fd, n, got, r, err: INT; info: Sys.Info; |
| 492 | 492 | begin |
| 493 | 493 | info, err := Sys.info(path); |
| @@ -619,7 +619,7 @@ | ||
| 619 | 619 | end; |
| 620 | 620 | |
| 621 | 621 | (* 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; | |
| 623 | 623 | begin |
| 624 | 624 | return Diag.source({f: cur.f, a: a, b: b}); |
| 625 | 625 | end; |
| @@ -817,7 +817,7 @@ | ||
| 817 | 817 | |
| 818 | 818 | (* s is digits, a point, digits, and maybe E, a sign and digits. False if |
| 819 | 819 | 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); | |
| 821 | 821 | var |
| 822 | 822 | num, den, d: Big; i, digits, e, ex: INT; neg, half, sticky: BOOL; |
| 823 | 823 | q, b: U64; x: F64; bits: ^F64; |
| @@ -1165,5 +1165,5 @@ | ||
| 1165 | 1165 | nameHash := ^INT(grab(nameCap * SIZE(INT))); |
| 1166 | 1166 | tableMask := 2 * nameCap - 1; |
| 1167 | 1167 | 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; | |
| 1169 | 1169 | end Scan. |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | sname*: INT; (* the name of its symbols: List(I64) for an instance *) |
| 127 | 127 | args*: Args; |
| 128 | 128 | scope*: INT; |
| 129 | - path*: []U8; | |
| 129 | + path*: []const U8; | |
| 130 | 130 | first*, last*: ^Obj; (* its top-level declarations, in order *) |
| 131 | 131 | locals*, lastLocal*: ^Obj; (* its procedures' declarations, in order *) |
| 132 | 132 | imports*: ^Import; |
| @@ -368,7 +368,7 @@ | ||
| 368 | 368 | (* How far apart two names are: the edits, a character put in, taken out, |
| 369 | 369 | changed or swapped with the next, that make one the other, ignoring |
| 370 | 370 | case. *) |
| 371 | -proc distance(a, b: []U8): INT; | |
| 371 | +proc distance(a, b: []const U8): INT; | |
| 372 | 372 | var d: [Scan.MaxIdent + 2][Scan.MaxIdent + 2]INT; i, j, c: INT; |
| 373 | 373 | begin |
| 374 | 374 | for i := 0 to LEN(a) do d[i][0] := i; end; |
| @@ -392,7 +392,7 @@ | ||
| 392 | 392 | if none is within an edit for every three characters. Only after an |
| 393 | 393 | error, so it looks at every object. *) |
| 394 | 394 | 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; | |
| 396 | 396 | begin |
| 397 | 397 | n := Scan.nameOf(name); |
| 398 | 398 | best := LEN(n) div 3 + 1; |
| @@ -633,7 +633,7 @@ | ||
| 633 | 633 | end; |
| 634 | 634 | |
| 635 | 635 | (* A name for t, kept for good, as every message is *) |
| 636 | -proc typeName*(t: ^Type): []U8; | |
| 636 | +proc typeName*(t: ^Type): []const U8; | |
| 637 | 637 | var b: ^Buf.Buf; |
| 638 | 638 | begin |
| 639 | 639 | b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf))); |
| @@ -700,12 +700,12 @@ | ||
| 700 | 700 | |
| 701 | 701 | (* The universe *) |
| 702 | 702 | |
| 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; | |
| 704 | 704 | var t: ^Type; o: ^Obj; |
| 705 | 705 | begin |
| 706 | 706 | t := newType(form, size, size); |
| 707 | 707 | 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); | |
| 709 | 709 | o^.exported := true; |
| 710 | 710 | t^.obj := o; |
| 711 | 711 | _ := insert(o, 0); |
| @@ -713,13 +713,13 @@ | ||
| 713 | 713 | end; |
| 714 | 714 | |
| 715 | 715 | (* The name s, interned *) |
| 716 | -proc internOf(s: []U8): INT; | |
| 716 | +proc internOf(s: []const U8): INT; | |
| 717 | 717 | begin |
| 718 | - return Scan.intern(ADR(s[0]), LEN(s)); | |
| 718 | + return Scan.intern(PTR(s), LEN(s)); | |
| 719 | 719 | end; |
| 720 | 720 | |
| 721 | 721 | (* 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); | |
| 723 | 723 | var o: ^Obj; |
| 724 | 724 | begin |
| 725 | 725 | o := newObj(cls, internOf(name), t); |
| @@ -730,7 +730,7 @@ | ||
| 730 | 730 | end; |
| 731 | 731 | |
| 732 | 732 | (* 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); | |
| 734 | 734 | begin |
| 735 | 735 | enterIn(0, name, cls, t, v); |
| 736 | 736 | end; |
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | (* The text of the instruction that starts at at, for the listing *) |
| 51 | 51 | Said = record |
| 52 | 52 | at: INT; |
| 53 | - text: []U8; | |
| 53 | + text: []const U8; | |
| 54 | 54 | end; |
| 55 | 55 | |
| 56 | 56 | var |
| @@ -226,7 +226,7 @@ | ||
| 226 | 226 | numSaid := n; |
| 227 | 227 | end; |
| 228 | 228 | |
| 229 | -proc sayAt*(at: INT; s: []U8); | |
| 229 | +proc sayAt*(at: INT; s: []const U8); | |
| 230 | 230 | begin |
| 231 | 231 | if not listing then return; end; |
| 232 | 232 | if numSaid = saidCap then |
| @@ -239,14 +239,14 @@ | ||
| 239 | 239 | end; |
| 240 | 240 | |
| 241 | 241 | (* The text of the instruction about to be written *) |
| 242 | -proc say*(s: []U8); | |
| 242 | +proc say*(s: []const U8); | |
| 243 | 243 | begin |
| 244 | 244 | sayAt(Chunk.pc, s); |
| 245 | 245 | end; |
| 246 | 246 | |
| 247 | 247 | (* The text of the instruction at at, said again, as when its operand is |
| 248 | 248 | patched *) |
| 249 | -proc restate*(at: INT; s: []U8); | |
| 249 | +proc restate*(at: INT; s: []const U8); | |
| 250 | 250 | var i: INT; |
| 251 | 251 | begin |
| 252 | 252 | i := numSaid - 1; |
| @@ -255,7 +255,7 @@ | ||
| 255 | 255 | end; |
| 256 | 256 | |
| 257 | 257 | const |
| 258 | - RegNames: [4][16][]U8 = [ | |
| 258 | + RegNames: [4][16][]const U8 = [ | |
| 259 | 259 | ["rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", |
| 260 | 260 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"], |
| 261 | 261 | ["eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", |
| @@ -264,13 +264,13 @@ | ||
| 264 | 264 | "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"], |
| 265 | 265 | ["al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil", |
| 266 | 266 | "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 *) | |
| 271 | 271 | |
| 272 | 272 | (* The name of register r, of size bytes *) |
| 273 | -proc rnSized(r, size: INT): []U8; | |
| 273 | +proc rnSized(r, size: INT): []const U8; | |
| 274 | 274 | begin |
| 275 | 275 | if size = 1 then return RegNames[3][r]; end; |
| 276 | 276 | if size = 2 then return RegNames[2][r]; end; |
| @@ -278,19 +278,19 @@ | ||
| 278 | 278 | return RegNames[0][r]; |
| 279 | 279 | end; |
| 280 | 280 | |
| 281 | -proc rn(r: INT): []U8; | |
| 281 | +proc rn(r: INT): []const U8; | |
| 282 | 282 | begin |
| 283 | 283 | return RegNames[0][r]; |
| 284 | 284 | end; |
| 285 | 285 | |
| 286 | -proc xn(x: INT): []U8; | |
| 286 | +proc xn(x: INT): []const U8; | |
| 287 | 287 | begin |
| 288 | 288 | return Diag.say("xmm{}", [Fmt.int(x)]); |
| 289 | 289 | end; |
| 290 | 290 | |
| 291 | 291 | (* A memory operand, with the size of what it holds, as the assembler |
| 292 | 292 | reads it *) |
| 293 | -proc mnSized(m: Mem; size: INT): []U8; | |
| 293 | +proc mnSized(m: Mem; size: INT): []const U8; | |
| 294 | 294 | var b: ^Buf.Buf; |
| 295 | 295 | begin |
| 296 | 296 | b := ^Buf.Buf(Scan.grab(SIZE(Buf.Buf))); |
| @@ -312,24 +312,24 @@ | ||
| 312 | 312 | return Buf.bytes(b^); |
| 313 | 313 | end; |
| 314 | 314 | |
| 315 | -proc mn(m: Mem): []U8; | |
| 315 | +proc mn(m: Mem): []const U8; | |
| 316 | 316 | begin |
| 317 | 317 | return mnSized(m, 0); |
| 318 | 318 | end; |
| 319 | 319 | |
| 320 | 320 | (* "op a, b" and "op a" *) |
| 321 | -proc text2(op, a, b: []U8): []U8; | |
| 321 | +proc text2(op, a, b: []const U8): []const U8; | |
| 322 | 322 | begin |
| 323 | 323 | return Diag.say("{} {}, {}", [Fmt.str(op), Fmt.str(a), Fmt.str(b)]); |
| 324 | 324 | end; |
| 325 | 325 | |
| 326 | -proc text1(op, a: []U8): []U8; | |
| 326 | +proc text1(op, a: []const U8): []const U8; | |
| 327 | 327 | begin |
| 328 | 328 | return Diag.say("{} {}", [Fmt.str(op), Fmt.str(a)]); |
| 329 | 329 | end; |
| 330 | 330 | |
| 331 | 331 | (* v in decimal *) |
| 332 | -proc num(v: INT): []U8; | |
| 332 | +proc num(v: INT): []const U8; | |
| 333 | 333 | begin |
| 334 | 334 | return Diag.say("{}", [Fmt.int(v)]); |
| 335 | 335 | end; |
| @@ -537,7 +537,7 @@ | ||
| 537 | 537 | lowest, one bit, 0F BD and 0F BC. ZF is set if r is 0, which has no |
| 538 | 538 | one bit, and r is then left undefined. *) |
| 539 | 539 | proc bitScan*(reverse: BOOL; r: INT); |
| 540 | -var opc: INT; name: []U8; | |
| 540 | +var opc: INT; name: []const U8; | |
| 541 | 541 | begin |
| 542 | 542 | if reverse then opc := 0BD0FH; name := "bsr"; else opc := 0BC0FH; name := "bsf"; end; |
| 543 | 543 | if listing then say(text2(name, rn(r), rn(r))); end; |
| @@ -674,7 +674,7 @@ | ||
| 674 | 674 | long forms of nop, of up to 8 bytes, that x86 decodes as one *) |
| 675 | 675 | proc align*(n: INT); |
| 676 | 676 | 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", | |
| 678 | 678 | "\x0F\x1F\x44\x00\x00", "\x66\x0F\x1F\x44\x00\x00", "\x0F\x1F\x80\x00\x00\x00\x00", |
| 679 | 679 | "\x0F\x1F\x84\x00\x00\x00\x00\x00"]; |
| 680 | 680 | var k, i: INT; |
| @@ -779,7 +779,7 @@ | ||
| 779 | 779 | return 0F2H; |
| 780 | 780 | end; |
| 781 | 781 | |
| 782 | -proc realEnd(single: BOOL): []U8; | |
| 782 | +proc realEnd(single: BOOL): []const U8; | |
| 783 | 783 | begin |
| 784 | 784 | if single then return "ss"; end; |
| 785 | 785 | return "sd"; |
| @@ -798,7 +798,7 @@ | ||
| 798 | 798 | opM(realPfx(single), false, 110FH, x, m, false); |
| 799 | 799 | end; |
| 800 | 800 | |
| 801 | -proc sseName(op: INT; single: BOOL): []U8; | |
| 801 | +proc sseName(op: INT; single: BOOL): []const U8; | |
| 802 | 802 | begin |
| 803 | 803 | if op = 58H then return Diag.say("add{}", [Fmt.str(realEnd(single))]); end; |
| 804 | 804 | if op = 59H then return Diag.say("mul{}", [Fmt.str(realEnd(single))]); end; |
| @@ -962,7 +962,7 @@ | ||
| 962 | 962 | |
| 963 | 963 | (* The current symbol as a word: an identifier, or a reserved word that |
| 964 | 964 | is also an instruction *) |
| 965 | -proc asmWord: []U8; | |
| 965 | +proc asmWord: []const U8; | |
| 966 | 966 | begin |
| 967 | 967 | match Scan.tok of |
| 968 | 968 | | sIdent: return Scan.nameOf(Scan.id); |
| @@ -980,7 +980,7 @@ | ||
| 980 | 980 | |
| 981 | 981 | (* Whether w names a register: rax, eax, ax, al and so on, or xmm0 to |
| 982 | 982 | 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; | |
| 984 | 984 | const Sizes: [4]INT = [8, 4, 2, 1]; |
| 985 | 985 | var i, j, n, d: INT; |
| 986 | 986 | begin |
| @@ -1005,7 +1005,7 @@ | ||
| 1005 | 1005 | |
| 1006 | 1006 | (* Which word of list, a list of words each with a space either side, |
| 1007 | 1007 | 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; | |
| 1009 | 1009 | var i, n, start: INT; |
| 1010 | 1010 | begin |
| 1011 | 1011 | n := 0; |
| @@ -1021,7 +1021,7 @@ | ||
| 1021 | 1021 | end; |
| 1022 | 1022 | |
| 1023 | 1023 | (* 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; | |
| 1025 | 1025 | var e: INT; |
| 1026 | 1026 | begin |
| 1027 | 1027 | e := from + n; |
| @@ -1031,9 +1031,9 @@ | ||
| 1031 | 1031 | end; |
| 1032 | 1032 | |
| 1033 | 1033 | (* 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; | |
| 1035 | 1035 | 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"]; | |
| 1037 | 1037 | AliasCc: [12]INT = [2, 2, 3, 3, 4, 5, 6, 7, 12, 13, 14, 15]; |
| 1038 | 1038 | var i: INT; |
| 1039 | 1039 | begin |
| @@ -1047,7 +1047,7 @@ | ||
| 1047 | 1047 | end; |
| 1048 | 1048 | |
| 1049 | 1049 | 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; | |
| 1051 | 1051 | begin |
| 1052 | 1052 | o^ := {}; |
| 1053 | 1053 | w := asmWord(); |
| @@ -1141,7 +1141,7 @@ | ||
| 1141 | 1141 | BitPfx: [5]INT = [0, 0, 0F3H, 0F3H, 0F3H]; |
| 1142 | 1142 | BitCodes: [5]INT = [0BC0FH, 0BD0FH, 0BC0FH, 0BD0FH, 0B80FH]; |
| 1143 | 1143 | (* 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", | |
| 1145 | 1145 | "pause", "nop", "ud2", "int3", "hlt", "cqo", "cdq", "mfence", "lfence", "sfence", |
| 1146 | 1146 | "cli", "sti", "iretq", "swapgs", "rdmsr", "wrmsr", "wbinvd"]; |
| 1147 | 1147 | PlainOp: [22]INT = [0C3H, 0C9H, 050FH, 0A20FH, 310FH, |
| @@ -1155,7 +1155,7 @@ | ||
| 1155 | 1155 | |
| 1156 | 1156 | var |
| 1157 | 1157 | (* the instruction being assembled *) |
| 1158 | - aw: []U8; (* its word *) | |
| 1158 | + aw: []const U8; (* its word *) | |
| 1159 | 1159 | ao: [3]Operand; (* its operands *) |
| 1160 | 1160 | an: INT; (* how many *) |
| 1161 | 1161 | asize, apfx: INT; |
| @@ -1448,7 +1448,7 @@ | ||
| 1448 | 1448 | Scan.next; |
| 1449 | 1449 | if Scan.tok = Scan.sColon then |
| 1450 | 1450 | 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))); | |
| 1452 | 1452 | if lplaces[k] >= 0 then |
| 1453 | 1453 | return Scan.markAt(aat, Diag.say("label {} is defined twice", [Fmt.str(aw)])); |
| 1454 | 1454 | end; |
| @@ -1540,7 +1540,7 @@ | ||
| 1540 | 1540 | end; |
| 1541 | 1541 | |
| 1542 | 1542 | (* Whether s holds a space *) |
| 1543 | -proc hasSpace(s: []U8): BOOL; | |
| 1543 | +proc hasSpace(s: []const U8): BOOL; | |
| 1544 | 1544 | var i: INT; |
| 1545 | 1545 | begin |
| 1546 | 1546 | for i := 0 to LEN(s) - 1 do |
| @@ -1551,7 +1551,7 @@ | ||
| 1551 | 1551 | |
| 1552 | 1552 | (* n, in decimal, at least w wide, as write(n: w) *) |
| 1553 | 1553 | proc padded(n, w: INT); |
| 1554 | -var s: []U8; i: INT; | |
| 1554 | +var s: []const U8; i: INT; | |
| 1555 | 1555 | begin |
| 1556 | 1556 | s := Diag.say("{}", [Fmt.int(n)]); |
| 1557 | 1557 | for i := LEN(s) to w - 1 do Out.str(" "); end; |
| @@ -1563,7 +1563,7 @@ | ||
| 1563 | 1563 | instructions made for it, at their offsets in the procedure; a jump |
| 1564 | 1564 | within it says where to by its offset too. *) |
| 1565 | 1565 | 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; | |
| 1567 | 1567 | begin |
| 1568 | 1568 | order := ^INT(Scan.grab(Chunk.numChunks * SIZE(INT))); |
| 1569 | 1569 | n := 0; |
| @@ -11,27 +11,27 @@ | ||
| 11 | 11 | completion for concha. |
| 12 | 12 | |
| 13 | 13 | 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); | |
| 17 | 17 | end; |
| 18 | 18 | |
| 19 | 19 | type Parser* = record |
| 20 | 20 | letter*: U8; (* the option just read *) |
| 21 | - value*: []U8; (* its value; "" for a flag *) | |
| 21 | + value*: []const U8; (* its value; "" for a flag *) | |
| 22 | 22 | 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 *) | |
| 24 | 24 | (* 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; | |
| 28 | 28 | 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 *) | |
| 30 | 30 | ended: BOOL; (* the scope's options have ended *) |
| 31 | 31 | help: BOOL; (* the option just read is -h or --help *) |
| 32 | 32 | end; |
| 33 | 33 | |
| 34 | -proc init*(var p: Parser; name: []U8; table: []Row); | |
| 34 | +proc init*(var p: Parser; name: []const U8; table: []const Row); | |
| 35 | 35 | p reads the arguments from 1 on, by table, in the program's own |
| 36 | 36 | scope; name begins the messages. |
| 37 | 37 | |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | The next option, in p.letter, p.value and p.long; false when the |
| 40 | 40 | scope's options end. |
| 41 | 41 | |
| 42 | -proc operand*(var p: Parser): ([]U8, BOOL); | |
| 42 | +proc operand*(var p: Parser): ([]const U8, BOOL); | |
| 43 | 43 | The next operand, after what options are left; false when there are |
| 44 | 44 | no more. |
| 45 | 45 | |
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | options are left: the operands from there on are Files.arg(i), for |
| 49 | 49 | i up to ARGC() - 1, as an interpreter hands them to its script. |
| 50 | 50 | |
| 51 | -proc scope*(var p: Parser; name: []U8); | |
| 51 | +proc scope*(var p: Parser; name: []const U8); | |
| 52 | 52 | The options of the subcommand name, from the word after its own, |
| 53 | 53 | which operand has given. |
| 54 | 54 | |
| @@ -57,16 +57,16 @@ | ||
| 57 | 57 | anything else is a mistake. A number with no top is given the |
| 58 | 58 | largest I64 for hi, and the mistake says "from lo up". |
| 59 | 59 | |
| 60 | -proc refuse*(const p: Parser; wants: []U8); | |
| 60 | +proc refuse*(const p: Parser; wants: []const U8); | |
| 61 | 61 | The value of the option just read refused, as number refuses one: |
| 62 | 62 | "-b wants wants, not 'value'", the option as it was written, with |
| 63 | 63 | the scope's synopsis lines, and status 2. |
| 64 | 64 | |
| 65 | -proc fail*(const p: Parser; text: []U8); | |
| 65 | +proc fail*(const p: Parser; text: []const U8); | |
| 66 | 66 | The program's own mistake, written as Opt's are but alone, and |
| 67 | 67 | status 2. |
| 68 | 68 | |
| 69 | -proc misuse*(const p: Parser; text: []U8); | |
| 69 | +proc misuse*(const p: Parser; text: []const U8); | |
| 70 | 70 | The program's own mistake, written as Opt's are, with the scope's |
| 71 | 71 | synopsis lines after it, and status 2. |
| 72 | 72 |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | 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 | |
| 3 | 3 | module orders, searches and hashes them, trims them and takes them |
| 4 | 4 | apart, tells an ASCII character's kind and changes a letter's case, |
| 5 | 5 | joins them and replaces in them, reads and writes their UTF-8, reads |
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | gives is a slice of the string it was given, with no memory of its |
| 8 | 8 | own. |
| 9 | 9 | |
| 10 | -proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL); | |
| 10 | +proc copy*(a: ^Mem.Allocator; s: []const U8): ([]U8, BOOL); | |
| 11 | 11 | s's bytes, copied into memory from a, to keep after s's own are |
| 12 | 12 | gone; "" and false if a has no room. |
| 13 | 13 | |
| @@ -15,32 +15,32 @@ | ||
| 15 | 15 | Gives back to a a copy that copy made from it; "", which copy gives |
| 16 | 16 | for an empty string, was never a's, and is left alone. |
| 17 | 17 | |
| 18 | -proc cmp*(a, b: []U8): INT; | |
| 18 | +proc cmp*(a, b: []const U8): INT; | |
| 19 | 19 | -1, 0 or 1 as a sorts before, with or after b, byte by byte. |
| 20 | 20 | |
| 21 | -proc eq*(a, b: []U8): BOOL; | |
| 21 | +proc eq*(a, b: []const U8): BOOL; | |
| 22 | 22 | Whether a and b hold the same bytes: a = b, as a procedure value. |
| 23 | 23 | |
| 24 | -proc eqFold*(a, b: []U8): BOOL; | |
| 24 | +proc eqFold*(a, b: []const U8): BOOL; | |
| 25 | 25 | Whether a and b are the same but for the case of ASCII letters. |
| 26 | 26 | |
| 27 | -proc hash*(s: []U8): U64; | |
| 27 | +proc hash*(s: []const U8): U64; | |
| 28 | 28 | FNV-1a, 64 bits. |
| 29 | 29 | |
| 30 | -proc find*(s, sub: []U8): INT; | |
| 30 | +proc find*(s, sub: []const U8): INT; | |
| 31 | 31 | Where sub first starts in s, or -1. |
| 32 | 32 | |
| 33 | -proc findFrom*(s, sub: []U8; from: INT): INT; | |
| 33 | +proc findFrom*(s, sub: []const U8; from: INT): INT; | |
| 34 | 34 | Where sub first starts in s at or after from, or -1; from is at |
| 35 | 35 | most LEN(s). |
| 36 | 36 | |
| 37 | -proc findLast*(s, sub: []U8): INT; | |
| 37 | +proc findLast*(s, sub: []const U8): INT; | |
| 38 | 38 | Where sub last starts in s, or -1. |
| 39 | 39 | |
| 40 | -proc hasPrefix*(s, p: []U8): BOOL; | |
| 40 | +proc hasPrefix*(s, p: []const U8): BOOL; | |
| 41 | 41 | Whether s starts with p. |
| 42 | 42 | |
| 43 | -proc hasSuffix*(s, x: []U8): BOOL; | |
| 43 | +proc hasSuffix*(s, x: []const U8): BOOL; | |
| 44 | 44 | Whether s ends with x. |
| 45 | 45 | |
| 46 | 46 | proc isSpace*(c: U8): BOOL; |
| @@ -60,20 +60,20 @@ | ||
| 60 | 60 | proc hexVal*(c: U8): INT; |
| 61 | 61 | c's value as a hexadecimal digit, capital or small; -1 if it isn't one. |
| 62 | 62 | |
| 63 | -proc trimLeft*(s: []U8): []U8; | |
| 63 | +proc trimLeft*(s: []const U8): []const U8; | |
| 64 | 64 | s without the spaces at its start. |
| 65 | 65 | |
| 66 | -proc trimRight*(s: []U8): []U8; | |
| 66 | +proc trimRight*(s: []const U8): []const U8; | |
| 67 | 67 | s without the spaces at its end. |
| 68 | 68 | |
| 69 | -proc trim*(s: []U8): []U8; | |
| 69 | +proc trim*(s: []const U8): []const U8; | |
| 70 | 70 | s without the spaces at either end. |
| 71 | 71 | |
| 72 | -proc cut*(s, sep: []U8): ([]U8, []U8, BOOL); | |
| 72 | +proc cut*(s, sep: []const U8): ([]const U8, []const U8, BOOL); | |
| 73 | 73 | What comes before the first sep in s, what comes after it, and true; |
| 74 | 74 | or s, an empty string and false if s has no sep. |
| 75 | 75 | |
| 76 | -proc field*(s: []U8): ([]U8, []U8); | |
| 76 | +proc field*(s: []const U8): ([]const U8, []const U8); | |
| 77 | 77 | The first word of s, the bytes after the spaces at its start up to |
| 78 | 78 | the next space or the end, and the rest of s from there; two empty |
| 79 | 79 | strings if s holds only spaces. |
| @@ -84,10 +84,10 @@ | ||
| 84 | 84 | proc upper*(s: []U8); |
| 85 | 85 | s's small ASCII letters made capitals, in place. |
| 86 | 86 | |
| 87 | -proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8); | |
| 87 | +proc join*(var b: Buf.Buf; parts: [][]const U8; sep: []const U8); | |
| 88 | 88 | The parts added to b, with sep between each two. |
| 89 | 89 | |
| 90 | -proc replace*(var b: Buf.Buf; s, old, new: []U8); | |
| 90 | +proc replace*(var b: Buf.Buf; s, old, new: []const U8); | |
| 91 | 91 | s added to b, with new for each old in it, from the left, none |
| 92 | 92 | overlapping another; s as it is if old is empty. |
| 93 | 93 | |
| @@ -96,34 +96,34 @@ | ||
| 96 | 96 | character, a surrogate or one past 10FFFFH, becomes FFFDH, the |
| 97 | 97 | character that stands for a wrong one. |
| 98 | 98 | |
| 99 | -proc decode*(s: []U8): (I32, INT); | |
| 99 | +proc decode*(s: []const U8): (I32, INT); | |
| 100 | 100 | The character s starts with, and its length in bytes: FFFDH and 1 |
| 101 | 101 | if its first byte doesn't start one rightly, being a continuation, |
| 102 | 102 | or followed by too few continuations, or spelling a surrogate or a |
| 103 | 103 | character in more bytes than it needs; 0 and 0 if s is empty. |
| 104 | 104 | |
| 105 | -proc decodeLast*(s: []U8): (I32, INT); | |
| 105 | +proc decodeLast*(s: []const U8): (I32, INT); | |
| 106 | 106 | The character s ends with, and its length in bytes, read as decode |
| 107 | 107 | reads one: FFFDH and 1 if the last byte doesn't end one rightly; 0 |
| 108 | 108 | and 0 if s is empty. |
| 109 | 109 | |
| 110 | -proc next*(s: []U8; i: INT): (I32, INT); | |
| 110 | +proc next*(s: []const U8; i: INT): (I32, INT); | |
| 111 | 111 | The character at i in s, as decode reads it, and where the one after |
| 112 | 112 | it starts; 0 and -1 if i is at the end or past it. |
| 113 | 113 | |
| 114 | -proc chars*(s: []U8): INT; | |
| 114 | +proc chars*(s: []const U8): INT; | |
| 115 | 115 | The characters in s, as decode reads them, each byte that doesn't |
| 116 | 116 | start one rightly counted as one. |
| 117 | 117 | |
| 118 | -proc valid*(s: []U8): BOOL; | |
| 118 | +proc valid*(s: []const U8): BOOL; | |
| 119 | 119 | Whether s is UTF-8: decode finds no byte that doesn't start a |
| 120 | 120 | character rightly. |
| 121 | 121 | |
| 122 | -proc toInt*(s: []U8): (I64, BOOL); | |
| 122 | +proc toInt*(s: []const U8): (I64, BOOL); | |
| 123 | 123 | s as a decimal number, with a - or + before it if any, and nothing |
| 124 | 124 | else; false if it isn't one, or an I64 can't hold it. |
| 125 | 125 | |
| 126 | -proc toHex*(s: []U8): (U64, BOOL); | |
| 126 | +proc toHex*(s: []const U8): (U64, BOOL); | |
| 127 | 127 | s in hexadecimal, digits only, capitals or not; false if it isn't |
| 128 | 128 | that, or a U64 can't hold it. |
| 129 | 129 | |
| @@ -136,18 +136,18 @@ | ||
| 136 | 136 | proc base64Size*(n: INT): INT; |
| 137 | 137 | The bytes base64 makes of n bytes: 4 for each 3, or part of 3. |
| 138 | 138 | |
| 139 | -proc base64With*(s, out, alphabet: []U8; pad: BOOL): INT; | |
| 139 | +proc base64With*(s: []const U8; out: []U8; alphabet: []const U8; pad: BOOL): INT; | |
| 140 | 140 | s in base64 into out, which holds base64Size(LEN(s)) bytes at least; |
| 141 | 141 | a shorter out stops the program at the byte it lacks, as any slice |
| 142 | 142 | does. alphabet holds the 64 digits (Base64 or Base64Url, or one's |
| 143 | 143 | own). A last group of 1 or 2 bytes is padded with = to four if pad, |
| 144 | 144 | and else has 2 or 3 digits. The bytes written. |
| 145 | 145 | |
| 146 | -proc base64*(s, out: []U8): INT; | |
| 146 | +proc base64*(s: []const U8; out: []U8): INT; | |
| 147 | 147 | s in base64 (RFC 4648, section 4), padded, into out as base64With |
| 148 | 148 | writes it. |
| 149 | 149 | |
| 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); | |
| 151 | 151 | s, base64 with the digits of alphabet, decoded into out, which holds |
| 152 | 152 | (LEN(s) + 3) div 4 * 3 bytes at least; a shorter out stops the |
| 153 | 153 | program at the byte it lacks, as any slice does. The bytes written, |
| @@ -161,32 +161,32 @@ | ||
| 161 | 161 | it (RFC 4648, section 3.5 allows a decoder to take that). Line |
| 162 | 162 | breaks, and padding or its lack, are the caller's to mend first. |
| 163 | 163 | |
| 164 | -proc unbase64*(s, out: []U8): (INT, BOOL); | |
| 164 | +proc unbase64*(s: []const U8; out: []U8): (INT, BOOL); | |
| 165 | 165 | s, base64 (RFC 4648, section 4), padded, decoded into out as |
| 166 | 166 | unbase64With reads it; out holds LEN(s) div 4 * 3 bytes at least. |
| 167 | 167 | |
| 168 | -proc toU64*(s: []U8): (U64, BOOL); | |
| 168 | +proc toU64*(s: []const U8): (U64, BOOL); | |
| 169 | 169 | s as a decimal number, digits only; false if it isn't one, or a U64 |
| 170 | 170 | can't hold it. |
| 171 | 171 | |
| 172 | -proc fromC*(p: ^U8): []U8; | |
| 172 | +proc fromC*(p: ^U8): []const U8; | |
| 173 | 173 | The bytes at p up to its zero byte, not copied; "" for nil. |
| 174 | 174 | |
| 175 | -proc toC*(s, out: []U8): ^U8; | |
| 175 | +proc toC*(s: []const U8; out: []U8): ^U8; | |
| 176 | 176 | s copied into out with a zero byte after it, for C: out holds |
| 177 | 177 | 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). | |
| 179 | 179 | |
| 180 | 180 | proc fromInt*(n: I64): ([20]U8, INT); |
| 181 | 181 | n in decimal, as Out.int writes it: its bytes, the first of the 20, |
| 182 | 182 | and how many. |
| 183 | 183 | |
| 184 | -proc le*(s: []U8): U64; | |
| 184 | +proc le*(s: []const U8): U64; | |
| 185 | 185 | The bytes of s, at most 8, as an unsigned number, the first byte |
| 186 | 186 | the lowest: how a file or a message in little-endian order is read, |
| 187 | 187 | whatever the machine's own order. |
| 188 | 188 | |
| 189 | -proc be*(s: []U8): U64; | |
| 189 | +proc be*(s: []const U8): U64; | |
| 190 | 190 | As le, the first byte the highest: big-endian, network order. |
| 191 | 191 | |
| 192 | 192 | proc putLE*(s: []U8; v: U64); |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module SetEnvC; |
| 4 | 4 | import Out, Rt, Sys; |
| 5 | 5 | |
| 6 | -proc run(env: [][]U8); | |
| 6 | +proc run(env: [][]const U8); | |
| 7 | 7 | var p: Sys.Program; pid: INT; |
| 8 | 8 | begin |
| 9 | 9 | p.path := "/bin/sh"; |
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | 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 | |
| 3 | 3 | in BufCut.main at test/run/BufCut.raz:11:5 |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | 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 | |
| 4 | 4 | in BufFull.main at test/run/BufFull.raz:11:5 |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | 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 | |
| 5 | 5 | in BufInit.main at test/run/BufInit.raz:9:5 |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | 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? | |
| 7 | 7 | in HeapDebugEnd.main at test/run/HeapDebugEnd.raz:12:5: p = 0x? |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | 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? | |
| 7 | 7 | in HeapDebugFree.main at test/run/HeapDebugFree.raz:15:9: p = 0x?, q = 0x?, i = 1023 |
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | 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 | |
| 3 | 3 | in HeapSure.main at test/run/HeapSure.raz:8:5 |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | (* Map.done: the slots given back to the allocator, through one that |
| 2 | 2 | counts its blocks; the map empty after, and used again. *) |
| 3 | 3 | 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); | |
| 5 | 5 | |
| 6 | 6 | var counting: Mem.Allocator; live: INT; |
| 7 | 7 |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | module SetEnv; |
| 4 | 4 | import Out, Rt, Sys; |
| 5 | 5 | |
| 6 | -proc run(env: [][]U8); | |
| 6 | +proc run(env: [][]const U8); | |
| 7 | 7 | var p: Sys.Program; pid: INT; |
| 8 | 8 | begin |
| 9 | 9 | p.path := "/bin/sh"; |
| @@ -3,4 +3,4 @@ | ||
| 3 | 3 | in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1926 |
| 4 | 4 | and 1926 more the same |
| 5 | 5 | 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? |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | test/run/ThreadOverflowC.raz:7:1: stopped by a stack overflow |
| 2 | 2 | in ThreadOverflowC.big at test/run/ThreadOverflowC.raz:7:1 |
| 3 | 3 | 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? |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | 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 | |
| 4 | 4 | in VecFull.main at test/run/VecFull.raz:11:28: i = 257 |
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | |
| 30 | 30 | var |
| 31 | 31 | sc: Scan.Scanner; (* the text being read, at the current symbol *) |
| 32 | - src: []U8; | |
| 32 | + src: []const U8; | |
| 33 | 33 | docStart, docEnd: INT; (* the comment just before it, or -1 *) |
| 34 | 34 | man: BOOL; (* writing mdoc *) |
| 35 | 35 | atStart: BOOL; (* emit is at the start of a line *) |
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | end; |
| 69 | 69 | |
| 70 | 70 | (* a line of mdoc's own, such as .Ed *) |
| 71 | -proc control(s: []U8); | |
| 71 | +proc control(s: []const U8); | |
| 72 | 72 | begin |
| 73 | 73 | Out.str(s); |
| 74 | 74 | Out.ln; |
| @@ -89,12 +89,12 @@ | ||
| 89 | 89 | shown := false; |
| 90 | 90 | end; |
| 91 | 91 | |
| 92 | -proc text: []U8; | |
| 92 | +proc text: []const U8; | |
| 93 | 93 | begin |
| 94 | 94 | return Scan.text(sc); |
| 95 | 95 | end; |
| 96 | 96 | |
| 97 | -proc is(s: []U8): BOOL; | |
| 97 | +proc is(s: []const U8): BOOL; | |
| 98 | 98 | begin |
| 99 | 99 | return text() = s; |
| 100 | 100 | end; |
| @@ -252,7 +252,7 @@ | ||
| 252 | 252 | (* One declaration, from its first token, the comment before it kept. |
| 253 | 253 | In mdoc a module's test, its main, is left out, and declarations |
| 254 | 254 | 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); | |
| 256 | 256 | begin |
| 257 | 257 | if not exported then return; end; |
| 258 | 258 | if (groupStart >= 0) and (LEN(prefix) > 0) then heading; end; |
| @@ -315,7 +315,7 @@ | ||
| 315 | 315 | end; |
| 316 | 316 | |
| 317 | 317 | 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; | |
| 319 | 319 | begin |
| 320 | 320 | word := text(); |
| 321 | 321 | groupStart := docStart; groupEnd := docEnd; |
| @@ -342,7 +342,7 @@ | ||
| 342 | 342 | next; |
| 343 | 343 | end; |
| 344 | 344 | |
| 345 | -proc document(path: []U8); | |
| 345 | +proc document(path: []const U8); | |
| 346 | 346 | var b: Buf.Buf; start, ds, de: INT; |
| 347 | 347 | begin |
| 348 | 348 | groupStart := -1; |
| @@ -378,7 +378,7 @@ | ||
| 378 | 378 | (* line, from the report or a manual page's literal block, added to b |
| 379 | 379 | as the program has it: in a page, \e is a backslash, \(ga a |
| 380 | 380 | 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); | |
| 382 | 382 | var i: INT; |
| 383 | 383 | begin |
| 384 | 384 | i := 0; |
| @@ -399,7 +399,7 @@ | ||
| 399 | 399 | end; |
| 400 | 400 | |
| 401 | 401 | (* 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); | |
| 403 | 403 | begin |
| 404 | 404 | Buf.reset(out); |
| 405 | 405 | Buf.str(out, dir); Buf.str(out, "/"); Buf.str(out, name); Buf.str(out, ext); |
| @@ -411,9 +411,9 @@ | ||
| 411 | 411 | -literal and .Ed. In a page, a block that starts on the line after |
| 412 | 412 | a module's is what that program prints, written to dir/Name.shown, |
| 413 | 413 | so that the page can be checked against the program. *) |
| 414 | -proc examples(path, dir: []U8); | |
| 414 | +proc examples(path, dir: []const U8); | |
| 415 | 415 | 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; | |
| 417 | 417 | i, k, n, after: INT; inBlock, whole, page, fence: BOOL; |
| 418 | 418 | begin |
| 419 | 419 | Buf.init(b, Heap.heap); |
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | import Out, Rt, Buf, Heap, Scan, Files; |
| 11 | 11 | |
| 12 | 12 | var |
| 13 | - src: []U8; | |
| 13 | + src: []const U8; | |
| 14 | 14 | state: U64; (* the generator: xorshift64 *) |
| 15 | 15 | |
| 16 | 16 | (* A number from the generator, below n. *) |
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | end; |
| 24 | 24 | |
| 25 | 25 | (* The seed, as a nonzero state. *) |
| 26 | -proc seed(s: []U8); | |
| 26 | +proc seed(s: []const U8); | |
| 27 | 27 | var i: INT; |
| 28 | 28 | begin |
| 29 | 29 | state := 88172645463325252; |
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | |
| 34 | 34 | var |
| 35 | 35 | sc: Scan.Scanner; (* the source, at the symbol being written *) |
| 36 | - src: []U8; | |
| 36 | + src: []const U8; | |
| 37 | 37 | out: Buf.Buf; |
| 38 | 38 | lineAt: INT; (* where the line being written starts in out *) |
| 39 | 39 | lineDelta: INT; (* how far this line's indent moved *) |
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | |
| 61 | 61 | (* Drops the spaces at the end of the line in out. *) |
| 62 | 62 | proc trim; |
| 63 | -var s: []U8; | |
| 63 | +var s: []const U8; | |
| 64 | 64 | begin |
| 65 | 65 | s := Buf.bytes(out); |
| 66 | 66 | while (out.len > lineAt) and ((s[out.len - 1] = ' ') or (s[out.len - 1] = '\t')) do |
| @@ -134,7 +134,7 @@ | ||
| 134 | 134 | (* Whether the current symbol, first on its line, goes on with the |
| 135 | 135 | expression of the line before. *) |
| 136 | 136 | proc continues: BOOL; |
| 137 | -var t: []U8; | |
| 137 | +var t: []const U8; | |
| 138 | 138 | begin |
| 139 | 139 | if (brackets > 0) or prevBinary or Scan.is(prev, ",") then return true; end; |
| 140 | 140 | t := Scan.text(sc); |
| @@ -252,7 +252,7 @@ | ||
| 252 | 252 | (* After a symbol that isn't a comment: the blocks and brackets it opens |
| 253 | 253 | or closes. *) |
| 254 | 254 | proc track(binaryNow: BOOL); |
| 255 | -var t: []U8; | |
| 255 | +var t: []const U8; | |
| 256 | 256 | begin |
| 257 | 257 | t := Scan.text(sc); |
| 258 | 258 | if sc.kind = Scan.word then |
| @@ -285,7 +285,7 @@ | ||
| 285 | 285 | end; |
| 286 | 286 | |
| 287 | 287 | (* src, formatted, into out. *) |
| 288 | -proc format(text: []U8); | |
| 288 | +proc format(text: []const U8); | |
| 289 | 289 | var b: BOOL; |
| 290 | 290 | begin |
| 291 | 291 | src := text; |
| @@ -323,7 +323,7 @@ | ||
| 323 | 323 | end; |
| 324 | 324 | |
| 325 | 325 | proc main*; |
| 326 | -var b: Buf.Buf; i: INT; path: []U8; | |
| 326 | +var b: Buf.Buf; i: INT; path: []const U8; | |
| 327 | 327 | begin |
| 328 | 328 | Buf.init(b, Heap.heap); |
| 329 | 329 | Buf.init(out, Heap.heap); |
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | (* word is an identifier or a reserved word; literal a string or a |
| 13 | 13 | character; symbol an operator or delimiter. *) |
| 14 | 14 | Scanner* = record |
| 15 | - src*: []U8; | |
| 15 | + src*: []const U8; | |
| 16 | 16 | pos*: INT; (* where the next symbol is looked for *) |
| 17 | 17 | kind*: Kind; (* the current symbol *) |
| 18 | 18 | start*, stop*: INT; (* its text: src[start..stop] *) |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | (* Whether w is one of the words of list, which are separated by |
| 42 | 42 | single spaces. *) |
| 43 | -proc among*(w, list: []U8): BOOL; | |
| 43 | +proc among*(w, list: []const U8): BOOL; | |
| 44 | 44 | var i, j: INT; |
| 45 | 45 | begin |
| 46 | 46 | i := 0; |
| @@ -54,19 +54,19 @@ | ||
| 54 | 54 | end; |
| 55 | 55 | |
| 56 | 56 | (* Whether w is one of the report's reserved words. *) |
| 57 | -proc reserved*(w: []U8): BOOL; | |
| 57 | +proc reserved*(w: []const U8): BOOL; | |
| 58 | 58 | begin |
| 59 | 59 | return among(w, words); |
| 60 | 60 | end; |
| 61 | 61 | |
| 62 | 62 | (* 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); | |
| 64 | 64 | begin |
| 65 | 65 | s := {src: src, kind: eof}; |
| 66 | 66 | end; |
| 67 | 67 | |
| 68 | 68 | (* Past the comment that starts at p, its nested comments with it. *) |
| 69 | -proc pastComment(src: []U8; p: INT): INT; | |
| 69 | +proc pastComment(src: []const U8; p: INT): INT; | |
| 70 | 70 | var depth: INT; |
| 71 | 71 | begin |
| 72 | 72 | depth := 0; |
| @@ -84,7 +84,7 @@ | ||
| 84 | 84 | |
| 85 | 85 | (* Past the number that starts at p: digits and letters, then a real's |
| 86 | 86 | point, digits and exponent, as in 0FFH and 2.0E-3. *) |
| 87 | -proc pastNumber(src: []U8; p: INT): INT; | |
| 87 | +proc pastNumber(src: []const U8; p: INT): INT; | |
| 88 | 88 | begin |
| 89 | 89 | while (p < LEN(src)) and isWord(src[p]) do INC(p); end; |
| 90 | 90 | if (p + 1 < LEN(src)) and (src[p] = '.') and isDigit(src[p + 1]) then |
| @@ -101,7 +101,7 @@ | ||
| 101 | 101 | (* Past the string or character that starts at p, or to its line's end; |
| 102 | 102 | a raw string, between backquotes, has no escapes and may run over |
| 103 | 103 | lines. *) |
| 104 | -proc pastLiteral(src: []U8; p: INT): INT; | |
| 104 | +proc pastLiteral(src: []const U8; p: INT): INT; | |
| 105 | 105 | var q: U8; |
| 106 | 106 | begin |
| 107 | 107 | q := src[p]; |
| @@ -115,14 +115,14 @@ | ||
| 115 | 115 | end; |
| 116 | 116 | |
| 117 | 117 | (* 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; | |
| 119 | 119 | begin |
| 120 | 120 | return (p + LEN(t) <= LEN(src)) and (src[p..p + LEN(t)] = t); |
| 121 | 121 | end; |
| 122 | 122 | |
| 123 | 123 | (* On to the next symbol. *) |
| 124 | 124 | proc next*(var s: Scanner); |
| 125 | -var src: []U8; p: INT; c: U8; | |
| 125 | +var src: []const U8; p: INT; c: U8; | |
| 126 | 126 | begin |
| 127 | 127 | src := s.src; |
| 128 | 128 | p := s.pos; |
| @@ -159,13 +159,13 @@ | ||
| 159 | 159 | s.pos := p; |
| 160 | 160 | end; |
| 161 | 161 | |
| 162 | -proc text*(const s: Scanner): []U8; | |
| 162 | +proc text*(const s: Scanner): []const U8; | |
| 163 | 163 | begin |
| 164 | 164 | return s.src[s.start..s.stop]; |
| 165 | 165 | end; |
| 166 | 166 | |
| 167 | 167 | (* 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; | |
| 169 | 169 | begin |
| 170 | 170 | return text(s) = t; |
| 171 | 171 | end; |
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | can't tell: it is 1. *) |
| 58 | 58 | module Test; |
| 59 | 59 | 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); | |
| 61 | 61 | |
| 62 | 62 | const |
| 63 | 63 | TapKey = 1; (* the keys of --tap and --junit, which have no letter *) |
| @@ -95,10 +95,10 @@ | ||
| 95 | 95 | |
| 96 | 96 | (* A test and how it is going. *) |
| 97 | 97 | 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 *) | |
| 102 | 102 | phase: Phase; |
| 103 | 103 | pid: INT; (* the compiler's or the test's, while building or running *) |
| 104 | 104 | began: I64; (* Sys.clock when its build started *) |
| @@ -109,31 +109,31 @@ | ||
| 109 | 109 | end; |
| 110 | 110 | |
| 111 | 111 | var |
| 112 | - raz: []U8; (* the compiler: $RAZ, or raz on PATH *) | |
| 112 | + raz: []const U8; (* the compiler: $RAZ, or raz on PATH *) | |
| 113 | 113 | includes: Names.Vec; (* the -I directories *) |
| 114 | 114 | operands: Names.Vec; (* the files and directories given *) |
| 115 | 115 | jobs: INT; (* -j: tests at once *) |
| 116 | 116 | 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 "" *) | |
| 119 | 119 | tests: Jobs.Vec; (* in the order they are reported *) |
| 120 | 120 | busy: INT; (* tests being built or run *) |
| 121 | 121 | devNull: INT; (* /dev/null, each test's standard input *) |
| 122 | 122 | signals: INT; (* the fd the interrupting signals come on *) |
| 123 | 123 | colour: BOOL; (* the words of the results are coloured *) |
| 124 | 124 | 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 "" *) | |
| 126 | 126 | watch: BOOL; (* -w: run again when a file changes *) |
| 127 | 127 | clearing: BOOL; (* the screen is cleared before each run of -w *) |
| 128 | 128 | |
| 129 | 129 | (* 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; | |
| 131 | 131 | begin |
| 132 | 132 | return Str.cmp(a, b) < 0; |
| 133 | 133 | end; |
| 134 | 134 | |
| 135 | 135 | (* 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); | |
| 137 | 137 | var b: Buf.Buf; |
| 138 | 138 | begin |
| 139 | 139 | Buf.init(b, Heap.heap); |
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | end; |
| 145 | 145 | |
| 146 | 146 | (* 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; | |
| 148 | 148 | var s: Buf.Buf; |
| 149 | 149 | begin |
| 150 | 150 | Buf.init(s, Heap.heap); |
| @@ -153,8 +153,8 @@ | ||
| 153 | 153 | end; |
| 154 | 154 | |
| 155 | 155 | (* 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; | |
| 158 | 158 | begin |
| 159 | 159 | Buf.init(b, Heap.heap); |
| 160 | 160 | defer Buf.done(b); |
| @@ -164,8 +164,8 @@ | ||
| 164 | 164 | end; |
| 165 | 165 | |
| 166 | 166 | (* 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; | |
| 169 | 169 | begin |
| 170 | 170 | name := path[Str.findLast(path, "/") + 1..LEN(path)]; |
| 171 | 171 | if Str.hasSuffix(name, ".raz") then name := name[0..LEN(name) - 4]; end; |
| @@ -177,8 +177,8 @@ | ||
| 177 | 177 | end; |
| 178 | 178 | |
| 179 | 179 | (* 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; | |
| 182 | 182 | begin |
| 183 | 183 | err := Sys.openDir(d, dir); |
| 184 | 184 | if err < 0 then die("can't read {}: {}", [Fmt.str(dir), Fmt.str(Sys.errorText(err))]); end; |
| @@ -195,7 +195,7 @@ | ||
| 195 | 195 | end; |
| 196 | 196 | |
| 197 | 197 | (* Adds what an operand names: a directory's tests, or a file. *) |
| 198 | -proc addOperand(path: []U8); | |
| 198 | +proc addOperand(path: []const U8); | |
| 199 | 199 | var f: Sys.Info; err: INT; |
| 200 | 200 | begin |
| 201 | 201 | f, err := Sys.info(path); |
| @@ -218,7 +218,7 @@ | ||
| 218 | 218 | end; |
| 219 | 219 | |
| 220 | 220 | (* Sets the environment variable name to value, for the tests. *) |
| 221 | -proc setProp(name, value: []U8); | |
| 221 | +proc setProp(name, value: []const U8); | |
| 222 | 222 | begin |
| 223 | 223 | if Sys.setEnv(name, value) # 0 then die("can't set {}", [Fmt.str(name)]); end; |
| 224 | 224 | end; |
| @@ -236,7 +236,7 @@ | ||
| 236 | 236 | |
| 237 | 237 | (* Reads the command line into the settings and the list of tests. *) |
| 238 | 238 | 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; | |
| 240 | 240 | begin |
| 241 | 241 | jobs := 1; timeout := 60 * Second; outDir := "build/raztest"; |
| 242 | 242 | Names.init(includes, Heap.heap); |
| @@ -278,7 +278,7 @@ | ||
| 278 | 278 | end; |
| 279 | 279 | |
| 280 | 280 | (* Makes the directory dir and those it is in, as mkdir -p does. *) |
| 281 | -proc makeDirs(dir: []U8); | |
| 281 | +proc makeDirs(dir: []const U8); | |
| 282 | 282 | var i, err: INT; f: Sys.Info; |
| 283 | 283 | begin |
| 284 | 284 | for i := 1 to LEN(dir) - 1 do |
| @@ -326,7 +326,7 @@ | ||
| 326 | 326 | |
| 327 | 327 | (* Starts args[0] with its output and errors into j's log, as j's next |
| 328 | 328 | 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; | |
| 330 | 330 | var fd: INT; |
| 331 | 331 | begin |
| 332 | 332 | fd := Sys.create(j.log); |
| @@ -368,7 +368,7 @@ | ||
| 368 | 368 | (* The test j's phase has ended, how and with value as Sys.wait says: |
| 369 | 369 | on to running it, or the end. *) |
| 370 | 370 | proc ended(var j: Job; how: Sys.Status; value: INT); |
| 371 | -var args: [1][]U8; | |
| 371 | +var args: [1][]const U8; | |
| 372 | 372 | begin |
| 373 | 373 | if (j.phase = building) and (how = Sys.exited) and (value = 0) then |
| 374 | 374 | args[0] := j.bin; |
| @@ -409,7 +409,7 @@ | ||
| 409 | 409 | end; |
| 410 | 410 | |
| 411 | 411 | (* 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); | |
| 413 | 413 | var i: INT; |
| 414 | 414 | begin |
| 415 | 415 | if colour then Out.str(c); Out.str(word); Out.str(Plain); else Out.str(word); end; |
| @@ -417,8 +417,8 @@ | ||
| 417 | 417 | end; |
| 418 | 418 | |
| 419 | 419 | (* 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; | |
| 422 | 422 | begin |
| 423 | 423 | Buf.init(b, Heap.heap); |
| 424 | 424 | defer Buf.done(b); |
| @@ -433,7 +433,7 @@ | ||
| 433 | 433 | end; |
| 434 | 434 | |
| 435 | 435 | (* 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; | |
| 437 | 437 | begin |
| 438 | 438 | if j.result = timedOut then return "timed out"; end; |
| 439 | 439 | return Buf.bytes(j.why); |
| @@ -522,7 +522,7 @@ | ||
| 522 | 522 | each control byte but tab, newline and carriage return, which XML 1.0 |
| 523 | 523 | forbids, written as ?. Bytes from 128 up, valid UTF-8 or not, are |
| 524 | 524 | passed through as they are. *) |
| 525 | -proc xml(var b: Buf.Buf; s: []U8); | |
| 525 | +proc xml(var b: Buf.Buf; s: []const U8); | |
| 526 | 526 | var i: INT; c: U8; |
| 527 | 527 | begin |
| 528 | 528 | for i := 0 to LEN(s) - 1 do |
| @@ -605,7 +605,7 @@ | ||
| 605 | 605 | end; |
| 606 | 606 | |
| 607 | 607 | (* The directory of the file path. *) |
| 608 | -proc dirOf(path: []U8): []U8; | |
| 608 | +proc dirOf(path: []const U8): []const U8; | |
| 609 | 609 | var i: INT; |
| 610 | 610 | begin |
| 611 | 611 | i := Str.findLast(path, "/"); |
| @@ -615,7 +615,7 @@ | ||
| 615 | 615 | end; |
| 616 | 616 | |
| 617 | 617 | (* 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); | |
| 619 | 619 | var i: INT; |
| 620 | 620 | begin |
| 621 | 621 | for i := 0 to dirs.len - 1 do |
| @@ -627,7 +627,7 @@ | ||
| 627 | 627 | (* The directories to watch: those given, those of the test files given, |
| 628 | 628 | and the -I ones. *) |
| 629 | 629 | 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; | |
| 631 | 631 | begin |
| 632 | 632 | Names.init(dirs, Heap.heap); |
| 633 | 633 | for i := 0 to operands.len - 1 do |
| @@ -641,8 +641,8 @@ | ||
| 641 | 641 | (* Adds to the fingerprint and the count the *.raz files of dir. It |
| 642 | 642 | runs every few hundred milliseconds for as long as -w does, so the |
| 643 | 643 | 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; | |
| 646 | 646 | begin |
| 647 | 647 | if Sys.openDir(d, dir) < 0 then return; end; |
| 648 | 648 | Buf.init(path, Heap.heap); |
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | w: [Last + 1]U8; (* each character's width, 1 unless a file says *) |
| 21 | 21 | |
| 22 | 22 | (* 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; | |
| 24 | 24 | begin |
| 25 | 25 | Buf.init(b, Heap.heap); |
| 26 | 26 | if not Files.read(path, b) then |
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | end; |
| 32 | 32 | |
| 33 | 33 | (* 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; | |
| 35 | 35 | var v: U64; ok: BOOL; |
| 36 | 36 | begin |
| 37 | 37 | v, ok := Str.toHex(Str.trim(s)); |
| @@ -52,8 +52,8 @@ | ||
| 52 | 52 | (* EastAsianWidth.txt: lines of a code point, or a range lo..hi, ";" |
| 53 | 53 | and the property; W and F are 2 columns. Its first line names the |
| 54 | 54 | 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; | |
| 57 | 57 | begin |
| 58 | 58 | line, rest, ok := Str.cut(text, "\n"); |
| 59 | 59 | _, version, ok := Str.cut(line, "-"); |
| @@ -77,8 +77,8 @@ | ||
| 77 | 77 | (* UnicodeData.txt: lines of fields between ";", the code point, the |
| 78 | 78 | name and the general category first. A range is two lines, its |
| 79 | 79 | 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; | |
| 82 | 82 | begin |
| 83 | 83 | rest := text; |
| 84 | 84 | first := -1; |
| @@ -100,8 +100,8 @@ | ||
| 100 | 100 | (* PropList.txt: lines of a code point, or a range lo..hi, ";" and a |
| 101 | 101 | property; a Prepended_Concatenation_Mark, a sign set over the digits |
| 102 | 102 | 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; | |
| 105 | 105 | begin |
| 106 | 106 | rest := text; |
| 107 | 107 | while LEN(rest) > 0 do |
| @@ -127,7 +127,7 @@ | ||
| 127 | 127 | |
| 128 | 128 | (* The constant name, the ranges of characters whose width is width, |
| 129 | 129 | 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); | |
| 131 | 131 | var c, lo, n: INT; |
| 132 | 132 | begin |
| 133 | 133 | Buf.str(b, " "); Buf.str(b, name); Buf.str(b, ": []I32 = ["); |
| @@ -147,7 +147,7 @@ | ||
| 147 | 147 | end; |
| 148 | 148 | |
| 149 | 149 | 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; | |
| 151 | 151 | begin |
| 152 | 152 | if LEN(Files.arg(4)) = 0 then |
| 153 | 153 | Out.str("usage: Widths lib/Width.raz EastAsianWidth.txt UnicodeData.txt PropList.txt\n"); |
| @@ -103,7 +103,7 @@ | ||
| 103 | 103 | " its errnos beside Linux's, and errno and closeFrom.\n\n" |
| 104 | 104 | " Written by tools/cabi.c, from the system's own headers; not to be\n" |
| 105 | 105 | " edited, but written again. *)\n", target); |
| 106 | - printf("module CAbi;\n\nconst\n"); | |
| 106 | + printf("module CAbi;\nimport SYSTEM;\n\nconst\n"); | |
| 107 | 107 | |
| 108 | 108 | SAY("open's flags, fcntl's requests, seek, flock, mmap, access"); |
| 109 | 109 | K("oRdonly", O_RDONLY); K("oWronly", O_WRONLY); K("oRdwr", O_RDWR); |