Source linked

Slisp compile Lisp en assemblée autonome sans GC, sans macros, sans citation

Le compilateur de Steve Kemp produit l'assemblage natif Linux/amd64 à partir de programmes Lisp, en utilisant un allocateur de choc et en évitant explicitement la collecte de déchets, les macros et les citations pour une mise en œuvre maigre.

slispsteve kemplispcompilerassemblylinux amd64

Steve Kemp's Slisp is a compiler that reads Lisp programs and spits out standalone assembly for Linux/amd64. No REPL, no interpreter, no garbage collector, no macros, no quote. Just a straight shot from s-expression to an ELF binary.

What Slisp Actually Does

Input a Lisp file and Slisp emits x86-64 assembly following the SysV ABI. You assemble with NASM, link with ld, and get a native executable. The compiler supports integers, strings, lambdas with closures, lists, and a small set of special forms: cond, defun, do, if, lambda, let, list, and set!. A standard library written in Slisp itself (in stdlib.slisp) gets prepended unless you pass -stdlib=false.

Take the factorial example: (defun fact (n) (if (<= n 1) 1 (* n (fact (- n 1))))). Compile it, link it, run it. That's it.

The Anti-Features Are the Point

No garbage collection. Heap-allocated cons cells live in a rough bump-allocator. No macros, which Kemp explicitly calls out as "a lot of work" without quasiquote. No quote, because that would need eval, and a compiler can't eval at compile time easily. These aren't bugs; they're deliberate constraints that keep the implementation small and fast.

Kemp built Slisp after getting bogged down in a previous homegrown language (s-lang) where typing and syntax complexity forced a rewrite. Lisp's trivial parse tree and the well-known SysV ABI let him focus on the compiler core.

Compilation Pipeline and Testing

Build the compiler with go build ., then pipe the output through NASM and ld. A Makefile automates it. The test/ directory contains functional tests that compile programs (factorial, fibonacci, fizzbuzz, even a brainfuck interpreter) and compare output to known-good results. There are also Go unit tests for the lexer, parser, compiler, and environment packages, plus fuzz testing via go test -fuzz=FuzzProject.

Slisp isn't a toy; it passes a real test suite and handles recursion, closures, and type detection (int?, cons?). It's a compiler you can actually trace through from source to machine code.

For engineers who want to understand how a compiler can map Lisp to assembly without the overhead of a runtime or GC, Slisp is a clean, working implementation. No bloat, no hand-waving.


Source: Slisp: Simple Lisp compiler (Linux/amd64)
Domain: github.com

Read original source ->

External source stays available while the OJO article and comment thread stay local.

Comments load interactively on the live page.