Add vm and compile modules

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-16 12:56:52 -04:00
parent a60471f526
commit a15dde0fc2
13 changed files with 392 additions and 46 deletions

49
src/vm/frame.rs Normal file
View File

@@ -0,0 +1,49 @@
use crate::obj::prelude::*;
use std::collections::BTreeMap;
#[derive(Default)]
pub struct Frame {
stack: Vec<DynRef>,
ip: usize,
return_value: Option<DynRef>,
locals: BTreeMap<Sym, DynRef>,
}
impl Frame {
pub fn new() -> Self {
Default::default()
}
pub fn push(&mut self, obj_ref: DynRef) {
self.stack.push(obj_ref)
}
pub fn pop(&mut self) -> Option<DynRef> {
self.stack.pop()
}
pub fn ip(&self) -> usize {
self.ip
}
pub fn set_ip(&mut self, ip: usize) {
self.ip = ip;
}
pub fn return_value(&self) -> Option<DynRef> {
self.return_value
}
pub fn set_return_value(&mut self, obj_ref: DynRef) {
self.return_value = Some(obj_ref);
}
pub fn get_local(&self, sym: Sym) -> Option<DynRef> {
self.locals.get(&sym).copied()
}
pub fn set_local(&mut self, sym: Sym, obj_ref: DynRef) -> Option<DynRef> {
self.locals.insert(sym, obj_ref)
}
}