Extract scoping
This commit is contained in:
parent
6dbe397ebf
commit
d9b86f430f
|
|
@ -66,6 +66,12 @@ mod scope {
|
|||
scope: HashMap<ast::Ident, Ident>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ScopeInfo {
|
||||
pub locals: Vec<ast::Ident>,
|
||||
pub upvalues: Vec<(ast::Ident, Ident)>,
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
pub fn new_toplevel() -> Self {
|
||||
Self {
|
||||
|
|
@ -77,6 +83,13 @@ mod scope {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn finish(self) -> ScopeInfo {
|
||||
ScopeInfo {
|
||||
locals: self.locals,
|
||||
upvalues: self.upvalues,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup(&self, name: &ast::Ident) -> Option<Ident> {
|
||||
self.scope.get(name).copied()
|
||||
}
|
||||
|
|
@ -210,11 +223,12 @@ fn build_function(parent: &BuildContext<'_>, code: &ast::Function) -> Function {
|
|||
}
|
||||
}
|
||||
}
|
||||
let scope = scope.scope.into_inner().finish();
|
||||
Function {
|
||||
name: code.name.clone(),
|
||||
args: code.args.clone(),
|
||||
locals: vec![],
|
||||
upvalues: vec![],
|
||||
locals: scope.locals,
|
||||
upvalues: scope.upvalues,
|
||||
body,
|
||||
ret: Box::new(Expression::Constant(ast::Constant::Nil)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user