Skip to content

Commit 791495f

Browse files
committed
moved PyNumber_XXX nodes from PythonCextBuiltins to PythonCextNumberBuiltins
1 parent 24dcf49 commit 791495f

File tree

3 files changed

+269
-181
lines changed

3 files changed

+269
-181
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@
110110
import com.oracle.graal.python.builtins.modules.bz2.BZ2DecompressorBuiltins;
111111
import com.oracle.graal.python.builtins.modules.bz2.BZ2ModuleBuiltins;
112112
import com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins;
113+
import com.oracle.graal.python.builtins.modules.cext.PythonCextComplexBuiltins;
113114
import com.oracle.graal.python.builtins.modules.cext.PythonCextDictBuiltins;
115+
import com.oracle.graal.python.builtins.modules.cext.PythonCextFloatBuiltins;
114116
import com.oracle.graal.python.builtins.modules.cext.PythonCextListBuiltins;
115117
import com.oracle.graal.python.builtins.modules.cext.PythonCextLongBuiltins;
118+
import com.oracle.graal.python.builtins.modules.cext.PythonCextNumberBuiltins;
116119
import com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins;
117120
import com.oracle.graal.python.builtins.modules.csv.CSVDialectBuiltins;
118121
import com.oracle.graal.python.builtins.modules.csv.CSVModuleBuiltins;
@@ -478,6 +481,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
478481
new PythonCextFloatBuiltins(),
479482
new PythonCextListBuiltins(),
480483
new PythonCextLongBuiltins(),
484+
new PythonCextNumberBuiltins(),
481485
new PythonCextSetBuiltins(),
482486
new WeakRefModuleBuiltins(),
483487
new ReferenceTypeBuiltins(),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 2 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
5151
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.METH_CLASS;
5252
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.isClassOrStaticMethod;
53-
import static com.oracle.graal.python.nodes.ErrorMessages.BASE_MUST_BE;
5453
import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP;
5554
import static com.oracle.graal.python.nodes.ErrorMessages.P_OBJ_DOES_NOT_SUPPORT_ITEM_ASSIGMENT;
5655
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DOC__;
@@ -96,11 +95,6 @@
9695
import com.oracle.graal.python.builtins.PythonBuiltins;
9796
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.MappingproxyNode;
9897
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;
10498
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.TupleNode;
10599
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.ChrNode;
106100
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
@@ -110,6 +104,7 @@
110104
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
111105
import static com.oracle.graal.python.builtins.modules.cext.PythonCextComplexBuiltins.PYTHON_CEXT_COMPLEX;
112106
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;
113108
import com.oracle.graal.python.builtins.objects.PNone;
114109
import com.oracle.graal.python.builtins.objects.PNotImplemented;
115110
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
@@ -431,6 +426,7 @@ public void postInitialize(Python3Core core) {
431426
addModuleDict(cext, PYTHON_CEXT_FLOAT, core);
432427
addModuleDict(cext, PYTHON_CEXT_LONG, core);
433428
addModuleDict(cext, PYTHON_CEXT_LIST, core);
429+
addModuleDict(cext, PYTHON_CEXT_NUMBER, core);
434430
addModuleDict(cext, PYTHON_CEXT_SET, core);
435431
}
436432

@@ -783,181 +779,6 @@ public Object values(Object obj) {
783779
}
784780
}
785781

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-
961782
///////////// sequence /////////////
962783

963784
@Builtin(name = "PySequence_Tuple", minNumOfPositionalArgs = 1)

0 commit comments

Comments
 (0)