From ae1e08ef7ea23a98f05a2de47ab92f99b6a84695 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 09:56:32 +0100 Subject: [PATCH] site: v0.16.0 --- diff --git a/site/public/_redirects b/site/public/_redirects index c44455a..931ca50 100644 --- a/site/public/_redirects +++ b/site/public/_redirects @@ -1 +1 @@ -/download/latest /download/raz-0.15.0-linux-x86_64.tar.gz 302 +/download/latest /download/raz-0.16.0-linux-x86_64.tar.gz 302 diff --git a/site/public/advanced/targets.html b/site/public/advanced/targets.html index 0ec5a45..f94f96a 100644 --- a/site/public/advanced/targets.html +++ b/site/public/advanced/targets.html @@ -52,7 +52,7 @@ Sys.raz Thread.linux-x86_64.raz $ cd $RAZLIB && grep -c SYSCALL Sys.linux-x86_64.raz Sys.raz -Sys.linux-x86_64.raz:97 +Sys.linux-x86_64.raz:128 Sys.raz:0

A module of your own

Here is a module with two files. Clock.linux-x86_64.raz is for this target; Clock.raz is what any other target would use. Both say what they are in Name, and both make ticks.

diff --git a/site/public/download/raz-0.16.0-linux-x86_64.tar.gz b/site/public/download/raz-0.16.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..a5182c8 Binary files /dev/null and b/site/public/download/raz-0.16.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.16.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.16.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..d01fc4d --- /dev/null +++ b/site/public/download/raz-0.16.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +8b612205f434398dd82d72fbe481c3d9aabf408ec82541b0b6317eeddc71b17c raz-0.16.0-linux-x86_64.tar.gz diff --git a/site/public/index.html b/site/public/index.html index d969fd9..2f20c6b 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -113,24 +113,24 @@ the library.

Download

-

raz 0.15.0 is a tarball for x86-64 Linux with the compiler, raz, +

raz 0.16.0 is a tarball for x86-64 Linux with the compiler, raz, its library, lib/, which it finds beside itself, the formatter and the documentation tool as sources in tools/, and the manual pages. It needs nothing else installed.

- Download raz 0.15.0 - SHA-256 + Download raz 0.16.0 + SHA-256
-
$ tar xzf raz-0.15.0-linux-x86_64.tar.gz
-$ ln -s $PWD/raz-0.15.0-linux-x86_64/raz ~/.local/bin/raz
+
$ tar xzf raz-0.16.0-linux-x86_64.tar.gz
+$ ln -s $PWD/raz-0.16.0-linux-x86_64/raz ~/.local/bin/raz
 $ raz run Hello.raz

The link works since raz finds lib/ beside its real path. The manual pages are in man/: man ./man/raz-tutorial.7. The address download/latest always leads to the newest release, -and download/raz-0.15.0-linux-x86_64.tar.gz to this one, for -good. Earlier releases: 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with +and download/raz-0.16.0-linux-x86_64.tar.gz to this one, for +good. Earlier releases: 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with .sha256 added to its name.

-

SHA-256 e10a7ae85fc10032c8cc7b2b36bfe023581f2412b3fc3f1a6f4193411f562eb3

+

SHA-256 8b612205f434398dd82d72fbe481c3d9aabf408ec82541b0b6317eeddc71b17c

raz is under the ISC license.
diff --git a/site/public/raz-lib.pdf b/site/public/raz-lib.pdf index 39b1c63..2dbb7b3 100644 Binary files a/site/public/raz-lib.pdf and b/site/public/raz-lib.pdf differ diff --git a/site/public/raz.pdf b/site/public/raz.pdf index cdb8562..19b448b 100644 Binary files a/site/public/raz.pdf and b/site/public/raz.pdf differ diff --git a/site/public/spec.html b/site/public/spec.html index ab6a23b..598b5db 100644 --- a/site/public/spec.html +++ b/site/public/spec.html @@ -38,7 +38,7 @@

raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.

This is the first volume of the report: the language, what an implementation chooses, and the grammar. The second, doc/raz-lib.md, is the library, which sections 3 and 10 and appendix A name.

This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.

-

This is version 2026-10.27 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone.

+

This is version 2026-10.29 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed []T takes its length from its literal (section 4); it breaks no program.

