From 934a390f2d93afd28372616be1696d991d0a6c29 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 16 Dec 2021 02:34:18 -0800 Subject: [PATCH] Walk impl block --- schala-lang/src/reduced_ir/mod.rs | 6 +++++- schala-lang/src/symbol_table/resolver.rs | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/reduced_ir/mod.rs b/schala-lang/src/reduced_ir/mod.rs index 709f8e3..2e7e3db 100644 --- a/schala-lang/src/reduced_ir/mod.rs +++ b/schala-lang/src/reduced_ir/mod.rs @@ -98,7 +98,11 @@ impl<'a, 'b> Reducer<'a, 'b> { } ast::Declaration::Binding { constant, expr, .. } => { 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, }, diff --git a/schala-lang/src/symbol_table/resolver.rs b/schala-lang/src/symbol_table/resolver.rs index 0811fdd..4dc368e 100644 --- a/schala-lang/src/symbol_table/resolver.rs +++ b/schala-lang/src/symbol_table/resolver.rs @@ -15,11 +15,14 @@ enum NameType { Import(Fqsn), } +type LexScope<'a> = ScopeStack<'a, Rc, NameType, ScopeType>; + #[derive(Debug)] enum ScopeType { Function { name: Rc }, Lambda, PatternMatch, + ImplBlock, //TODO add some notion of a let-like scope? } @@ -27,7 +30,7 @@ pub struct ScopeResolver<'a> { symbol_table: &'a mut super::SymbolTable, //TODO maybe this shouldn't be a scope stack, b/c the recursion behavior comes from multiple //instances of ScopeResolver - lexical_scopes: ScopeStack<'a, Rc, NameType, ScopeType>, + lexical_scopes: LexScope<'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()); //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() })); + //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 = ScopeStack::new(Some(ScopeType::Function { name: signature.name.clone() })); @@ -162,6 +167,15 @@ impl<'a> ASTVisitor for ScopeResolver<'a> { } 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, } }