class compiler::ClosureExpr

sys::Obj
  compiler::Node
    compiler::Expr
      compiler::ClosureExpr

Source

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.

call

MethodDef? call

Source

cls

TypeDef? cls

Source

code

Block? code

Source

collapseExprAndReturn

Void collapseExprAndReturn(MethodDef m)

Source

doCall

MethodDef? doCall

Source

enclosingClosure

ClosureExpr? enclosingClosure

Source

enclosingSlot

SlotDef enclosingSlot

Source

enclosingType

TypeDef enclosingType

Source

enclosingVars

[Str:MethodVar]? enclosingVars

Source

isDefiniteAssign

virtual override Bool isDefiniteAssign(|Expr->Bool| f)

Source

isItBlock

Bool isItBlock

Source

itType

CType? itType

Source

make

new make(Loc loc, TypeDef enclosingType, SlotDef enclosingSlot, ClosureExpr? enclosingClosure, FuncType signature, Str name)

Source

name

Str name

Source

outerThisField

CField outerThisField()

Source

print

virtual override Void print(AstWriter out)

Source

setInferredSignature

Void setInferredSignature(FuncType t)

Source

setsConst

Bool setsConst

Source

signature

FuncType signature

Source

substitute

CallExpr? substitute

Source

toStr

virtual override Str toStr()

Source

toWith

Expr toWith(Expr target)

Source