|
105 | 105 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
106 | 106 | import com.oracle.truffle.api.dsl.ImportStatic;
|
107 | 107 | import com.oracle.truffle.api.dsl.NodeFactory;
|
| 108 | +import com.oracle.truffle.api.dsl.ReportPolymorphism; |
108 | 109 | import com.oracle.truffle.api.dsl.Specialization;
|
109 | 110 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
110 | 111 | import com.oracle.truffle.api.frame.VirtualFrame;
|
@@ -456,6 +457,7 @@ PNotImplemented doGeneric(Object left, Object right) {
|
456 | 457 | @Builtin(name = __POW__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
|
457 | 458 | @TypeSystemReference(PythonArithmeticTypes.class)
|
458 | 459 | @GenerateNodeFactory
|
| 460 | + @ReportPolymorphism |
459 | 461 | abstract static class PowerNode extends PythonTernaryBuiltinNode {
|
460 | 462 | @Specialization
|
461 | 463 | double doDL(double left, long right, @SuppressWarnings("unused") PNone none,
|
@@ -555,13 +557,31 @@ Object doDPiToComplex(VirtualFrame frame, PInt left, double right, @SuppressWarn
|
555 | 557 | return doDDToComplex(frame, left.doubleValue(), right, none, callPow, negativeRaise);
|
556 | 558 | }
|
557 | 559 |
|
558 |
| - @Fallback |
559 |
| - Object doGeneric(@SuppressWarnings("unused") Object left, @SuppressWarnings("unused") Object right, Object mod) { |
560 |
| - if (mod instanceof PNone) { |
| 560 | + @Specialization |
| 561 | + Object doGeneric(VirtualFrame frame, Object left, Object right, Object mod, |
| 562 | + @CachedLibrary(limit = "5") PythonObjectLibrary lib, |
| 563 | + @Shared("powCall") @Cached("create(__POW__)") LookupAndCallTernaryNode callPow, |
| 564 | + @Shared("negativeRaise") @Cached BranchProfile negativeRaise) { |
| 565 | + if (!(mod instanceof PNone)) { |
| 566 | + throw raise(PythonBuiltinClassType.TypeError, "pow() 3rd argument not allowed unless all arguments are integers"); |
| 567 | + } |
| 568 | + double leftDouble; |
| 569 | + double rightDouble; |
| 570 | + if (lib.canBeJavaDouble(left)) { |
| 571 | + leftDouble = lib.asJavaDouble(left); |
| 572 | + } else if (left instanceof PInt) { |
| 573 | + leftDouble = ((PInt) left).doubleValue(); |
| 574 | + } else { |
561 | 575 | return PNotImplemented.NOT_IMPLEMENTED;
|
| 576 | + } |
| 577 | + if (lib.canBeJavaDouble(right)) { |
| 578 | + rightDouble = lib.asJavaDouble(right); |
| 579 | + } else if (right instanceof PInt) { |
| 580 | + rightDouble = ((PInt) right).doubleValue(); |
562 | 581 | } else {
|
563 |
| - throw raise(PythonBuiltinClassType.TypeError, "pow() 3rd argument not allowed unless all arguments are integers"); |
| 582 | + return PNotImplemented.NOT_IMPLEMENTED; |
564 | 583 | }
|
| 584 | + return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, callPow, negativeRaise); |
565 | 585 | }
|
566 | 586 | }
|
567 | 587 |
|
|
0 commit comments