
ClosureExpr is an "inlined anonymous method" which closes over it's lexical scope. ClosureExpr is placed into the AST by the parser with the code field containing the method implementation. In InitClosures we remap a ClosureExpr to an anonymous class TypeDef which extends Func. The function implementation is moved to the anonymous class's doCall() method. However we leave ClosureExpr in the AST in it's original location with a substitute expression. The substitute expr just creates an instance of the anonymous class. But by leaving the ClosureExpr in the tree, we can keep track of the original lexical scope of the closure.
Slots
- cls
-
TypeDef cls
- code
-
Block code
- doCall
-
MethodDef doCall
- enclosingClosure
-
ClosureExpr enclosingClosure
- enclosingLocals
- enclosingMethod
-
MethodDef enclosingMethod
- enclosingType
-
TypeDef enclosingType
- make
-
new make(Location location, TypeDef enclosingType, MethodDef enclosingMethod, ClosureExpr enclosingClosure, FuncType signature, Str name)
- name
-
Str name
- outerThisField
-
readonly CField outerThisField
-
override Void print(AstWriter out)
Pretty print this node and it's descendants.
- signature
-
FuncType signature
- substitute
-
CallExpr substitute
- toStr
-
override Str toStr()
Return a string representation of this object.
- usesCvars
-
Bool usesCvars