The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.

1. A first look

module Hello;
@@ -146,6 +146,9 @@
 ...
 p := Primes[i];

It is used as a variable of that type is, but can’t be changed: an array constant can be indexed and sliced and its LEN is n, a record constant’s fields can be read, and either can be assigned, compared as its type allows, and passed. Its parts are constant as a string’s bytes are (section 5.10). A part of it isn’t a constant, even at a constant index.

+

An array constant may be typed []T, with no length: its length is then its literal’s, as a string constant’s is the string’s, and it is an array constant of that length, [n]T, in all else. Its literal has at least one element.

+
const Wide: [][2]I32 = [[1100H, 115FH], [2E80H, 303EH], [0AC00H, 0D7A3H]];
+    Count = LEN(Wide);    (* 3, a constant *)

Variables of a module live as long as the program; variables of a procedure live as long as its call. Both start at zero: every byte of them is zero. So a number starts as 0 (0.0 for F32 and F64), a BOOL as false, a pointer, procedure or ERROR as nil, a slice as the empty slice (ptr is nil, len is 0), a variant as its first case with its fields zero, a set as the empty set, and an enumeration as its first name. No variable is ever read before it has a value.

5. Types

Type      = QualIdent
@@ -645,6 +648,9 @@
 

A procedure without parameters may leave out the parentheses, both where it is declared (proc main*;) and where it is called (Out.ln). Used without parentheses in an expression, a procedure is a procedure value, not a call.

Parameters. A value parameter is a copy: the procedure may change it, and the caller’s variable stays as it was. A var parameter is the caller’s variable itself; its argument must be a variable of exactly the parameter’s type.

Results. A procedure returns nothing, one value, or several. A call that returns several values can only stand on the right of a multiple assignment, alone as a statement, or alone after return in a procedure whose results are of the same types, in the same order, which then returns them as they are: return divmod(n, 2);. A procedure that can fail has an ERROR as its last result (section 5.8), which try passes on (section 7.8).

+

An array a call returns lives to the end of the statement the call is in. A slice of it may be used there, indexed, passed or compared; one kept past the statement, in a variable or anywhere else, points at what is gone, and is the exception of section 10:

+
s := f('a')[0..4];     (* f returns a [8]U8: s is undefined after this *)
+Out.str(f('a')[0..4]);   (* used in its statement: defined *)
module Divide;
 import Out;
 
@@ -700,7 +706,7 @@
 proc exit*(status: INT);
 proc trace*;                    (* the calls under way, on standard error *)

Rt.trace says on standard error the calls under way, from the one that calls it out, each with its variables, as a program that stops does.

-

Defined behaviour. Every variable starts at zero, integers wrap, and indexing arrays and slices is checked, so a program’s behaviour is defined by this report, with one exception: memory reached other than through a checked variable. Dereferencing a stale or made-up pointer, indexing through a pointer, a slice kept after the call whose frame holds what it points at (section 7.3), an index out of range in a module that says check off;, writing a string’s bytes, a code procedure that breaks its rules, and C code can read or write any memory, and what follows isn’t defined. Dereferencing nil, dividing by zero, calling a nil procedure and running out of stack stop the program, on every target, with status 2, as a failed check does. Before it stops, the program prints to standard error where it was, as file, line and column, and why, as far as it can tell: a nil pointer, a nil procedure, a stack overflow, a bad address or a division fault; then the calls under way, each with its variables of a basic, enumeration, set or pointer type. Whether the machine catches these or the compiled code checks for them is the implementation’s choice (appendix A); that they stop the program isn’t.

+

Defined behaviour. Every variable starts at zero, integers wrap, and indexing arrays and slices is checked, so a program’s behaviour is defined by this report, with one exception: memory reached other than through a checked variable. Dereferencing a stale or made-up pointer, indexing through a pointer, a slice kept after the call whose frame holds what it points at (section 7.3), a slice of an array a call returned kept past its statement (section 8), an index out of range in a module that says check off;, writing a string’s bytes, a code procedure that breaks its rules, and C code can read or write any memory, and what follows isn’t defined. Dereferencing nil, dividing by zero, calling a nil procedure and running out of stack stop the program, on every target, with status 2, as a failed check does. Before it stops, the program prints to standard error where it was, as file, line and column, and why, as far as it can tell: a nil pointer, a nil procedure, a stack overflow, a bad address or a division fault; then the calls under way, each with its variables of a basic, enumeration, set or pointer type. Whether the machine catches these or the compiled code checks for them is the implementation’s choice (appendix A); that they stop the program isn’t.

