Add function expr parsing

* Introduce new `fn` keyword
* Function example is added to examples/expr.not

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-18 16:39:06 -07:00
parent 337be88849
commit f0032afe12
7 changed files with 95 additions and 9 deletions

View File

@@ -48,5 +48,8 @@ impl Visit for CollectLocals<'_> {
fn visit_call_expr(&mut self, expr: &CallExpr) -> Self::Out { DefaultAccept::default_accept(expr, self); }
fn visit_index_expr(&mut self, expr: &IndexExpr) -> Self::Out { DefaultAccept::default_accept(expr, self); }
fn visit_access_expr(&mut self, expr: &AccessExpr) -> Self::Out { DefaultAccept::default_accept(expr, self); }
fn visit_fun_expr(&mut self, _expr: &FunExpr) -> Self::Out {
// Do not collect names for function expressions, since they have their own scope.
}
fn visit_atom(&mut self, atom: &Atom) -> Self::Out { DefaultAccept::default_accept(atom, self); }
}

View File

@@ -345,6 +345,11 @@ impl Visit for CompileBody<'_> {
Ok(thunk)
}
fn visit_fun_expr(&mut self, _expr: &FunExpr) -> Self::Out {
// TODO : fun exprs should be compiled as constants and put into the constant pool
todo!()
}
fn visit_atom(&mut self, atom: &Atom) -> Self::Out {
let thunk = match atom {
Atom::Ident(ident) => {