pub enum Op {
Show 31 variants
Const(f32),
Load(u16),
Store(u16),
Pop,
Neg,
Add,
Sub,
Mul,
Div,
Mod,
Pow,
Above,
Below,
AboveEq,
BelowEq,
Equal,
NotEqual,
Not,
BitAnd,
BitOr,
Fn1(Unary),
Fn2(Binary),
MemLoad(Mem),
MemStore(Mem),
Jump(u32),
JumpIfZero(u32),
JumpIfNotZero(u32),
LoopBegin(u32),
LoopEnd(u32),
WhileBegin(u32),
WhileEnd(u32),
}Expand description
One bytecode instruction.
A stack machine, not a register one, and deliberately: EEL2 is an
expression language whose statements are expressions, so a stack matches its
shape and the codegen is a post-order walk with no allocation. The named
variables are registers (Op::Load / Op::Store); the stack is only
the arithmetic’s scratch.
Variants§
Const(f32)
Push a literal.
Load(u16)
Push register n.
Store(u16)
Pop, store into register n, and push the value back — EEL2’s
assignment is an expression that yields what it assigned.
Pop
Discard the top of the stack. Emitted between the statements of a sequence, whose value is its last statement’s.
Neg
Arithmetic negation.
Add
Addition.
Sub
Subtraction.
Mul
Multiplication.
Div
Division. Total: a zero divisor yields 0, which is EEL2’s own
behaviour and what keeps the VM panic-free (Plan 0100 Phase 2).
Mod
Remainder, on the integer parts, EEL2’s %. Total the same way.
Pow
EEL2’s ^, which is exponentiation rather than xor.
EEL2’s pow.
Above
> — pushes 1 or 0.
Below
<.
AboveEq
>=.
BelowEq
<=.
Equal
==, against EEL2’s comparison epsilon.
NotEqual
!=, against the same epsilon.
Not
! — 1 when the operand is zero, else 0.
BitAnd
EEL2’s & — bitwise and on the truncated integer parts, not a
logical one. band is the logical operator, and the two are different
functions: 3 & 4 is 0 where band(3, 4) is 1.
BitOr
EEL2’s | — bitwise or, the counterpart of Op::BitAnd.
Fn1(Unary)
One-argument builtin.
Fn2(Binary)
Two-argument builtin.
MemLoad(Mem)
Pop an index, push that slot.
MemStore(Mem)
Pop a value and an index (value on top), store, and push the value back.
Jump(u32)
Unconditional jump to an absolute instruction index.
JumpIfZero(u32)
Pop; jump when the value is zero.
JumpIfNotZero(u32)
Pop; jump when the value is non-zero.
LoopBegin(u32)
Pop a count, open a loop frame, and jump past Op::LoopEnd when the
count rounds to less than one. The count is clamped to
Budget::loops.
LoopEnd(u32)
Close a loop iteration: discard the body’s value, decrement, and jump back
to the operand while iterations remain. Pushes 0 when the loop ends,
because a loop is an expression.
WhileBegin(u32)
Open a while frame with Budget::loops
iterations, jumping past
its Op::WhileEnd never — the test is at the end, because EEL2’s
while(body) runs the body first.
WhileEnd(u32)
Close a while iteration: pop the body’s value, decrement, and jump back
to the operand while it is non-zero and iterations remain. Pushes 0
when the loop ends.