Files
not-python/src/vm/frame.rs
Alek Ratzloff 3976b2135a Functions are implemented and VM should be able to handle function calls
* VM Signals are used by running functions to dictate whether a function
  should return, or if it should call another function. These signals
  can be injected at any time allowing for user functions to inject
  themselves at runtime.
* obj::Method is gone since it's not being used yet.
* Obj impls must implement as_any(&self) -> &dyn Any now. This allows
  for UserFun and NativeFun to be explicitly cast (among other things,
  in the future).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-09-24 15:29:44 -07:00

49 lines
942 B
Rust

use crate::obj::prelude::*;
use shredder::{GcSafe, Scan, Scanner};
/// A stack call frame.
#[derive(Debug, Clone)]
pub enum FrameKind {
Native(NativeFunRef, Vec<ObjRef>),
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)]
pub struct Frame {
locals: Names,
kind: FrameKind,
}
impl Frame {
pub fn new(locals: Names, kind: FrameKind) -> Self {
Self { locals, kind, }
}
pub fn locals(&self) -> &Names {
&self.locals
}
pub fn locals_mut(&mut self) -> &mut Names {
&mut self.locals
}
pub fn kind(&self) -> &FrameKind {
&self.kind
}
}