Zero bootstrap patches: all 11 moved to spec or runtime
- make-raise-guard-frame: was never defined in spec — added it - *last-error-kont*: set at error origination (host-error calls), not wrapped around every cek-run step. Zero overhead on normal path. - JIT: jit-try-call runtime function called from spec. Platform registers hook via _jit_try_call_fn ref. No bootstrap patching. - bootstrap.py compile_spec_to_ml() now returns transpiled output with zero post-processing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,9 +54,6 @@ let _strict_ref = ref (Bool false)
|
||||
let _prim_param_types_ref = ref Nil
|
||||
let _last_error_kont_ref = ref Nil
|
||||
|
||||
(* JIT call hook — platform-level optimization, registered by sx_server.ml *)
|
||||
let jit_call_hook : (value -> value list -> value option) option ref = ref None
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -209,50 +206,6 @@ def compile_spec_to_ml(spec_dir: str | None = None) -> str:
|
||||
# the transpiler directly — it emits !_ref for reads, _ref := for writes.
|
||||
import re
|
||||
|
||||
# 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",
|
||||
)
|
||||
|
||||
# === Platform-level patches (not spec concerns) ===
|
||||
|
||||
# Instrument recursive cek_run to capture kont on error (for comp-trace).
|
||||
cek_run_old = (
|
||||
'and cek_run state =\n'
|
||||
' (if sx_truthy ((cek_terminal_p (state))) then (cek_value (state)) else (cek_run ((cek_step (state)))))'
|
||||
)
|
||||
cek_run_new = (
|
||||
'and cek_run state =\n'
|
||||
' (if sx_truthy ((cek_terminal_p (state))) then (cek_value (state)) else\n'
|
||||
' try cek_run ((cek_step (state)))\n'
|
||||
' with Eval_error msg ->\n'
|
||||
' (if !_last_error_kont_ref = Nil then _last_error_kont_ref := cek_kont state);\n'
|
||||
' raise (Eval_error msg))'
|
||||
)
|
||||
if cek_run_old in output:
|
||||
output = output.replace(cek_run_old, cek_run_new, 1)
|
||||
|
||||
# Inject JIT dispatch into continue_with_call's lambda branch.
|
||||
# Replace final make_cek_state in the lambda branch with JIT check.
|
||||
jit_old = "(make_cek_state ((lambda_body (f))) (local) (kont))))))"
|
||||
jit_new = (
|
||||
"(match !jit_call_hook, f with "
|
||||
"| Some hook, Lambda l when l.l_name <> None -> "
|
||||
"let args_list = match args with List a | ListRef { contents = a } -> a | _ -> [] in "
|
||||
"(match hook f args_list with "
|
||||
"Some result -> make_cek_value result local kont "
|
||||
"| None -> make_cek_state (lambda_body f) local kont) "
|
||||
"| _ -> make_cek_state ((lambda_body (f))) (local) (kont))))))"
|
||||
)
|
||||
output = output.replace(jit_old, jit_new, 1)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user