Native bytecode compiler: 8x faster, compile-blob command
Rewrite compile-modules.js to use the native OCaml sx_server binary instead of the js_of_ocaml kernel in Node.js. Compiles 23 modules in 23s (was 3+ minutes). Uses batch epoch protocol with latin1 encoding to preserve byte positions for multi-byte UTF-8 content. - Add compile-blob server command: parse source natively, compile via SX compile-module, return bytecode dict - Fix orchestration.sxbc.json and boot.sxbc.json — never compiled successfully with the old JS kernel, now work with native compiler - Auto-copy compiled bytecode to shared/static/wasm/sx/ for serving Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -829,6 +829,29 @@ let rec dispatch env cmd =
|
||||
let src = read_blob () in
|
||||
dispatch env (List [Symbol "eval"; String src])
|
||||
|
||||
| List [Symbol "compile-blob"] ->
|
||||
(* Read source as blob, parse natively in OCaml, compile via SX compile-module.
|
||||
Returns the bytecode dict as SX text. Much faster than JS kernel. *)
|
||||
let src = read_blob () in
|
||||
(try
|
||||
let exprs = Sx_parser.parse_all src in
|
||||
let compile_module = env_get env "compile-module" in
|
||||
let result = Sx_ref.cek_call compile_module (List [List exprs]) in
|
||||
let rec raw_serialize = function
|
||||
| Nil -> "nil"
|
||||
| Bool true -> "true" | Bool false -> "false"
|
||||
| Number n -> if Float.is_integer n then string_of_int (int_of_float n) else Printf.sprintf "%g" n
|
||||
| String s -> "\"" ^ escape_sx_string s ^ "\""
|
||||
| Symbol s -> s | Keyword k -> ":" ^ k
|
||||
| List items | ListRef { contents = items } -> "(" ^ String.concat " " (List.map raw_serialize items) ^ ")"
|
||||
| Dict d -> let pairs = Hashtbl.fold (fun k v acc -> (Printf.sprintf ":%s %s" k (raw_serialize v)) :: acc) d [] in "{" ^ String.concat " " pairs ^ "}"
|
||||
| SxExpr s -> s | _ -> "nil"
|
||||
in
|
||||
send_ok_raw (raw_serialize result)
|
||||
with
|
||||
| Eval_error msg -> send_error msg
|
||||
| exn -> send_error (Printexc.to_string exn))
|
||||
|
||||
| List [Symbol "eval"; String src] ->
|
||||
(try
|
||||
let exprs = Sx_parser.parse_all src in
|
||||
|
||||
Reference in New Issue
Block a user