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.
32 lines
1.0 KiB
Common Lisp
32 lines
1.0 KiB
Common Lisp
; test_list.lisp — pairs, lists, predicates, quoting.
|
|
; Run: cat test_list.lisp | ./lisp
|
|
|
|
'() ; => ()
|
|
'(1 2 3) ; => (1 2 3)
|
|
'(a b c) ; => (a b c)
|
|
|
|
(cons 1 2) ; => (1 . 2)
|
|
(cons 1 '(2 3)) ; => (1 2 3)
|
|
(list 'x 'y 'z) ; => (x y z)
|
|
|
|
(car '(11 22 33)) ; => 11
|
|
(cdr '(11 22 33)) ; => (22 33)
|
|
(car (cdr '(1 2 3))) ; => 2
|
|
(car (cdr (cdr '(1 2 3)))) ; => 3
|
|
|
|
(null? '()) ; => #t
|
|
(null? '(1)) ; => #f
|
|
(pair? '(a)) ; => #t
|
|
(pair? 'a) ; => #f
|
|
|
|
(number? 42) ; => #t
|
|
(number? 'foo) ; => #f
|
|
(symbol? 'foo) ; => #t
|
|
(symbol? 1) ; => #f
|
|
(eq? 'a 'a) ; => #t
|
|
(eq? 'a 'b) ; => #f
|
|
|
|
; nested literal
|
|
'((1 2) (3 4) (5 6)) ; => ((1 2) (3 4) (5 6))
|
|
(car '((a b) (c d))) ; => (a b)
|