SBCL: The Assembly Code Breadboard (2014)

· ai · Source ↗

TLDR

  • Paul Khuong uses SBCL’s assembler as a live breadboard to prototype a register-mapped, modular-stack Forth-like VM with specialized dispatch per stack depth.

Key Takeaways

  • Stack slots map directly to x86-64 registers r8-r15 (32-bit); push/pop rotate a compile-time counter instead of moving data, mimicking x87 and the F18 processor.
  • Each primitive is specialized for all 8 stack-counter values, placed at fixed 4288-byte intervals, so NEXT dispatches via a single LEA+JMP with no branching on the counter.
  • A bug in NEXT encoded an index-only effective address, wasting 5 bytes per dispatch (14 bytes vs. 9 bytes after fix).
  • Control flow (jmp, call, ret) uses the native x86 stack as the Forth return stack, keeping ret to a single POP+NEXT.
  • SLIME REPL plus sb-disassem lets you assemble, inspect, and iterate machine code interactively without leaving the Lisp environment.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN