sys::Obj compiler::Node compiler::Expr compiler::ClosureExpr
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.
MethodDef? call
TypeDef? cls
Block? code
MethodDef? doCall
ClosureExpr? enclosingClosure
SlotDef enclosingSlot
TypeDef enclosingType
Bool isItBlock
CType? itType
new make(Loc loc, TypeDef enclosingType, SlotDef enclosingSlot, ClosureExpr? enclosingClosure, FuncType signature, Str name)
Str name
CField outerThisField()
Bool setsConst
FuncType signature
CallExpr? substitute
virtual override Str toStr()
compiler 1.0.82∙26-Jun-2025 Thu 13:18:36 EDT