|
50 | 50 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
|
51 | 51 | import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.METH_CLASS;
|
52 | 52 | import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.isClassOrStaticMethod;
|
53 |
| -import static com.oracle.graal.python.nodes.ErrorMessages.BASE_MUST_BE; |
54 | 53 | import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP;
|
55 | 54 | import static com.oracle.graal.python.nodes.ErrorMessages.P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT;
|
56 | 55 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DOC__;
|
|
96 | 95 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
97 | 96 | import com.oracle.graal.python.builtins.modules.BuiltinConstructors.MappingproxyNode;
|
98 | 97 | import com.oracle.graal.python.builtins.modules.BuiltinConstructors.StrNode;
|
99 |
| -import com.oracle.graal.python.builtins.modules.BuiltinFunctions.AbsNode; |
100 |
| -import com.oracle.graal.python.builtins.modules.BuiltinFunctions.BinNode; |
101 |
| -import com.oracle.graal.python.builtins.modules.BuiltinFunctions.DivModNode; |
102 |
| -import com.oracle.graal.python.builtins.modules.BuiltinFunctions.HexNode; |
103 |
| -import com.oracle.graal.python.builtins.modules.BuiltinFunctions.OctNode; |
104 | 98 | import com.oracle.graal.python.builtins.modules.BuiltinConstructors.TupleNode;
|
105 | 99 | import com.oracle.graal.python.builtins.modules.BuiltinFunctions.ChrNode;
|
106 | 100 | import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
|
|
110 | 104 | import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
|
111 | 105 | import static com.oracle.graal.python.builtins.modules.cext.PythonCextComplexBuiltins.PYTHON_CEXT_COMPLEX;
|
112 | 106 | import static com.oracle.graal.python.builtins.modules.cext.PythonCextFloatBuiltins.PYTHON_CEXT_FLOAT;
|
| 107 | +import static com.oracle.graal.python.builtins.modules.cext.PythonCextNumberBuiltins.PYTHON_CEXT_NUMBER; |
113 | 108 | import com.oracle.graal.python.builtins.objects.PNone;
|
114 | 109 | import com.oracle.graal.python.builtins.objects.PNotImplemented;
|
115 | 110 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
|
@@ -431,6 +426,7 @@ public void postInitialize(Python3Core core) {
|
431 | 426 | addModuleDict(cext, PYTHON_CEXT_FLOAT, core);
|
432 | 427 | addModuleDict(cext, PYTHON_CEXT_LONG, core);
|
433 | 428 | addModuleDict(cext, PYTHON_CEXT_LIST, core);
|
| 429 | + addModuleDict(cext, PYTHON_CEXT_NUMBER, core); |
434 | 430 | addModuleDict(cext, PYTHON_CEXT_SET, core);
|
435 | 431 | }
|
436 | 432 |
|
@@ -783,181 +779,6 @@ public Object values(Object obj) {
|
783 | 779 | }
|
784 | 780 | }
|
785 | 781 |
|
786 |
| - ///////////// number ///////////// |
787 |
| - |
788 |
| - @Builtin(name = "PyNumber_Check", minNumOfPositionalArgs = 1) |
789 |
| - @TypeSystemReference(PythonTypes.class) |
790 |
| - @GenerateNodeFactory |
791 |
| - abstract static class PyNumberCheckNode extends PythonUnaryBuiltinNode { |
792 |
| - @Specialization |
793 |
| - Object check(VirtualFrame frame, Object obj, |
794 |
| - @Cached com.oracle.graal.python.lib.PyNumberCheckNode checkNode, |
795 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
796 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
797 |
| - try { |
798 |
| - return checkNode.execute(frame, obj); |
799 |
| - } catch (PException e) { |
800 |
| - transformExceptionToNativeNode.execute(e); |
801 |
| - return getNativeNullNode.execute(); |
802 |
| - } |
803 |
| - } |
804 |
| - } |
805 |
| - |
806 |
| - @Builtin(name = "PyNumber_Index", minNumOfPositionalArgs = 1) |
807 |
| - @GenerateNodeFactory |
808 |
| - abstract static class PyNumberIndexNode extends PythonUnaryBuiltinNode { |
809 |
| - @Specialization |
810 |
| - Object index(VirtualFrame frame, Object obj, |
811 |
| - @Cached com.oracle.graal.python.lib.PyNumberIndexNode indexNode, |
812 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
813 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
814 |
| - try { |
815 |
| - return indexNode.execute(frame, obj); |
816 |
| - } catch (PException e) { |
817 |
| - transformExceptionToNativeNode.execute(e); |
818 |
| - return getNativeNullNode.execute(); |
819 |
| - } |
820 |
| - } |
821 |
| - } |
822 |
| - |
823 |
| - @Builtin(name = "PyNumber_Long", minNumOfPositionalArgs = 1) |
824 |
| - @GenerateNodeFactory |
825 |
| - abstract static class PyNumberLongNode extends PythonUnaryBuiltinNode { |
826 |
| - |
827 |
| - @Specialization |
828 |
| - int nlong(int i) { |
829 |
| - return i; |
830 |
| - } |
831 |
| - |
832 |
| - @Specialization |
833 |
| - long nlong(long i) { |
834 |
| - return i; |
835 |
| - } |
836 |
| - |
837 |
| - @Fallback |
838 |
| - Object nlong(VirtualFrame frame, Object obj, |
839 |
| - @Cached com.oracle.graal.python.builtins.modules.BuiltinConstructors.IntNode intNode, |
840 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
841 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
842 |
| - try { |
843 |
| - return intNode.executeWith(frame, obj, PNone.NO_VALUE); |
844 |
| - } catch (PException e) { |
845 |
| - transformExceptionToNativeNode.execute(e); |
846 |
| - return getNativeNullNode.execute(); |
847 |
| - } |
848 |
| - } |
849 |
| - } |
850 |
| - |
851 |
| - @Builtin(name = "PyNumber_Absolute", minNumOfPositionalArgs = 1) |
852 |
| - @GenerateNodeFactory |
853 |
| - abstract static class PyNumberAbsoluteNode extends PythonUnaryBuiltinNode { |
854 |
| - @Specialization |
855 |
| - Object abs(VirtualFrame frame, Object obj, |
856 |
| - @Cached AbsNode absNode, |
857 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
858 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
859 |
| - try { |
860 |
| - return absNode.execute(frame, obj); |
861 |
| - } catch (PException e) { |
862 |
| - transformExceptionToNativeNode.execute(e); |
863 |
| - return getNativeNullNode.execute(); |
864 |
| - } |
865 |
| - } |
866 |
| - } |
867 |
| - |
868 |
| - @Builtin(name = "PyNumber_Divmod", minNumOfPositionalArgs = 2) |
869 |
| - @GenerateNodeFactory |
870 |
| - abstract static class PyNumberDivmodeNode extends PythonBinaryBuiltinNode { |
871 |
| - @Specialization |
872 |
| - Object div(VirtualFrame frame, Object a, Object b, |
873 |
| - @Cached DivModNode divNode, |
874 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
875 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
876 |
| - try { |
877 |
| - return divNode.execute(frame, a, b); |
878 |
| - } catch (PException e) { |
879 |
| - transformExceptionToNativeNode.execute(e); |
880 |
| - return getNativeNullNode.execute(); |
881 |
| - } |
882 |
| - } |
883 |
| - } |
884 |
| - |
885 |
| - @Builtin(name = "PyNumber_ToBase", minNumOfPositionalArgs = 2) |
886 |
| - @GenerateNodeFactory |
887 |
| - abstract static class PyNumberToBaseNode extends PythonBinaryBuiltinNode { |
888 |
| - @Specialization(guards = "base == 2") |
889 |
| - Object toBase(VirtualFrame frame, Object n, @SuppressWarnings("unused") int base, |
890 |
| - @Cached com.oracle.graal.python.lib.PyNumberIndexNode indexNode, |
891 |
| - @Cached BinNode binNode, |
892 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
893 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
894 |
| - try { |
895 |
| - Object i = indexNode.execute(frame, n); |
896 |
| - return binNode.execute(frame, i); |
897 |
| - } catch (PException e) { |
898 |
| - transformExceptionToNativeNode.execute(e); |
899 |
| - return getNativeNullNode.execute(); |
900 |
| - } |
901 |
| - } |
902 |
| - |
903 |
| - @Specialization(guards = "base == 8") |
904 |
| - Object toBase(VirtualFrame frame, Object n, @SuppressWarnings("unused") int base, |
905 |
| - @Cached OctNode octNode, |
906 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
907 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
908 |
| - try { |
909 |
| - return octNode.execute(frame, n); |
910 |
| - } catch (PException e) { |
911 |
| - transformExceptionToNativeNode.execute(e); |
912 |
| - return getNativeNullNode.execute(); |
913 |
| - } |
914 |
| - } |
915 |
| - |
916 |
| - @Specialization(guards = "base == 10") |
917 |
| - Object toBase(VirtualFrame frame, Object n, @SuppressWarnings("unused") int base, |
918 |
| - @Cached com.oracle.graal.python.lib.PyNumberIndexNode indexNode, |
919 |
| - @Cached StrNode strNode, |
920 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
921 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
922 |
| - try { |
923 |
| - Object i = indexNode.execute(frame, n); |
924 |
| - if (i instanceof Boolean) { |
925 |
| - i = ((boolean) i) ? 1 : 0; |
926 |
| - } |
927 |
| - return strNode.executeWith(frame, i); |
928 |
| - } catch (PException e) { |
929 |
| - transformExceptionToNativeNode.execute(e); |
930 |
| - return getNativeNullNode.execute(); |
931 |
| - } |
932 |
| - } |
933 |
| - |
934 |
| - @Specialization(guards = "base == 16") |
935 |
| - Object toBase(VirtualFrame frame, Object n, @SuppressWarnings("unused") int base, |
936 |
| - @Cached PyNumberIndexNode indexNode, |
937 |
| - @Cached HexNode hexNode, |
938 |
| - @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
939 |
| - @Cached GetNativeNullNode getNativeNullNode) { |
940 |
| - try { |
941 |
| - Object i = indexNode.execute(frame, n); |
942 |
| - return hexNode.execute(frame, i); |
943 |
| - } catch (PException e) { |
944 |
| - transformExceptionToNativeNode.execute(e); |
945 |
| - return getNativeNullNode.execute(); |
946 |
| - } |
947 |
| - } |
948 |
| - |
949 |
| - @Specialization(guards = "!checkBase(base)") |
950 |
| - Object toBase(VirtualFrame frame, @SuppressWarnings("unused") Object n, @SuppressWarnings("unused") int base, |
951 |
| - @Cached GetNativeNullNode getNativeNullNode, |
952 |
| - @Cached PRaiseNativeNode raiseNativeNode) { |
953 |
| - return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BASE_MUST_BE); |
954 |
| - } |
955 |
| - |
956 |
| - protected boolean checkBase(int base) { |
957 |
| - return base == 2 || base == 8 || base == 10 || base == 16; |
958 |
| - } |
959 |
| - } |
960 |
| - |
961 | 782 | ///////////// sequence /////////////
|
962 | 783 |
|
963 | 784 | @Builtin(name = "PySequence_Tuple", minNumOfPositionalArgs = 1)
|
|
0 commit comments