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:
2026-03-19 19:30:54 +00:00
parent e14fc9b0e1
commit 5ca2ee92bc
4 changed files with 30 additions and 47 deletions

View File

@@ -265,12 +265,11 @@ class OcamlBridge:
_logger.info("Loaded %d definitions from .sx files into OCaml kernel (%d skipped)",
count, skipped)
# Auto-compile all lambdas to bytecode VM
try:
await self._send('(vm-compile)')
await self._read_until_ok(ctx=None)
except OcamlBridgeError as e:
_logger.warning("VM compilation skipped: %s", e)
# Auto-compile disabled for now — compiler needs more features
# (closures, scope ops, etc.) before it can safely replace
# live functions. Infrastructure is ready:
# await self._send('(vm-compile)')
# await self._read_until_ok(ctx=None)
except Exception as e:
_logger.error("Failed to load .sx files into OCaml kernel: %s", e)
self._components_loaded = False # retry next time