Files
not-python/src/vm/mod.rs

53 lines
943 B
Rust
Raw Normal View History

mod frame;
pub mod inst;
pub mod consts;
use crate::obj::prelude::*;
use frame::*;
#[derive(Debug)]
pub struct Vm {
stack: Vec<ObjRef>,
frames: Vec<Frame>,
pc: usize,
condition: bool,
}
impl Vm {
pub fn new() -> Self {
Self {
stack: Default::default(),
frames: vec![Default::default()], // Start with a root stack frame
pc: 0,
condition: false,
}
}
pub fn stack(&self) -> &Vec<ObjRef> {
&self.stack
}
pub fn stack_mut(&mut self) -> &mut Vec<ObjRef> {
&mut self.stack
}
pub fn push(&mut self, value: ObjRef) {
self.stack_mut().push(value);
}
pub fn pop(&mut self) -> Option<ObjRef> {
self.stack_mut().pop()
}
pub fn pc(&self) -> usize {
self.pc
}
pub fn condition(&self) -> bool {
self.condition
}
//pub fn new_local(&mut self, name: String,
}