|
83 | 83 | import com.oracle.graal.python.builtins.objects.PNotImplemented;
|
84 | 84 | import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
|
85 | 85 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
| 86 | +import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike; |
86 | 87 | import com.oracle.graal.python.builtins.objects.cell.PCell;
|
87 | 88 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
88 | 89 | import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
|
@@ -456,6 +457,7 @@ private static BigInteger[] divideAndRemainder(PInt a, PInt b) {
|
456 | 457 | public abstract static class EvalNode extends PythonBuiltinNode {
|
457 | 458 | @Child private GetItemNode getNameNode = GetItemNode.create();
|
458 | 459 | @Child private ReadCallerFrameNode readCallerFrameNode = ReadCallerFrameNode.create();
|
| 460 | + @Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode; |
459 | 461 |
|
460 | 462 | @Specialization
|
461 | 463 | public Object eval(VirtualFrame frame, String expression, @SuppressWarnings("unused") PNone globals, @SuppressWarnings("unused") PNone locals) {
|
@@ -515,6 +517,39 @@ public Object eval(VirtualFrame frame, PCode code, @SuppressWarnings("unused") P
|
515 | 517 | return evalExpression(code, callerGlobals, locals, callerClosure);
|
516 | 518 | }
|
517 | 519 |
|
| 520 | + @Specialization |
| 521 | + public Object eval(VirtualFrame frame, PBytes expression, PNone globals, PNone locals) { |
| 522 | + return eval(frame, getString(expression), globals, locals); |
| 523 | + } |
| 524 | + |
| 525 | + @Specialization |
| 526 | + public Object eval(VirtualFrame frame, PBytes expression, PythonObject globals, PNone locals) { |
| 527 | + return eval(frame, getString(expression), globals, locals); |
| 528 | + } |
| 529 | + |
| 530 | + @Specialization |
| 531 | + public Object eval(VirtualFrame frame, PBytes expression, PythonObject globals, PythonObject locals) { |
| 532 | + return eval(frame, getString(expression), globals, locals); |
| 533 | + } |
| 534 | + |
| 535 | + @Specialization |
| 536 | + public Object eval(VirtualFrame frame, PBytes expression, PNone globals, PythonObject locals) { |
| 537 | + return eval(frame, getString(expression), globals, locals); |
| 538 | + } |
| 539 | + |
| 540 | + @TruffleBoundary |
| 541 | + private String getString(PBytes expression) { |
| 542 | + return new String(getByteArray(expression)); |
| 543 | + } |
| 544 | + |
| 545 | + private byte[] getByteArray(PIBytesLike pByteArray) { |
| 546 | + if (toByteArrayNode == null) { |
| 547 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 548 | + toByteArrayNode = insert(SequenceStorageNodes.ToByteArrayNode.create()); |
| 549 | + } |
| 550 | + return toByteArrayNode.execute(pByteArray.getSequenceStorage()); |
| 551 | + } |
| 552 | + |
518 | 553 | @TruffleBoundary
|
519 | 554 | private static Object evalExpression(PCode code, PythonObject globals, PythonObject locals, PCell[] closure) {
|
520 | 555 | RootNode root = code.getRootNode();
|
|
0 commit comments