Demo program that lives entirely on lib/* and libwwrt.a — no @symbol
FFI of its own. The interpreter sits in lispcore.ww (exports for the
test driver); lisp.ww is a 3-line entry that calls lispcore.repl().
Language surface: integers, floats, symbols, strings, lists, lambdas
with closures, define / set! / if / quote / let / begin, recursion
(fact / fib / ackermann / gcd), map / filter / reduce as user code.
REPL is line-buffered: each read tries to parse one top-level form,
asks for more on "unterminated list", evaluates and prints, then
shifts consumed bytes off the front of the buffer. Lookahead-aware —
the parser primes one extra token so we shift to L.curstart, not
L.pos, otherwise the first byte of the next form gets eaten.
lisp_test.ww exec'd as a regular binary (ww test drops -I in single-
file mode); 66 probes cover arithmetic, lists, closures, recursion,
errors. test_*.lisp drive the live REPL through `make demo`.
The wwstage cgen still mis-lowers a handful of patterns at this
shape of program — top-level array indexing, global-ptr deref,
two-level field stores, f64 routing through *T, alloc(structlit{})
for f64/str fields, (slice | E) returns, xs[i].kind chains, f64
compound assigns. Each workaround is annotated at its use site;
the full taxonomy is in examples/lisp/CLAUDE.md.
27 lines
903 B
Common Lisp
27 lines
903 B
Common Lisp
; test_arith.lisp — arithmetic and comparisons.
|
|
; Run: cat test_arith.lisp | ./lisp
|
|
;
|
|
; Each form's expected result is in the trailing comment.
|
|
|
|
(+ 1 2 3 4 5) ; => 15
|
|
(* 6 7) ; => 42
|
|
(- 100 25 25) ; => 50
|
|
(/ 100 5) ; => 20
|
|
(/ 1000 10 5) ; => 20
|
|
(mod 17 5) ; => 2
|
|
(- 7) ; => -7
|
|
|
|
(+ (* 2 3) (* 4 5)) ; => 26
|
|
(+ (- 50 10) (* 2 5)) ; => 50
|
|
|
|
(= 5 5) ; => #t
|
|
(= 5 6) ; => #f
|
|
(< 1 2 3 4) ; => #t
|
|
(<= 3 3 4) ; => #t
|
|
(> 5 3 1) ; => #t
|
|
|
|
; mixed int/float — int operands auto-promote
|
|
(+ 1 2.5) ; => 3.5
|
|
(* 2 3.0) ; => 6.0
|
|
(/ 22.0 7.0) ; => 3.142857
|