Skip to content

Commit ef1038e

Browse files
committed
moved PyLong_XXX nodes from PythonCextBuiltins to PythonCextLongBuiltins
1 parent eab019c commit ef1038e

File tree

4 files changed

+242
-151
lines changed

4 files changed

+242
-151
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
import com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins;
113113
import com.oracle.graal.python.builtins.modules.cext.PythonCextDictBuiltins;
114114
import com.oracle.graal.python.builtins.modules.cext.PythonCextListBuiltins;
115+
import com.oracle.graal.python.builtins.modules.cext.PythonCextLongBuiltins;
115116
import com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins;
116117
import com.oracle.graal.python.builtins.modules.csv.CSVDialectBuiltins;
117118
import com.oracle.graal.python.builtins.modules.csv.CSVModuleBuiltins;
@@ -474,6 +475,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
474475
new PythonCextBytesBuiltins(),
475476
new PythonCextDictBuiltins(),
476477
new PythonCextListBuiltins(),
478+
new PythonCextLongBuiltins(),
477479
new PythonCextSetBuiltins(),
478480
new WeakRefModuleBuiltins(),
479481
new ReferenceTypeBuiltins(),

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

Lines changed: 13 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules.cext;
4242

43+
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins.PYTHON_CEXT_BYTES;
4344
import static com.oracle.graal.python.builtins.modules.cext.PythonCextDictBuiltins.PYTHON_CEXT_DICT;
45+
import static com.oracle.graal.python.builtins.modules.cext.PythonCextListBuiltins.PYTHON_CEXT_LIST;
46+
import static com.oracle.graal.python.builtins.modules.cext.PythonCextLongBuiltins.PYTHON_CEXT_LONG;
4447
import static com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins.PYTHON_CEXT_SET;
4548
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
4649
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
@@ -108,8 +111,6 @@
108111
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
109112
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins.InternNode;
110113
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
111-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins.PYTHON_CEXT_BYTES;
112-
import static com.oracle.graal.python.builtins.modules.cext.PythonCextListBuiltins.PYTHON_CEXT_LIST;
113114
import com.oracle.graal.python.builtins.objects.PNone;
114115
import com.oracle.graal.python.builtins.objects.PNotImplemented;
115116
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
@@ -225,7 +226,6 @@
225226
import com.oracle.graal.python.builtins.objects.dict.PDict;
226227
import com.oracle.graal.python.builtins.objects.ellipsis.PEllipsis;
227228
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
228-
import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins.IntNode;
229229
import com.oracle.graal.python.builtins.objects.frame.PFrame;
230230
import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference;
231231
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -234,7 +234,6 @@
234234
import com.oracle.graal.python.builtins.objects.function.PKeyword;
235235
import com.oracle.graal.python.builtins.objects.function.Signature;
236236
import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
237-
import com.oracle.graal.python.builtins.objects.ints.IntBuiltins.NegNode;
238237
import com.oracle.graal.python.builtins.objects.ints.PInt;
239238
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
240239
import com.oracle.graal.python.builtins.objects.list.ListBuiltins;
@@ -246,6 +245,7 @@
246245
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
247246
import com.oracle.graal.python.builtins.objects.module.PythonModule;
248247
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
248+
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
249249
import com.oracle.graal.python.builtins.objects.object.PythonObject;
250250
import com.oracle.graal.python.builtins.objects.str.NativeCharSequence;
251251
import com.oracle.graal.python.builtins.objects.str.PString;
@@ -429,19 +429,23 @@ public void postInitialize(Python3Core core) {
429429
PythonModule cext = core.lookupBuiltinModule(PYTHON_CEXT);
430430
addModuleDict(cext, PYTHON_CEXT_BYTES, core);
431431
addModuleDict(cext, PYTHON_CEXT_DICT, core);
432+
addModuleDict(cext, PYTHON_CEXT_LONG, core);
432433
addModuleDict(cext, PYTHON_CEXT_LIST, core);
433434
addModuleDict(cext, PYTHON_CEXT_SET, core);
434435
}
435436

436437
private void addModuleDict(PythonModule cext, String module, Python3Core core) {
437-
PythonModule cext_dict = core.lookupBuiltinModule(module);
438-
PDict dict = GetDictIfExistsNodeGen.getUncached().execute(cext_dict);
438+
PythonModule cext_module = core.lookupBuiltinModule(module);
439+
PDict dict = GetDictIfExistsNodeGen.getUncached().execute(cext_module);
439440
HashingStorageIterable<Object> keys = dict.keys();
440441
HashingStorageIterator<Object> it = keys.iterator();
441442
while (it.hasNext()) {
442443
Object key = it.next();
443444
Object value = dict.getItem(key);
444-
cext.setAttribute(key, value);
445+
if(value instanceof PythonBuiltinObject) {
446+
assert cext.getAttribute(key) == PNone.NO_VALUE || cext.getAttribute(key) == null : "python_cext dict already contains value " + cext.getAttribute(key) + " for key " + key;
447+
cext.setAttribute(key, value);
448+
}
445449
}
446450
}
447451

