Walk impl block

This commit is contained in:
Greg Shuflin 2021-12-16 02:34:18 -08:00
parent 8e8be1b449
commit 934a390f2d
2 changed files with 20 additions and 2 deletions

View File

@ -98,7 +98,11 @@ impl<'a, 'b> Reducer<'a, 'b> {
} }
ast::Declaration::Binding { constant, expr, .. } => { ast::Declaration::Binding { constant, expr, .. } => {
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap(); let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
Some(Statement::Binding { id: symbol.def_id(), constant: *constant, expr: self.expression(expr) }) Some(Statement::Binding {
id: symbol.def_id(),
constant: *constant,
expr: self.expression(expr),
})
} }
_ => None, _ => None,
}, },

View File

@ -15,11 +15,14 @@ enum NameType {
Import(Fqsn), Import(Fqsn),
} }
type LexScope<'a> = ScopeStack<'a, Rc<String>, NameType, ScopeType>;
#[derive(Debug)] #[derive(Debug)]
enum ScopeType { enum ScopeType {
Function { name: Rc<String> }, Function { name: Rc<String> },
Lambda, Lambda,
PatternMatch, PatternMatch,
ImplBlock,
//TODO add some notion of a let-like scope? //TODO add some notion of a let-like scope?
} }
@ -27,7 +30,7 @@ pub struct ScopeResolver<'a> {
symbol_table: &'a mut super::SymbolTable, symbol_table: &'a mut super::SymbolTable,
//TODO maybe this shouldn't be a scope stack, b/c the recursion behavior comes from multiple //TODO maybe this shouldn't be a scope stack, b/c the recursion behavior comes from multiple
//instances of ScopeResolver //instances of ScopeResolver
lexical_scopes: ScopeStack<'a, Rc<String>, NameType, ScopeType>, lexical_scopes: LexScope<'a>,
} }
impl<'a> ScopeResolver<'a> { impl<'a> ScopeResolver<'a> {
@ -138,6 +141,8 @@ impl<'a> ASTVisitor for ScopeResolver<'a> {
let param_names = signature.params.iter().map(|param| param.name.clone()); let param_names = signature.params.iter().map(|param| param.name.clone());
//TODO I'm 90% sure this is right, until I get to closures //TODO I'm 90% sure this is right, until I get to closures
//let mut new_scope = self.lexical_scopes.new_scope(Some(ScopeType::Function { name: signature.name.clone() })); //let mut new_scope = self.lexical_scopes.new_scope(Some(ScopeType::Function { name: signature.name.clone() }));
//TODO this will recurse unwantedly into scopes; need to pop an outer function
//scope off first before going into a non-closure scope
let mut new_scope = let mut new_scope =
ScopeStack::new(Some(ScopeType::Function { name: signature.name.clone() })); ScopeStack::new(Some(ScopeType::Function { name: signature.name.clone() }));
@ -162,6 +167,15 @@ impl<'a> ASTVisitor for ScopeResolver<'a> {
} }
Recursion::Continue Recursion::Continue
} }
Declaration::Impl { block, .. } => {
let mut new_scope = ScopeStack::new(Some(ScopeType::ImplBlock));
let mut new_resolver =
ScopeResolver { symbol_table: self.symbol_table, lexical_scopes: new_scope };
for stmt in block.iter() {
walk_declaration(&mut new_resolver, &stmt.kind, &stmt.id);
}
Recursion::Stop
}
_ => Recursion::Continue, _ => Recursion::Continue,
} }
} }