session
Update 10: The direct PE emitter
The flagship backend landed: emit goes from source to a finished .exe with zero external tools.
- Full x86-64 instruction encoder: REX prefixes, ModR/M + SIB bytes, displacement and immediate encoding, all 16 registers.
- Complete PE file construction: DOS/PE headers,
.text+.rdatasections, import directory, and an Import Address Table pullingGetStdHandle,WriteFile, andExitProcessfromkernel32.dll. - Print, panic, and allocation runtime generated inline as machine code, with no libc anywhere in the binary.
- Deferred label relocation for jumps and calls; Windows x64 ABI-compliant stack frames.
Bugs worth remembering
Three subtle codegen bugs were found and fixed along the way:
- Swapped REX.R/REX.B bits in register-to-register moves, so any
movinvolving R8-R15 selected the wrong register, causing access violations. - A 64-bit store clobbering adjacent stack data: zeroing a 4-byte variable wrote 8 bytes, silently corrupting the neighboring newline and digit bytes.
- An off-by-one in integer print length that dropped the trailing newline.
Output now matches the interpreter and MASM backends byte-for-byte, and exit codes propagate correctly.