|
119 | 119 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
120 | 120 | import com.oracle.truffle.api.dsl.Fallback;
|
121 | 121 | import com.oracle.truffle.api.dsl.GenerateCached;
|
| 122 | +import com.oracle.truffle.api.dsl.GenerateInline; |
122 | 123 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
123 | 124 | import com.oracle.truffle.api.dsl.NodeFactory;
|
124 | 125 | import com.oracle.truffle.api.dsl.Specialization;
|
@@ -729,69 +730,68 @@ private static BigInteger toBigInteger(double d) {
|
729 | 730 | }
|
730 | 731 | }
|
731 | 732 |
|
| 733 | + @GenerateInline |
732 | 734 | @GenerateCached(false)
|
733 |
| - public abstract static class AbstractComparisonNode extends PythonBinaryBuiltinNode { |
| 735 | + public abstract static class ComparisonHelperNode extends Node { |
734 | 736 |
|
735 |
| - protected abstract boolean op(double a, double b); |
| 737 | + @FunctionalInterface |
| 738 | + interface Op { |
| 739 | + boolean compute(double a, double b); |
| 740 | + } |
| 741 | + |
| 742 | + abstract Object execute(Node inliningTarget, Object left, Object right, Op op); |
736 | 743 |
|
737 | 744 | @Specialization
|
738 |
| - boolean doDD(double a, double b) { |
739 |
| - return op(a, b); |
| 745 | + static boolean doDD(double a, double b, Op op) { |
| 746 | + return op.compute(a, b); |
740 | 747 | }
|
741 | 748 |
|
742 | 749 | @Specialization
|
743 |
| - boolean doDI(double a, int b) { |
744 |
| - return op(a, b); |
| 750 | + static boolean doDI(double a, int b, Op op) { |
| 751 | + return op.compute(a, b); |
745 | 752 | }
|
746 | 753 |
|
747 | 754 | @Specialization(guards = "check.execute(inliningTarget, bObj)", replaces = "doDD", limit = "1")
|
748 |
| - @SuppressWarnings("truffle-static-method") |
749 |
| - boolean doOO(Object aObj, Object bObj, |
750 |
| - @Bind("this") Node inliningTarget, |
| 755 | + static boolean doOO(Node inliningTarget, Object aObj, Object bObj, Op op, |
751 | 756 | @SuppressWarnings("unused") @Cached PyFloatCheckNode check,
|
752 | 757 | @Exclusive @Cached CastToJavaDoubleNode cast) {
|
753 | 758 | double a = castToDoubleChecked(inliningTarget, aObj, cast);
|
754 | 759 | double b = castToDoubleChecked(inliningTarget, bObj, cast);
|
755 |
| - return op(a, b); |
| 760 | + return op.compute(a, b); |
756 | 761 | }
|
757 | 762 |
|
758 | 763 | @Specialization(replaces = "doDI")
|
759 |
| - boolean doOI(Object aObj, int b, |
760 |
| - @Bind("this") Node inliningTarget, |
| 764 | + static boolean doOI(Node inliningTarget, Object aObj, int b, Op op, |
761 | 765 | @Shared @Cached CastToJavaDoubleNode cast) {
|
762 | 766 | double a = castToDoubleChecked(inliningTarget, aObj, cast);
|
763 |
| - return op(a, b); |
| 767 | + return op.compute(a, b); |
764 | 768 | }
|
765 | 769 |
|
766 | 770 | @Specialization
|
767 |
| - @SuppressWarnings("truffle-static-method") |
768 |
| - boolean doOL(Object aObj, long b, |
769 |
| - @Bind("this") Node inliningTarget, |
| 771 | + static boolean doOL(Node inliningTarget, Object aObj, long b, Op op, |
770 | 772 | @Exclusive @Cached CastToJavaDoubleNode cast,
|
771 | 773 | @Cached InlinedConditionProfile longFitsToDoubleProfile) {
|
772 | 774 | double a = castToDoubleChecked(inliningTarget, aObj, cast);
|
773 |
| - return op(compareDoubleToLong(inliningTarget, a, b, longFitsToDoubleProfile), 0.0); |
| 775 | + return op.compute(compareDoubleToLong(inliningTarget, a, b, longFitsToDoubleProfile), 0.0); |
774 | 776 | }
|
775 | 777 |
|
776 | 778 | @Specialization
|
777 |
| - boolean doOPInt(Object aObj, PInt b, |
778 |
| - @Bind("this") Node inliningTarget, |
| 779 | + static boolean doOPInt(Node inliningTarget, Object aObj, PInt b, Op op, |
779 | 780 | @Shared @Cached CastToJavaDoubleNode cast) {
|
780 | 781 | double a = castToDoubleChecked(inliningTarget, aObj, cast);
|
781 |
| - return op(compareDoubleToLargeInt(a, b), 0.0); |
| 782 | + return op.compute(compareDoubleToLargeInt(a, b), 0.0); |
782 | 783 | }
|
783 | 784 |
|
784 | 785 | @Specialization
|
785 |
| - boolean doOB(Object aObj, boolean b, |
786 |
| - @Bind("this") Node inliningTarget, |
| 786 | + static boolean doOB(Node inliningTarget, Object aObj, boolean b, Op op, |
787 | 787 | @Shared @Cached CastToJavaDoubleNode cast) {
|
788 | 788 | double a = castToDoubleChecked(inliningTarget, aObj, cast);
|
789 |
| - return op(a, b ? 1 : 0); |
| 789 | + return op.compute(a, b ? 1 : 0); |
790 | 790 | }
|
791 | 791 |
|
792 | 792 | @Fallback
|
793 | 793 | @SuppressWarnings("unused")
|
794 |
| - static PNotImplemented fallback(Object a, Object b) { |
| 794 | + static PNotImplemented fallback(Object a, Object b, Op op) { |
795 | 795 | return PNotImplemented.NOT_IMPLEMENTED;
|
796 | 796 | }
|
797 | 797 |
|
@@ -833,55 +833,67 @@ private static double compareUsingBigDecimal(double v, BigInteger w) {
|
833 | 833 |
|
834 | 834 | @Builtin(name = J___EQ__, minNumOfPositionalArgs = 2)
|
835 | 835 | @GenerateNodeFactory
|
836 |
| - public abstract static class EqNode extends AbstractComparisonNode { |
837 |
| - @Override |
838 |
| - protected boolean op(double a, double b) { |
839 |
| - return a == b; |
| 836 | + public abstract static class EqNode extends PythonBinaryBuiltinNode { |
| 837 | + @Specialization |
| 838 | + static Object doIt(double left, double right, |
| 839 | + @Bind("this") Node inliningTarget, |
| 840 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 841 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a == b); |
840 | 842 | }
|
841 | 843 | }
|
842 | 844 |
|
843 | 845 | @Builtin(name = J___NE__, minNumOfPositionalArgs = 2)
|
844 | 846 | @GenerateNodeFactory
|
845 |
| - abstract static class NeNode extends AbstractComparisonNode { |
846 |
| - @Override |
847 |
| - protected boolean op(double a, double b) { |
848 |
| - return a != b; |
| 847 | + abstract static class NeNode extends PythonBinaryBuiltinNode { |
| 848 | + @Specialization |
| 849 | + static Object doIt(double left, double right, |
| 850 | + @Bind("this") Node inliningTarget, |
| 851 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 852 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a != b); |
849 | 853 | }
|
850 | 854 | }
|
851 | 855 |
|
852 | 856 | @Builtin(name = J___LT__, minNumOfPositionalArgs = 2)
|
853 | 857 | @GenerateNodeFactory
|
854 |
| - public abstract static class LtNode extends AbstractComparisonNode { |
855 |
| - @Override |
856 |
| - protected boolean op(double a, double b) { |
857 |
| - return a < b; |
| 858 | + public abstract static class LtNode extends PythonBinaryBuiltinNode { |
| 859 | + @Specialization |
| 860 | + static Object doIt(double left, double right, |
| 861 | + @Bind("this") Node inliningTarget, |
| 862 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 863 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a < b); |
858 | 864 | }
|
859 | 865 | }
|
860 | 866 |
|
861 | 867 | @Builtin(name = J___LE__, minNumOfPositionalArgs = 2)
|
862 | 868 | @GenerateNodeFactory
|
863 |
| - public abstract static class LeNode extends AbstractComparisonNode { |
864 |
| - @Override |
865 |
| - protected boolean op(double a, double b) { |
866 |
| - return a <= b; |
| 869 | + public abstract static class LeNode extends PythonBinaryBuiltinNode { |
| 870 | + @Specialization |
| 871 | + static Object doIt(double left, double right, |
| 872 | + @Bind("this") Node inliningTarget, |
| 873 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 874 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a <= b); |
867 | 875 | }
|
868 | 876 | }
|
869 | 877 |
|
870 | 878 | @Builtin(name = J___GT__, minNumOfPositionalArgs = 2)
|
871 | 879 | @GenerateNodeFactory
|
872 |
| - public abstract static class GtNode extends AbstractComparisonNode { |
873 |
| - @Override |
874 |
| - protected boolean op(double a, double b) { |
875 |
| - return a > b; |
| 880 | + public abstract static class GtNode extends PythonBinaryBuiltinNode { |
| 881 | + @Specialization |
| 882 | + static Object doIt(double left, double right, |
| 883 | + @Bind("this") Node inliningTarget, |
| 884 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 885 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a > b); |
876 | 886 | }
|
877 | 887 | }
|
878 | 888 |
|
879 | 889 | @Builtin(name = J___GE__, minNumOfPositionalArgs = 2)
|
880 | 890 | @GenerateNodeFactory
|
881 |
| - public abstract static class GeNode extends AbstractComparisonNode { |
882 |
| - @Override |
883 |
| - protected boolean op(double a, double b) { |
884 |
| - return a >= b; |
| 891 | + public abstract static class GeNode extends PythonBinaryBuiltinNode { |
| 892 | + @Specialization |
| 893 | + static Object doIt(double left, double right, |
| 894 | + @Bind("this") Node inliningTarget, |
| 895 | + @Cached ComparisonHelperNode comparisonHelperNode) { |
| 896 | + return comparisonHelperNode.execute(inliningTarget, left, right, (a, b) -> a >= b); |
885 | 897 | }
|
886 | 898 | }
|
887 | 899 |
|
|
0 commit comments