sui-bytecode 0.1.200

Bytecode compiler and VM for the sui Rust-native Nix evaluator
Documentation

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/in with local binding
  • Functions: lambda, apply, pattern destructuring with defaults
  • Lists: construction, ++ concatenation
  • Attribute sets: construction, . selection, ? has-attr, // update, or default
  • Control flow: if/then/else, assert
  • Upvalue capture: Lua 5.x-style closures over non-local variables
  • with scopes: dynamic variable lookup via with-scope stack
  • rec attribute sets: self-referencing bindings
  • inherit and inherit (source): in both let and 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)
  • import with 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