| | @@ -1590,3 +1590,92 @@ |
| 1590 | 1590 | kernel's `code` procedures would want if their operands take constants. |
| 1591 | 1591 | |
| 1592 | 1592 | Met in mosaico and rx11. |
| 1593 | + |
| 1594 | +## The compiler on another host: `Host`, and what it asks of the library |
| 1595 | + |
| 1596 | +**Status.** Built on the branch `moss-platform-boundary` (3eded0c), |
| 1597 | +which Moss pins: there raz compiles programs, rebuilds itself byte for |
| 1598 | +byte, and builds again after a restart (moss c606069, |
| 1599 | +`docs/native-raz.md`). Waiting for the owner's word on the questions |
| 1600 | +below before it is rebased and merged. |
| 1601 | + |
| 1602 | +The host is the system the compiler runs on; the target, the system |
| 1603 | +its program will run on. Until the branch they were one, Linux, and |
| 1604 | +the compiler reached Linux outside `Sys`: `Parse.identity` read a |
| 1605 | +`struct stat` by `SYSCALL(4)` into a guessed `[18]INT`; `Raz` read |
| 1606 | +`ARGC()` and `ARGV()`, found the library through `/proc/self/exe`, |
| 1607 | +probed two loader paths for musl, and ran a program by `memfd_create` |
| 1608 | +and `execve`; `Elf` set mode 755. The branch does three things. |
| 1609 | + |
| 1610 | +**1. A file's identity from `Sys.info`** (2644329). Its `dev` and |
| 1611 | +`ino`, so the parser makes no system call of its own. A plain fix: |
| 1612 | +merge it. |
| 1613 | + |
| 1614 | +**2. A main file at the root, and a directory ending in `/`** |
| 1615 | +(3eded0c). `/Main.raz` has `/` as its directory, not `""`, and a |
| 1616 | +directory given as `lib/` doesn't make `lib//Sys.raz`. A plain fix: |
| 1617 | +merge it. |
| 1618 | + |
| 1619 | +**3. `Host`, a module of what the compiler asks of its host** |
| 1620 | +(bb03e48): `argCount`, `arg`, `libraryDir`, `preferMusl`, `canRun`, |
| 1621 | +`canLinkC`, `writeExecutable`, `prepareRun`, `execute`. `src/Host.raz` |
| 1622 | +is Linux's; Moss stages the compiler's sources with its own |
| 1623 | +`Host.raz` (27 lines: the library at `/lib`, no run, no C, no mode |
| 1624 | +bits) and its own `Sys`, `Rt` and `Files`. |
| 1625 | + |
| 1626 | +Questions before the merge: |
| 1627 | + |
| 1628 | +**a. A smaller `Host`.** Two of its nine procedures are there only |
| 1629 | +because `Raz` reads the command line by built-ins: |
| 1630 | +- `argCount` and `arg` go if the library has the count beside |
| 1631 | + `Files.arg`: a `Files.argCount()`, which Moss's `Files` gives from |
| 1632 | + `Sys.argc`. `Files.arg` is already the library's, and Moss already |
| 1633 | + replaces it. |
| 1634 | +- `preferMusl` and `canLinkC` are one question, which C library to |
| 1635 | + link against: `Host.cLibrary(): CLib` with `CLib = (none, glibc, |
| 1636 | + musl)`, or keep the two booleans. |
| 1637 | +- `canRun` goes if `prepareRun` is called while the command line is |
| 1638 | + read, before any source, so that its error is the refusal. |
| 1639 | +That leaves `libraryDir`, `cLibrary`, `writeExecutable`, `prepareRun` |
| 1640 | +and `execute`: five procedures, each a real difference between hosts. |
| 1641 | + |
| 1642 | +**b. How a host is chosen.** The branch stages: copy `src/`, put the |
| 1643 | +host's `Host.raz` in place of raz's, build. The main directory is |
| 1644 | +searched first, so `-I` alone can't replace it, which is right: a |
| 1645 | +module isn't silently replaced. The other way is a target name, as |
| 1646 | +`Sys.linux-x86_64.raz` is chosen today from fixed suffixes: a |
| 1647 | +`-os moss` that makes the suffixes `.moss-x86_64`, `.moss`, `.x86_64`, |
| 1648 | +`""`, so that `Host.moss.raz` and `Sys.moss.raz` are found beside the |
| 1649 | +generic files. That puts Moss's files in raz's tree, and raz would |
| 1650 | +then know of Moss. The proposal is to keep staging, raz knowing |
| 1651 | +nothing of any host but Linux, and to document it in |
| 1652 | +`doc/compiler.md` as the one way to build for another host. |
| 1653 | + |
| 1654 | +**c. What the compiler asks of the library, written down.** Moss's |
| 1655 | +`Sys` has 23 exported procedures against Linux's 104, and is enough. |
| 1656 | +`doc/compiler.md` should list what the compiler and the modules it |
| 1657 | +imports (`Rt`, `Mem`, `Heap`, `Lock`, `Arena`, `Out`, `Fmt`, `Buf`, |
| 1658 | +`Str`, `Bytes`, `Files`) use of `Sys`, `Rt` and `Files`, as Moss's |
| 1659 | +`docs/raz-port.md` measured it, and a test should hold it: the |
| 1660 | +compiler built against a `Sys` with only those exports. Then a change |
| 1661 | +to the compiler that reaches for one more of `Sys` is seen in raz, |
| 1662 | +not in Moss's next build. The test host on the branch |
| 1663 | +(`test/host/Host.raz`) checks the `Host` side only. |
| 1664 | + |
| 1665 | +**d. The stack.** A self-build passed in 64 KiB of stack on Linux, |
| 1666 | +but 64 nested parentheses don't, and Moss gives a stored program 1 |
| 1667 | +MiB. That is "Implementation limits, and a compiler for a small |
| 1668 | +stack", above; the merge needn't wait for it. |
| 1669 | + |
| 1670 | +**e. The tests in Python.** The branch adds `test/compiler-host.py` |
| 1671 | +(177 lines) and grows `test/library-path.py`, which came with |
| 1672 | +RAZ_PATH. raz's tests are otherwise `sh`, as a public project's |
| 1673 | +should be, needing nothing but a shell to run. The proposal is to |
| 1674 | +write both in `sh` before the merge. |
| 1675 | + |
| 1676 | +**f. Before the merge, in any case.** The system call numbers in |
| 1677 | +`Host.raz` named as constants, as `Raz` had them (`MemfdCreate`, |
| 1678 | +`MfdCloexec`, `Execve`); a comment on every procedure; the new section |
| 1679 | +of `doc/compiler.md` made as short and plain as the rest; a rebase on |
| 1680 | +main (`doc/compiler.md` and `src/Raz.raz` conflict). Moss's |
| 1681 | +`RAZ_PORT.lock` then pins a commit on main. |