Restore all OCaml + request-handler to working state (aa4c911)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 22:11:17 +00:00
parent 4e89b9a66b
commit a38b5a9b44
4 changed files with 106 additions and 132 deletions

View File

@@ -280,10 +280,7 @@ and render_list_to_html head args env =
| _ ->
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in
do_render_to_html result env)
with Eval_error _ ->
(* Symbol not in env — might be a primitive; eval the full expression *)
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in
do_render_to_html result env)
with Eval_error _ -> "")
| _ ->
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in
do_render_to_html result env
@@ -533,13 +530,10 @@ and render_list_buf buf head args env =
| _ ->
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in
render_to_buf buf result env)
with Eval_error _ ->
(* Symbol not in envmight be a primitive; eval the full expression *)
(try
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in
render_to_buf buf result env
with Eval_error msg ->
Printf.eprintf "[ssr-skip] %s\n%!" msg))
with Eval_error msg ->
(* Unknown symbol/componentskip silently during SSR.
The client will render from page-sx. *)
Printf.eprintf "[ssr-skip] %s\n%!" msg)
| _ ->
(try
let result = Sx_ref.eval_expr (List (head :: args)) (Env env) in

View File

@@ -576,12 +576,14 @@ let jit_compile_lambda (l : lambda) globals =
let fn_expr = List [Symbol "fn"; param_syms; l.l_body] in
let quoted = List [Symbol "quote"; fn_expr] in
let result = Sx_ref.eval_expr (List [compile_fn; quoted]) (Env (make_env ())) in
(* Inject closure bindings into globals so GLOBAL_GET can find them.
Only injects values not already present in globals (preserves
existing defines). Mutable closure vars get stale snapshots here
but GLOBAL_SET writes back to vm_closure_env, and GLOBAL_GET
falls through to vm_closure_env if the global is stale. *)
(* If the lambda has closure-captured variables, merge them into globals
so the VM can find them via GLOBAL_GET. The compiler doesn't know
about the enclosing scope, so closure vars get compiled as globals. *)
let effective_globals =
(* Use the LIVE globals table directly. Inject only truly local
closure bindings (not already in globals) into the live table.
This ensures GLOBAL_GET always sees the latest define values.
Previous approach copied globals, creating a stale snapshot. *)
let closure = l.l_closure in
let count = ref 0 in
let rec inject env =
@@ -623,14 +625,16 @@ let jit_compile_lambda (l : lambda) globals =
as a NativeFn if it's callable (so the CEK can dispatch to it). *)
(try
let value = execute_module outer_code globals in
ignore (fn_name, value, bc); (* resolved — not a closure, CEK handles it *)
Printf.eprintf "[jit] RESOLVED %s: %s (bc[0]=%d)\n%!"
fn_name (type_of value) (if Array.length bc > 0 then bc.(0) else -1);
(* If the resolved value is a NativeFn, we can't wrap it as a
vm_closure — just let the CEK handle it directly. Return None
so the lambda falls through to CEK, which will find the
resolved value in the env on next lookup. *)
None
with _ ->
ignore fn_name; (* non-closure, execution failed — CEK fallback *)
Printf.eprintf "[jit] SKIP %s: non-closure execution failed (bc[0]=%d, len=%d)\n%!"
fn_name (if Array.length bc > 0 then bc.(0) else -1) (Array.length bc);
None)
end
| _ ->