OCaml runtime: R7RS parameters, VM closure introspection, import suspension
- R7RS parameter primitives (make-parameter, parameter?, parameterize support) - VM closure get_val introspection (vm-code, vm-upvalues, vm-name, vm-globals) - Lazy list caching on vm_code for transpiled VM performance - VM import suspension: check_io_suspension + resume_module for browser lazy loading - 23 new R7RS tests (parameter-basic, parameterize-basic, syntax-rules-basic) - Playwright bytecode-loading spec + WASM rebuild Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -131,6 +131,38 @@ let get_val container key =
|
||||
| "frames" -> List (List.map (fun f -> VmFrame f) m.vm_frames)
|
||||
| "globals" -> Dict m.vm_globals
|
||||
| _ -> Nil)
|
||||
| VmClosure cl, String k ->
|
||||
(match k with
|
||||
| "vm-code" ->
|
||||
(* Return vm_code fields as a Dict. The bytecode and constants arrays
|
||||
are lazily converted to Lists and cached on the vm_code record so
|
||||
the transpiled VM loop (which re-derives bc/consts each iteration)
|
||||
doesn't allocate on every step. *)
|
||||
let c = cl.vm_code in
|
||||
let bc = match c.vc_bytecode_list with
|
||||
| Some l -> l
|
||||
| None ->
|
||||
let l = Array.to_list (Array.map (fun i -> Number (float_of_int i)) c.vc_bytecode) in
|
||||
c.vc_bytecode_list <- Some l; l in
|
||||
let consts = match c.vc_constants_list with
|
||||
| Some l -> l
|
||||
| None ->
|
||||
let l = Array.to_list c.vc_constants in
|
||||
c.vc_constants_list <- Some l; l in
|
||||
let d = Hashtbl.create 4 in
|
||||
Hashtbl.replace d "vc-bytecode" (List bc);
|
||||
Hashtbl.replace d "vc-constants" (List consts);
|
||||
Hashtbl.replace d "vc-arity" (Number (float_of_int c.vc_arity));
|
||||
Hashtbl.replace d "vc-locals" (Number (float_of_int c.vc_locals));
|
||||
Dict d
|
||||
| "vm-upvalues" ->
|
||||
List (Array.to_list (Array.map (fun uv -> uv.uv_value) cl.vm_upvalues))
|
||||
| "vm-name" ->
|
||||
(match cl.vm_name with Some n -> String n | None -> Nil)
|
||||
| "vm-globals" -> Dict cl.vm_env_ref
|
||||
| "vm-closure-env" ->
|
||||
(match cl.vm_closure_env with Some e -> Env e | None -> Nil)
|
||||
| _ -> Nil)
|
||||
| Dict d, String k -> dict_get d k
|
||||
| Dict d, Keyword k -> dict_get d k
|
||||
| (List l | ListRef { contents = l }), Number n ->
|
||||
|
||||
Reference in New Issue
Block a user