Transpiler native record support for VM types (Step 5.5 unblock)

- Add VmFrame/VmMachine types to sx_types.ml (alongside CekState/CekFrame)
- Add VmFrame/VmMachine value variants to the value sum type
- Extend get_val in sx_runtime.ml to dispatch on VmFrame/VmMachine fields
- Extend sx_dict_set_b for VmFrame/VmMachine field mutation
- Extend transpiler ml-emit-dict-native to detect VM dict patterns
  and emit native OCaml record construction (same mechanism as CekState)
- Retranspile evaluator — no diff (transpiler extension is additive)
- Update bootstrap_vm.py output location

The transpiler now handles 4 native record types:
  CekState (5 fields), CekFrame (10 fields),
  VmFrame (4 fields), VmMachine (5 fields)

Full VM replacement (sx_vm.ml → transpiled) still needs vm.sx
feature parity: JIT dispatch, CEK fallback, suspension handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 12:39:20 +00:00
parent fc2b5e502f
commit df89d8249b
3 changed files with 125 additions and 16 deletions

View File

@@ -573,22 +573,52 @@
(ef "first-render")
:else "Nil")
" })"))
(str
"(let _d = Hashtbl.create "
(str (round (len items)))
" in "
(join
"; "
(map
(fn
(k)
(str
"Hashtbl.replace _d "
(ml-quote-string k)
" "
(ml-expr-inner (get d k) set-vars)))
items))
"; Dict _d)"))))))
(if
(and
(some (fn (k) (= k "ip")) items)
(some (fn (k) (= k "closure")) items)
(some (fn (k) (= k "base")) items))
(str
"(VmFrame { vf_closure = (match "
(ml-expr-inner (get d "closure") set-vars)
" with VmClosure c -> c | _ -> failwith \"vf_closure\")"
"; vf_ip = val_to_int "
(ml-expr-inner (get d "ip") set-vars)
"; vf_base = val_to_int "
(ml-expr-inner (get d "base") set-vars)
"; vf_local_cells = Hashtbl.create 4 })")
(if
(and
(some (fn (k) (= k "sp")) items)
(some (fn (k) (= k "stack")) items)
(some (fn (k) (= k "globals")) items))
(str
"(VmMachine { vm_stack = (match "
(ml-expr-inner (get d "stack") set-vars)
" with List _ -> Array.make 4096 Nil | _ -> Array.make 4096 Nil)"
"; vm_sp = val_to_int "
(ml-expr-inner (get d "sp") set-vars)
"; vm_frames = []"
"; vm_globals = (match "
(ml-expr-inner (get d "globals") set-vars)
" with Dict d -> d | _ -> Hashtbl.create 0)"
"; vm_pending_cek = None })")
(str
"(let _d = Hashtbl.create "
(str (round (len items)))
" in "
(join
"; "
(map
(fn
(k)
(str
"Hashtbl.replace _d "
(ml-quote-string k)
" "
(ml-expr-inner (get d k) set-vars)))
items))
"; Dict _d)"))))))))
(define
ml-emit-list