Bytecode compiler and VM for the Nix evaluator.
This crate provides an alternative evaluation backend for sui-eval. Instead of tree-walking the rnix AST, expressions are compiled to a stack-based bytecode and executed by a virtual machine.
Architecture
Nix source --> rnix parser (CST) --> Compiler --> Chunk (bytecode)
|
v
VM --> VMValue
Phase 1 + 2 Coverage
Currently supports:
- Literals: int, float, bool, null, string, path
- Arithmetic:
+,-,*,/, unary- - Comparison:
==,!=,<,>,<=,>= - Logical:
!,&&,||,->(with short-circuit) - Strings: literals, interpolation
- Variables:
let/inwith local binding - Functions: lambda, apply, pattern destructuring with defaults
- Lists: construction,
++concatenation - Attribute sets: construction,
.selection,?has-attr,//update,ordefault - Control flow:
if/then/else,assert - Upvalue capture: Lua 5.x-style closures over non-local variables
withscopes: dynamic variable lookup via with-scope stackrecattribute sets: self-referencing bindingsinheritandinherit (source): in bothletand attrset- Dotted attribute paths:
{ a.b = 1; a.c = 2; }merging - Dynamic attribute keys:
{ ${expr} = value; } - Builtins: 50+ functions (type checks, list ops, attrset ops, string ops, arithmetic, control flow, conversion)
importwith file caching- Thunks / lazy evaluation (MakeThunk/Force opcodes, blackhole detection)
- Lazy attrset values (non-trivial values wrapped in thunks)
derivation/derivationStrict(native implementation via sui-compat)builtins.getFlake(path-based flake references)builtins.scopedImport(with-wrapping approach)- VM-level dispatch for interner-dependent builtins (attrNames, listToAttrs, removeAttrs, hasAttr, getAttr, catAttrs)
- Deep-force at VM boundary (recursively forces thunks in attrsets/lists)
Not Yet Implemented
- String interpolation contexts