Update how visitors work, add NameId type
* Visitors are now defined on a per-type level, allowing for greater flexibility in combining and re-using behavior * NameId is used for namespaces, which are used to index locally scoped variables. Syms are used for free namespaces, specifically in objects. All NameIDs are symbols, while not all symbols are NameIDs. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -2,13 +2,13 @@ use crate::{
|
||||
obj::prelude::*,
|
||||
vm::op::Op,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{collections::BTreeMap, rc::Rc};
|
||||
|
||||
pub struct Frame {
|
||||
stack: Vec<DynRef>,
|
||||
ip: usize,
|
||||
return_value: Option<DynRef>,
|
||||
locals: Ns,
|
||||
locals: BTreeMap<NameId, DynRef>,
|
||||
ops: Rc<Vec<Op>>,
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ impl Frame {
|
||||
self.return_value = Some(obj_ref);
|
||||
}
|
||||
|
||||
pub fn get_local(&self, sym: Sym) -> Option<DynRef> {
|
||||
self.locals.get(&sym).copied()
|
||||
pub fn get_local(&self, name: NameId) -> Option<DynRef> {
|
||||
self.locals.get(&name).copied()
|
||||
}
|
||||
|
||||
pub fn set_local(&mut self, sym: Sym, obj_ref: DynRef) -> Option<DynRef> {
|
||||
pub fn set_local(&mut self, sym: NameId, obj_ref: DynRef) -> Option<DynRef> {
|
||||
self.locals.insert(sym, obj_ref)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user