Skip to content

Commit 8fb6c02

Browse files
committed
Allow to replace the uninitialized body of a function
1 parent 417f1a8 commit 8fb6c02

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public boolean visit(Node node) {
461461
}
462462
return true;
463463
}
464-
});
464+
}, x -> x);
465465

466466
String name = func.getName();
467467
builtinFunc = factory().createFunction(name, func.getEnclosingClassName(),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionRootNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.oracle.graal.python.parser.ExecutionCellSlots;
3636
import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
3737
import com.oracle.graal.python.runtime.PythonContext;
38+
import com.oracle.graal.python.util.Function;
3839
import com.oracle.truffle.api.CompilerAsserts;
3940
import com.oracle.truffle.api.CompilerDirectives;
4041
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -116,8 +117,8 @@ protected RootNode cloneUninitialized() {
116117
* Returns a new function that has its signature replaced and whose body has been modified by
117118
* the given node visitor.
118119
*/
119-
public FunctionRootNode rewriteWithNewSignature(Signature newSignature, NodeVisitor nodeVisitor) {
120-
ExpressionNode newUninitializedBody = NodeUtil.cloneNode(uninitializedBody);
120+
public FunctionRootNode rewriteWithNewSignature(Signature newSignature, NodeVisitor nodeVisitor, Function<ExpressionNode, ExpressionNode> bodyFun) {
121+
ExpressionNode newUninitializedBody = bodyFun.apply(NodeUtil.cloneNode(uninitializedBody));
121122
newUninitializedBody.accept(nodeVisitor);
122123
return new FunctionRootNode(PythonLanguage.getCurrent(), getSourceSection(), functionName, isGenerator, true, getFrameDescriptor(), newUninitializedBody, executionCellSlots,
123124
newSignature);

0 commit comments

Comments
 (0)