R7RS guard special form + transpiler fixes
- guard as CEK special form in evaluator.sx, desugars to call/cc + handler-bind with sentinel-based re-raise (avoids handler loop) - bootstrap.py: fix bind_lambda_with_rest type annotations, auto-inject make_raise_guard_frame when transpiler drops it - mcp_tree: add timeout param to sx_test (default 300s) - 2566/2568 tests pass (2 pre-existing scope failures) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -320,7 +320,8 @@ def compile_spec_to_ml(spec_dir: str | None = None) -> str:
|
||||
# The transpiler can't handle the index-of-based approach, so we inject it.
|
||||
REST_HELPER = """
|
||||
(* &rest lambda param binding — injected by bootstrap.py *)
|
||||
and bind_lambda_with_rest params args local =
|
||||
and bind_lambda_with_rest (params : value) (args : value) (local_val : value) : bool =
|
||||
let local = match local_val with Env e -> e | _ -> failwith "bind_lambda_with_rest: expected env" in
|
||||
let param_list = sx_to_list params in
|
||||
let arg_list = sx_to_list args in
|
||||
let rec find_rest i = function
|
||||
@@ -333,12 +334,12 @@ and bind_lambda_with_rest params args local =
|
||||
let positional = List.filteri (fun i _ -> i < pos) param_list in
|
||||
List.iteri (fun i p ->
|
||||
let v = if i < List.length arg_list then List.nth arg_list i else Nil in
|
||||
ignore (env_bind local (value_to_str p) v)
|
||||
ignore (Sx_types.env_bind local (value_to_str p) v)
|
||||
) positional;
|
||||
let rest_args = if List.length arg_list > pos
|
||||
then List (List.filteri (fun i _ -> i >= pos) arg_list)
|
||||
else List [] in
|
||||
ignore (env_bind local rest_name rest_args);
|
||||
ignore (Sx_types.env_bind local rest_name rest_args);
|
||||
true
|
||||
| None -> false
|
||||
"""
|
||||
@@ -348,6 +349,18 @@ and bind_lambda_with_rest params args local =
|
||||
REST_HELPER + "\n(* call-lambda *)\nand call_lambda",
|
||||
)
|
||||
|
||||
# Inject make_raise_guard_frame if missing (transpiler merge bug drops it)
|
||||
if "and make_raise_guard_frame" not in output:
|
||||
RAISE_GUARD_FRAME = """
|
||||
(* make-raise-guard-frame — injected by bootstrap.py *)
|
||||
and make_raise_guard_frame env saved_kont =
|
||||
(CekFrame { cf_type = "raise-guard"; cf_env = env; cf_name = Nil; cf_body = Nil; cf_remaining = saved_kont; cf_f = Nil; cf_args = Nil; cf_results = Nil; cf_extra = Nil; cf_extra2 = Nil })
|
||||
"""
|
||||
output = output.replace(
|
||||
"(* make-signal-return-frame *)\nand make_signal_return_frame",
|
||||
RAISE_GUARD_FRAME + "\n(* make-signal-return-frame *)\nand make_signal_return_frame",
|
||||
)
|
||||
|
||||
# Patch call_lambda to use &rest-aware binding
|
||||
call_lambda_marker = "(* call-lambda *)\nand call_lambda f args caller_env =\n"
|
||||
call_comp_marker = "\n(* call-component *)"
|
||||
|
||||
Reference in New Issue
Block a user