Separate compilation. An importer depends only on a module’s interface: what it exports, as an importer sees it, never its source or its code. An implementation that compiles modules on its own makes the same program as if every module were compiled together (appendix A).

Errors. A program that breaks a rule of this report that says it is an error isn’t a raz program, and an implementation must reject it: say what is wrong and make no executable. Such a rule is one whose breach would leave the program with no meaning this report can give: a mistake of types, a name that isn’t declared or is declared twice, an assignment to what is read-only, a call with the wrong number of arguments, a type name or a procedure with no result used as a value, type arguments given to a module that isn’t generic, or too many, an import that can’t be found, a procedure declared forward and never defined, a module that imports itself. A fault that is only a lint isn’t an error: a name declared and never used, or a result that a call standing on its own drops (Sys.write(fd, s);, where _ := Sys.write(fd, s); says it is meant). A program with one is valid, and an implementation may warn of it. The text of its messages, how many it reports and which warnings it gives are its own (appendix A).

11. Versions

@@ -836,7 +842,7 @@ Sys -system calls: open, openMode, openRead, create, read, write, seek, position, truncate, sync, syncAll, lock, close, mmap, munmap, isTerminal, yield, exit; files and directories, rename, remove, removeDir, makeDir, chmod, symlink, readLink, info, linkInfo, infoOf, openDir, nextEntry, closeDir; the terminal, rawMode, restoreMode, termSize, ready; the environment, env, workDir, setWorkDir; programs, pipes and signals; time, clock, now, sleep; random; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and Sys.raz over the C library for the others +system calls: open, openMode, openRead, create, read, write, seek, position, truncate, sync, syncAll, lock, close, dup, dupTo, dupAbove, keepOnExec, mmap, munmap, isTerminal, yield, exit; files and directories, rename, remove, removeDir, makeDir, chmod, access, umask, symlink, readLink, info, linkInfo, infoOf, openDir, nextEntry, entryKind, closeDir; the terminal, rawMode, restoreMode, getMode, setMode, termSize, ready; the environment, env, envAt, workDir, setWorkDir; programs, spawn and exec, pipes and signals; the user, the machine, time used and limits; time, clock, now, sleep; random; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and Sys.raz over the C library for the others Out @@ -918,7 +924,7 @@ const Full*: ERROR = "too many procedures to run at exit"; proc atExit*(p: proc): ERROR; (* p run when the program ends by exit *) proc exit*(status: INT); (* the atExit procedures, the last first, then the end *) -proc stop*(msg: []U8); (* msg on standard error, then exit with status 2 *) +proc stop*(msg: []U8); (* msg, and a line feed, on standard error, then exit with status 2 *) proc trace*; (* the calls under way, and their variables, on standard error *)

Rt also holds what the compiler’s checks call when they fail, and the handlers of the signals that stop a program (section 10). exit takes each procedure off the list before it runs it, so it runs once even if it fails or calls exit itself; in a program that uses C, it ends through C’s exit, so that C flushes its buffers too.

module Mem;
@@ -990,9 +996,13 @@
     sigHup* = 1; sigInt* = 2; sigQuit* = 3; sigKill* = 9; sigPipe* = 13;
     sigTerm* = 15; sigChld* = 17; sigCont* = 18; sigStop* = 19;
     sigTstp* = 20; sigTtin* = 21; sigTtou* = 22; sigWinch* = 28;
+    sigUsr1* = 10; sigUsr2* = 12; sigAlrm* = 14;
+    (* the limits limit and setLimit take, by their numbers on Linux; each target has its own *)
+    limitCpu* = 0; limitFileSize* = 1; limitData* = 2; limitStack* = 3;
+    limitCore* = 4; limitProcs* = 6; limitFiles* = 7; limitMemory* = 9;
 
 type
