Skip to content

Commit 7879c95

Browse files
committed
fix more exec/eval tests
1 parent 99ef6ad commit 7879c95

File tree

5 files changed

+57
-37
lines changed

5 files changed

+57
-37
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@
7676
import com.oracle.graal.python.nodes.expression.OrNode;
7777
import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
7878
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
79-
import com.oracle.graal.python.nodes.frame.DeleteGlobalNode;
79+
import com.oracle.graal.python.nodes.frame.DeleteNameNode;
8080
import com.oracle.graal.python.nodes.frame.DestructuringAssignmentNode;
8181
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
82-
import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode;
83-
import com.oracle.graal.python.nodes.frame.WriteGlobalNode;
82+
import com.oracle.graal.python.nodes.frame.ReadNameNode;
8483
import com.oracle.graal.python.nodes.frame.WriteLocalVariableNode;
84+
import com.oracle.graal.python.nodes.frame.WriteNameNode;
8585
import com.oracle.graal.python.nodes.frame.WriteNode;
8686
import com.oracle.graal.python.nodes.function.FunctionDefinitionNode;
8787
import com.oracle.graal.python.nodes.function.GeneratorExpressionNode;
@@ -265,21 +265,21 @@ public void parseLiteralString() {
265265

266266
@Test
267267
public void parseGlobalVariable() {
268-
parseAs("foobar13_ddsA", ReadGlobalOrBuiltinNode.class);
268+
parseAs("foobar13_ddsA", ReadNameNode.class);
269269
}
270270

271271
@Test
272272
public void parsePropertyAccess() {
273273
parseAs("foobar13_ddsA.property", GetAttributeNode.class);
274274
GetAttributeNode anotherProperty = parseAs("foobar13_ddsA.property.anotherProperty", GetAttributeNode.class);
275275
GetAttributeNode property = assertInstanceOf(anotherProperty.getObject(), GetAttributeNode.class);
276-
assertInstanceOf(property.getObject(), ReadGlobalOrBuiltinNode.class);
276+
assertInstanceOf(property.getObject(), ReadNameNode.class);
277277
}
278278

279279
@Test
280280
public void parseSubscript() {
281281
GetItemNode node = parseAs("foobar[1]", GetItemNode.class);
282-
assertInstanceOf(node.getLeftNode(), ReadGlobalOrBuiltinNode.class);
282+
assertInstanceOf(node.getLeftNode(), ReadNameNode.class);
283283
parseAs("foobar[:]", GetItemNode.class);
284284
parseAs("foobar[::]", GetItemNode.class);
285285
parseAs("foobar[1:2:3]", GetItemNode.class);
@@ -312,22 +312,22 @@ public void parseLiteralSpecial() {
312312

313313
@Test
314314
public void parseDelStatement() {
315-
parseAs("del world", DeleteGlobalNode.class);
315+
parseAs("del world", DeleteNameNode.class);
316316
parseAs("del world[0]", DeleteItemNode.class);
317317
parseAs("del world.field", DeleteAttributeNode.class);
318318
}
319319

320320
@Test
321321
public void parseAssignments() {
322-
WriteGlobalNode parseAs = parseAs("a = 1", WriteGlobalNode.class);
322+
WriteNameNode parseAs = parseAs("a = 1", WriteNameNode.class);
323323
assertEquals("a", parseAs.getAttributeId());
324324

325325
SetAttributeNode parseAsField = parseAs("a.b = 1", SetAttributeNode.class);
326326
assertEquals("b", parseAsField.getAttributeId());
327327

328328
parseAs("a[1] = 1", SetItemNode.class);
329329

330-
parseAs = parseAs("a = 1,2", WriteGlobalNode.class);
330+
parseAs = parseAs("a = 1,2", WriteNameNode.class);
331331
assert parseAs.getRhs() instanceof TupleLiteralNode;
332332

333333
parseAs("a,b = 1,2", DestructuringAssignmentNode.class);
@@ -337,11 +337,11 @@ public void parseAssignments() {
337337

338338
@Test
339339
public void parseImport() {
340-
WriteGlobalNode importSet = parseAs("import foo", WriteGlobalNode.class);
340+
WriteNameNode importSet = parseAs("import foo", WriteNameNode.class);
341341
assertEquals("foo", importSet.getAttributeId());
342342
assert importSet.getRhs() instanceof ImportNode.ImportExpression;
343343

344-
importSet = parseAs("import foo as bar", WriteGlobalNode.class);
344+
importSet = parseAs("import foo as bar", WriteNameNode.class);
345345
assertEquals("bar", importSet.getAttributeId());
346346
assert importSet.getRhs() instanceof ImportNode.ImportExpression;
347347

@@ -410,27 +410,27 @@ public void parseBinaryOp() {
410410

411411
@Test
412412
public void parseFuncdef() {
413-
WriteGlobalNode parseAs = parseAs("def fun(): pass", WriteGlobalNode.class);
413+
WriteNameNode parseAs = parseAs("def fun(): pass", WriteNameNode.class);
414414
assertEquals("fun", parseAs.getAttributeId());
415415
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
416416

417-
parseAs = parseAs("def fun(a): pass", WriteGlobalNode.class);
417+
parseAs = parseAs("def fun(a): pass", WriteNameNode.class);
418418
assertEquals("fun", parseAs.getAttributeId());
419419
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
420420

421-
parseAs = parseAs("def fun(a,b=1): pass", WriteGlobalNode.class);
421+
parseAs = parseAs("def fun(a,b=1): pass", WriteNameNode.class);
422422
assertEquals("fun", parseAs.getAttributeId());
423423
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
424424

425-
parseAs = parseAs("def fun(a,b=1,*c): pass", WriteGlobalNode.class);
425+
parseAs = parseAs("def fun(a,b=1,*c): pass", WriteNameNode.class);
426426
assertEquals("fun", parseAs.getAttributeId());
427427
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
428428

429-
parseAs = parseAs("def fun(a,b=1,*c,d=2): pass", WriteGlobalNode.class);
429+
parseAs = parseAs("def fun(a,b=1,*c,d=2): pass", WriteNameNode.class);
430430
assertEquals("fun", parseAs.getAttributeId());
431431
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
432432

433-
parseAs = parseAs("def fun(a,b=1,*c,d=2,**kwargs): pass", WriteGlobalNode.class);
433+
parseAs = parseAs("def fun(a,b=1,*c,d=2,**kwargs): pass", WriteNameNode.class);
434434
assertEquals("fun", parseAs.getAttributeId());
435435
assert parseAs.getRhs() instanceof FunctionDefinitionNode;
436436
}

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ private void inheritLocals(Frame callerFrame, Object[] args) {
524524
}
525525
PDict callerLocals = pFrame.getLocals(factory());
526526
PArguments.setSpecialArgument(args, callerLocals);
527+
PArguments.setPFrame(args, factory().createPFrame(callerLocals));
527528
}
528529

529530
private void setBuiltinsInGlobals(PDict globals, HashingCollectionNodes.SetItemNode setBuiltins, PythonModule builtins) {
@@ -547,49 +548,45 @@ private void setCustomGlobals(PDict globals, HashingCollectionNodes.SetItemNode
547548
}
548549

549550
@Specialization
550-
PNone execInheritGlobalsInheritLocals(VirtualFrame frame, Object source, @SuppressWarnings("unused") PNone globals, @SuppressWarnings("unused") PNone locals,
551+
Object execInheritGlobalsInheritLocals(VirtualFrame frame, Object source, @SuppressWarnings("unused") PNone globals, @SuppressWarnings("unused") PNone locals,
551552
@Cached("create()") ReadCallerFrameNode readCallerFrameNode) {
552553
PCode code = createAndCheckCode(source);
553554
Frame callerFrame = readCallerFrameNode.executeWith(frame);
554555
Object[] args = PArguments.create();
555556
inheritGlobals(callerFrame, args);
556557
inheritLocals(callerFrame, args);
557-
indirectCallNode.call(code.getRootCallTarget(), args);
558-
return PNone.NO_VALUE;
558+
return indirectCallNode.call(code.getRootCallTarget(), args);
559559
}
560560

561561
@Specialization
562-
PNone execCustomGlobalsGlobalLocals(Object source, PDict globals, @SuppressWarnings("unused") PNone locals,
562+
Object execCustomGlobalsGlobalLocals(Object source, PDict globals, @SuppressWarnings("unused") PNone locals,
563563
@Cached("create()") HashingCollectionNodes.SetItemNode setBuiltins) {
564564
PCode code = createAndCheckCode(source);
565565
Object[] args = PArguments.create();
566566
setCustomGlobals(globals, setBuiltins, args);
567567
PArguments.setSpecialArgument(args, globals);
568-
indirectCallNode.call(code.getRootCallTarget(), args);
569-
return PNone.NO_VALUE;
568+
return indirectCallNode.call(code.getRootCallTarget(), args);
570569
}
571570

572571
@Specialization(guards = {"isMapping(locals)"})
573-
PNone execInheritGlobalsCustomLocals(VirtualFrame frame, Object source, @SuppressWarnings("unused") PNone globals, Object locals,
572+
Object execInheritGlobalsCustomLocals(VirtualFrame frame, Object source, @SuppressWarnings("unused") PNone globals, Object locals,
574573
@Cached("create()") ReadCallerFrameNode readCallerFrameNode) {
575574
PCode code = createAndCheckCode(source);
576575
Frame callerFrame = readCallerFrameNode.executeWith(frame);
577576
Object[] args = PArguments.create();
578577
inheritGlobals(callerFrame, args);
579578
PArguments.setSpecialArgument(args, locals);
580-
indirectCallNode.call(code.getRootCallTarget(), args);
581-
return PNone.NO_VALUE;
579+
return indirectCallNode.call(code.getRootCallTarget(), args);
582580
}
583581

584582
@Specialization(guards = {"isMapping(locals)"})
585-
PNone execCustomGlobalsCustomLocals(Object source, PDict globals, Object locals,
583+
Object execCustomGlobalsCustomLocals(Object source, PDict globals, Object locals,
586584
@Cached("create()") HashingCollectionNodes.SetItemNode setBuiltins) {
587585
PCode code = createAndCheckCode(source);
588586
Object[] args = PArguments.create();
589587
setCustomGlobals(globals, setBuiltins, args);
590588
PArguments.setSpecialArgument(args, locals);
591-
indirectCallNode.call(code.getRootCallTarget(), args);
592-
return PNone.NO_VALUE;
589+
return indirectCallNode.call(code.getRootCallTarget(), args);
593590
}
594591

595592
@Specialization(guards = {"!isAnyNone(globals)", "!isDict(globals)"})
@@ -622,6 +619,14 @@ protected PCode createAndCheckCode(Object source) {
622619
assertNoFreeVars(code);
623620
return code;
624621
}
622+
623+
protected abstract Object executeInternal(VirtualFrame frame);
624+
625+
@Override
626+
public final Object execute(VirtualFrame frame) {
627+
executeInternal(frame);
628+
return PNone.NONE;
629+
}
625630
}
626631

627632
// compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
@@ -1570,6 +1575,12 @@ public String doIt(PMethod method) {
15701575
return NodeUtil.printTreeToString(method.getCallTarget().getRootNode());
15711576
}
15721577

1578+
@Specialization
1579+
@TruffleBoundary
1580+
public String doIt(PCode code) {
1581+
return NodeUtil.printTreeToString(code.getRootNode());
1582+
}
1583+
15731584
@Fallback
15741585
@TruffleBoundary
15751586
public Object doit(Object object) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/LocalsStorage.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,16 @@ private boolean loadNext() {
216216
while (keysIterator().hasNext()) {
217217
FrameSlot nextCandidate = keysIterator().next();
218218
Object identifier = nextCandidate.getIdentifier();
219-
if (!RETURN_SLOT_ID.equals(identifier) && !isTempLocal(identifier)) {
220-
Object nextValue = frame.getValue(nextCandidate);
221-
if (skipCells && nextValue instanceof PCell) {
222-
continue;
223-
}
224-
if (nextValue != null) {
225-
nextSlot = nextCandidate;
226-
return true;
219+
if (identifier instanceof String) {
220+
if (!RETURN_SLOT_ID.equals(identifier) && !isTempLocal(identifier)) {
221+
Object nextValue = frame.getValue(nextCandidate);
222+
if (skipCells && nextValue instanceof PCell) {
223+
continue;
224+
}
225+
if (nextValue != null) {
226+
nextSlot = nextCandidate;
227+
return true;
228+
}
227229
}
228230
}
229231
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/PythonCallNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
3939
import com.oracle.graal.python.nodes.expression.ExpressionNode;
4040
import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode;
41+
import com.oracle.graal.python.nodes.frame.ReadNameNode;
4142
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
4243
import com.oracle.graal.python.runtime.exception.PythonErrorType;
4344
import com.oracle.truffle.api.debug.DebuggerTags;
@@ -91,6 +92,8 @@ public static PythonCallNode create(ExpressionNode calleeNode, ExpressionNode[]
9192

9293
if (calleeNode instanceof ReadGlobalOrBuiltinNode) {
9394
calleeName = ((ReadGlobalOrBuiltinNode) calleeNode).getAttributeId();
95+
} else if (calleeNode instanceof ReadNameNode) {
96+
calleeName = ((ReadNameNode) calleeNode).getAttributeId();
9497
} else if (calleeNode instanceof GetAttributeNode) {
9598
getCallableNode = GetCallAttributeNodeGen.create(((GetAttributeNode) calleeNode).getKey(), ((GetAttributeNode) calleeNode).getObject());
9699
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteNameNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ public void doWrite(VirtualFrame frame, Object value) {
8484

8585
public abstract void executeWithValue(VirtualFrame frame, Object value);
8686

87+
public Object getAttributeId() {
88+
return attributeId;
89+
}
90+
8791
}

0 commit comments

Comments
 (0)