mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
//! The bytecode that is executed in the vm
|
|
|
|
use crate::errors::Span;
|
|
use crate::vm::Value;
|
|
use bumpalo::collections::Vec;
|
|
|
|
#[derive(Debug)]
|
|
pub struct FnBlock<'bc> {
|
|
pub code: Vec<'bc, Instr>,
|
|
pub stack_sizes: Vec<'bc, usize>,
|
|
pub spans: Vec<'bc, Span>,
|
|
pub arity: u8,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub enum Instr {
|
|
Nop,
|
|
|
|
/// Store the current value on the stack to the stack location with the local offset `usize`
|
|
Store(usize),
|
|
/// Load the variable value from the local offset `usize` onto the stack
|
|
Load(usize),
|
|
/// Push a value onto the stack
|
|
PushVal(Value),
|
|
/// Negate the top value on the stack. Only works with numbers and booleans
|
|
Neg,
|
|
BinAdd,
|
|
BinSub,
|
|
BinMul,
|
|
BinDiv,
|
|
BinMod,
|
|
BinAnd,
|
|
BinOr,
|
|
CmpGreater,
|
|
CmpGreaterEq,
|
|
CmpLess,
|
|
CmpLessEq,
|
|
CmpEq,
|
|
CmpNotEq,
|
|
|
|
/// Println the value on top of the stack
|
|
Print,
|
|
|
|
/// If the current stack value is true, skip `usize` instructions. When jumping backwards
|
|
JumpFalse(isize),
|
|
/// Same as `JumpCond`, but unconditional
|
|
Jmp(isize),
|
|
}
|