Skip to content

Commit 5f6d230

Browse files
timfelcosminbasca
authored andcommitted
co_consts must return nested code
1 parent 85a26a0 commit 5f6d230

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
import java.util.ArrayList;
4444
import java.util.Arrays;
4545
import java.util.HashSet;
46+
import java.util.List;
4647
import java.util.Set;
4748

4849
import com.oracle.graal.python.PythonLanguage;
50+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4951
import com.oracle.graal.python.builtins.objects.function.Signature;
5052
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
5153
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
@@ -57,14 +59,17 @@
5759
import com.oracle.graal.python.nodes.argument.ReadVarKeywordsNode;
5860
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
5961
import com.oracle.graal.python.nodes.frame.GlobalNode;
62+
import com.oracle.graal.python.nodes.function.FunctionDefinitionNode;
6063
import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
6164
import com.oracle.graal.python.nodes.literal.SimpleLiteralNode;
6265
import com.oracle.truffle.api.CompilerDirectives;
6366
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6467
import com.oracle.truffle.api.RootCallTarget;
6568
import com.oracle.truffle.api.interop.UnsupportedMessageException;
6669
import com.oracle.truffle.api.library.ExportMessage;
70+
import com.oracle.truffle.api.nodes.Node;
6771
import com.oracle.truffle.api.nodes.NodeUtil;
72+
import com.oracle.truffle.api.nodes.NodeVisitor;
6873
import com.oracle.truffle.api.nodes.RootNode;
6974
import com.oracle.truffle.api.source.SourceSection;
7075

@@ -235,7 +240,21 @@ private static Object[] extractVarnames(RootNode rootNode, String[] parameterIds
235240

236241
@TruffleBoundary
237242
private static Object[] extractConstants(RootNode rootNode) {
238-
return NodeUtil.findAllNodeInstances(rootNodeForExtraction(rootNode), SimpleLiteralNode.class).stream().map((n) -> n.getValue()).toArray();
243+
List<Object> constants = new ArrayList<>();
244+
rootNode.accept(new NodeVisitor() {
245+
public boolean visit(Node node) {
246+
if (node instanceof SimpleLiteralNode) {
247+
constants.add(((SimpleLiteralNode) node).getValue());
248+
return false;
249+
} else if (node instanceof FunctionDefinitionNode) {
250+
constants.add(new PCode(PythonBuiltinClassType.PCode, ((FunctionDefinitionNode) node).getCallTarget()));
251+
return false;
252+
} else {
253+
return true;
254+
}
255+
}
256+
});
257+
return constants.toArray();
239258
}
240259

241260
@TruffleBoundary

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public String getFunctionName() {
220220
return functionName;
221221
}
222222

223+
public RootCallTarget getCallTarget() {
224+
return callTarget;
225+
}
226+
223227
public RootNode getFunctionRoot() {
224228
return callTarget.getRootNode();
225229
}

0 commit comments

Comments
 (0)