From 3829cbb06f30ee44c2127e8b1f7dd2f34a520d5a Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:26:20 +0000 Subject: [PATCH] Report 2026-11.0: darwin-arm64, a second target; PLAN.md 5, the port The report names arm64 macOS as a target (section 3), its file names as uname gives them, and its calling convention and assembly language (appendix A); the sizes given for x86-64 hold on arm64. No language changes. PLAN.md 5 is the port, v0.26.0, with the owner's answers; the clean-up moves to v0.27.0. --- diff --git a/PLAN.md b/PLAN.md index 13f8033..443835c 100644 --- a/PLAN.md +++ b/PLAN.md @@ -151,8 +151,107 @@ v0.25.3, 2026-10-29: `raz -q def` on a module, used or imported, gives its `module` line. -## 5. Clean-up: v0.26.0, the last before 1.0 +## 5. arm64 macOS: v0.26.0 + +Started by the owner's word of 2026-11-15: raz on an Apple Silicon Mac, +natively, as a second target, `darwin-arm64`. Report 2026-11.0 names +it and changes no language (section 3, appendix A). + +**The shape.** `Gen` is the only unit that knows the machine, and +`Elf` the only one that knows the executable, so the port is new +units beside them, not a change to `Parse` or `Item`: + +- `A64.raz`, beside `X64.raz`: arm64's instructions encoded, branches + within a procedure, and the assembler for code procedures (Arm's + syntax, the instructions the library's code procedures use; `db` for + any other). +- `Gen.arm64.raz`, beside `Gen.raz` (to be `Gen.x86_64.raz`): the same + calls, the stack machine kept in arm64's registers; Apple's calling + convention (x18 never touched, a frame record in x29, the arguments + past a variadic C procedure's own on the stack); every address by + `adrp` and `add`, since macOS runs no executable at a fixed address; + the atomics by the LSE instructions every Apple processor has. + Two things x86 does for free and arm64 doesn't, which the report + binds: a division by zero, or the smallest value by -1, stops the + program (arm64's `sdiv` gives 0), so it is checked; a real out of an + `I64`'s range, or a NaN, gives the smallest `I64` (arm64's `fcvtzs` + saturates), so it is mended after. +- `MachO.raz`, beside `Elf.raz`: a Mach-O executable for dyld, linked + to libSystem, as every macOS program must be; C's symbols bound into + a table of quadwords, as GLOB_DAT does now; every address in data + rebased, since the program is position-independent; its symbol table + for lldb's backtraces; and an ad-hoc code signature, SHA-256 hashes + of its pages, without which arm64 macOS won't run it. No line + numbers for a debugger at first. +- `Host.darwin.raz`: the library beside the compiler by + `_NSGetExecutablePath`, C always, a program run from a file written + and made executable (no `memfd_create`). +- `Link`: the places in data that hold an address, listed for + `MachO`'s rebasing. + +A compiler compiles for the system it runs on, as now: its target is +the one it was built for, its back end and executable chosen at its +build by the target's suffixes (section 3), `Gen.arm64.raz` and +`Host.darwin.raz` as `Sys.linux-x86_64.raz` is today. No `-target`. +A compiler for one system that runs on another is built by staging, +as appendix (b) proposes for Moss: `src/cross.sh` copies `src/` with +the other target's files in place. It is needed once, for the first +Mac compiler, and wherever a release for one system is made on the +other. + +**The library.** Over libSystem, through `lib/Sys.raz`, the C one, +with `CAbi.darwin-arm64.raz` made by `tools/cabi.c` on the Mac, never +by hand. `Rt.darwin-arm64.raz`: the signals and their own stack, the +place a fault stopped at from the Mac's `ucontext`, and `framePtr`, +`liveRegs`, `here` and `sigReturn` in arm64. `Thread.darwin.raz` over +pthreads, its `Mutex` on `os_unfair_lock`. `Bytes.arm64.raz`. `Math`'s +`sqrt`, `mul` and `div128` and `Str`'s code procedure move into +`.x86_64` files with arm64 twins: no generic file keeps machine code. +None of it breaks a program. + +**Steps**, one commit each, `make check` passing first (in a +linux/amd64 container on the Mac until there is a Mac compiler): + +1. Report 2026-11.0, for the owner's review. (This commit.) +2. A container to build and check in on the Mac (`make docker-check`), + the budget raised to 18,000 in `CLAUDE.md` and `doc/compiler.md`, + and the Makefile and scripts made to run on BSD's tools as on GNU's + (`sed -i`, `stat`, `sha256sum`). +3. `Gen.raz` to `Gen.x86_64.raz`, `Elf` behind a unit of the target's + (`Exe`), `src/cross.sh`: Linux's compiler unchanged, byte for byte. +4. `A64.raz`, its encoder checked against `llvm-mc`'s bytes. +5. `Gen.arm64.raz`, in pieces: values and operations; jumps and + checks; calls and frames; reals; atomics, deferred statements, the + entry point. +6. `MachO.raz` and `Link`'s rebases, its line numbers for lldb; + `Host.darwin.raz`. +7. The library: `CAbi`, `Sys`, `Rt`, `Thread`, `Bytes`, `Math`, `Str`. +8. `test/` and `conform/` passing on the Mac; what differs by target + (signals' words, errors' numbers) in files of the target's. +9. The first Mac compiler, by the staged cross compiler; it builds + itself; `make fixpoint` on the Mac; `make bench` at 400,000 lines a + second there. +10. The release: two tarballs, `linux-x86_64` and `darwin-arm64`; + `BOOT` names one for each host, with its sum. + +**The owner's answers**, 2026-11-15: + +a. The budget is 18,000 lines of code. +b. The names are `darwin-arm64`. +c. No CI for now: the Mac's tarball is made here by `make dist`. +d. The port is v0.26.0; the clean-up and 1.0 move one on. +e. Line numbers for lldb are in v0.26.0 (below). +**Line numbers on the Mac.** `Elf` writes DWARF 4 already: the line +table `makeLines` makes, target-blind, and the one compile unit +`putDebug` writes. lldb reads DWARF from an executable's `__DWARF` +segment, as it does Go's, so `MachO` writes the same three sections, +`__debug_line`, `__debug_info` and `__debug_abbrev`, there, unloaded, +before `__LINKEDIT`; `make gdb`'s twin drives `lldb --batch`. About 50 +lines, `makeLines` and `putDebug` shared by the two writers. + +## 6. Clean-up: v0.27.0, the last before 1.0 + The files that served the thaws are made a record, short and true: - `PROPOSALS.md` and `MEM_PROPOSAL.md`: gone, done early (2026-10-26); @@ -169,11 +268,11 @@ - The programs in `~/r` that pin an older raz (rmacs, ravite, rnet, ...) moved to the release. -## 6. 1.0 +## 7. 1.0 -No date. raz is 1.0 when use shows it: programs written against v0.26.0 +No date. raz is 1.0 when use shows it: programs written against v0.27.0 for long enough that no defect is outstanding. Until then it is -0.26.x, mending defects only. +0.27.x, mending defects only. ## Appendix: the Moss work, as proposed diff --git a/doc/raz.md b/doc/raz.md index 2f7ec3c..adaa897 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -13,7 +13,7 @@ This report defines the language. It is short on purpose. Whatever it doesn't allow, raz doesn't have. -This is version 2026-10.38 of the report; section 11 says where each +This is version 2026-11.0 of the report; section 11 says where each version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler @@ -81,7 +81,8 @@ is for a program on the bare machine: a code procedure names a procedure or a global variable in three operands (section 8), and section 10 gives the least an implementation accepts, and what it does -past its own limits; it breaks no program. +past its own limits; it breaks no program. 2026-11.0 names a second +target, arm64 macOS, and changes no language. The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program @@ -354,8 +355,10 @@ directories, with its target-specific files beside them. In each directory the compiler takes the first of `Name.OS-ARCH.raz`, `Name.OS.raz`, `Name.ARCH.raz` and -`Name.raz` that exists, where `OS-ARCH` is the target, for now only -`linux-x86_64`. So a module whose code depends on the machine or the +`Name.raz` that exists, where `OS-ARCH` is the target: `linux-x86_64` +or `darwin-arm64`. The names are the system's and the machine's as +`uname` gives them, in lower case, and a machine has one name on every +system: `arm64` on Linux too. So a module whose code depends on the machine or the system comes in one file per target, and the modules that import it don't change. Machine code (section 8) and system calls belong in such files. @@ -530,7 +533,7 @@ | Type | Size | Values | |---|---|---| | `I8` `I16` `I32` `I64` | 1, 2, 4, 8 | signed integers, two's complement | -| `INT` | an address's: 8 on x86-64 | signed, as big as an address | +| `INT` | an address's: 8 on x86-64 and arm64 | signed, as big as an address | | `UINT` | an address's | unsigned, as big as an address | | `U8` `U16` `U32` `U64` | 1, 2, 4, 8 | unsigned integers | | `BOOL` | 1 | `false` (0), `true` (1) | @@ -552,7 +555,8 @@ used code names isn't, so a module like `Fmt` keeps one interface on every target. -Each is aligned as the target's C aligns it: to its size on x86-64. +Each is aligned as the target's C aligns it: to its size on x86-64 +and arm64. So are `ERROR` (section 5.8), pointers and procedures, each as big as an address; a slice is aligned as an address is. @@ -565,7 +569,7 @@ ### 5.3 Slices `[]T` is a view of elements that live elsewhere: a pointer to the first -and a count, two addresses' worth, 16 bytes on x86-64. +and a count, two addresses' worth, 16 bytes on x86-64 and arm64. ``` Slice = record ptr: ^T; len: INT; end; (* its layout *) @@ -657,7 +661,8 @@ in that space as a record's would be, after the tag, and the cases share it, so the variant is as big as its largest case needs, padded to its alignment, the largest of an `INT`'s and its fields'. -`variant a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64. A +`variant a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64 and +arm64. A variant that starts at zero therefore holds its first case. ### 5.7 Enumerations and sets @@ -1980,7 +1985,7 @@ `conform/check.sh` runs them. - **The target.** Which machines and systems it compiles for, and the - names of their files (`linux-x86_64`, section 3); for each, the size + names of their files (`linux-x86_64`, `darwin-arm64`, section 3); for each, the size of an address, and so of `INT`, whether it has reals, and which C library a program that uses C is linked against. - **Separate compilation.** Whether modules are compiled on their own, @@ -1993,7 +1998,9 @@ on one with a single processor, by holding off interrupts while they run, for one. - **The calling convention.** On x86-64 Linux it is System V - (sections 8 and 9); elsewhere it is the C library's own, so that + (sections 8 and 9); on arm64 macOS, Apple's arm64 one, which passes + the arguments past a C procedure's own parameters on the stack; + elsewhere it is the C library's own, so that `extern` procedures and callbacks work. How a procedure returns several results, and how its frame is laid out, are the implementation's. @@ -2001,10 +2008,11 @@ target's machine code, written in its assembly language, and exist only where the implementation says so; `SYSTEM.SYSCALL` exists only on Linux targets (section 6.8). A record's layout is the target's C layout (section 5.5), and the order of a - value's bytes is the target's (little-endian on x86-64). + value's bytes is the target's (little-endian on x86-64 and arm64). - **The assembly language.** How a code procedure's instructions are written (section 8). On x86-64 it is Intel's syntax, as NASM writes - it, destination first. Which instructions it knows is the + it, destination first; on arm64, Arm's, as its reference manual + writes it, destination first. Which instructions it knows is the implementation's; `db` gives any others. - **Sizes in the library.** How many bytes `Out` keeps before it writes them, `Sys.outSize` (the library volume): 4 KB on Linux, fewer on a diff --git a/doc/report-history.md b/doc/report-history.md index 6e4a746..3e23033 100644 --- a/doc/report-history.md +++ b/doc/report-history.md @@ -299,3 +299,10 @@ labels, deferred statements, type arguments), and says that past its own limits it rejects the program with an error naming the limit; appendix A leaves how far past to it. It breaks no program. +- **2026-11.0.** A second target, `darwin-arm64`: arm64 macOS. The + names of a target's files are the system's and the machine's as + `uname` gives them, in lower case, a machine's the same on every + system (section 3). Appendix A gives arm64 macOS's calling + convention, Apple's, and its assembly language, Arm's. The sizes the + report gives for x86-64 hold on arm64. It changes no language and + breaks no program. diff --git a/src/Raz.raz b/src/Raz.raz index 64ada60..773c385 100644 --- a/src/Raz.raz +++ b/src/Raz.raz @@ -38,7 +38,7 @@ import SYSTEM; const - Report = "2026-10.38"; (* the version of doc/raz.md it follows *) + Report = "2026-11.0"; (* the version of doc/raz.md it follows *) var links: [4]Gen.Link;