Fold runtime/ crate into this source tree
While I like the idea of having a runtime completely decoupled from the syntax and compiler, I don't think this is that big of a project for that to be necessary or even useful yet. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
52
src/vm/mod.rs
Normal file
52
src/vm/mod.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user