|
38 | 38 | import com.oracle.graal.python.parser.ExecutionCellSlots;
|
39 | 39 | import com.oracle.truffle.api.RootCallTarget;
|
40 | 40 | import com.oracle.truffle.api.frame.VirtualFrame;
|
| 41 | +import com.oracle.truffle.api.nodes.ExplodeLoop; |
41 | 42 | import com.oracle.truffle.api.nodes.RootNode;
|
42 | 43 |
|
43 | 44 | public class FunctionDefinitionNode extends ExpressionDefinitionNode {
|
@@ -67,22 +68,34 @@ public FunctionDefinitionNode(String functionName, String enclosingClassName, Ex
|
67 | 68 |
|
68 | 69 | @Override
|
69 | 70 | public Object execute(VirtualFrame frame) {
|
70 |
| - Object[] defaultValues = null; |
71 |
| - if (defaults != null) { |
72 |
| - defaultValues = new Object[defaults.length]; |
73 |
| - for (int i = 0; i < defaults.length; i++) { |
74 |
| - defaultValues[i] = defaults[i].execute(frame); |
75 |
| - } |
76 |
| - } |
| 71 | + Object[] defaultValues = computeDefaultValues(frame); |
| 72 | + PKeyword[] kwDefaultValues = computeKwDefaultValues(frame); |
| 73 | + PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame); |
| 74 | + return withDocString(frame, factory().createFunction(functionName, enclosingClassName, callTarget, PArguments.getGlobals(frame), defaultValues, kwDefaultValues, closure)); |
| 75 | + } |
| 76 | + |
| 77 | + @ExplodeLoop |
| 78 | + private PKeyword[] computeKwDefaultValues(VirtualFrame frame) { |
77 | 79 | PKeyword[] kwDefaultValues = null;
|
78 | 80 | if (kwDefaults != null) {
|
79 | 81 | kwDefaultValues = new PKeyword[kwDefaults.length];
|
80 | 82 | for (int i = 0; i < kwDefaults.length; i++) {
|
81 | 83 | kwDefaultValues[i] = new PKeyword(kwDefaults[i].name, kwDefaults[i].execute(frame));
|
82 | 84 | }
|
83 | 85 | }
|
84 |
| - PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame); |
85 |
| - return withDocString(frame, factory().createFunction(functionName, enclosingClassName, callTarget, PArguments.getGlobals(frame), defaultValues, kwDefaultValues, closure)); |
| 86 | + return kwDefaultValues; |
| 87 | + } |
| 88 | + |
| 89 | + @ExplodeLoop |
| 90 | + private Object[] computeDefaultValues(VirtualFrame frame) { |
| 91 | + Object[] defaultValues = null; |
| 92 | + if (defaults != null) { |
| 93 | + defaultValues = new Object[defaults.length]; |
| 94 | + for (int i = 0; i < defaults.length; i++) { |
| 95 | + defaultValues[i] = defaults[i].execute(frame); |
| 96 | + } |
| 97 | + } |
| 98 | + return defaultValues; |
86 | 99 | }
|
87 | 100 |
|
88 | 101 | protected final <T extends PFunction> T withDocString(VirtualFrame frame, T func) {
|
|
0 commit comments