Stack: [value] -> []
Operands: None
Description: Pops the top value from the stack and returns it from the current function. Exits the current call frame.
Stack: [] -> [value]
Operands: 1 byte (constant index)
Description: Loads a constant from the constant pool at the given index and pushes it onto the stack.
Stack: [] -> [value]
Operands: 2 bytes (16-bit constant index)
Description: Loads a constant from the constant pool at the given 16-bit index and pushes it onto the stack. Used for large constant pools.
Stack: [number] -> [number]
Operands: None
Description: Negates a value on the stack in place.
Stack: [left, right] -> [result]
Operands: None
Description: Pops two values from the stack, adds them together, and pushes the result. Supports numeric addition and string concatenation.
Stack: [left, right] -> [result]
Operands: None
Description: Pops two numeric values from the stack, subtracts the top value from the second value, and pushes the result.
Stack: [left, right] -> [result]
Operands: None
Description: Pops two numeric values from the stack, multiplies them, and pushes the result.
Stack: [left, right] -> [result]
Operands: None
Description: Pops two numeric values from the stack, divides the second value by the top value, and pushes the result.
Stack: [] -> [nil]
Operands: None
Description: Pushes the nil value onto the stack.
Stack: [] -> [uninitialized]
Operands: None
Description: Pushes an uninitialized marker value onto the stack (used to detect uninitialized variable access)
Stack: [] -> [true]
Operands: None
Description: Pushes the boolean value true onto the stack.
Stack: [] -> [false]
Operands: None
Description: Pushes the boolean value false onto the stack.
Stack: [value] -> [boolean]
Operands: None
Description: Pops a value from the stack, applies logical NOT operation, and pushes the boolean result. It pushes the result of calling is_falsey() on the value. So true values become false, and false values become true.
Stack: [left, right] -> [boolean]
Operands: None
Description: Pops two values from the stack, compares them for equality, and pushes the boolean result. TODO: Real numbers are compared by == which does not work correctly
Stack: [left, right] -> [boolean]
Operands: None
Description: Pops two values from the stack, checks if the second is greater than the top, and pushes the boolean result.
Stack: [left, right] -> [boolean]
Operands: None
Description: Pops two values from the stack, checks if the second is less than the top, and pushes the boolean result.
Stack: [value] -> []
Operands: None
Description: Pops a value from the stack and prints it to output stream.
Stack: [value] -> []
Operands: None
Description: Pops and discards the top value from the stack.
Stack: [value] -> []
Operands: 2 byte (name index)
Description: Pops a value from the stack and defines a global variable with the name from the constant pool.
Stack: [value] -> [value]
Operands: 2 byte (name index)
Description: Loads a value from the top of the stack and stores it in an existing global variable. It differs from DEFINE_GLOBAL as it does not pop the value after storing it, so it can be used in other expressions.
Stack: [] -> [value]
Operands: 2 byte (name index)
Description: Loads a global variable value by name from the constant pool and pushes it onto the stack.
Stack: [value] -> [value]
Operands: 2 byte (slot index)
Description: Loads a value from the top of the stack and stores it in a local variable slot. It does not pop the value, since assignment is an expression.
Stack: [] -> [value]
Operands: 2 byte (slot index)
Description: Loads a local variable from the given slot and pushes it onto the stack.
Stack: [value] -> [value]
Operands: 2 byte (upvalue index)
Description: Loads a value from the top of the stack and stores it in an upvalue (captured variable).
Stack: [] -> [value]
Operands: 2 byte (upvalue index)
Description: Loads an upvalue (captured variable) and pushes it onto the stack.
Stack: [instance, value] -> [value]
Operands: 2 byte (property name index)
Description: Pops value and instance from the stack, sets the property on the instance. And then pushes back the value onto the stack so that it can be used in other expressions.
Stack: [instance] -> [value]
Operands: 2 byte (property name index)
Description: Pops an instance from the stack, gets the property value, and pushes it onto the stack.
Stack: [instance] -> [value | nil]
Operands: 2 byte (property name index)
Description: Safe property access that returns nil if property doesn't exist instead of throwing an error.
Stack: [instance] -> [method]
Operands: 2 byte (method name index)
Description: Loads a method from the superclass, binds it to the instance and pushes it onto the stack.
Stack: [object, index] -> [value]
Operands: None
Description: Pops index and object, performs indexing operation, and pushes the result.
Stack: [object, index, value] -> [value]
Operands: None
Description: Pops value, index, and object from the stack, stores value at the given index in the object. Pushes back the value at the end so that it can be used in other expressions.
Stack: [...] -> [...]
Operands: None
Description: Closes upvalues for local variables that are going out of scope.
Stack: [condition] -> [condition]
Operands: 2 bytes (jump offset)
Description: Peeks at the top value, jumps by offset if it's falsy, leaves the value on stack.
Stack: [condition] -> [condition]
Operands: 2 bytes (jump offset)
Description: Peeks at the top value, jumps by offset if it's truthy, leaves the value on stack.
Stack: [condition] -> []
Operands: 2 bytes (jump offset)
Description: Pops the top value, jumps by offset if it's falsy.
Stack: [...] -> [...]
Operands: 2 bytes (jump offset)
Description: Unconditionally jumps forward by the given offset.
Stack: [...] -> [...]
Operands: 2 bytes (jump offset)
Description: Unconditionally jumps backward by the given offset (for loops).
Stack: [value] -> [value, value]
Operands: None
Description: Duplicates the top value on the stack.
Stack: [function, arg1, arg2, ...] -> [result]
Operands: 1 byte (argument count)
Description: Calls a function with the given number of arguments, replacing them and the function with the result.
Stack: [] -> [class]
Operands: 2 byte (class name index)
Description: Creates a new class with the given name and pushes it onto the stack.
Stack: [instance, arg1, arg2, ...] -> [result]
Operands: 3 bytes (method name index (2), argument count(1))
Description: Invokes a method on an instance with the given arguments.
Stack: [instance, arg1, arg2, ...] -> [result]
Operands: 3 bytes (method name index (2), argument count(1))
Description: Invokes a method from the superclass on an instance.
Stack: [superclass, subclass] -> [superclass]
Operands: None
Description: Peeks superclass and pops subclass, copies methods from superclass to subclass.
Stack: [] -> [closure]
Operands: 2 bytes (function index) + variable bytes for upvalue data
Description: Creates a closure from a function and pushes it onto the stack. For each upvalue, reads 1 byte (is_local flag) + 2 bytes (index). If is_local is true, captures a local variable as an upvalue, otherwise, references an upvalue from the current function. This is a variable length instruction.
Stack: [] -> [0]
Operands: None
Description: Pushes the numeric value 0 onto the stack.
Stack: [] -> [-1]
Operands: None
Description: Pushes the numeric value -1 onto the stack.
Stack: [] -> [1]
Operands: None
Description: Pushes the numeric value 1 onto the stack.
Stack: [class, closure] -> [class]
Operands: 2 byte (method name index)
Description: Peeks closure (for the method) and class, binds the closure to the class. Pops the closure from the top of the stack.
Stack: [item1, item2, ...] -> [list]
Operands: 1 byte (item count)
Description: Pops the specified number of items and creates a list containing them.
Stack: [list, item] -> [list]
Operands: None
Description: Pops an item and list, appends the item to the list, pushes the list back.