lumbda/tests/ursa-scheme.lsp
russell@unturf.com 99b0622520 asm: values + call-with-values + #(...) reader + exit + vector equal?
Closes the remaining asm-side gaps from ticket 0005's follow-up
discussion. Every test in tests/cl-compat.lsp and tests/ursa.lsp
now runs unmodified on default asm (Scheme port) and asm-full (full
CL path) — no more commented-out tests or shim syntax.

Landed (all in default asm — useful beyond cl-compat):

  * (values . xs) / (call-with-values producer consumer). values
    packs a tagged pair (mval_marker . xs) when multiple; a lone arg
    passes through unchanged so legacy single-value code is
    undisturbed. call-with-values invokes the producer, destructures
    the multi-value packet if present, applies consumer positionally.
    The marker is a gensymed symbol interned once at init, so no
    user-constructed pair can masquerade as a multi-value packet.

  * (exit [code]) builtin. Default code is 0 when called with no
    args. Passes through to the SYS_EXIT syscall.

  * #(...) vector literal in the reader. .sr_hash now dispatches on
    '(' as a vector literal alongside 't' and 'f'. list_to_vector_
    reader is a standalone helper callable from the reader (separate
    from bi_listtovec which uses the GETARG builtin convention).
    Matches R7RS vector literal syntax. Existing vector builtins
    already handled construction; this just teaches the reader.

  * deep_equal extended to vectors. equal? now descends into vectors
    (length + elementwise recursive compare), matching R7RS.
    Previously only strings and pairs were handled; vectors fell
    through to shallow pointer compare which only matched identical
    heap objects.

Test file reverts (picking up the new capabilities):

  * tests/cl-compat.lsp — multiple-value-bind test restored
    (previously commented out because asm lacked values /
    call-with-values).
  * tests/ursa-scheme.lsp — #(1 0 1 0 1 0) literal restored
    (previously worked around with (vector->list (digits ...)));
    (exit 1) failure trailer restored (previously removed because
    asm had no exit builtin).
  * tests/ursa.lsp — same digits literal restoration.

Verified:
  * asm regression: 158/158.
  * asm-full regression: 158/158.
  * Zoë-favorites across Python + C + asm + asm-full: all suites
    green with native reader syntax and multi-value tests.
  * make test-all stays green.
2026-04-24 12:38:47 -04:00

41 lines
1.9 KiB
Text

;; tests/ursa-scheme.lsp — Scheme-port only half of the Zoë
;; acceptance suite. Uses zero macros, so it runs under every tier
;; including the minimal asm (no cl-compat needed). Counterpart to
;; tests/ursa.lsp which adds the CL-path tests on top.
(define *pass* 0)
(define *fail* 0)
(define (check name got expected)
(cond ((equal? got expected)
(set! *pass* (+ *pass* 1))
(display "PASS: ") (display name) (newline))
(else
(set! *fail* (+ *fail* 1))
(display "FAIL: ") (display name)
(display " got=") (write got)
(display " expected=") (write expected) (newline))))
(load "examples/ursa-scheme.lsp")
(random-seed! 42)
(check "s:expt-mod-3^7%100" (expt-mod 3 7 100) 87)
(check "s:expt-mod-big" (expt-mod 2 100 1000) 376)
(check "s:primep-97" (primep 97) 97)
(check "s:primep-100" (primep 100) #f)
(check "s:factor-12" (factor 12) '(2 2 3))
(check "s:factor-1001" (factor 1001) '(7 11 13))
(check "s:mersenne-5" (mersenne-number 5) 31)
(check "s:ll-residue-5" (lucas-lehmer-residue 5) 0)
(check "s:ll-primep-5" (lucas-lehmer-primep 5) #t)
(check "s:ll-primep-11" (lucas-lehmer-primep 11) #f)
(check "s:ll-primep-13" (lucas-lehmer-primep 13) #t)
(check "s:repunit-5" (repunit-value 5) 31)
(check "s:digits-42-2" (digits 42 2) #(1 0 1 0 1 0))
(check "s:digits-roundtrip" (digits (digits 1234 16) 16) 1234)
(let ((v (of-n-bits 8)))
(check "s:of-n-bits" (and (>= v 128) (< v 256)) #t))
(display "══════════════════════════════") (newline)
(display "ursa-scheme: ") (display *pass*) (display " passed, ")
(display *fail*) (display " failed") (newline)
(if (> *fail* 0) (exit 1))