lang: ast: Implement lambdas

This is a big giant patch that implements the AST part of lambdas!

I don't know how Sam is able to understand the AST so well, but he does,
and we're all grateful for it. Most of this code was written by him.

Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
This commit is contained in:
James Shubin
2023-09-25 18:02:07 -04:00
parent d1f1ed8957
commit 6e1cde815c
2 changed files with 709 additions and 637 deletions

View File

@@ -70,7 +70,19 @@ func FuncPrefixToFunctionsScope(prefix string) map[string]interfaces.Expr {
}
exprs[name] = fn
}
return exprs
// Wrap every Expr in ExprPoly, so that the function can be used with
// different types. Those functions are all builtins, so they don't need to
// access the surrounding scope.
exprPolys := make(map[string]interfaces.Expr)
for name, expr := range exprs {
exprPolys[name] = &ExprPoly{
Definition: expr,
CapturedScope: interfaces.EmptyScope(),
}
}
return exprPolys
}
// VarPrefixToVariablesScope is a helper function to return the variables