VM auto-compile infrastructure + disable until compiler is complete
Added vm-compile command: iterates env, compiles lambdas to bytecode, replaces with NativeFn VM wrappers (with CEK fallback on error). Tested: 3/109 compile, reduces CEK steps 23%. Disabled auto-compile in production — the compiler doesn't handle closures with upvalues yet, and compiled functions that reference dynamic env vars crash. Infrastructure stays for when compiler handles all SX features. Also: added set-nth! and mutable-list primitives (needed by compiler.sx for bytecode patching). Fixed compiler.sx to use mutable lists on OCaml (ListRef for append!/set-nth! mutation). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -529,6 +529,17 @@ let () =
|
||||
match args with [Dict d] -> List (dict_keys d) | _ -> raise (Eval_error "keys: 1 dict"));
|
||||
register "vals" (fun args ->
|
||||
match args with [Dict d] -> List (dict_vals d) | _ -> raise (Eval_error "vals: 1 dict"));
|
||||
register "mutable-list" (fun _args -> ListRef (ref []));
|
||||
register "set-nth!" (fun args ->
|
||||
match args with
|
||||
| [ListRef r; Number n; v] ->
|
||||
let i = int_of_float n in
|
||||
let l = !r in
|
||||
r := List.mapi (fun j x -> if j = i then v else x) l;
|
||||
Nil
|
||||
| [List _; _; _] ->
|
||||
raise (Eval_error "set-nth!: list is immutable, use ListRef")
|
||||
| _ -> raise (Eval_error "set-nth!: expected (list idx val)"));
|
||||
register "dict-set!" (fun args ->
|
||||
match args with
|
||||
| [Dict d; String k; v] -> dict_set d k v; v
|
||||
|
||||
Reference in New Issue
Block a user