Wire adapter-html.sx into OCaml server, replacing hand-written renderer
sx_server.ml: sx_render_to_html() calls the SX adapter-html.sx render-to-html via CEK eval, falling back to Sx_render.render_to_html if adapter not loaded. CLI --render mode now loads render.sx + adapter-html.sx. sx_primitives.ml: Added ~25 primitives needed by adapter-html.sx: scope-push!/pop!/peek/emit!, emitted, provide-push!/pop! (hashtable stack), lambda?/island?/component?/macro?, component-closure/name/params/body/ has-children?, lambda-closure/params/body, is-else-clause?, for-each-indexed, empty-dict?, make-raw-html, raw-html-content run_tests.ml: Loads render.sx + adapter-html.sx for test-render-html.sx. Registers trampoline, eval-expr, scope stubs, expand-macro, cond-scheme?. Status: 1105/1114 OCaml tests pass. 8 remaining failures are env-merge edge cases in render-lambda-html/component-children/island rendering — same adapter code works in JS (143/143). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -898,6 +898,21 @@ let make_server_env () =
|
||||
env
|
||||
|
||||
|
||||
(* ====================================================================== *)
|
||||
(* SX render-to-html — calls adapter-html.sx via CEK *)
|
||||
(* ====================================================================== *)
|
||||
|
||||
(** Render an SX expression to HTML using the SX adapter (adapter-html.sx).
|
||||
Falls back to Sx_render.render_to_html if the SX adapter isn't loaded. *)
|
||||
let sx_render_to_html expr env =
|
||||
if env_has env "render-to-html" then
|
||||
let fn = env_get env "render-to-html" in
|
||||
let result = Sx_ref.cek_call fn (List [expr; Env env]) in
|
||||
match result with String s -> s | _ -> Sx_runtime.value_to_str result
|
||||
else
|
||||
Sx_render.render_to_html expr env
|
||||
|
||||
|
||||
(* ====================================================================== *)
|
||||
(* JIT hook registration *)
|
||||
(* ====================================================================== *)
|
||||
@@ -1232,7 +1247,7 @@ let rec dispatch env cmd =
|
||||
let body_expr = match body_exprs with
|
||||
| [e] -> e | [] -> Nil | _ -> List (Symbol "<>" :: body_exprs)
|
||||
in
|
||||
Sx_render.render_to_html body_expr env
|
||||
sx_render_to_html body_expr env
|
||||
with e ->
|
||||
Printf.eprintf "[ssr] render-to-html failed: %s\n%!" (Printexc.to_string e);
|
||||
"" (* fallback: client renders from SX source. Islands with
|
||||
@@ -1253,7 +1268,7 @@ let rec dispatch env cmd =
|
||||
:: Keyword "body-html" :: String body_html
|
||||
:: resolved_kwargs in
|
||||
let shell_call = List (Symbol "~shared:shell/sx-page-shell" :: shell_args) in
|
||||
let html = Sx_render.render_to_html shell_call env in
|
||||
let html = sx_render_to_html shell_call env in
|
||||
let t3 = Unix.gettimeofday () in
|
||||
Printf.eprintf "[sx-page-full] aser=%.3fs io=%.3fs ssr=%.3fs shell=%.3fs total=%.3fs body=%d ssr=%d html=%d\n%!"
|
||||
(t1 -. t0) (t2 -. t1) (t2b -. t2) (t3 -. t2b) (t3 -. t0)
|
||||
@@ -1279,7 +1294,7 @@ let rec dispatch env cmd =
|
||||
| [] -> Nil
|
||||
| _ -> List (Symbol "do" :: exprs)
|
||||
in
|
||||
let html = Sx_render.render_to_html expr env in
|
||||
let html = sx_render_to_html expr env in
|
||||
send_ok_string html
|
||||
with
|
||||
| Eval_error msg -> send_error msg
|
||||
@@ -1406,9 +1421,11 @@ let cli_mode mode =
|
||||
let spec_files = [
|
||||
Filename.concat base "parser.sx";
|
||||
Filename.concat base "render.sx";
|
||||
Filename.concat web_base "adapter-html.sx";
|
||||
Filename.concat web_base "adapter-sx.sx";
|
||||
] in
|
||||
(if mode = "aser" || mode = "aser-slot" then
|
||||
(* Load spec files for all CLI modes that need rendering *)
|
||||
(if mode = "aser" || mode = "aser-slot" || mode = "render" then
|
||||
cli_load_files env spec_files);
|
||||
(* Load any files passed via --load *)
|
||||
let load_files = ref [] in
|
||||
@@ -1434,7 +1451,7 @@ let cli_mode mode =
|
||||
let exprs = Sx_parser.parse_all src in
|
||||
let expr = match exprs with
|
||||
| [e] -> e | [] -> Nil | _ -> List (Symbol "do" :: exprs) in
|
||||
let html = Sx_render.render_to_html expr env in
|
||||
let html = sx_render_to_html expr env in
|
||||
print_string html; flush stdout
|
||||
| "aser" ->
|
||||
let exprs = Sx_parser.parse_all src in
|
||||
|
||||
Reference in New Issue
Block a user