Auto-compile: lambdas → bytecode VM at load time
After loading .sx files, (vm-compile) iterates all named lambdas, compiles each body to bytecode, replaces with NativeFn VM wrapper. Results: 3/109 functions compiled (compiler needs more features). CEK steps: 49911 → 38083 (23% fewer) for home page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -215,9 +215,9 @@ class OcamlBridge:
|
||||
# Collect files to load
|
||||
all_files: list[str] = []
|
||||
|
||||
# Spec files needed by aser
|
||||
# Spec files needed by aser + bytecode compiler
|
||||
spec_dir = os.path.join(os.path.dirname(__file__), "../../spec")
|
||||
for spec_file in ["parser.sx", "render.sx"]:
|
||||
for spec_file in ["parser.sx", "render.sx", "bytecode.sx", "compiler.sx"]:
|
||||
path = os.path.normpath(os.path.join(spec_dir, spec_file))
|
||||
if os.path.isfile(path):
|
||||
all_files.append(path)
|
||||
@@ -264,6 +264,13 @@ class OcamlBridge:
|
||||
filepath, e)
|
||||
_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)
|
||||
except Exception as e:
|
||||
_logger.error("Failed to load .sx files into OCaml kernel: %s", e)
|
||||
self._components_loaded = False # retry next time
|
||||
|
||||
Reference in New Issue
Block a user