|
26 | 26 | package com.oracle.graal.python.builtins.objects.floats;
|
27 | 27 |
|
28 | 28 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
|
29 |
| -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; |
30 | 29 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
|
31 | 30 | import static com.oracle.graal.python.nodes.BuiltinNames.J_FLOAT;
|
32 | 31 | import static com.oracle.graal.python.nodes.SpecialMethodNames.J___ABS__;
|
|
92 | 91 | import com.oracle.graal.python.builtins.objects.floats.FloatBuiltinsClinicProviders.FormatNodeClinicProviderGen;
|
93 | 92 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
94 | 93 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
95 |
| -import com.oracle.graal.python.lib.PyFloatCheckNode; |
96 |
| -import com.oracle.graal.python.lib.PyLongCheckNode; |
97 | 94 | import com.oracle.graal.python.lib.PyObjectHashNode;
|
98 | 95 | import com.oracle.graal.python.nodes.ErrorMessages;
|
99 |
| -import com.oracle.graal.python.nodes.PRaiseNode; |
100 | 96 | import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode;
|
101 | 97 | import com.oracle.graal.python.nodes.call.special.LookupAndCallVarargsNode;
|
102 | 98 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
|
|
108 | 104 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
109 | 105 | import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
|
110 | 106 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
111 |
| -import com.oracle.graal.python.nodes.object.InlinedGetClassNode; |
112 | 107 | import com.oracle.graal.python.nodes.object.InlinedGetClassNode.GetPythonObjectClassNode;
|
113 | 108 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
114 | 109 | import com.oracle.graal.python.nodes.util.CannotCastException;
|
|
124 | 119 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
125 | 120 | import com.oracle.truffle.api.dsl.Fallback;
|
126 | 121 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
127 |
| -import com.oracle.truffle.api.dsl.GenerateUncached; |
128 | 122 | import com.oracle.truffle.api.dsl.ImportStatic;
|
129 | 123 | import com.oracle.truffle.api.dsl.NodeFactory;
|
130 | 124 | import com.oracle.truffle.api.dsl.ReportPolymorphism;
|
131 | 125 | import com.oracle.truffle.api.dsl.Specialization;
|
132 | 126 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
133 | 127 | import com.oracle.truffle.api.frame.VirtualFrame;
|
134 |
| -import com.oracle.truffle.api.interop.InteropLibrary; |
135 |
| -import com.oracle.truffle.api.library.CachedLibrary; |
136 | 128 | import com.oracle.truffle.api.nodes.Node;
|
137 | 129 | import com.oracle.truffle.api.nodes.UnexpectedResultException;
|
138 | 130 | import com.oracle.truffle.api.profiles.InlinedConditionProfile;
|
@@ -298,68 +290,13 @@ static boolean isFloatSubtype(Node inliningTarget, PythonAbstractNativeObject ob
|
298 | 290 | }
|
299 | 291 | }
|
300 | 292 |
|
301 |
| - @GenerateUncached |
302 |
| - abstract static class ConvertToDoubleCheckNode extends Node { |
303 |
| - abstract boolean execute(Object obj); |
304 |
| - |
305 |
| - @Specialization |
306 |
| - static boolean doDouble(@SuppressWarnings("unused") Double object) { |
307 |
| - return true; |
308 |
| - } |
309 |
| - |
310 |
| - @Specialization |
311 |
| - static boolean doInt(@SuppressWarnings("unused") Integer object) { |
312 |
| - return true; |
313 |
| - } |
314 |
| - |
315 |
| - @Specialization |
316 |
| - static boolean doLong(@SuppressWarnings("unused") Long object) { |
317 |
| - return true; |
318 |
| - } |
319 |
| - |
320 |
| - @Specialization |
321 |
| - static boolean doBoolean(@SuppressWarnings("unused") Boolean object) { |
322 |
| - return true; |
323 |
| - } |
324 |
| - |
325 |
| - @Specialization |
326 |
| - static boolean doString(@SuppressWarnings("unused") TruffleString object) { |
327 |
| - return false; |
328 |
| - } |
329 |
| - |
330 |
| - @Specialization |
331 |
| - static boolean doPBCT(@SuppressWarnings("unused") PythonBuiltinClassType object) { |
332 |
| - return false; |
333 |
| - } |
334 |
| - |
335 |
| - @Specialization |
336 |
| - static boolean typeCheck(Object obj, |
337 |
| - @Cached PyFloatCheckNode floatCheckNode, |
338 |
| - @Cached PyLongCheckNode longCheckNode, |
339 |
| - @Bind("this") Node inliningTarget, |
340 |
| - @Cached InlinedGetClassNode getClassNode, |
341 |
| - @CachedLibrary(limit = "3") InteropLibrary interopLibrary) { |
342 |
| - if (floatCheckNode.execute(inliningTarget, obj) || longCheckNode.execute(obj)) { |
343 |
| - return true; |
344 |
| - } |
345 |
| - Object type = getClassNode.execute(inliningTarget, obj); |
346 |
| - if (type == PythonBuiltinClassType.ForeignObject) { |
347 |
| - if (interopLibrary.fitsInDouble(obj) || interopLibrary.fitsInLong(obj) || interopLibrary.isBoolean(obj)) { |
348 |
| - return true; |
349 |
| - } |
350 |
| - } |
351 |
| - return false; |
352 |
| - } |
353 |
| - } |
354 |
| - |
355 |
| - static double convertToDouble(Object obj, |
356 |
| - CastToJavaDoubleNode asDoubleNode, |
357 |
| - PRaiseNode raiseNode) { |
| 293 | + static Object convertToDouble(Object obj, |
| 294 | + CastToJavaDoubleNode asDoubleNode) { |
358 | 295 | try {
|
359 | 296 | return asDoubleNode.execute(obj);
|
360 | 297 | } catch (CannotCastException e) {
|
361 | 298 | // This can only happen to values that are expected to be long.
|
362 |
| - throw raiseNode.raise(TypeError, ErrorMessages.INTEGER_REQUIRED); |
| 299 | + return PNotImplemented.NOT_IMPLEMENTED; |
363 | 300 | }
|
364 | 301 | }
|
365 | 302 |
|
@@ -412,22 +349,20 @@ static Object doDP(VirtualFrame frame, PythonAbstractNativeObject left, double r
|
412 | 349 |
|
413 | 350 | @Fallback
|
414 | 351 | Object doGeneric(Object left, Object right,
|
415 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
416 | 352 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
417 |
| - double leftDouble; |
418 |
| - double rightDouble; |
419 | 353 |
|
420 |
| - if (convertToDoubleCheckNode.execute(left)) { |
421 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
422 |
| - } else { |
| 354 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 355 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
423 | 356 | return PNotImplemented.NOT_IMPLEMENTED;
|
424 | 357 | }
|
425 | 358 |
|
426 |
| - if (convertToDoubleCheckNode.execute(right)) { |
427 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
428 |
| - } else { |
| 359 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 360 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
429 | 361 | return PNotImplemented.NOT_IMPLEMENTED;
|
430 | 362 | }
|
| 363 | + |
| 364 | + double leftDouble = (double) objLeft; |
| 365 | + double rightDouble = (double) objRight; |
431 | 366 | return leftDouble + rightDouble;
|
432 | 367 | }
|
433 | 368 | }
|
@@ -464,22 +399,20 @@ static double doLD(long left, double right) {
|
464 | 399 |
|
465 | 400 | @Fallback
|
466 | 401 | Object doGeneric(Object left, Object right,
|
467 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
468 | 402 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
469 |
| - double leftDouble; |
470 |
| - double rightDouble; |
471 | 403 |
|
472 |
| - if (convertToDoubleCheckNode.execute(left)) { |
473 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
474 |
| - } else { |
| 404 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 405 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
475 | 406 | return PNotImplemented.NOT_IMPLEMENTED;
|
476 | 407 | }
|
477 | 408 |
|
478 |
| - if (convertToDoubleCheckNode.execute(right)) { |
479 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
480 |
| - } else { |
| 409 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 410 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
481 | 411 | return PNotImplemented.NOT_IMPLEMENTED;
|
482 | 412 | }
|
| 413 | + |
| 414 | + double leftDouble = (double) objLeft; |
| 415 | + double rightDouble = (double) objRight; |
483 | 416 | return leftDouble - rightDouble;
|
484 | 417 | }
|
485 | 418 | }
|
@@ -544,22 +477,20 @@ Object doDP(VirtualFrame frame, PythonAbstractNativeObject left, PInt right,
|
544 | 477 |
|
545 | 478 | @Fallback
|
546 | 479 | Object doGeneric(Object left, Object right,
|
547 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
548 | 480 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
549 |
| - double leftDouble; |
550 |
| - double rightDouble; |
551 | 481 |
|
552 |
| - if (convertToDoubleCheckNode.execute(left)) { |
553 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
554 |
| - } else { |
| 482 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 483 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
555 | 484 | return PNotImplemented.NOT_IMPLEMENTED;
|
556 | 485 | }
|
557 | 486 |
|
558 |
| - if (convertToDoubleCheckNode.execute(right)) { |
559 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
560 |
| - } else { |
| 487 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 488 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
561 | 489 | return PNotImplemented.NOT_IMPLEMENTED;
|
562 | 490 | }
|
| 491 | + |
| 492 | + double leftDouble = (double) objLeft; |
| 493 | + double rightDouble = (double) objRight; |
563 | 494 | return leftDouble * rightDouble;
|
564 | 495 | }
|
565 | 496 | }
|
@@ -673,26 +604,24 @@ Object doDPiToComplex(VirtualFrame frame, PInt left, double right, @SuppressWarn
|
673 | 604 |
|
674 | 605 | @Specialization
|
675 | 606 | Object doGeneric(VirtualFrame frame, Object left, Object right, Object mod,
|
676 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
677 | 607 | @Cached CastToJavaDoubleNode castToJavaDoubleNode,
|
678 | 608 | @Shared("powCall") @Cached("create(Pow)") LookupAndCallTernaryNode callPow) {
|
679 | 609 | if (!(mod instanceof PNone)) {
|
680 | 610 | throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.POW_3RD_ARG_NOT_ALLOWED_UNLESS_INTEGERS);
|
681 | 611 | }
|
682 |
| - double leftDouble; |
683 |
| - double rightDouble; |
684 | 612 |
|
685 |
| - if (convertToDoubleCheckNode.execute(left)) { |
686 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
687 |
| - } else { |
| 613 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 614 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
688 | 615 | return PNotImplemented.NOT_IMPLEMENTED;
|
689 | 616 | }
|
690 | 617 |
|
691 |
| - if (convertToDoubleCheckNode.execute(right)) { |
692 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
693 |
| - } else { |
| 618 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 619 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
694 | 620 | return PNotImplemented.NOT_IMPLEMENTED;
|
695 | 621 | }
|
| 622 | + |
| 623 | + double leftDouble = (double) objLeft; |
| 624 | + double rightDouble = (double) objRight; |
696 | 625 | return doDDToComplex(frame, leftDouble, rightDouble, PNone.NONE, callPow);
|
697 | 626 | }
|
698 | 627 |
|
@@ -775,22 +704,20 @@ PTuple doGenericFloat(VirtualFrame frame, Object left, Object right,
|
775 | 704 |
|
776 | 705 | @Fallback
|
777 | 706 | Object doGeneric(Object left, Object right,
|
778 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
779 | 707 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
780 |
| - double leftDouble; |
781 |
| - double rightDouble; |
782 | 708 |
|
783 |
| - if (convertToDoubleCheckNode.execute(left)) { |
784 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
785 |
| - } else { |
| 709 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 710 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
786 | 711 | return PNotImplemented.NOT_IMPLEMENTED;
|
787 | 712 | }
|
788 | 713 |
|
789 |
| - if (convertToDoubleCheckNode.execute(right)) { |
790 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
791 |
| - } else { |
| 714 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 715 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
792 | 716 | return PNotImplemented.NOT_IMPLEMENTED;
|
793 | 717 | }
|
| 718 | + |
| 719 | + double leftDouble = (double) objLeft; |
| 720 | + double rightDouble = (double) objRight; |
794 | 721 | return doDD(leftDouble, rightDouble);
|
795 | 722 | }
|
796 | 723 |
|
@@ -979,22 +906,20 @@ public abstract static class ModNode extends FloatBinaryBuiltinNode {
|
979 | 906 |
|
980 | 907 | @Fallback
|
981 | 908 | Object doGeneric(Object left, Object right,
|
982 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
983 | 909 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
984 |
| - double leftDouble; |
985 |
| - double rightDouble; |
986 | 910 |
|
987 |
| - if (convertToDoubleCheckNode.execute(left)) { |
988 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
989 |
| - } else { |
| 911 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 912 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
990 | 913 | return PNotImplemented.NOT_IMPLEMENTED;
|
991 | 914 | }
|
992 | 915 |
|
993 |
| - if (convertToDoubleCheckNode.execute(right)) { |
994 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
995 |
| - } else { |
| 916 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 917 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
996 | 918 | return PNotImplemented.NOT_IMPLEMENTED;
|
997 | 919 | }
|
| 920 | + |
| 921 | + double leftDouble = (double) objLeft; |
| 922 | + double rightDouble = (double) objRight; |
998 | 923 | return doDD(leftDouble, rightDouble);
|
999 | 924 | }
|
1000 | 925 |
|
@@ -1060,22 +985,20 @@ Object doDP(VirtualFrame frame, long left, PythonAbstractNativeObject right,
|
1060 | 985 |
|
1061 | 986 | @Fallback
|
1062 | 987 | Object doGeneric(Object left, Object right,
|
1063 |
| - @Cached ConvertToDoubleCheckNode convertToDoubleCheckNode, |
1064 | 988 | @Cached CastToJavaDoubleNode castToJavaDoubleNode) {
|
1065 |
| - double leftDouble; |
1066 |
| - double rightDouble; |
1067 | 989 |
|
1068 |
| - if (convertToDoubleCheckNode.execute(left)) { |
1069 |
| - leftDouble = convertToDouble(left, castToJavaDoubleNode, getRaiseNode()); |
1070 |
| - } else { |
| 990 | + Object objLeft = convertToDouble(left, castToJavaDoubleNode); |
| 991 | + if (objLeft == PNotImplemented.NOT_IMPLEMENTED) { |
1071 | 992 | return PNotImplemented.NOT_IMPLEMENTED;
|
1072 | 993 | }
|
1073 | 994 |
|
1074 |
| - if (convertToDoubleCheckNode.execute(right)) { |
1075 |
| - rightDouble = convertToDouble(right, castToJavaDoubleNode, getRaiseNode()); |
1076 |
| - } else { |
| 995 | + Object objRight = convertToDouble(right, castToJavaDoubleNode); |
| 996 | + if (objRight == PNotImplemented.NOT_IMPLEMENTED) { |
1077 | 997 | return PNotImplemented.NOT_IMPLEMENTED;
|
1078 | 998 | }
|
| 999 | + |
| 1000 | + double leftDouble = (double) objLeft; |
| 1001 | + double rightDouble = (double) objRight; |
1079 | 1002 | return doDD(leftDouble, rightDouble);
|
1080 | 1003 | }
|
1081 | 1004 | }
|
|
0 commit comments