From 37ce12b6d8bfa675c79a06d358d5778c60b90888 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 24 Oct 2021 19:05:41 -0700 Subject: [PATCH] Handle lambdas --- .../language/src/symbol_table/resolver.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/schala-lang/language/src/symbol_table/resolver.rs b/schala-lang/language/src/symbol_table/resolver.rs index 11fffca..8a58fba 100644 --- a/schala-lang/language/src/symbol_table/resolver.rs +++ b/schala-lang/language/src/symbol_table/resolver.rs @@ -19,6 +19,7 @@ enum ScopeType { Function { name: Rc }, + Lambda, //TODO add some notion of a let-like scope? } @@ -195,6 +196,23 @@ impl<'a> ASTVisitor for ScopeResolver<'a> { NamedStruct { name, fields: _ } => { self.lookup_name_in_scope(name); }, + Lambda { params, body, .. } => { + let param_names = params.iter().map(|param| param.name.clone()); + //TODO need to properly handle closure scope, this is currently broken + //let mut new_scope = self.lexical_scopes.new_scope(Some(ScopeType::Function { name: signature.name.clone() })); + let mut new_scope = ScopeStack::new(Some(ScopeType::Lambda)); + + for (n, param) in param_names.enumerate().into_iter() { + new_scope.insert(param, NameType::Param(n as u8)); + } + + let mut new_resolver = ScopeResolver { + symbol_table: self.symbol_table, + lexical_scopes: new_scope, + }; + walk_block(&mut new_resolver, body); + return Recursion::Stop; + } _ => (), } Recursion::Continue