Skip to content

Commit fbbb9c1

Browse files
committed
save the flags directly, use the NOFREE flag as module flag
1 parent e43785f commit fbbb9c1

File tree

1 file changed

+25
-20
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code

1 file changed

+25
-20
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@
7777

7878
public final class PCode extends PythonBuiltinObject {
7979
private static final String[] EMPTY_STRINGS = new String[0];
80-
private final static long FLAG_POS_GENERATOR = 5;
81-
private final static long FLAG_POS_VAR_ARGS = 2;
82-
private final static long FLAG_POS_VAR_KW_ARGS = 3;
80+
private final static long FLAG_GENERATOR = 32;
81+
private final static long FLAG_VAR_ARGS = 0x0004;
82+
private final static long FLAG_VAR_KW_ARGS = 0x0008;
83+
private final static long FLAG_MODULE = 0x0040; // CO_NOFREE on CPython, we only set it on
84+
// modules
8385

8486
private final RootCallTarget callTarget;
8587
private final Arity arity;
@@ -300,23 +302,26 @@ private static Object[] extractVarnames(RootNode rootNode, String[] parameterIds
300302

301303
@TruffleBoundary
302304
private static int extractFlags(RootNode rootNode) {
303-
// 0x20 - generator
304305
int flags = 0;
305306
RootNode funcRootNode = rootNode;
306-
if (funcRootNode instanceof GeneratorFunctionRootNode) {
307-
flags |= (1 << FLAG_POS_GENERATOR);
308-
funcRootNode = ((GeneratorFunctionRootNode) funcRootNode).getFunctionRootNode();
309-
}
310-
311-
// 0x04 - *arguments
312-
if (NodeUtil.findFirstNodeInstance(funcRootNode, ReadVarArgsNode.class) != null) {
313-
flags |= (1 << FLAG_POS_VAR_ARGS);
314-
}
315-
// 0x08 - **keywords
316-
if (NodeUtil.findFirstNodeInstance(funcRootNode, ReadVarKeywordsNode.class) != null) {
317-
flags |= (1 << FLAG_POS_VAR_KW_ARGS);
307+
if (funcRootNode instanceof ModuleRootNode) {
308+
// Not on CPython
309+
flags |= FLAG_MODULE;
310+
} else {
311+
// 0x20 - generator
312+
if (funcRootNode instanceof GeneratorFunctionRootNode) {
313+
flags |= FLAG_GENERATOR;
314+
funcRootNode = ((GeneratorFunctionRootNode) funcRootNode).getFunctionRootNode();
315+
}
316+
// 0x04 - *arguments
317+
if (NodeUtil.findFirstNodeInstance(funcRootNode, ReadVarArgsNode.class) != null) {
318+
flags |= FLAG_VAR_ARGS;
319+
}
320+
// 0x08 - **keywords
321+
if (NodeUtil.findFirstNodeInstance(funcRootNode, ReadVarKeywordsNode.class) != null) {
322+
flags |= FLAG_VAR_KW_ARGS;
323+
}
318324
}
319-
320325
return flags;
321326
}
322327

@@ -432,15 +437,15 @@ public byte[] getLnotab() {
432437
}
433438

434439
public boolean isGenerator() {
435-
return (getFlags() & (1 << FLAG_POS_GENERATOR)) > 0;
440+
return (getFlags() & FLAG_GENERATOR) > 0;
436441
}
437442

438443
public boolean takesVarArgs() {
439-
return (getFlags() & (1 << FLAG_POS_VAR_ARGS)) > 0;
444+
return (getFlags() & FLAG_VAR_ARGS) > 0;
440445
}
441446

442447
public boolean takesVarKeywordArgs() {
443-
return (getFlags() & (1 << FLAG_POS_VAR_KW_ARGS)) > 0;
448+
return (getFlags() & FLAG_VAR_KW_ARGS) > 0;
444449
}
445450

446451
public Arity getArity() {

0 commit comments

Comments
 (0)