Add vm and compile modules
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
49
src/vm/frame.rs
Normal file
49
src/vm/frame.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user