-    Access* = (reading, writing, creating, exclusive, truncating, appending);
+    Access* = (reading, writing, creating, exclusive, truncating, appending, executing);
     Accesses* = set of Access;
     Info* = record
         size*: I64;      (* in bytes *)
@@ -1002,7 +1012,9 @@
         file*: BOOL;     (* a regular file: not a directory, device, pipe or socket *)
         symlink*: BOOL;  (* the path itself is a symbolic link *)
         ino*: U64;       (* its inode, which a rename keeps and a new file doesn't *)
+        dev*: U64;       (* the file system it is on; with ino, it names the file *)
     end;
+    Kind* = (unknown, isFile, isDir, isLink, isOther);   (* what a directory says a name in it is *)
     Dir* = record ... end;   (* an open directory; its fields are the target's *)
     Program* = record
         path*: []U8;
@@ -1014,8 +1026,10 @@
         group*: INT;        (* the process group it joins: 0 for this program's, -1 a new one it leads *)
         foreground*: BOOL;  (* its group takes the terminal on standard input *)
         tty*: INT;          (* a pseudo-terminal's fd, to start a session on; 0 for none *)
+        more*: []INT;       (* fds above 2 passed on to it, at the same numbers *)
     end;
     Status* = (running, exited, killed, stopped);
+    Mode* = record ... end;   (* a terminal's modes; its fields are the target's *)
     Peer* = record ... end;   (* whom a datagram came from *)
 
 proc write*(fd: INT; s: []U8): INT;     (* the bytes written *)
@@ -1031,6 +1045,10 @@
 proc syncAll*(fd: INT): INT;             (* all that was written to its file system, on the disk *)
 proc lock*(fd: INT; wait: BOOL): INT;    (* the file's lock, held until fd is closed *)
 proc close*(fd: INT);
+proc dup*(fd: INT): INT;                 (* a new fd for the same file, the lowest free *)
+proc dupTo*(fd, into: INT): INT;         (* into made the same file as fd, closing what it was *)
+proc dupAbove*(fd, least: INT): INT;     (* a new fd for the same file, the lowest free from least on, closed on exec *)
+proc keepOnExec*(fd: INT; yes: BOOL): INT;   (* fd left open, or not, in the program exec runs *)
 proc isTerminal*(fd: INT): BOOL;
 proc mmap*(size: INT): ^U8;              (* size bytes of zeroed memory, in whole pages; or nil *)
 proc munmap*(p: ^U8; size: INT);
@@ -1042,6 +1060,8 @@
 proc removeDir*(path: []U8): INT;        (* an empty directory *)
 proc makeDir*(path: []U8): INT;          (* readable by all, writable by its owner *)
 proc chmod*(path: []U8; mode: INT): INT;
+proc access*(path: []U8; how: Accesses): INT;   (* 0 if this user may read, write or execute it *)
+proc umask*(mask: INT): INT;             (* the bits taken from every file made; the mask it was *)
 proc symlink*(target, path: []U8): INT;  (* path made a link to target *)
 proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *)
 proc info*(path: []U8): (Info, INT);     (* following a symbolic link *)
@@ -1051,10 +1071,13 @@
 
 proc openDir*(d: ^Dir; path: []U8): INT;
 proc nextEntry*(d: ^Dir): ([]U8, BOOL);  (* a name, good until the next call; false at the end *)
+proc entryKind*(d: ^Dir): Kind;          (* what the name nextEntry gave last is *)
 proc closeDir*(d: ^Dir);
 
 proc rawMode*(fd: INT): BOOL;      (* the terminal on fd: no echo, no lines, no signals *)
 proc restoreMode*(fd: INT);        (* as rawMode found it *)
+proc getMode*(fd: INT): (Mode, INT);     (* the terminal's modes, to set again *)
+proc setMode*(fd: INT; m: Mode): INT;    (* once what was written to it is sent *)
 proc termSize*(fd: INT): (INT, INT);   (* columns and rows; 80 and 24 if unknown *)
 proc ready*(fd, ms: INT): BOOL;          (* something to read within ms, or ever if ms < 0 *)
 proc readyOf*(fds: []INT; ms: INT): INT;   (* the first of fds with something to read within ms, or -1 *)
@@ -1062,6 +1085,7 @@
 proc setBlocking*(fd: INT; yes: BOOL): INT;   (* if not yes, a read or write that would wait is -11 at once *)
 
 proc env*(name: []U8): []U8;       (* the environment variable's value; "" if unset *)
+proc envAt*(i: INT): ([]U8, BOOL); (* the environment's ith NAME=value, from 0; false past the last *)
 proc workDir*: ([]U8, INT);        (* the working directory, good until the next call *)
 proc setWorkDir*(path: []U8): INT;
 
@@ -1069,16 +1093,27 @@
 proc openPty*: INT;                (* a pseudo-terminal: the fd of its controlling side *)
 proc setTermSize*(fd, cols, rows: INT): INT;   (* the size its programs are told of *)
 proc spawn*(p: Program): INT;      (* a program started: its process id *)
+proc exec*(p: Program): INT;       (* p run in this program's place; returns only if it can't *)
+proc fork*: INT;                   (* this program copied: 0 in the copy, its process id in this one *)
 proc wait*(pid: INT; block: BOOL): (INT, Status, INT);   (* which program, how, and its code *)
 proc kill*(pid, signal: INT): INT;
 proc pid*: INT;                    (* this program's process id *)
+proc group*: INT;                  (* the process group this program is in *)
 proc setGroup*(pid, group: INT): INT;    (* pid 0 is this program; group 0 a new one pid leads *)
 proc foreground*(fd, group: INT): INT;   (* the terminal on fd gives its keys to group *)
 proc foregroundOf*(fd: INT): INT;  (* the group the terminal on fd gives its keys to *)
+proc uid*: INT;                    (* the user this program runs as *)
+proc euid*: INT;                   (* the user whose rights it has: 0 is root *)
+proc hostName*: ([]U8, INT);       (* this machine's name, good until the next call *)
+proc cpuTime*(children: BOOL): (I64, I64);   (* ns used in the program and in the system; or by its children *)
+proc limit*(which: INT): (I64, I64, INT);    (* the soft limit and the hard; -1 for none *)
+proc setLimit*(which: INT; soft, hard: I64): INT;
 
 proc catch*(sigs: []INT): INT;     (* sigs caught: an fd to wait on *)
 proc caught*(fd: INT): INT;        (* the next signal caught, or 0 if none is waiting *)
 proc ignore*(sig: INT; yes: BOOL): INT;  (* sig ignored; or, if not yes, back to what it does at first *)
+proc handle*(sig: INT): INT;       (* sig noted, for came; a system call it comes during is -4 *)
+proc came*(sig: INT): BOOL;        (* whether sig came since the last time it was asked *)
 
 proc clock*: I64;                  (* nanoseconds, on a clock that only goes forward *)
 proc now*: I64;                    (* nanoseconds since 1970-01-01, UTC *)
@@ -1103,13 +1138,16 @@
 proc memFile*(size: INT): INT;     (* a file of size zero bytes, in memory, with no name: its fd *)
 proc mapFile*(fd, size: INT): ^U8; (* the first size bytes of fd, shared; munmap gives them back; or nil *)

info follows a symbolic link: size, dir and file are those of what it names, and symlink says the path was a link, so that a program walking a tree can choose not to follow one back up it. A link to nothing is -ENOENT, as a missing file is. file lets a walk open only what holds data: opening a pipe would wait for a program to write to it.

-

nextEntry gives every name in the directory except . and .., in no particular order. rawMode turns off what the terminal does with keys before the program reads them (echo, line editing, signals, flow control), and NL to CR NL on output. A program that turns it on restores it before it ends: Rt.atExit is the place.

-

Files. open gives a file for what how asks: reading, writing or both; creating it if it is missing, readable by all and writable by its owner; with exclusive, failing with -17 (EEXIST) if it is there, as a program does that makes a lock or a file of its own; truncating it to nothing; appending, each write going to its end, however other programs write it too. openMode is open that gives a file it makes the bits mode, less those the umask takes away: 1EDH (755) for a program, 124H (444) for a file never to be written; open gives 1A4H (644). seek moves to pos from the start of the file, or from its end if fromEnd, where a negative pos reads back from the end; position says where the file is, without moving. truncate makes the file size bytes long, cutting it or adding zeros, and leaves the position where it was. sync returns once what was written to the file is on the disk, as a program needs before it says a file is saved; syncAll returns once everything written to the file system that holds the file is on the disk, at once rather than a file at a time, and may flush other file systems too. lock takes the file’s lock, which one open file holds at a time: another that asks for it waits if wait, and otherwise fails with -11 (EAGAIN). The lock goes when the file is closed or the program ends, however it ends, so it never goes stale as a file made with exclusive does. infoOf is info of an open file: its size is what it holds now, however it was written; linkInfo is info of a symbolic link itself, not what it names, so that symlink is true, dir and file false, and size the length of what it names, which need not be there. Info.mtime is what a program checks to see whether a file changed under it, and Info.ino whether it is still the same file, not one renamed over it; 0 on a target whose files have none. Info.mode holds the nine bits of rwxrwxrwx, and chmod sets them, 1EDH (755) for a program, 1A4H (644) for data.

+

nextEntry gives every name in the directory except . and .., in no particular order. entryKind says what the name it gave last is, a file, a directory, a symbolic link (whatever it names) or something else, as the directory itself records it, so that a program walking a tree needn’t ask linkInfo of every name, a system call each; where the file system doesn’t record it, it is unknown, and linkInfo must be asked. rawMode turns off what the terminal does with keys before the program reads them (echo, line editing, signals, flow control), and NL to CR NL on output. A program that turns it on restores it before it ends: Rt.atExit is the place.

+

Files. open gives a file for what how asks: reading, writing or both; creating it if it is missing, readable by all and writable by its owner; with exclusive, failing with -17 (EEXIST) if it is there, as a program does that makes a lock or a file of its own; truncating it to nothing; appending, each write going to its end, however other programs write it too. openMode is open that gives a file it makes the bits mode, less those the umask takes away: 1EDH (755) for a program, 124H (444) for a file never to be written; open gives 1A4H (644). seek moves to pos from the start of the file, or from its end if fromEnd, where a negative pos reads back from the end; position says where the file is, without moving. truncate makes the file size bytes long, cutting it or adding zeros, and leaves the position where it was. sync returns once what was written to the file is on the disk, as a program needs before it says a file is saved; syncAll returns once everything written to the file system that holds the file is on the disk, at once rather than a file at a time, and may flush other file systems too. lock takes the file’s lock, which one open file holds at a time: another that asks for it waits if wait, and otherwise fails with -11 (EAGAIN). The lock goes when the file is closed or the program ends, however it ends, so it never goes stale as a file made with exclusive does. infoOf is info of an open file: its size is what it holds now, however it was written; linkInfo is info of a symbolic link itself, not what it names, so that symlink is true, dir and file false, and size the length of what it names, which need not be there. Info.mtime is what a program checks to see whether a file changed under it, and Info.ino whether it is still the same file, not one renamed over it; 0 on a target whose files have none. Info.dev is the file system the file is on: two files are one only if both dev and ino agree, which is how a program following links finds that one has led it back into a directory it is already in. Info.mode holds the nine bits of rwxrwxrwx, and chmod sets them, 1EDH (755) for a program, 1A4H (644) for data.

Programs. openPty makes a pseudo-terminal, a terminal that a program, a terminal emulator, plays the screen and the keyboard of: what it writes to the fd is typed, and what the programs on the terminal write it reads.

-

spawn starts the program at p.path, with p.args as its arguments, the first being its name. Its environment is this program’s with each NAME=value of p.env added or put in place of the old value, or, if p.onlyEnv, p.env alone. It starts in p.dir. Its standard input, output and error are p.fds; a 0 gives it this program’s own, so {path: "/bin/ls", args: ["ls"]} runs ls as a shell runs it, with every other field zero. It gets no other open file, every signal does what it does at first, and none is blocked. If p.tty is a pseudo-terminal’s fd, the program starts a session on that terminal: it is its controlling terminal, and its standard input, output and error, and p.fds and p.group are not used.

+

spawn starts the program at p.path, with p.args as its arguments, the first being its name. A p.path without a / is looked for as a shell looks for a command, and as C’s execvp does: in each directory of this program’s PATH in turn, an empty one being the working directory, or of /bin:/usr/bin if PATH is unset or empty; the first that runs is the program. Its environment is this program’s with each NAME=value of p.env added or put in place of the old value, or, if p.onlyEnv, p.env alone. It starts in p.dir. Its standard input, output and error are p.fds; a 0 gives it this program’s own, so {path: "ls", args: ["ls"]} runs ls as a shell runs it, with every other field zero. It gets no other open file but those of p.more, each at its own number, as a shell passes 3<file on, every signal does what it does at first, and none is blocked. If p.tty is a pseudo-terminal’s fd, the program starts a session on that terminal: it is its controlling terminal, and its standard input, output and error, and p.fds and p.group are not used.

p.group puts the program in a process group, the programs that a shell’s job is made of: -1 makes it the first of a new group, whose number is its process id, and the other programs of the job join that number. The terminal gives its keys, and the signals of Ctrl-C and Ctrl-Z, to one group, the one in its foreground: p.foreground puts the program’s group there before it starts, and foreground puts any group there, as a shell does to take the terminal back. setGroup moves a program to a group, as the shell does for each program it starts, for whichever of the two runs first; a shell runs in a group of its own, setGroup(0, 0).

-

wait waits for the program pid to change, or for any of this program’s if pid is -1, and says which one, and how: exited, with its exit status; killed, with the number of the signal that ended it; or stopped, by Ctrl-Z or a signal, with the signal’s number. Without block it doesn’t wait, and is 0 and running if no program changed. A program that has nothing to wait for is -10 (ECHILD). kill sends a program a signal, sigTerm to end it; to a group, if pid is minus its number.

+

exec runs the program p describes in this program’s place, as a shell’s exec cmd does, found and started as spawn would start it, p.tty, p.group, p.foreground, p.fds and p.dir included, except that it keeps this program’s other open files: each stays open in the program unless keepOnExec(fd, false) was said of it, as it is of pipe’s, and those of p.more are kept. It returns only if the program can’t run: -2 (ENOENT) or -13 (EACCES) if there is none to run, with nothing done; or, if the program is found but won’t start, minus the errno, with what p asks of the terminal, the group, the files and the directory done, and this program’s signals as they were.

+

A shell moves its own files with dup and dupTo, for 2>&1 and exec >log and around a builtin: dupTo(fd, into) makes into the same open file as fd, closing what into was, and dup gives a new fd for it, the lowest free, as a shell saves a file to give it back. dupAbove(fd, 10) gives one at 10 or above, closed on exec, out of the way of the fds a script names (3>log), as a shell keeps its own. fork copies this program, which goes on from there in both: it is 0 in the copy and the copy’s process id in this one, as a shell runs a builtin or a procedure as a stage of a pipe. Only the thread that calls it is copied, so a program with threads mustn’t; and what Out keeps is copied too, to be written twice, so Out.flush comes first. group is the process group this program is in: a shell starting on a terminal waits until it is foregroundOf(0) before it takes it. access says whether this user, by its real ids, may read, write or execute a file, as test -r, -w and -x ask, which Info.mode alone can’t say; an empty how asks only whether it is there. open refuses executing, with -22 (EINVAL). umask sets the bits taken away from the mode of every file this program, and those it starts, make, and says what they were. envAt gives the environment one variable at a time, from 0, for a shell to list it and to pass it on whole with onlyEnv. getMode reads a terminal’s modes, and setMode sets them again once what was written is sent, so that a shell keeps them for each job: a program stopped by Ctrl-Z with its terminal raw gets it back raw, and the shell its own between. cpuTime says how long the processor ran this program, in its own code and in the system for it, or, if children, the programs it started and has waited for, as time and times say. limit gives a limit, limitFiles say, soft and hard, and setLimit sets them, as ulimit does: a program may raise its soft limit up to the hard one, and lower either. uid is the user this program runs as, euid the one whose rights it has, 0 for root, as a prompt shows #; hostName is the machine’s name.

+

wait waits for the program pid to change, for any of this program’s if pid is -1, or for any of the group g if pid is -g, as a shell waits for a job’s programs, and says which one, and how: exited, with its exit status; killed, with the number of the signal that ended it; or stopped, by Ctrl-Z or a signal, with the signal’s number. Without block it doesn’t wait, and is 0 and running if no program changed. A program that has nothing to wait for is -10 (ECHILD). kill sends a program a signal, sigTerm to end it; to a group, if pid is minus its number.

Signals. catch takes the signals sigs away from what they would do, ending the program most of them, and gives an fd that is ready to read when one comes, so that a program waits for signals with ready and readyOf as it waits for keys or a server. caught gives each signal that came, in turn. A later catch adds to the signals caught and gives the same fd. Catching sigKill or sigStop, or the signals Rt reports, SIGSEGV and SIGFPE, is -22 (EINVAL). ignore makes a signal do nothing, as a shell ignores sigTtou so that it can take its terminal back, and ignore(sig, false) gives it back what it does at first. A program that spawn starts begins with neither.

+

handle is for a program that must see a signal while it waits in a system call, as a shell waiting for its foreground program, or for a key, sees Ctrl-C: the signal is noted, and the call it comes during, wait, read, ready and the rest, fails with -4 (EINTR) rather than going on; sleep sleeps its time all the same. came(sig) says whether it came since the last time it was asked. Nothing else runs when the signal comes, so the program does what it does after it, in its own time; Out and Files try again after -4. ignore(sig, false) gives the signal back what it does at first, and the signals catch refuses, handle refuses too.

Time. clock is for measuring how long something takes: it never goes back, and says nothing of the date. now is the date and time, which a person or the network may set back. sleep waits ms milliseconds.

Sockets. connect is for talking to a server on the same machine, an X server at /tmp/.X11-unix/X0 say; connectTcp for one across the network, given its address as numbers, "127.0.0.1" or "::1": turning a name into an address is a library’s work over these. connectUdp gives a socket of datagrams, each send one message to that address and each read one message from it, as a program asks a name server. What a socket receives comes by read, what it sends goes by send, and close ends it. send is write for a socket, except when the other end has closed it: write would stop the program with the signal SIGPIPE, where send returns -32 (EPIPE), so that a program learns its server has gone and can end as it wants. listen and listenTcp are the other side: a server’s socket, on path, which must not be there yet, or on port at addr, "0.0.0.0" or "::" for every address the machine has; accept gives each connection that comes, as a socket of its own. A server started on port 0 gets a port the system chooses, which localPort says, as a test does that must not take a port in use. connectTcp waits as long as the system does, minutes for a host that never answers; connectTcpWithin gives up after ms milliseconds, with -110 (ETIMEDOUT).

listenUdp is the server’s side of connectUdp: a socket of datagrams from anyone, as a name server has. receive gives the next datagram, at most LEN(buf) bytes of it, the rest lost, and a Peer that reply sends an answer to.

@@ -1122,6 +1160,7 @@ proc eq*(a, b: []U8): BOOL; proc eqFold*(a, b: []U8): BOOL; (* eq, an ASCII letter's capital and small the same *) proc copy*(a: ^Mem.Allocator; s: []U8): ([]U8, BOOL); (* s's bytes in memory from a; false if a has none *) +proc free*(a: ^Mem.Allocator; s: []U8); (* what copy gave from a, given back; "" is none *) proc hash*(s: []U8): U64; (* FNV-1a, 64 bits *) proc find*(s, sub: []U8): INT; (* where sub first starts in s, or -1 *) proc findLast*(s, sub: []U8): INT; (* where sub last starts in s, or -1 *) @@ -1191,6 +1230,7 @@ proc remove*(m: ^Map; k: K): BOOL; (* false if k wasn't there *) proc get*(m: ^Map; k: K): (V, BOOL); (* what k maps to, and whether it maps to anything *) proc next*(m: ^Map; i: INT): (INT, K, V); (* the entry after i *) +proc done*(m: ^Map); (* its memory given back, leaving it empty *) module Vec(T); type Vec* = record len*: INT; ... end; @@ -1261,6 +1301,7 @@
module Files;
 proc arg*(i: INT): []U8;                     (* argument i; 0 is the program's name *)
 proc read*(path: []U8; b: ^Buf.Buf): BOOL;   (* the whole file added to b *)
+proc load*(path: []U8; b: ^Buf.Buf): INT;    (* as read: 0, or minus the errno that stopped it *)
 proc write*(path, data: []U8): BOOL;         (* the file made to hold data *)
 
 module Opt;