raz / commit 3829cbb0

commit
3829cbb06f30ee44c2127e8b1f7dd2f34a520d5a
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
54014f91
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.

patch · log

4 files changed, +131 -17

PLAN.md (history) modified +103 -4

@@ -151,8 +151,107 @@
151151 v0.25.3, 2026-10-29: `raz -q def` on a module, used or imported, gives
152152 its `module` line.
153153
154-## 5. Clean-up: v0.26.0, the last before 1.0
154+## 5. arm64 macOS: v0.26.0
155+
156+Started by the owner's word of 2026-11-15: raz on an Apple Silicon Mac,
157+natively, as a second target, `darwin-arm64`. Report 2026-11.0 names
158+it and changes no language (section 3, appendix A).
159+
160+**The shape.** `Gen` is the only unit that knows the machine, and
161+`Elf` the only one that knows the executable, so the port is new
162+units beside them, not a change to `Parse` or `Item`:
163+
164+- `A64.raz`, beside `X64.raz`: arm64's instructions encoded, branches
165+ within a procedure, and the assembler for code procedures (Arm's
166+ syntax, the instructions the library's code procedures use; `db` for
167+ any other).
168+- `Gen.arm64.raz`, beside `Gen.raz` (to be `Gen.x86_64.raz`): the same
169+ calls, the stack machine kept in arm64's registers; Apple's calling
170+ convention (x18 never touched, a frame record in x29, the arguments
171+ past a variadic C procedure's own on the stack); every address by
172+ `adrp` and `add`, since macOS runs no executable at a fixed address;
173+ the atomics by the LSE instructions every Apple processor has.
174+ Two things x86 does for free and arm64 doesn't, which the report
175+ binds: a division by zero, or the smallest value by -1, stops the
176+ program (arm64's `sdiv` gives 0), so it is checked; a real out of an
177+ `I64`'s range, or a NaN, gives the smallest `I64` (arm64's `fcvtzs`
178+ saturates), so it is mended after.
179+- `MachO.raz`, beside `Elf.raz`: a Mach-O executable for dyld, linked
180+ to libSystem, as every macOS program must be; C's symbols bound into
181+ a table of quadwords, as GLOB_DAT does now; every address in data
182+ rebased, since the program is position-independent; its symbol table
183+ for lldb's backtraces; and an ad-hoc code signature, SHA-256 hashes
184+ of its pages, without which arm64 macOS won't run it. No line
185+ numbers for a debugger at first.
186+- `Host.darwin.raz`: the library beside the compiler by
187+ `_NSGetExecutablePath`, C always, a program run from a file written
188+ and made executable (no `memfd_create`).
189+- `Link`: the places in data that hold an address, listed for
190+ `MachO`'s rebasing.
191+
192+A compiler compiles for the system it runs on, as now: its target is
193+the one it was built for, its back end and executable chosen at its
194+build by the target's suffixes (section 3), `Gen.arm64.raz` and
195+`Host.darwin.raz` as `Sys.linux-x86_64.raz` is today. No `-target`.
196+A compiler for one system that runs on another is built by staging,
197+as appendix (b) proposes for Moss: `src/cross.sh` copies `src/` with
198+the other target's files in place. It is needed once, for the first
199+Mac compiler, and wherever a release for one system is made on the
200+other.
201+
202+**The library.** Over libSystem, through `lib/Sys.raz`, the C one,
203+with `CAbi.darwin-arm64.raz` made by `tools/cabi.c` on the Mac, never
204+by hand. `Rt.darwin-arm64.raz`: the signals and their own stack, the
205+place a fault stopped at from the Mac's `ucontext`, and `framePtr`,
206+`liveRegs`, `here` and `sigReturn` in arm64. `Thread.darwin.raz` over
207+pthreads, its `Mutex` on `os_unfair_lock`. `Bytes.arm64.raz`. `Math`'s
208+`sqrt`, `mul` and `div128` and `Str`'s code procedure move into
209+`.x86_64` files with arm64 twins: no generic file keeps machine code.
210+None of it breaks a program.
211+
212+**Steps**, one commit each, `make check` passing first (in a
213+linux/amd64 container on the Mac until there is a Mac compiler):
214+
215+1. Report 2026-11.0, for the owner's review. (This commit.)
216+2. A container to build and check in on the Mac (`make docker-check`),
217+ the budget raised to 18,000 in `CLAUDE.md` and `doc/compiler.md`,
218+ and the Makefile and scripts made to run on BSD's tools as on GNU's
219+ (`sed -i`, `stat`, `sha256sum`).
220+3. `Gen.raz` to `Gen.x86_64.raz`, `Elf` behind a unit of the target's
221+ (`Exe`), `src/cross.sh`: Linux's compiler unchanged, byte for byte.
222+4. `A64.raz`, its encoder checked against `llvm-mc`'s bytes.
223+5. `Gen.arm64.raz`, in pieces: values and operations; jumps and
224+ checks; calls and frames; reals; atomics, deferred statements, the
225+ entry point.
226+6. `MachO.raz` and `Link`'s rebases, its line numbers for lldb;
227+ `Host.darwin.raz`.
228+7. The library: `CAbi`, `Sys`, `Rt`, `Thread`, `Bytes`, `Math`, `Str`.
229+8. `test/` and `conform/` passing on the Mac; what differs by target
230+ (signals' words, errors' numbers) in files of the target's.
231+9. The first Mac compiler, by the staged cross compiler; it builds
232+ itself; `make fixpoint` on the Mac; `make bench` at 400,000 lines a
233+ second there.
234+10. The release: two tarballs, `linux-x86_64` and `darwin-arm64`;
235+ `BOOT` names one for each host, with its sum.
236+
237+**The owner's answers**, 2026-11-15:
238+
239+a. The budget is 18,000 lines of code.
240+b. The names are `darwin-arm64`.
241+c. No CI for now: the Mac's tarball is made here by `make dist`.
242+d. The port is v0.26.0; the clean-up and 1.0 move one on.
243+e. Line numbers for lldb are in v0.26.0 (below).
155244
245+**Line numbers on the Mac.** `Elf` writes DWARF 4 already: the line
246+table `makeLines` makes, target-blind, and the one compile unit
247+`putDebug` writes. lldb reads DWARF from an executable's `__DWARF`
248+segment, as it does Go's, so `MachO` writes the same three sections,
249+`__debug_line`, `__debug_info` and `__debug_abbrev`, there, unloaded,
250+before `__LINKEDIT`; `make gdb`'s twin drives `lldb --batch`. About 50
251+lines, `makeLines` and `putDebug` shared by the two writers.
252+
253+## 6. Clean-up: v0.27.0, the last before 1.0
254+
156255 The files that served the thaws are made a record, short and true:
157256
158257 - `PROPOSALS.md` and `MEM_PROPOSAL.md`: gone, done early (2026-10-26);
@@ -169,11 +268,11 @@
169268 - The programs in `~/r` that pin an older raz (rmacs, ravite, rnet, ...)
170269 moved to the release.
171270
172-## 6. 1.0
271+## 7. 1.0
173272
174-No date. raz is 1.0 when use shows it: programs written against v0.26.0
273+No date. raz is 1.0 when use shows it: programs written against v0.27.0
175274 for long enough that no defect is outstanding. Until then it is
176-0.26.x, mending defects only.
275+0.27.x, mending defects only.
177276
178277 ## Appendix: the Moss work, as proposed
179278

doc/raz.md (history) modified +20 -12

@@ -13,7 +13,7 @@
1313 This report defines the language. It is short on purpose. Whatever it
1414 doesn't allow, raz doesn't have.
1515
16-This is version 2026-10.38 of the report; section 11 says where each
16+This is version 2026-11.0 of the report; section 11 says where each
1717 version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1818 for a language anyone can build again. They break programs written
1919 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
@@ -81,7 +81,8 @@
8181 is for a program on the bare machine: a code procedure names a
8282 procedure or a global variable in three operands (section 8), and
8383 section 10 gives the least an implementation accepts, and what it does
84-past its own limits; it breaks no program.
84+past its own limits; it breaks no program. 2026-11.0 names a second
85+target, arm64 macOS, and changes no language.
8586
8687 The language is frozen, softly, from this version on: it changes only
8788 to mend a defect, and its library grows only by what breaks no program
@@ -354,8 +355,10 @@
354355 directories, with its target-specific files beside them. In each
355356 directory the compiler takes the
356357 first of `Name.OS-ARCH.raz`, `Name.OS.raz`, `Name.ARCH.raz` and
357-`Name.raz` that exists, where `OS-ARCH` is the target, for now only
358-`linux-x86_64`. So a module whose code depends on the machine or the
358+`Name.raz` that exists, where `OS-ARCH` is the target: `linux-x86_64`
359+or `darwin-arm64`. The names are the system's and the machine's as
360+`uname` gives them, in lower case, and a machine has one name on every
361+system: `arm64` on Linux too. So a module whose code depends on the machine or the
359362 system comes in one file per target, and the modules that import it
360363 don't change. Machine code (section 8) and system calls belong in such
361364 files.
@@ -530,7 +533,7 @@
530533 | Type | Size | Values |
531534 |---|---|---|
532535 | `I8` `I16` `I32` `I64` | 1, 2, 4, 8 | signed integers, two's complement |
533-| `INT` | an address's: 8 on x86-64 | signed, as big as an address |
536+| `INT` | an address's: 8 on x86-64 and arm64 | signed, as big as an address |
534537 | `UINT` | an address's | unsigned, as big as an address |
535538 | `U8` `U16` `U32` `U64` | 1, 2, 4, 8 | unsigned integers |
536539 | `BOOL` | 1 | `false` (0), `true` (1) |
@@ -552,7 +555,8 @@
552555 used code names isn't, so a module like `Fmt` keeps one interface on
553556 every target.
554557
555-Each is aligned as the target's C aligns it: to its size on x86-64.
558+Each is aligned as the target's C aligns it: to its size on x86-64
559+and arm64.
556560 So are `ERROR` (section 5.8), pointers
557561 and procedures, each as big as an address; a slice is aligned as an
558562 address is.
@@ -565,7 +569,7 @@
565569 ### 5.3 Slices
566570
567571 `[]T` is a view of elements that live elsewhere: a pointer to the first
568-and a count, two addresses' worth, 16 bytes on x86-64.
572+and a count, two addresses' worth, 16 bytes on x86-64 and arm64.
569573
570574 ```
571575 Slice = record ptr: ^T; len: INT; end; (* its layout *)
@@ -657,7 +661,8 @@
657661 in that space as a record's would be, after the tag, and the cases
658662 share it, so the variant is as big as its largest case needs, padded
659663 to its alignment, the largest of an `INT`'s and its fields'.
660-`variant a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64. A
664+`variant a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64 and
665+arm64. A
661666 variant that starts at zero therefore holds its first case.
662667
663668 ### 5.7 Enumerations and sets
@@ -1980,7 +1985,7 @@
19801985 `conform/check.sh` runs them.
19811986
19821987 - **The target.** Which machines and systems it compiles for, and the
1983- names of their files (`linux-x86_64`, section 3); for each, the size
1988+ names of their files (`linux-x86_64`, `darwin-arm64`, section 3); for each, the size
19841989 of an address, and so of `INT`, whether it has reals, and which C
19851990 library a program that uses C is linked against.
19861991 - **Separate compilation.** Whether modules are compiled on their own,
@@ -1993,7 +1998,9 @@
19931998 on one with a single processor, by holding off interrupts while
19941999 they run, for one.
19952000 - **The calling convention.** On x86-64 Linux it is System V
1996- (sections 8 and 9); elsewhere it is the C library's own, so that
2001+ (sections 8 and 9); on arm64 macOS, Apple's arm64 one, which passes
2002+ the arguments past a C procedure's own parameters on the stack;
2003+ elsewhere it is the C library's own, so that
19972004 `extern` procedures and callbacks work. How a procedure returns
19982005 several results, and how its frame is laid out, are the
19992006 implementation's.
@@ -2001,10 +2008,11 @@
20012008 target's machine code, written in its assembly language, and exist
20022009 only where the implementation says so; `SYSTEM.SYSCALL` exists only on Linux targets (section 6.8). A record's
20032010 layout is the target's C layout (section 5.5), and the order of a
2004- value's bytes is the target's (little-endian on x86-64).
2011+ value's bytes is the target's (little-endian on x86-64 and arm64).
20052012 - **The assembly language.** How a code procedure's instructions are
20062013 written (section 8). On x86-64 it is Intel's syntax, as NASM writes
2007- it, destination first. Which instructions it knows is the
2014+ it, destination first; on arm64, Arm's, as its reference manual
2015+ writes it, destination first. Which instructions it knows is the
20082016 implementation's; `db` gives any others.
20092017 - **Sizes in the library.** How many bytes `Out` keeps before it
20102018 writes them, `Sys.outSize` (the library volume): 4 KB on Linux, fewer on a

doc/report-history.md (history) modified +7 -0

@@ -299,3 +299,10 @@
299299 labels, deferred statements, type arguments), and says that past its
300300 own limits it rejects the program with an error naming the limit;
301301 appendix A leaves how far past to it. It breaks no program.
302+- **2026-11.0.** A second target, `darwin-arm64`: arm64 macOS. The
303+ names of a target's files are the system's and the machine's as
304+ `uname` gives them, in lower case, a machine's the same on every
305+ system (section 3). Appendix A gives arm64 macOS's calling
306+ convention, Apple's, and its assembly language, Arm's. The sizes the
307+ report gives for x86-64 hold on arm64. It changes no language and
308+ breaks no program.

src/Raz.raz (history) modified +1 -1

@@ -38,7 +38,7 @@
3838 import SYSTEM;
3939
4040 const
41- Report = "2026-10.38"; (* the version of doc/raz.md it follows *)
41+ Report = "2026-11.0"; (* the version of doc/raz.md it follows *)
4242
4343 var
4444 links: [4]Gen.Link;