sel
sel is a small, Lisp-like language compiled to register-based bytecode and executed by an iterative stack VM, with optional JIT compilation via MIR. The tokenizer, AST, compiler, VM, and runtime are written in C; MIR (JIT), libffi (FFI), and linenoise (REPL editing) are vendored as git submodules and built statically — no system runtime dependencies beyond libc.
; classic recursive Fibonacci (tail-recursive accumulator form)
(let fib
(fn fib (n acc)
(if (= n 0)
acc
(fib (- n 1) (+ acc n)))))
(println (fib 100 0))
Highlights
| Feature | Detail |
|---|---|
| Syntax | Uniform S-expression syntax |
| Numbers | Native long, double, arbitrary-precision bigint and bigfloat |
| Strings | '…' ASCII with escape sequences; "…" raw UTF-8 literal |
| Lists | Linked cons cells — cons, car, cdr |
| Functions | First-class, lexically-scoped closures |
| Macros | Compile-time defmacro with textual substitution |
| Tail calls | Self-tail-call → JMP; general TCO via OP_TAIL_CALL |
| JIT | Lazy per-function native compile via MIR; disable with --no-jit |
| FFI | (ffi "name" ret-type arg-types…) via libffi; struct by-value via defstruct; dynamic loading via loadlibrary |
| Standard library | core.sel — load explicitly with (load "core.sel") |
| REPL | Interactive read-eval-print loop (linenoise), multi-line aware |
Quick navigation
- Getting Started — build, REPL, run a file, flags
- Syntax — tokens, S-expressions, comments
- Types — integers, floats, bignum, strings, lists, closures, nil
- Special Forms —
if,fn,let,begin,defmacro - Operators — arithmetic, comparison, bitwise, shift
- Built-in Functions —
cons,car,cdr,print,println - Standard Library —
core.sel: booleans, math, list functions - Closures — higher-order functions, captures, currying
- Tail Calls — TCO, tail-recursive patterns
- Internals — macro system, compiler passes, VM, JIT, FFI trampoline