Handle lambdas
This commit is contained in:
parent
4193971303
commit
37ce12b6d8
@ -19,6 +19,7 @@ enum ScopeType {
|
||||
Function {
|
||||
name: Rc<String>
|
||||
},
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user