| | @@ -2439,6 +2439,68 @@ |
| 2439 | 2439 | |
| 2440 | 2440 | The recipe for an interrupt's entry, and its test, follow. |
| 2441 | 2441 | |
| 2442 | +## What the compiler asks of Sys, Rt and Files |
| 2443 | + |
| 2444 | +What `src/` takes from `lib/`, for a host that has to supply it |
| 2445 | +(`Host`, and a program that brings its own library): every qualified |
| 2446 | +name, in code, of a library module. Nothing else of `lib/` is used by |
| 2447 | +`src/` itself; the library modules listed import others in turn |
| 2448 | +(`Heap`, `Mem`, `Out`, `Files` and the rest call `Sys` and `Rt`), and a |
| 2449 | +replacement for one has to give what the others ask of it. `Rt` is |
| 2450 | +also found by name for `fail`, `exit` and the places, as the previous |
| 2451 | +section says, and `NEW(p, a)` needs `a` to be a `^Mem.Allocator` and |
| 2452 | +calls its `alloc` field, the one library type the compiler knows by |
| 2453 | +name. Besides the library, `src/` makes two system calls itself, |
| 2454 | +`stat` in `Parse.identity` (a file's device and inode, for the |
| 2455 | +one-module-of-each-name check) and `memfd_create` and `execve` in |
| 2456 | +`Raz.raz` (`raz run`), and reads `SYSTEM.ARGV`. |
| 2457 | + |
| 2458 | +`test/asks.sh` keeps this list true: it fails when `src/` uses a |
| 2459 | +library name that is not a row here, or a row names one that `src/` |
| 2460 | +no longer uses. Each row is one name; a type is listed with its |
| 2461 | +fields as the code reads them. |
| 2462 | + |
| 2463 | +`Sys`, the system: |
| 2464 | + |
| 2465 | +| Name | What for | |
| 2466 | +|---|---| |
| 2467 | +| `Sys.access` | `Raz.muslHere`: whether the dynamic loaders of glibc and musl are installed | |
| 2468 | +| `Sys.chmod` | `Elf.writeElf`: makes the program's file executable (mode 755) | |
| 2469 | +| `Sys.close` | `Scan` and `Parse`: closes a source or `RAZ-VERSION` file after reading | |
| 2470 | +| `Sys.closeDir`, `Sys.openDir`, `Sys.nextEntry`, `Sys.Dir` | `Parse`: the files of a directory, to find a module's other files for the one-module-of-each-name check | |
| 2471 | +| `Sys.env`, `Sys.envAt` | `Diag` (`NO_COLOR`) and `Raz.userLibraries` (`RAZ_PATH`, `HOME`; `envAt` tells unset from empty) | |
| 2472 | +| `Sys.errDenied`, `Sys.errNoEntry` | `Scan`: "permission denied" and "there is no such file" in a message | |
| 2473 | +| `Sys.info`, `Sys.Info` | `Scan` and `Parse`: whether a path is a file (`file`) and its length (`size`) | |
| 2474 | +| `Sys.isTerminal` | `Diag`: colour only when standard error is a terminal | |
| 2475 | +| `Sys.openRead`, `Sys.read` | `Scan`: reads a source file whole; `Parse`: the library's `RAZ-VERSION` | |
| 2476 | +| `Sys.readLink` | `Raz`: `/proc/self/exe`, to find the library beside the compiler | |
| 2477 | +| `Sys.stderr`, `Sys.write` | `Diag`: its messages | |
| 2478 | +| `Sys.workDir` | `Diag`: shows a path relative to the working directory; `Elf`: the compilation directory of the line table | |
| 2479 | + |
| 2480 | +`Rt`, the run time, besides `fail`, `exit` and the places (above): |
| 2481 | + |
| 2482 | +| Name | What for | |
| 2483 | +|---|---| |
| 2484 | +| `Rt.exit` | `Diag`: ends the compiler, with status 1, after an error that stops it | |
| 2485 | + |
| 2486 | +`Files`, whole files and the command line: |
| 2487 | + |
| 2488 | +| Name | What for | |
| 2489 | +|---|---| |
| 2490 | +| `Files.arg` | `Raz`: the command line's words, and `ARGC()` for how many | |
| 2491 | +| `Files.write` | `Elf.writeElf`: writes the executable | |
| 2492 | + |
| 2493 | +The rest of the library, which `Diag`, `Sym`, `X64` and `Parse` use for |
| 2494 | +text and `Scan` for tables: |
| 2495 | + |
| 2496 | +| Name | What for | |
| 2497 | +|---|---| |
| 2498 | +| `Buf.Buf`, `Buf.init`, `Buf.add`, `Buf.str`, `Buf.bytes`, `Buf.reset`, `Buf.done` | A growing buffer: `Diag`'s message and working directory, a type's name in `Sym`, an instruction's text in `X64`, a name made in `Parse` | |
| 2499 | +| `Fmt.write`, `Fmt.Arg`, `Fmt.str`, `Fmt.int`, `Fmt.char`, `Fmt.hex` | Formatting: `Diag.say`'s `{}` messages and a type's name | |
| 2500 | +| `Out.str`, `Out.ln`, `Out.flush` | Standard output: the `-S` listing, `-h` and `--version` | |
| 2501 | +| `Str.copy`, `Str.find`, `Str.hasPrefix`, `Str.hexVal` | A kept copy of a path (`Diag`), the one-character operators (`Scan`), a prefix of a path, a file name or a mnemonic (`Diag`, `Parse`, `X64`), and a hex digit (`Parse`) | |
| 2502 | +| `Heap.heap`, `Mem.alloc`, `Mem.free` | The allocator that `NEW`, `Buf.init` and `Str.copy` are given, and the blocks of `Scan`'s tables and `Diag`'s lists | |
| 2503 | + |
| 2442 | 2504 | ## This compiler's choices |
| 2443 | 2505 | |
| 2444 | 2506 | What the report's appendix A leaves to an implementation, and what |