Skip to content

Commit 221c79e

Browse files
authored
refactor(vm): extract baml_vm_types crate to decouple compiler from runtime (#2959)
Create new baml_vm_types crate containing: - Bytecode and Instruction definitions (617+ instructions) - Program<T> struct generic over native function bindings - Value, Object, Function, Class, Enum types - Type-safe pool indexing (ObjectPool, GlobalPool, Index<K>) - Jump table data structures for O(1) match dispatch Key architectural changes: - baml_compiler_emit now depends only on baml_vm_types, not baml_vm - Compiler emits Program<()> with unbound native function stubs - VM binds native functions at construction: Program<()> → Program<NativeFunction> - New attach_builtins() resolves native function names to implementations Benefits: - Compiled programs are now serializable (no function pointers) - Enables shipping pre-compiled bytecode in inlined_baml - Reduces code-gen: runtime loads bytecode instead of regenerating - Cleaner separation between compilation and execution BREAKING: Vm::from_program() now returns Result<Vm, VmError> since native function binding can fail if a builtin is not found.
1 parent e98ffe2 commit 221c79e

41 files changed

Lines changed: 4802 additions & 4235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

baml_language/Cargo.lock

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baml_language/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ baml_tests = { path = "crates/baml_tests" }
3333
baml_compiler_tir = { path = "crates/baml_compiler_tir" }
3434
baml_compiler_vir = { path = "crates/baml_compiler_vir" }
3535
baml_vm = { path = "crates/baml_vm" }
36+
baml_vm_types = { path = "crates/baml_vm_types" }
3637
baml_workspace = { path = "crates/baml_workspace" }
3738
baml_lsp_types = { path = "crates/baml_lsp_types" }
3839
baml_ide = { path = "crates/baml_ide" }

baml_language/architecture/architecture.svg

Lines changed: 257 additions & 215 deletions
Loading

0 commit comments

Comments
 (0)