Sys's directories take the Dir by var (report 2026-10.33) Sys.openDir, nextEntry, entryKind and closeDir take var d: Dir, in both Sys files; none kept the pointer. entryKind only reads, but Sys is compiled by the seed, which doesn't know const: it takes const when the seed is gone, which breaks no caller. nextEntry returns a slice of the caller's Dir, which a var parameter is. The fixpoint holds; test/libc passes over glibc and musl.
| @@ -266,10 +266,10 @@ | ||
| 266 | 266 | proc infoOf*(fd: INT): (Info, INT); (* the open file's *) |
| 267 | 267 | proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *) |
| 268 | 268 | |
| 269 | -proc openDir*(d: ^Dir; path: []U8): INT; | |
| 270 | -proc nextEntry*(d: ^Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *) | |
| 271 | -proc entryKind*(d: ^Dir): Kind; (* what the name nextEntry gave last is *) | |
| 272 | -proc closeDir*(d: ^Dir); | |
| 269 | +proc openDir*(var d: Dir; path: []U8): INT; | |
| 270 | +proc nextEntry*(var d: Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *) | |
| 271 | +proc entryKind*(var d: Dir): Kind; (* what the name nextEntry gave last is *) | |
| 272 | +proc closeDir*(var d: Dir); | |
| 273 | 273 | |
| 274 | 274 | proc rawMode*(fd: INT): BOOL; (* the terminal on fd: no echo, no lines, no signals *) |
| 275 | 275 | proc restoreMode*(fd: INT); (* as rawMode found it *) |
| @@ -526,38 +526,38 @@ | ||
| 526 | 526 | end; |
| 527 | 527 | |
| 528 | 528 | (* Opens the directory at path, for nextEntry. *) |
| 529 | -proc openDir*(d: ^Dir; path: []U8): INT; | |
| 529 | +proc openDir*(var d: Dir; path: []U8): INT; | |
| 530 | 530 | var a: [4096]U8; |
| 531 | 531 | begin |
| 532 | - d^.kind := unknown; | |
| 533 | - d^.pos := 0; | |
| 534 | - d^.len := 0; | |
| 532 | + d.kind := unknown; | |
| 533 | + d.pos := 0; | |
| 534 | + d.len := 0; | |
| 535 | 535 | if not cstr(path, a) then return -36; end; |
| 536 | - d^.fd := SYSCALL(2, ADR(a), 10000H); (* open, O_RDONLY, O_DIRECTORY *) | |
| 537 | - if d^.fd < 0 then return d^.fd; end; | |
| 536 | + d.fd := SYSCALL(2, ADR(a), 10000H); (* open, O_RDONLY, O_DIRECTORY *) | |
| 537 | + if d.fd < 0 then return d.fd; end; | |
| 538 | 538 | return 0; |
| 539 | 539 | end; |
| 540 | 540 | |
| 541 | 541 | (* The next name in the directory, good until the next call, but . and |
| 542 | 542 | .., in no order; false at the end. *) |
| 543 | -proc nextEntry*(d: ^Dir): ([]U8, BOOL); | |
| 543 | +proc nextEntry*(var d: Dir): ([]U8, BOOL); | |
| 544 | 544 | var n, at: INT; |
| 545 | 545 | begin |
| 546 | 546 | while true do |
| 547 | - if d^.pos >= d^.len then | |
| 548 | - d^.len := SYSCALL(217, d^.fd, ADR(d^.buf), LEN(d^.buf)); (* getdents64 *) | |
| 549 | - d^.pos := 0; | |
| 550 | - if d^.len <= 0 then return "", false; end; | |
| 547 | + if d.pos >= d.len then | |
| 548 | + d.len := SYSCALL(217, d.fd, ADR(d.buf), LEN(d.buf)); (* getdents64 *) | |
| 549 | + d.pos := 0; | |
| 550 | + if d.len <= 0 then return "", false; end; | |
| 551 | 551 | end; |
| 552 | 552 | (* a record: d_ino and d_off, 8 bytes each; d_reclen, 2; d_type, |
| 553 | 553 | 1; then d_name, ending in a zero *) |
| 554 | - at := d^.pos + 19; | |
| 554 | + at := d.pos + 19; | |
| 555 | 555 | n := 0; |
| 556 | - while d^.buf[at + n] # 0 do INC(n); end; | |
| 557 | - d^.kind := kindOf(d^.buf[d^.pos + 18]); | |
| 558 | - INC(d^.pos, INT(d^.buf[d^.pos + 16]) + INT(d^.buf[d^.pos + 17]) * 256); | |
| 559 | - if (d^.buf[at..at + n] # ".") and (d^.buf[at..at + n] # "..") then | |
| 560 | - return d^.buf[at..at + n], true; | |
| 556 | + while d.buf[at + n] # 0 do INC(n); end; | |
| 557 | + d.kind := kindOf(d.buf[d.pos + 18]); | |
| 558 | + INC(d.pos, INT(d.buf[d.pos + 16]) + INT(d.buf[d.pos + 17]) * 256); | |
| 559 | + if (d.buf[at..at + n] # ".") and (d.buf[at..at + n] # "..") then | |
| 560 | + return d.buf[at..at + n], true; | |
| 561 | 561 | end; |
| 562 | 562 | end; |
| 563 | 563 | return "", false; |
| @@ -566,15 +566,15 @@ | ||
| 566 | 566 | (* What the name nextEntry gave last is, as the directory says, so that |
| 567 | 567 | a walk needn't ask each file with linkInfo; unknown where the file |
| 568 | 568 | system doesn't say. A link is isLink, whatever it names. *) |
| 569 | -proc entryKind*(d: ^Dir): Kind; | |
| 569 | +proc entryKind*(var d: Dir): Kind; | |
| 570 | 570 | begin |
| 571 | - return d^.kind; | |
| 571 | + return d.kind; | |
| 572 | 572 | end; |
| 573 | 573 | |
| 574 | 574 | (* Closes the directory d that openDir opened. *) |
| 575 | -proc closeDir*(d: ^Dir); | |
| 575 | +proc closeDir*(var d: Dir); | |
| 576 | 576 | begin |
| 577 | - _ := SYSCALL(3, d^.fd); | |
| 577 | + _ := SYSCALL(3, d.fd); | |
| 578 | 578 | end; |
| 579 | 579 | |
| 580 | 580 | (* Puts the terminal on fd into raw mode: no echo, no lines, no signals, |
| @@ -2249,18 +2249,18 @@ | ||
| 2249 | 2249 | _ := remove("/tmp/raz-sys-dir/h"); |
| 2250 | 2250 | i, err := info("/no/such/file"); |
| 2251 | 2251 | if err >= 0 then exit(2); end; |
| 2252 | - if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end; | |
| 2253 | - name, ok := nextEntry(ADR(d)); | |
| 2252 | + if openDir(d, "/tmp/raz-sys-dir") # 0 then exit(2); end; | |
| 2253 | + name, ok := nextEntry(d); | |
| 2254 | 2254 | if not ok or (name # "g") then exit(2); end; |
| 2255 | - if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end; | |
| 2255 | + if (entryKind(d) # isFile) and (entryKind(d) # unknown) then exit(2); end; | |
| 2256 | 2256 | i, err := info("/tmp/raz-sys-dir/g"); |
| 2257 | 2257 | j, err := info("/tmp/raz-sys-dir"); |
| 2258 | 2258 | if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end; |
| 2259 | - name, ok := nextEntry(ADR(d)); | |
| 2259 | + name, ok := nextEntry(d); | |
| 2260 | 2260 | if ok then exit(2); end; |
| 2261 | - closeDir(ADR(d)); | |
| 2261 | + closeDir(d); | |
| 2262 | 2262 | if (remove("/tmp/raz-sys-dir/g") # 0) or (remove("/tmp/raz-sys-dir/g") >= 0) then exit(2); end; |
| 2263 | - if openDir(ADR(d), "/no/such/dir") >= 0 then exit(2); end; | |
| 2263 | + if openDir(d, "/no/such/dir") >= 0 then exit(2); end; | |
| 2264 | 2264 | (* the terminal: none here, fd -1 *) |
| 2265 | 2265 | if rawMode(-1) or ready(-1, 0) then exit(2); end; |
| 2266 | 2266 | w, h := termSize(-1); |
| @@ -599,25 +599,25 @@ | ||
| 599 | 599 | end; |
| 600 | 600 | |
| 601 | 601 | (* Opens the directory at path, for nextEntry. *) |
| 602 | -proc openDir*(d: ^Dir; path: []U8): INT; | |
| 602 | +proc openDir*(var d: Dir; path: []U8): INT; | |
| 603 | 603 | var a: [4096]U8; |
| 604 | 604 | begin |
| 605 | - d^.kind := unknown; | |
| 605 | + d.kind := unknown; | |
| 606 | 606 | if not cstr(path, a) then return -36; end; |
| 607 | - d^.d := C.opendir(ADR(a[0])); | |
| 608 | - if d^.d = nil then return failed(); end; | |
| 607 | + d.d := C.opendir(ADR(a[0])); | |
| 608 | + if d.d = nil then return failed(); end; | |
| 609 | 609 | return 0; |
| 610 | 610 | end; |
| 611 | 611 | |
| 612 | 612 | (* The next name in the directory, good until the next call, but . and |
| 613 | 613 | .., in no order; false at the end. *) |
| 614 | -proc nextEntry*(d: ^Dir): ([]U8, BOOL); | |
| 614 | +proc nextEntry*(var d: Dir): ([]U8, BOOL); | |
| 615 | 615 | var e: ^U8; n: INT; |
| 616 | 616 | begin |
| 617 | 617 | while true do |
| 618 | - e := C.readdir(d^.d); | |
| 618 | + e := C.readdir(d.d); | |
| 619 | 619 | if e = nil then return "", false; end; |
| 620 | - d^.kind := kindOf(e[CAbi.dTypeAt]); | |
| 620 | + d.kind := kindOf(e[CAbi.dTypeAt]); | |
| 621 | 621 | e := e + CAbi.dNameAt; |
| 622 | 622 | n := 0; |
| 623 | 623 | while e[n] # 0 do INC(n); end; |
| @@ -629,15 +629,15 @@ | ||
| 629 | 629 | (* What the name nextEntry gave last is, as the directory says, so that |
| 630 | 630 | a walk needn't ask each file with linkInfo; unknown where the file |
| 631 | 631 | system doesn't say. A link is isLink, whatever it names. *) |
| 632 | -proc entryKind*(d: ^Dir): Kind; | |
| 632 | +proc entryKind*(var d: Dir): Kind; | |
| 633 | 633 | begin |
| 634 | - return d^.kind; | |
| 634 | + return d.kind; | |
| 635 | 635 | end; |
| 636 | 636 | |
| 637 | 637 | (* Closes the directory d that openDir opened. *) |
| 638 | -proc closeDir*(d: ^Dir); | |
| 638 | +proc closeDir*(var d: Dir); | |
| 639 | 639 | begin |
| 640 | - _ := C.closedir(d^.d); | |
| 640 | + _ := C.closedir(d.d); | |
| 641 | 641 | end; |
| 642 | 642 | |
| 643 | 643 | (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no |
| @@ -2173,18 +2173,18 @@ | ||
| 2173 | 2173 | _ := remove("/tmp/raz-sys-dir/h"); |
| 2174 | 2174 | i, err := info("/no/such/file"); |
| 2175 | 2175 | if err >= 0 then exit(2); end; |
| 2176 | - if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end; | |
| 2177 | - name, ok := nextEntry(ADR(d)); | |
| 2176 | + if openDir(d, "/tmp/raz-sys-dir") # 0 then exit(2); end; | |
| 2177 | + name, ok := nextEntry(d); | |
| 2178 | 2178 | if not ok or (name # "g") then exit(2); end; |
| 2179 | - if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end; | |
| 2179 | + if (entryKind(d) # isFile) and (entryKind(d) # unknown) then exit(2); end; | |
| 2180 | 2180 | i, err := info("/tmp/raz-sys-dir/g"); |
| 2181 | 2181 | j, err := info("/tmp/raz-sys-dir"); |
| 2182 | 2182 | if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end; |
| 2183 | - name, ok := nextEntry(ADR(d)); | |
| 2183 | + name, ok := nextEntry(d); | |
| 2184 | 2184 | if ok then exit(2); end; |
| 2185 | - closeDir(ADR(d)); | |
| 2185 | + closeDir(d); | |
| 2186 | 2186 | if (remove("/tmp/raz-sys-dir/g") # 0) or (remove("/tmp/raz-sys-dir/g") >= 0) then exit(2); end; |
| 2187 | - if openDir(ADR(d), "/no/such/dir") >= 0 then exit(2); end; | |
| 2187 | + if openDir(d, "/no/such/dir") >= 0 then exit(2); end; | |
| 2188 | 2188 | (* the terminal: none here, fd -1 *) |
| 2189 | 2189 | if rawMode(-1) or ready(-1, 0) then exit(2); end; |
| 2190 | 2190 | w, h := termSize(-1); |
| @@ -109,15 +109,15 @@ | ||
| 109 | 109 | _ := Sys.makeDir("proj/src"); |
| 110 | 110 | put("proj/b.txt", "bb"); |
| 111 | 111 | put("proj/a.txt", "a"); |
| 112 | - if Sys.openDir(ADR(d), "proj") < 0 then return; end; | |
| 112 | + if Sys.openDir(d, "proj") < 0 then return; end; | |
| 113 | 113 | n := 0; |
| 114 | - name, more := Sys.nextEntry(ADR(d)); | |
| 114 | + name, more := Sys.nextEntry(d); | |
| 115 | 115 | while more do |
| 116 | 116 | copy, ok := Str.copy(Heap.heap, name); |
| 117 | 117 | if ok and (n < 16) then names[n] := copy; INC(n); end; |
| 118 | - name, more := Sys.nextEntry(ADR(d)); | |
| 118 | + name, more := Sys.nextEntry(d); | |
| 119 | 119 | end; |
| 120 | - Sys.closeDir(ADR(d)); | |
| 120 | + Sys.closeDir(d); | |
| 121 | 121 | Order.sort(names[0..n]); |
| 122 | 122 | Buf.init(path, Heap.heap); |
| 123 | 123 | for i := 0 to n - 1 do |
| @@ -3992,9 +3992,9 @@ | ||
| 3992 | 3992 | begin |
| 3993 | 3993 | prefix := say1("{}.", nameOf(n)); |
| 3994 | 3994 | numOthers := 0; |
| 3995 | - if Sys.openDir(ADR(dp), dir) # 0 then return nil; end; | |
| 3995 | + if Sys.openDir(dp, dir) # 0 then return nil; end; | |
| 3996 | 3996 | repeat |
| 3997 | - e, more := Sys.nextEntry(ADR(dp)); | |
| 3997 | + e, more := Sys.nextEntry(dp); | |
| 3998 | 3998 | if not more then break; end; |
| 3999 | 3999 | if (LEN(e) > 4) and Str.hasPrefix(e, prefix) and (e[LEN(e) - 4..LEN(e)] = ".raz") |
| 4000 | 4000 | and (e # chosen) and (numOthers < 32) then |
| @@ -4002,7 +4002,7 @@ | ||
| 4002 | 4002 | INC(numOthers); |
| 4003 | 4003 | end; |
| 4004 | 4004 | until false; |
| 4005 | - Sys.closeDir(ADR(dp)); | |
| 4005 | + Sys.closeDir(dp); | |
| 4006 | 4006 | for i := 0 to numOthers - 1 do |
| 4007 | 4007 | sib := try compileFile(say2("{}/{}", dir, others[i]), n, args, true); |
| 4008 | 4008 | compareIface(m, sib); |