Commit e9a5365
π Bytecode VM (#93)
## Summary
Replaces the tree-walk interpreter with a bytecode-compiled stack-based
VM as the single execution path (~192 commits).
### Compiler & VM
- Bytecode compiler translates the annotated AST into a flat `OpCode`
sequence
- Stack-based VM executes bytecode with support for locals, globals,
upvalues, and closures
- Upvalue hoisting in the analyser enables mutable closed-over variables
- Control flow: `if`/`while`/`for`/`break`/`continue`/`return` all
compile to jump instructions
- Tuple destructuring via `Unpack` opcode
- Map/set/list comprehensions compile to inline loops
- Op-assignment (`+=`, etc.) for identifiers, index expressions, and
destructuring
- Closure capture and upvalue resolution (including nested closures)
- Memoization support for pure functions
### Stdlib & dispatch
- `FunctionRegistry` + `vm_native` field on `Function` for bridge-free
native dispatch
- Arithmetic, comparison, boolean, trig/math operators migrated to
VM-native dispatch
- HOF callbacks (`map`, `filter`, `fold`, `all`, `any`, etc.) work with
VM closures
- Dynamic dispatch for overloaded functions at runtime
### Infrastructure
- `ndc_vm` crate with compiler and VM
- `vm-trace` feature for source-annotated instruction tracing
- -disassemble` CLI subcommand
- All existing tests pass against the VM backend
## Benchmarks (v0.2.1 tree-walk vs VM)
| Benchmark | v0.2.1 (tree-walk) | VM | Speedup |
|:---|---:|---:|---:|
| ackermann | stack overflow | 155.0 ms | - |
| bigint | 9.3 ms | 6.7 ms | 1.4x |
| closures | 248.5 ms | 78.6 ms | **3.2x** |
| fibonacci | 318.0 ms | 80.1 ms | **4.0x** |
| hof_pipeline | 84.8 ms | 36.7 ms | **2.3x** |
| map_ops | 74.7 ms | 28.7 ms | **2.6x** |
| matrix_mul | 133.1 ms | 67.0 ms | **2.0x** |
| perlin | 216.5 ms | 67.5 ms | **3.2x** |
| pi_approx | 103.8 ms | 32.3 ms | **3.2x** |
| print_heavy | 8.9 ms | 5.6 ms | 1.6x |
| quicksort | 192.0 ms | 75.2 ms | **2.6x** |
| sieve | 439.4 ms | 125.2 ms | **3.5x** |
| string_concat | 16.0 ms | 13.4 ms | 1.2x |
π€ Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 <[email protected]>1 parent 601c499 commit e9a5365
167 files changed
Lines changed: 11557 additions & 7564 deletions
File tree
- .cargo
- benches
- programs
- src
- compiler_tests
- tests
- manual/src
- features
- getting-started
- reference
- types
- troubleshooting
- ndc_analyser
- src
- ndc_bin
- src
- ndc_core
- src
- ndc_interpreter
- src
- evaluate
- semantic
- ndc_lexer/src
- ndc_lsp
- src
- ndc_macros
- src
- ndc_parser
- src
- ndc_stdlib
- src
- ndc_vm
- src
- value
- tests
- programs
- 001_math
- 004_basic
- 005_functions
- 006_lists
- 007_map_and_set
- 008_iterators
- 011_heap
- 014_comprehensive
- 603_stdlib_seq
- 604_stdlib_math
- 900_bugs
- 998_not_desired
- src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments