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:
2020-09-14 14:14:21 -07:00
parent 8e2cbb10a4
commit 372e58f620
21 changed files with 12 additions and 25 deletions

52
src/vm/mod.rs Normal file
View 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,
}