From 138ba0611c72e45d9bf290650bd32da38bfa855d Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:16:58 +0100 Subject: [PATCH] Several results in place of var parameters Step 53: Sys.workDir returns the directory, from a buffer of the module's, and an errno (report 2026-10.8). cstr fills its caller's storage, so it takes a slice, as read does. The var parameters left are the tests of the feature. The compiler follows report 2026-10.8. --- diff --git a/CLAUDE.md b/CLAUDE.md index e13a0f2..ba41e83 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,13 +64,14 @@ stage 6, the language of report 2026-10.3 (steps 42-47), and stage 8, one module to a name (report 2026-10.5, step 51), and stage 7, `Sys` for rlX11 and rat (reports 2026-10.4 and 10.7, steps 49a-c), with -`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d). The -compiler says it follows report 2026-10.7, the last version all done. +`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and +stage 9, several results in place of var parameters (2026-10.8, +steps 52-53). The compiler says it follows report 2026-10.8, the last +version all done. New work starts only on the owner's word. Keep `doc/compiler.md`'s table of lines and its routine names true when the -compiler changes. Left for later at the owner's word: a rewrite of -var parameters. +compiler changes. A release is an annotated tag `vX.Y.Z` on `main`, its message what `raz --version` will print (`raz 0.3.0, report 2026-10.0`); `make diff --git a/PLAN.md b/PLAN.md index a905200..0a45f87 100644 --- a/PLAN.md +++ b/PLAN.md @@ -518,3 +518,15 @@ ravite's `ravite-c`, still build through their link to `lib/Sys.raz`. `Report` in `src/raz.pas` goes to 2026-10.5 with it, or with step 49, whichever comes last. + +Stage 9: several results in place of var parameters, report 2026-10.8 + +At the owner's word: a procedure gives back what it makes as its +results, not through a `var` parameter. Done. + +- [x] 52. The report, version 2026-10.8: `Sys.workDir` returns the + directory, good until the next call, and an errno. +- [x] 53. Both Sys files: `workDir` from a buffer of the module's; + `cstr`, which fills its caller's storage rather than making a + result, takes a slice, as `read` does. What is left of `var` is + the tests of the feature itself. diff --git a/lib/Sys.linux-x86_64.raz b/lib/Sys.linux-x86_64.raz index d655acf..a263c97 100644 --- a/lib/Sys.linux-x86_64.raz +++ b/lib/Sys.linux-x86_64.raz @@ -38,6 +38,7 @@ end; var + cwd: [4096]U8; (* what workDir gives *) saved: Termios; (* the terminal as rawMode found it *) (* Writes s to the file descriptor fd; the number of bytes written, or @@ -57,7 +58,7 @@ end; (* path, a C string in buf, or false if it doesn't fit. *) -proc cstr(path: []U8; var buf: [4096]U8): BOOL; +proc cstr(path, buf: []U8): BOOL; var i: I64; begin if LEN(path) >= LEN(buf) then return false; end; @@ -300,13 +301,14 @@ return ""; end; -(* The working directory into buf: its length, or minus an errno. *) -proc workDir*(var buf: [4096]U8): I64; +(* The working directory, good until the next call; and 0, or minus an + errno. *) +proc workDir*: ([]U8, I64); var r: I64; begin - r := SYSCALL(79, ADR(buf), LEN(buf)); (* getcwd: its length with its zero *) - if r < 0 then return r; end; - return r - 1; + r := SYSCALL(79, ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *) + if r < 0 then return "", r; end; + return cwd[0..r - 1], 0; end; (* A pseudo-terminal: the file descriptor of its controlling side, or @@ -563,8 +565,8 @@ if (w # 80) or (h # 24) then exit(2); end; (* the environment *) if (LEN(env("PATH")) = 0) or (LEN(env("RAZ_NO_SUCH_VARIABLE")) # 0) then exit(2); end; - n := workDir(dir); - if (n <= 0) or (dir[0] # '/') then exit(2); end; + name, err := workDir(); + if (err # 0) or (LEN(name) = 0) or (name[0] # '/') then exit(2); end; (* a socket: nothing at a path, then a listener that a connection makes ready, and a byte from it to the connection *) if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) diff --git a/lib/Sys.raz b/lib/Sys.raz index 81c3f55..7dd4d06 100644 --- a/lib/Sys.raz +++ b/lib/Sys.raz @@ -43,6 +43,7 @@ end; var + cwd: [4096]U8; (* what workDir gives *) saved: [256]U8; (* the terminal as rawMode found it: a struct termios, of the C library's size *) (* minus errno, as a system call returns it *) @@ -76,7 +77,7 @@ end; (* path, a C string in buf, or false if it doesn't fit. *) -proc cstr(path: []U8; var buf: [4096]U8): BOOL; +proc cstr(path, buf: []U8): BOOL; var i: I64; begin if LEN(path) >= LEN(buf) then return false; end; @@ -297,14 +298,15 @@ return s[0..n]; end; -(* The working directory into buf: its length, or minus an errno. *) -proc workDir*(var buf: [4096]U8): I64; +(* The working directory, good until the next call; and 0, or minus an + errno. *) +proc workDir*: ([]U8, I64); var n: I64; begin - if C.getcwd(ADR(buf[0]), LEN(buf)) = nil then return failed(); end; + if C.getcwd(ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end; n := 0; - while buf[n] # 0 do INC(n); end; - return n; + while cwd[n] # 0 do INC(n); end; + return cwd[0..n], 0; end; (* A pseudo-terminal: the file descriptor of its controlling side, or @@ -567,8 +569,8 @@ if (w # 80) or (h # 24) then exit(2); end; (* the environment *) if (LEN(env("PATH")) = 0) or (LEN(env("RAZ_NO_SUCH_VARIABLE")) # 0) then exit(2); end; - n := workDir(dir); - if (n <= 0) or (dir[0] # '/') then exit(2); end; + name, err := workDir(); + if (err # 0) or (LEN(name) = 0) or (name[0] # '/') then exit(2); end; (* a socket: nothing at a path, then a listener that a connection makes ready, and a byte from it to the connection *) if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) diff --git a/src/raz.pas b/src/raz.pas index 24452f7..0295cee 100644 --- a/src/raz.pas +++ b/src/raz.pas @@ -31,7 +31,7 @@ { what git describe says, made by make: 0.3.0 at the tag v0.3.0, 0.3.0-5-g38d29a8 five commits past it } Version = {$I version.inc}; - Report = '2026-10.7'; { the version of doc/raz.md it follows } + Report = '2026-10.8'; { the version of doc/raz.md it follows } MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it } MfdCloexec = 1; { an ELF still executes: the kernel opens it first }