Files
ww/examples/lisp/test_error.lisp
Hojun-Cho ab173b095a examples: lisp — pure-ww Lisp interpreter, REPL, in-process tests
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.
2026-05-12 22:33:24 +09:00

19 lines
812 B
Common Lisp

; test_error.lisp — runtime errors. Each form should produce
; `error: <message>` on stderr; the REPL keeps going and prints
; surviving results on stdout.
;
; Run: cat test_error.lisp | ./lisp
undefined-symbol ; error: unbound symbol
(car 1) ; error: car: not a pair
(cdr '()) ; error: cdr: not a pair
(/ 5 0) ; error: divide by zero
(mod 7 0) ; error: mod by zero
(+ 'a 'b) ; error: expected number
(car) ; error: car: need 1 arg
(cons 1) ; error: cons: need 2 args
; sanity: the REPL recovers — these should print normally.
(+ 1 2) ; => 3
"still alive" ; => "still alive"