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.
| @@ -64,13 +64,14 @@ | ||
| 64 | 64 | stage 6, the language of report 2026-10.3 (steps 42-47), and stage 8, |
| 65 | 65 | one module to a name (report 2026-10.5, step 51), and stage 7, `Sys` |
| 66 | 66 | 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. | |
| 69 | 71 | New work starts |
| 70 | 72 | only on the owner's word. Keep |
| 71 | 73 | `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. | |
| 74 | 75 | |
| 75 | 76 | A release is an annotated tag `vX.Y.Z` on `main`, its message what |
| 76 | 77 | `raz --version` will print (`raz 0.3.0, report 2026-10.0`); `make |
| @@ -518,3 +518,15 @@ | ||
| 518 | 518 | ravite's `ravite-c`, still build through their link to |
| 519 | 519 | `lib/Sys.raz`. `Report` in `src/raz.pas` goes to 2026-10.5 |
| 520 | 520 | 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. |
| @@ -38,6 +38,7 @@ | ||
| 38 | 38 | end; |
| 39 | 39 | |
| 40 | 40 | var |
| 41 | + cwd: [4096]U8; (* what workDir gives *) | |
| 41 | 42 | saved: Termios; (* the terminal as rawMode found it *) |
| 42 | 43 | |
| 43 | 44 | (* Writes s to the file descriptor fd; the number of bytes written, or |
| @@ -57,7 +58,7 @@ | ||
| 57 | 58 | end; |
| 58 | 59 | |
| 59 | 60 | (* 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; | |
| 61 | 62 | var i: I64; |
| 62 | 63 | begin |
| 63 | 64 | if LEN(path) >= LEN(buf) then return false; end; |
| @@ -300,13 +301,14 @@ | ||
| 300 | 301 | return ""; |
| 301 | 302 | end; |
| 302 | 303 | |
| 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); | |
| 305 | 307 | var r: I64; |
| 306 | 308 | 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; | |
| 310 | 312 | end; |
| 311 | 313 | |
| 312 | 314 | (* A pseudo-terminal: the file descriptor of its controlling side, or |
| @@ -563,8 +565,8 @@ | ||
| 563 | 565 | if (w # 80) or (h # 24) then exit(2); end; |
| 564 | 566 | (* the environment *) |
| 565 | 567 | 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; | |
| 568 | 570 | (* a socket: nothing at a path, then a listener that a connection |
| 569 | 571 | makes ready, and a byte from it to the connection *) |
| 570 | 572 | if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) |
| @@ -43,6 +43,7 @@ | ||
| 43 | 43 | end; |
| 44 | 44 | |
| 45 | 45 | var |
| 46 | + cwd: [4096]U8; (* what workDir gives *) | |
| 46 | 47 | saved: [256]U8; (* the terminal as rawMode found it: a struct termios, of the C library's size *) |
| 47 | 48 | |
| 48 | 49 | (* minus errno, as a system call returns it *) |
| @@ -76,7 +77,7 @@ | ||
| 76 | 77 | end; |
| 77 | 78 | |
| 78 | 79 | (* 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; | |
| 80 | 81 | var i: I64; |
| 81 | 82 | begin |
| 82 | 83 | if LEN(path) >= LEN(buf) then return false; end; |
| @@ -297,14 +298,15 @@ | ||
| 297 | 298 | return s[0..n]; |
| 298 | 299 | end; |
| 299 | 300 | |
| 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); | |
| 302 | 304 | var n: I64; |
| 303 | 305 | 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; | |
| 305 | 307 | 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; | |
| 308 | 310 | end; |
| 309 | 311 | |
| 310 | 312 | (* A pseudo-terminal: the file descriptor of its controlling side, or |
| @@ -567,8 +569,8 @@ | ||
| 567 | 569 | if (w # 80) or (h # 24) then exit(2); end; |
| 568 | 570 | (* the environment *) |
| 569 | 571 | 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; | |
| 572 | 574 | (* a socket: nothing at a path, then a listener that a connection |
| 573 | 575 | makes ready, and a byte from it to the connection *) |
| 574 | 576 | if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) |
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | { what git describe says, made by make: 0.3.0 at the tag v0.3.0, |
| 32 | 32 | 0.3.0-5-g38d29a8 five commits past it } |
| 33 | 33 | 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 } | |
| 35 | 35 | MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it } |
| 36 | 36 | MfdCloexec = 1; { an ELF still executes: the kernel opens it first } |
| 37 | 37 |