32
32
import com .oracle .graal .python .nodes .EmptyNode ;
33
33
import com .oracle .graal .python .nodes .control .BlockNode ;
34
34
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
35
+ import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
35
36
import com .oracle .graal .python .nodes .statement .StatementNode ;
36
37
import com .oracle .graal .python .parser .DefinitionCellSlots ;
37
38
import com .oracle .graal .python .parser .ExecutionCellSlots ;
38
39
import com .oracle .graal .python .runtime .PythonCore ;
39
40
import com .oracle .truffle .api .CompilerDirectives ;
40
41
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
41
42
import com .oracle .truffle .api .RootCallTarget ;
43
+ import com .oracle .truffle .api .Truffle ;
42
44
import com .oracle .truffle .api .frame .FrameDescriptor ;
43
45
import com .oracle .truffle .api .frame .VirtualFrame ;
44
46
45
47
public class GeneratorFunctionDefinitionNode extends FunctionDefinitionNode {
46
-
47
48
protected final int numOfActiveFlags ;
48
49
protected final int numOfGeneratorBlockNode ;
49
50
protected final int numOfGeneratorForNode ;
51
+ @ CompilationFinal private RootCallTarget generatorCallTarget ;
50
52
51
53
public GeneratorFunctionDefinitionNode (String name , String enclosingClassName , ExpressionNode doc , PythonCore core , Arity arity , StatementNode defaults , RootCallTarget callTarget ,
52
54
FrameDescriptor frameDescriptor , DefinitionCellSlots definitionCellSlots , ExecutionCellSlots executionCellSlots ,
@@ -76,8 +78,18 @@ public PGeneratorFunction execute(VirtualFrame frame) {
76
78
defaults .executeVoid (frame );
77
79
78
80
PCell [] closure = getClosureFromLocals (frame );
79
- return withDocString (frame , factory ().createGeneratorFunction (functionName , enclosingClassName , arity , callTarget , frameDescriptor , PArguments .getGlobals (frame ), closure , executionCellSlots ,
80
- numOfActiveFlags , numOfGeneratorBlockNode , numOfGeneratorForNode ));
81
+ return withDocString (frame ,
82
+ factory ().createGeneratorFunction (functionName , enclosingClassName , arity , getGeneratorCallTarget (closure ), frameDescriptor , PArguments .getGlobals (frame ), closure ));
83
+ }
84
+
85
+ protected RootCallTarget getGeneratorCallTarget (PCell [] closure ) {
86
+ if (generatorCallTarget == null ) {
87
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
88
+ GeneratorFunctionRootNode generatorFunctionRootNode = new GeneratorFunctionRootNode (getContext ().getLanguage (), callTarget , functionName ,
89
+ frameDescriptor , closure , executionCellSlots , numOfActiveFlags , numOfGeneratorBlockNode , numOfGeneratorForNode );
90
+ generatorCallTarget = Truffle .getRuntime ().createCallTarget (generatorFunctionRootNode );
91
+ }
92
+ return generatorCallTarget ;
81
93
}
82
94
83
95
/**
@@ -101,8 +113,7 @@ public PGeneratorFunction execute(VirtualFrame frame) {
101
113
CompilerDirectives .transferToInterpreterAndInvalidate ();
102
114
PCell [] closure = getClosureFromLocals (frame );
103
115
cached = withDocString (frame ,
104
- factory ().createGeneratorFunction (functionName , enclosingClassName , arity , callTarget , frameDescriptor , PArguments .getGlobals (frame ), closure , executionCellSlots ,
105
- numOfActiveFlags , numOfGeneratorBlockNode , numOfGeneratorForNode ));
116
+ factory ().createGeneratorFunction (functionName , enclosingClassName , arity , getGeneratorCallTarget (closure ), frameDescriptor , PArguments .getGlobals (frame ), closure ));
106
117
}
107
118
return cached ;
108
119
}
0 commit comments