Bytecode Format

Technical reference for the Quartz bytecode (.qzb) format.

File Format

QZB files have the following structure:

+------------------+
| Magic Number (4B)|  "QZB\0"
+------------------+
| Version (4B)     |
+------------------+
| Metadata Section |
+------------------+
| Constant Pool    |
+------------------+
| Code Section     |
+------------------+

Inspecting Bytecode

# Compile to bytecode
./quartz --compile -o program.qzb program.qz

# Dump metadata
./quartz --dump-qzb-meta program.qzb

# Disassemble
python3 tools/qzb_disasm.py program.qzb

Common Opcodes

OpcodeDescription
LOAD_CONSTPush constant onto stack
LOAD_VARLoad variable value
STORE_VARStore to variable
ADDAdd top two stack values
SUBSubtract
MULMultiply
DIVDivide
CALLCall function
RETURNReturn from function
JUMPUnconditional jump
JUMP_IF_FALSEConditional jump

For more details, see the Bytecode Compilation guide.