Add some base VM implementations
Some instructions are currently implemented. Others are not. This is mostly just a checkpoint so I can implement lexical name definitions. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,6 +1,52 @@
|
||||
use crate::obj::prelude::*;
|
||||
use shredder::{GcSafe, Scan, Scanner};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// A stack call frame.
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Frame {
|
||||
last_pc: usize,
|
||||
stack_base: usize,
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FrameKind {
|
||||
Root,
|
||||
Native,
|
||||
User {
|
||||
last_pc: usize,
|
||||
stack_base: usize,
|
||||
fun: UserFunRef,
|
||||
},
|
||||
}
|
||||
|
||||
unsafe impl Scan for FrameKind {
|
||||
fn scan(&self, scanner: &mut Scanner<'_>) {
|
||||
match self {
|
||||
FrameKind::User { fun, .. } => scanner.scan(fun),
|
||||
_ => { /* no-op */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl GcSafe for FrameKind {}
|
||||
|
||||
pub type Locals = BTreeMap<usize, ObjRef>;
|
||||
|
||||
#[derive(Scan, Debug, Clone)]
|
||||
pub struct Frame {
|
||||
locals: Locals,
|
||||
kind: FrameKind,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
pub fn new(locals: Locals, kind: FrameKind) -> Self {
|
||||
Self { locals, kind, }
|
||||
}
|
||||
|
||||
pub fn locals(&self) -> &Locals {
|
||||
&self.locals
|
||||
}
|
||||
|
||||
pub fn locals_mut(&mut self) -> &mut Locals {
|
||||
&mut self.locals
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> &FrameKind {
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user