snix/users/tazjin/rlox/src/bytecode/opcode.rs
Vincent Ambo 670662a360 feat(tazjin/rlox): Implement simple conditionals
... basically just optional blocks (no else).

Change-Id: If091c6b8fdeb6c13a5f3dd284d0a9a87f9f4228d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3739
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
2021-10-22 09:42:38 +00:00

55 lines
998 B
Rust

#[derive(Clone, Copy, Debug)]
pub struct ConstantIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct StackIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct CodeIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct CodeOffset(pub usize);
#[derive(Debug)]
pub enum OpCode {
/// Push a constant onto the stack.
OpConstant(ConstantIdx),
// Literal pushes
OpNil,
OpTrue,
OpFalse,
/// Return from the current function.
OpReturn,
// Boolean & comparison operators
OpNot,
OpEqual,
OpGreater,
OpLess,
/// Unary negation
OpNegate,
// Arithmetic operators
OpAdd,
OpSubtract,
OpMultiply,
OpDivide,
// Built in operations
OpPrint,
OpPop,
// Variable management
OpDefineGlobal(ConstantIdx),
OpGetGlobal(ConstantIdx),
OpSetGlobal(ConstantIdx),
OpGetLocal(StackIdx),
OpSetLocal(StackIdx),
// Control flow
OpJumpPlaceholder(bool),
OpJumpIfFalse(CodeOffset),
}