R7RS core: call/cc, raise/guard, multi-arity map, cond =>, do iteration

Phase 1 engine step 4 — R7RS compatibility primitives for the CEK evaluator.

call/cc: undelimited continuation capture with separate CallccContinuation
type (distinct from delimited shift/reset continuations). Escape semantics —
invoking k replaces the current continuation entirely.

raise/raise-continuable: proper CEK arg evaluation via raise-eval frame.
Non-continuable raise uses raise-guard frame that errors on handler return.
host-error primitive for safe unhandled exception fallback.

Multi-arity map: (map fn list1 list2 ...) zips multiple lists. Single-list
path unchanged for performance. New multi-map frame type.

cond =>: arrow clause syntax (cond (test => fn)) calls fn with test value.
New cond-arrow frame type.

R7RS do: shape-detecting dispatch — (do ((var init step) ...) (test result) body)
desugars to named let. Existing (do expr1 expr2) sequential form preserved.

integer? primitive, host-error alias. Transpiler fixes: match/case routing,
wildcard _ support, nested match arm handling.

2522/2524 OCaml tests pass (2 pre-existing scope failures from transpiler
match codegen, not related to these changes).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 00:29:53 +00:00
parent ede05c26f5
commit 67c4a6a14d
7 changed files with 2025 additions and 1374 deletions

View File

@@ -100,7 +100,7 @@ let rec value_to_js (v : value) : Js.Unsafe.any =
Js.Unsafe.set obj (Js.string k) (value_to_js v)) d;
Js.Unsafe.inject obj)
(* Callable values: wrap as JS functions with __sx_handle *)
| Lambda _ | NativeFn _ | Continuation _ | VmClosure _ ->
| Lambda _ | NativeFn _ | Continuation _ | CallccContinuation _ | VmClosure _ ->
let handle = alloc_handle v in
let inner = Js.wrap_callback (fun args_js ->
try