2020-09-14 16:32:00 -07:00
|
|
|
use crate::obj::prelude::*;
|
|
|
|
|
use shredder::{GcSafe, Scan, Scanner};
|
|
|
|
|
|
2020-09-01 17:32:48 -07:00
|
|
|
/// A stack call frame.
|
2020-09-14 16:32:00 -07:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum FrameKind {
|
2020-09-24 15:29:44 -07:00
|
|
|
Native(NativeFunRef, Vec<ObjRef>),
|
2020-09-14 16:32:00 -07:00
|
|
|
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 {}
|
|
|
|
|
|
|
|
|
|
#[derive(Scan, Debug, Clone)]
|
2020-09-01 17:32:48 -07:00
|
|
|
pub struct Frame {
|
2020-09-18 13:57:51 -07:00
|
|
|
locals: Names,
|
2020-09-14 16:32:00 -07:00
|
|
|
kind: FrameKind,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Frame {
|
2020-09-18 13:57:51 -07:00
|
|
|
pub fn new(locals: Names, kind: FrameKind) -> Self {
|
2020-09-14 16:32:00 -07:00
|
|
|
Self { locals, kind, }
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 13:57:51 -07:00
|
|
|
pub fn locals(&self) -> &Names {
|
2020-09-14 16:32:00 -07:00
|
|
|
&self.locals
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 13:57:51 -07:00
|
|
|
pub fn locals_mut(&mut self) -> &mut Names {
|
2020-09-14 16:32:00 -07:00
|
|
|
&mut self.locals
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn kind(&self) -> &FrameKind {
|
|
|
|
|
&self.kind
|
|
|
|
|
}
|
2020-09-01 17:32:48 -07:00
|
|
|
}
|