2020-09-01 17:32:48 -07:00
|
|
|
mod frame;
|
|
|
|
|
pub mod inst;
|
2020-09-14 14:09:29 -07:00
|
|
|
pub mod consts;
|
2020-09-01 17:32:48 -07:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|