Skip to main content

Module opcode

Module opcode 

Source
Expand description

Bytecode instruction set. Bytecode instruction set for the Nix evaluator.

A stack-based instruction set: operands are pushed/popped from the value stack, and inline operands (constant indices, jump offsets, counts) are encoded as 16-bit values following the opcode byte.

§One authored table — the opcodes! macro

The entire instruction set is declared once in the opcodes! { … } table below. From that single table the macro generates, by construction:

This kills the drift class the hand-transcribed instruction set carried: previously the enum, a hand-written from_byte match, and a hand-written roundtrip-test array each restated the byte↔variant map, and the test array silently passed when a new variant was omitted (it only checked what was listed). Now OpCode::ALL and the disasm_operands match are generated from the same table as the enum — a new opcode is a single new row, and the exhaustive roundtrip test (driven off ALL, not a parallel array) cannot skip it. disasm_operands is a match self { … } over every variant, so a missing operand-arity column is a compile error.

Enums§

OpCode
Bytecode instructions for the Nix VM.