* Currently, scopes are only allowed to look at their locals and the
globals. Inner functions cannot refer to values in their parent
functions. This will change eventually.
* Scope lookup is split between globals and locals. Locals are defined
in a scope if they are explicitly assigned to.
* i.e. `a = foo` will treat `a` as a local in the current scope if
it appears anywhere in that scope. This does not extend to
setattrs; `a.b = foo` will not trigger `a` into being a local var.
* `Package` objects are no longer returned from the compiler - instead,
a user function is returned.
* Other various changes and renames
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
52 lines
1.0 KiB
Rust
52 lines
1.0 KiB
Rust
use crate::obj::prelude::*;
|
|
use shredder::{GcSafe, Scan, Scanner};
|
|
use std::collections::BTreeMap;
|
|
|
|
/// 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: FrameLocals,
|
|
kind: FrameKind,
|
|
}
|
|
|
|
impl Frame {
|
|
pub fn new(locals: FrameLocals, kind: FrameKind) -> Self {
|
|
Self { locals, kind, }
|
|
}
|
|
|
|
pub fn locals(&self) -> &FrameLocals {
|
|
&self.locals
|
|
}
|
|
|
|
pub fn locals_mut(&mut self) -> &mut FrameLocals {
|
|
&mut self.locals
|
|
}
|
|
|
|
pub fn kind(&self) -> &FrameKind {
|
|
&self.kind
|
|
}
|
|
}
|
|
|
|
pub type FrameLocals = BTreeMap<usize, ObjRef>;
|