|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.modules.cext;
|
42 | 42 |
|
| 43 | +import static com.oracle.graal.python.builtins.modules.cext.PythonCextBytesBuiltins.PYTHON_CEXT_BYTES; |
43 | 44 | 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; |
44 | 47 | import static com.oracle.graal.python.builtins.modules.cext.PythonCextSetBuiltins.PYTHON_CEXT_SET;
|
45 | 48 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
|
46 | 49 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
|
|
108 | 111 | import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
|
109 | 112 | import com.oracle.graal.python.builtins.modules.SysModuleBuiltins.InternNode;
|
110 | 113 | 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; |
113 | 114 | import com.oracle.graal.python.builtins.objects.PNone;
|
114 | 115 | import com.oracle.graal.python.builtins.objects.PNotImplemented;
|
115 | 116 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
|
|
225 | 226 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
226 | 227 | import com.oracle.graal.python.builtins.objects.ellipsis.PEllipsis;
|
227 | 228 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
228 |
| -import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins.IntNode; |
229 | 229 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
230 | 230 | import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference;
|
231 | 231 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
|
234 | 234 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
235 | 235 | import com.oracle.graal.python.builtins.objects.function.Signature;
|
236 | 236 | import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
|
237 |
| -import com.oracle.graal.python.builtins.objects.ints.IntBuiltins.NegNode; |
238 | 237 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
239 | 238 | import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
|
240 | 239 | import com.oracle.graal.python.builtins.objects.list.ListBuiltins;
|
|
246 | 245 | import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
|
247 | 246 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
248 | 247 | import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
|
| 248 | +import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; |
249 | 249 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
250 | 250 | import com.oracle.graal.python.builtins.objects.str.NativeCharSequence;
|
251 | 251 | import com.oracle.graal.python.builtins.objects.str.PString;
|
@@ -429,19 +429,23 @@ public void postInitialize(Python3Core core) {
|
429 | 429 | PythonModule cext = core.lookupBuiltinModule(PYTHON_CEXT);
|
430 | 430 | addModuleDict(cext, PYTHON_CEXT_BYTES, core);
|
431 | 431 | addModuleDict(cext, PYTHON_CEXT_DICT, core);
|
| 432 | + addModuleDict(cext, PYTHON_CEXT_LONG, core); |
432 | 433 | addModuleDict(cext, PYTHON_CEXT_LIST, core);
|
433 | 434 | addModuleDict(cext, PYTHON_CEXT_SET, core);
|
434 | 435 | }
|
435 | 436 |
|
436 | 437 | 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); |
439 | 440 | HashingStorageIterable<Object> keys = dict.keys();
|
440 | 441 | HashingStorageIterator<Object> it = keys.iterator();
|
441 | 442 | while (it.hasNext()) {
|
442 | 443 | Object key = it.next();
|
443 | 444 | 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 | + } |
445 | 449 | }
|
446 | 450 | }
|
447 | 451 |
|
@@ -507,6 +511,7 @@ Object run(VirtualFrame frame, Object o) {
|
507 | 511 | public abstract static class PyErrorHandlerNode extends PythonUnaryBuiltinNode {
|
508 | 512 | @Specialization
|
509 | 513 | Object run(PythonModule cextPython) {
|
| 514 | + System.err.println("+++ Py_ErrorHandler " + cextPython); |
510 | 515 | return ((PythonCextBuiltins) cextPython.getBuiltins()).errorHandler;
|
511 | 516 | }
|
512 | 517 | }
|
@@ -777,149 +782,7 @@ public Object values(Object obj) {
|
777 | 782 | return PNone.NONE;
|
778 | 783 | }
|
779 | 784 | }
|
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 | + |
923 | 786 | ///////////// float /////////////
|
924 | 787 |
|
925 | 788 | @Builtin(name = "PyFloat_FromDouble", minNumOfPositionalArgs = 1)
|
|
0 commit comments