@@ -507,6 +511,7 @@ Object run(VirtualFrame frame, Object o) {
507511
public abstract static class PyErrorHandlerNode extends PythonUnaryBuiltinNode {
508512
@Specialization
509513
Object run(PythonModule cextPython) {
514+
System.err.println("+++ Py_ErrorHandler " + cextPython);
510515
return ((PythonCextBuiltins) cextPython.getBuiltins()).errorHandler;
511516
}
512517
}
@@ -777,149 +782,7 @@ public Object values(Object obj) {
777782
return PNone.NONE;
778783
}
779784
}
780-
781-
///////////// long /////////////
782-
783-
@Builtin(name = "_PyLong_Sign", minNumOfPositionalArgs = 1)
784-
@GenerateNodeFactory
785-
abstract static class PyLongSignNode extends PythonUnaryBuiltinNode {
786-
787-
@SuppressWarnings("unused")
788-
@Specialization(guards = "n == 0")
789-
int sign(int n) {
790-
return 0;
791-
}
792-
793-
@SuppressWarnings("unused")
794-
@Specialization(guards = "n < 0")
795-
int signNeg(int n) {
796-
return -1;
797-
}
798-
799-
@SuppressWarnings("unused")
800-
@Specialization(guards = "n > 0")
801-
int signPos(int n) {
802-
return 1;
803-
}
804-
805-
@SuppressWarnings("unused")
806-
@Specialization(guards = "n == 0")
807-
int sign(long n) {
808-
return 0;
809-
}
810-
811-
@SuppressWarnings("unused")
812-
@Specialization(guards = "n < 0")
813-
int signNeg(long n) {
814-
return -1;
815-
}
816-
817-
@SuppressWarnings("unused")
818-
@Specialization(guards = "n > 0")
819-
int signPos(long n) {
820-
return 1;
821-
}
822-
823-
@SuppressWarnings("unused")
824-
@Specialization(guards = "b")
825-
int signTrue(boolean b) {
826-
return 1;
827-
}
828-
829-
@SuppressWarnings("unused")
830-
@Specialization(guards = "!b")
831-
int signFalse(boolean b) {
832-
return 0;
833-
}
834-
835-
@Specialization
836-
int sign(PInt n,
837-
@Cached BranchProfile zeroProfile,
838-
@Cached BranchProfile negProfile) {
839-
if (n.isNegative()) {
840-
negProfile.enter();
841-
return -1;
842-
} else if (n.isZero()) {
843-
zeroProfile.enter();
844-
return 0;
845-
} else {
846-
return 1;
847-
}
848-
}
849-
850-
@SuppressWarnings("unused")
851-
@Specialization(guards = {"!canBeInteger(obj)", "isPIntSubtype(frame, obj, getClassNode, isSubtypeNode)"})
852-
public Object signNative(VirtualFrame frame, Object obj,
853-
@Cached GetClassNode getClassNode,
854-
@Cached IsSubtypeNode isSubtypeNode) {
855-
// function returns int, but -1 is expected result for 'n < 0'
856-
throw CompilerDirectives.shouldNotReachHere("not yet implemented");
857-
}
858-
859-
@Specialization(guards = {"!isInteger(obj)", "!isPInt(obj)", "!isPIntSubtype(frame, obj,getClassNode,isSubtypeNode)"})
860-
public Object sign(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object obj,
861-
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
862-
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode) {
863-
// assert(PyLong_Check(v));
864-
throw CompilerDirectives.shouldNotReachHere();
865-
}
866-
867-
protected boolean isPIntSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
868-
return isSubtypeNode.execute(frame, getClassNode.execute(obj), PythonBuiltinClassType.PInt);
869-
}
870-
}
871-
872-
@Builtin(name = "PyLong_FromDouble", minNumOfPositionalArgs = 1)
873-
@GenerateNodeFactory
874-
abstract static class PyLongFromDoubleNode extends PythonUnaryBuiltinNode {
875-
876-
@Specialization
877-
Object fromDouble(VirtualFrame frame, double d,
878-
@Cached IntNode intNode,
879-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
880-
@Cached GetNativeNullNode getNativeNullNode) {
881-
try {
882-
return intNode.execute(frame, d);
883-
} catch (PException e) {
884-
transformExceptionToNativeNode.execute(e);
885-
return getNativeNullNode.execute();
886-
}
887-
}
888-
}
889-
890-
@Builtin(name = "PyLong_FromString", minNumOfPositionalArgs = 3)
891-
@TypeSystemReference(PythonTypes.class)
892-
@GenerateNodeFactory
893-
abstract static class PyLongFromStringNode extends PythonTernaryBuiltinNode {
894-
895-
@Specialization(guards = "negative == 0")
896-
Object fromString(VirtualFrame frame, String s, long base, @SuppressWarnings("unused") long negative,
897-
@Cached com.oracle.graal.python.builtins.modules.BuiltinConstructors.IntNode intNode,
898-
@Shared("transforEx") @Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
899-
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
900-
try {
901-
return intNode.executeWith(frame, s, base);
902-
} catch (PException e) {
903-
transformExceptionToNativeNode.execute(e);
904-
return getNativeNullNode.execute();
905-
}
906-
}
907-
908-
@Specialization(guards = "negative != 0")
909-
Object fromString(VirtualFrame frame, String s, long base, @SuppressWarnings("unused") long negative,
910-
@Cached com.oracle.graal.python.builtins.modules.BuiltinConstructors.IntNode intNode,
911-
@Cached NegNode negNode,
912-
@Shared("transforEx") @Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
913-
@Shared("nativeNull") @Cached GetNativeNullNode getNativeNullNode) {
914-
try {
915-
return negNode.execute(frame, intNode.executeWith(frame, s, base));
916-
} catch (PException e) {
917-
transformExceptionToNativeNode.execute(e);
918-
return getNativeNullNode.execute();
919-
}
920-
}
921-
}
922-
785+
923786
///////////// float /////////////
924787

925788
@Builtin(name = "PyFloat_FromDouble", minNumOfPositionalArgs = 1)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
@GenerateNodeFactory
8181
public class PythonCextBytesBuiltins extends PythonBuiltins {
8282

83-
public static final String PYTHON_CEXT_BYTES = "python_cext_BYTES";
83+
public static final String PYTHON_CEXT_BYTES = "python_cext_bytes";
8484

8585
@Override
8686
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {

0 commit comments

Comments
 (0)