blob: b42a9c8c43f6ffcb54a6b2aaccabc98f39cfd088 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
|
# an ahead-of-time compiler to darwin arm64
no code from this stage survives except where a code/ folder sits next to this file. these are the notes as they were written in the transcript.
## message 4
> now let's move in stages. write a compiler that takes this assembler's code and converts it into darwin arm
**summary:** an ungolfed c89 compiler from vm assembly to darwin arm64 assembly. every word got its own label, the image was emitted as an addressable data array, x19/x20/x21 held the memory base and the two stack pointers, and computed jumps went through a table of offsets. a literal followed by a jump became a direct branch. `Q` and `G` went through `sxtb`, since char is signed on apple arm64, and `J` was read with `ldrb`. it was verified by assembling with llvm-mc for darwin, then rewriting to linux with sed and running under qemu, where it matched the vm byte for byte. this version couldn't handle self-modifying code.
|