raz / commit 138ba061

commit
138ba0611c72e45d9bf290650bd32da38bfa855d
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
f9222ab9
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.

patch · log

5 files changed, +38 -21

CLAUDE.md modified +5 -4

@@ -64,13 +64,14 @@
6464 stage 6, the language of report 2026-10.3 (steps 42-47), and stage 8,
6565 one module to a name (report 2026-10.5, step 51), and stage 7, `Sys`
6666 for rlX11 and rat (reports 2026-10.4 and 10.7, steps 49a-c), with
67-`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d). The
68-compiler says it follows report 2026-10.7, the last version all done.
67+`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and
68+stage 9, several results in place of var parameters (2026-10.8,
69+steps 52-53). The compiler says it follows report 2026-10.8, the last
70+version all done.
6971 New work starts
7072 only on the owner's word. Keep
7173 `doc/compiler.md`'s table of lines and its routine names true when the
72-compiler changes. Left for later at the owner's word: a rewrite of
73-var parameters.
74+compiler changes.
7475
7576 A release is an annotated tag `vX.Y.Z` on `main`, its message what
7677 `raz --version` will print (`raz 0.3.0, report 2026-10.0`); `make

PLAN.md (history) modified +12 -0

@@ -518,3 +518,15 @@
518518 ravite's `ravite-c`, still build through their link to
519519 `lib/Sys.raz`. `Report` in `src/raz.pas` goes to 2026-10.5
520520 with it, or with step 49, whichever comes last.
521+
522+Stage 9: several results in place of var parameters, report 2026-10.8
523+
524+At the owner's word: a procedure gives back what it makes as its
525+results, not through a `var` parameter. Done.
526+
527+- [x] 52. The report, version 2026-10.8: `Sys.workDir` returns the
528+ directory, good until the next call, and an errno.
529+- [x] 53. Both Sys files: `workDir` from a buffer of the module's;
530+ `cstr`, which fills its caller's storage rather than making a
531+ result, takes a slice, as `read` does. What is left of `var` is
532+ the tests of the feature itself.

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

@@ -38,6 +38,7 @@
3838 end;
3939
4040 var
41+ cwd: [4096]U8; (* what workDir gives *)
4142 saved: Termios; (* the terminal as rawMode found it *)
4243
4344 (* Writes s to the file descriptor fd; the number of bytes written, or
@@ -57,7 +58,7 @@
5758 end;
5859
5960 (* path, a C string in buf, or false if it doesn't fit. *)
60-proc cstr(path: []U8; var buf: [4096]U8): BOOL;
61+proc cstr(path, buf: []U8): BOOL;
6162 var i: I64;
6263 begin
6364 if LEN(path) >= LEN(buf) then return false; end;
@@ -300,13 +301,14 @@
300301 return "";
301302 end;
302303
303-(* The working directory into buf: its length, or minus an errno. *)
304-proc workDir*(var buf: [4096]U8): I64;
304+(* The working directory, good until the next call; and 0, or minus an
305+ errno. *)
306+proc workDir*: ([]U8, I64);
305307 var r: I64;
306308 begin
307- r := SYSCALL(79, ADR(buf), LEN(buf)); (* getcwd: its length with its zero *)
308- if r < 0 then return r; end;
309- return r - 1;
309+ r := SYSCALL(79, ADR(cwd), LEN(cwd)); (* getcwd: its length with its zero *)
310+ if r < 0 then return "", r; end;
311+ return cwd[0..r - 1], 0;
310312 end;
311313
312314 (* A pseudo-terminal: the file descriptor of its controlling side, or
@@ -563,8 +565,8 @@
563565 if (w # 80) or (h # 24) then exit(2); end;
564566 (* the environment *)
565567 if (LEN(env("PATH")) = 0) or (LEN(env("RAZ_NO_SUCH_VARIABLE")) # 0) then exit(2); end;
566- n := workDir(dir);
567- if (n <= 0) or (dir[0] # '/') then exit(2); end;
568+ name, err := workDir();
569+ if (err # 0) or (LEN(name) = 0) or (name[0] # '/') then exit(2); end;
568570 (* a socket: nothing at a path, then a listener that a connection
569571 makes ready, and a byte from it to the connection *)
570572 if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *)

lib/Sys.raz (history) modified +10 -8

@@ -43,6 +43,7 @@
4343 end;
4444
4545 var
46+ cwd: [4096]U8; (* what workDir gives *)
4647 saved: [256]U8; (* the terminal as rawMode found it: a struct termios, of the C library's size *)
4748
4849 (* minus errno, as a system call returns it *)
@@ -76,7 +77,7 @@
7677 end;
7778
7879 (* path, a C string in buf, or false if it doesn't fit. *)
79-proc cstr(path: []U8; var buf: [4096]U8): BOOL;
80+proc cstr(path, buf: []U8): BOOL;
8081 var i: I64;
8182 begin
8283 if LEN(path) >= LEN(buf) then return false; end;
@@ -297,14 +298,15 @@
297298 return s[0..n];
298299 end;
299300
300-(* The working directory into buf: its length, or minus an errno. *)
301-proc workDir*(var buf: [4096]U8): I64;
301+(* The working directory, good until the next call; and 0, or minus an
302+ errno. *)
303+proc workDir*: ([]U8, I64);
302304 var n: I64;
303305 begin
304- if C.getcwd(ADR(buf[0]), LEN(buf)) = nil then return failed(); end;
306+ if C.getcwd(ADR(cwd[0]), LEN(cwd)) = nil then return "", failed(); end;
305307 n := 0;
306- while buf[n] # 0 do INC(n); end;
307- return n;
308+ while cwd[n] # 0 do INC(n); end;
309+ return cwd[0..n], 0;
308310 end;
309311
310312 (* A pseudo-terminal: the file descriptor of its controlling side, or
@@ -567,8 +569,8 @@
567569 if (w # 80) or (h # 24) then exit(2); end;
568570 (* the environment *)
569571 if (LEN(env("PATH")) = 0) or (LEN(env("RAZ_NO_SUCH_VARIABLE")) # 0) then exit(2); end;
570- n := workDir(dir);
571- if (n <= 0) or (dir[0] # '/') then exit(2); end;
572+ name, err := workDir();
573+ if (err # 0) or (LEN(name) = 0) or (name[0] # '/') then exit(2); end;
572574 (* a socket: nothing at a path, then a listener that a connection
573575 makes ready, and a byte from it to the connection *)
574576 if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *)

src/raz.pas modified +1 -1

@@ -31,7 +31,7 @@
3131 { what git describe says, made by make: 0.3.0 at the tag v0.3.0,
3232 0.3.0-5-g38d29a8 five commits past it }
3333 Version = {$I version.inc};
34- Report = '2026-10.7'; { the version of doc/raz.md it follows }
34+ Report = '2026-10.8'; { the version of doc/raz.md it follows }
3535 MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it }
3636 MfdCloexec = 1; { an ELF still executes: the kernel opens it first }
3737