|
77 | 77 |
|
78 | 78 | public final class PCode extends PythonBuiltinObject {
|
79 | 79 | 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 |
83 | 85 |
|
84 | 86 | private final RootCallTarget callTarget;
|
85 | 87 | private final Arity arity;
|
@@ -300,23 +302,26 @@ private static Object[] extractVarnames(RootNode rootNode, String[] parameterIds
|
300 | 302 |
|
301 | 303 | @TruffleBoundary
|
302 | 304 | private static int extractFlags(RootNode rootNode) {
|
303 |
| - // 0x20 - generator |
304 | 305 | int flags = 0;
|
305 | 306 | 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 | + } |
318 | 324 | }
|
319 |
| - |
320 | 325 | return flags;
|
321 | 326 | }
|
322 | 327 |
|
@@ -432,15 +437,15 @@ public byte[] getLnotab() {
|
432 | 437 | }
|
433 | 438 |
|
434 | 439 | public boolean isGenerator() {
|
435 |
| - return (getFlags() & (1 << FLAG_POS_GENERATOR)) > 0; |
| 440 | + return (getFlags() & FLAG_GENERATOR) > 0; |
436 | 441 | }
|
437 | 442 |
|
438 | 443 | public boolean takesVarArgs() {
|
439 |
| - return (getFlags() & (1 << FLAG_POS_VAR_ARGS)) > 0; |
| 444 | + return (getFlags() & FLAG_VAR_ARGS) > 0; |
440 | 445 | }
|
441 | 446 |
|
442 | 447 | public boolean takesVarKeywordArgs() {
|
443 |
| - return (getFlags() & (1 << FLAG_POS_VAR_KW_ARGS)) > 0; |
| 448 | + return (getFlags() & FLAG_VAR_KW_ARGS) > 0; |
444 | 449 | }
|
445 | 450 |
|
446 | 451 | public Arity getArity() {
|
|
0 commit comments