Update how scope rules work, and update implementation
* 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>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::obj::prelude::*;
|
||||
use shredder::{GcSafe, Scan, Scanner};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// A stack call frame.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -25,20 +26,20 @@ unsafe impl GcSafe for FrameKind {}
|
||||
|
||||
#[derive(Scan, Debug, Clone)]
|
||||
pub struct Frame {
|
||||
locals: Names,
|
||||
locals: FrameLocals,
|
||||
kind: FrameKind,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
pub fn new(locals: Names, kind: FrameKind) -> Self {
|
||||
pub fn new(locals: FrameLocals, kind: FrameKind) -> Self {
|
||||
Self { locals, kind, }
|
||||
}
|
||||
|
||||
pub fn locals(&self) -> &Names {
|
||||
pub fn locals(&self) -> &FrameLocals {
|
||||
&self.locals
|
||||
}
|
||||
|
||||
pub fn locals_mut(&mut self) -> &mut Names {
|
||||
pub fn locals_mut(&mut self) -> &mut FrameLocals {
|
||||
&mut self.locals
|
||||
}
|
||||
|
||||
@@ -46,3 +47,5 @@ impl Frame {
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
pub type FrameLocals = BTreeMap<usize, ObjRef>;
|
||||
|
||||
Reference in New Issue
Block a user