|
53 | 53 | import com.oracle.graal.python.builtins.objects.cext.CExtNodes.MaterializeDelegateNode; |
54 | 54 | import com.oracle.graal.python.builtins.objects.cext.CExtNodes.ToJavaNode; |
55 | 55 | import com.oracle.graal.python.builtins.objects.cext.CExtNodes.ToSulongNode; |
56 | | -import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.BoolNativeWrapper; |
57 | 56 | import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.DynamicObjectNativeWrapper; |
| 57 | +import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PrimitiveNativeWrapper; |
58 | 58 | import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PySequenceArrayWrapper; |
59 | 59 | import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PyUnicodeData; |
60 | 60 | import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PyUnicodeState; |
|
65 | 65 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.GetSulongTypeNodeGen; |
66 | 66 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.InvalidateNativeObjectsAllManagedNodeGen; |
67 | 67 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.PAsPointerNodeGen; |
| 68 | +import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.PGetDynamicTypeNodeGen; |
68 | 69 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.ReadNativeMemberNodeGen; |
69 | 70 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.ToPyObjectNodeGen; |
70 | 71 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.WriteNativeMemberNodeGen; |
@@ -140,12 +141,57 @@ public class PythonObjectNativeWrapperMR { |
140 | 141 | @SuppressWarnings("unknown-message") |
141 | 142 | @Resolve(message = "com.oracle.truffle.llvm.spi.GetDynamicType") |
142 | 143 | abstract static class GetDynamicTypeNode extends Node { |
| 144 | + @Child private PGetDynamicTypeNode getDynamicTypeNode = PGetDynamicTypeNode.create(); |
| 145 | + |
| 146 | + public Object access(PythonNativeWrapper object) { |
| 147 | + return getDynamicTypeNode.execute(object); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + abstract static class PGetDynamicTypeNode extends PNodeWithContext { |
143 | 152 | @Child private GetLazyClassNode getLazyClassNode = GetLazyClassNode.create(); |
144 | 153 | @Child private GetSulongTypeNode getSulongTypeNode = GetSulongTypeNode.create(); |
145 | 154 | @Child private AsPythonObjectNode getDelegate = AsPythonObjectNode.create(); |
146 | 155 |
|
147 | | - public Object access(PythonNativeWrapper object) { |
148 | | - return getSulongTypeNode.execute(getLazyClassNode.execute(getDelegate.execute(object))); |
| 156 | + public abstract Object execute(PythonNativeWrapper obj); |
| 157 | + |
| 158 | + @Specialization(guards = "obj.isIntLike()") |
| 159 | + Object doIntLike(@SuppressWarnings("unused") PrimitiveNativeWrapper obj, |
| 160 | + @Cached("getLongobjectType()") Object cachedSulongType) { |
| 161 | + return cachedSulongType; |
| 162 | + } |
| 163 | + |
| 164 | + @Specialization(guards = "obj.isBool()") |
| 165 | + Object doBool(@SuppressWarnings("unused") PrimitiveNativeWrapper obj, |
| 166 | + @Cached("getBoolobjectType()") Object cachedSulongType) { |
| 167 | + return cachedSulongType; |
| 168 | + } |
| 169 | + |
| 170 | + @Specialization(guards = "obj.isDouble()") |
| 171 | + Object doDouble(@SuppressWarnings("unused") PrimitiveNativeWrapper obj, |
| 172 | + @Cached("getFloatobjectType()") Object cachedSulongType) { |
| 173 | + return cachedSulongType; |
| 174 | + } |
| 175 | + |
| 176 | + @Specialization |
| 177 | + Object doGeneric(PythonNativeWrapper obj) { |
| 178 | + return getSulongTypeNode.execute(getLazyClassNode.execute(getDelegate.execute(obj))); |
| 179 | + } |
| 180 | + |
| 181 | + protected Object getLongobjectType() { |
| 182 | + return getSulongTypeNode.execute(PythonBuiltinClassType.PInt); |
| 183 | + } |
| 184 | + |
| 185 | + protected Object getBoolobjectType() { |
| 186 | + return getSulongTypeNode.execute(PythonBuiltinClassType.Boolean); |
| 187 | + } |
| 188 | + |
| 189 | + protected Object getFloatobjectType() { |
| 190 | + return getSulongTypeNode.execute(PythonBuiltinClassType.PFloat); |
| 191 | + } |
| 192 | + |
| 193 | + public static PGetDynamicTypeNode create() { |
| 194 | + return PGetDynamicTypeNodeGen.create(); |
149 | 195 | } |
150 | 196 | } |
151 | 197 |
|
@@ -973,17 +1019,17 @@ abstract static class PAsPointerNode extends PNodeWithContext { |
973 | 1019 |
|
974 | 1020 | public abstract long execute(PythonNativeWrapper o); |
975 | 1021 |
|
976 | | - @Specialization(guards = "!obj.isNative()") |
977 | | - long doBoolNotNative(BoolNativeWrapper obj, |
| 1022 | + @Specialization(guards = {"obj.isBool()", "!obj.isNative()"}) |
| 1023 | + long doBoolNotNative(PrimitiveNativeWrapper obj, |
978 | 1024 | @Cached("create()") MaterializeDelegateNode materializeNode) { |
979 | 1025 | // special case for True and False singletons |
980 | 1026 | PInt boxed = (PInt) materializeNode.execute(obj); |
981 | 1027 | assert obj.getNativePointer() == boxed.getNativeWrapper().getNativePointer(); |
982 | 1028 | return doFast(obj); |
983 | 1029 | } |
984 | 1030 |
|
985 | | - @Specialization(guards = "obj.isNative()") |
986 | | - long doBoolNative(BoolNativeWrapper obj) { |
| 1031 | + @Specialization(guards = {"obj.isBool()", "obj.isNative()"}) |
| 1032 | + long doBoolNative(PrimitiveNativeWrapper obj) { |
987 | 1033 | return doFast(obj); |
988 | 1034 | } |
989 | 1035 |
|
@@ -1011,7 +1057,7 @@ private long ensureLong(Object nativePointer) { |
1011 | 1057 | } |
1012 | 1058 |
|
1013 | 1059 | protected static boolean isBoolNativeWrapper(Object obj) { |
1014 | | - return obj instanceof BoolNativeWrapper; |
| 1060 | + return obj instanceof PrimitiveNativeWrapper && ((PrimitiveNativeWrapper) obj).isBool(); |
1015 | 1061 | } |
1016 | 1062 |
|
1017 | 1063 | public static PAsPointerNode create() { |
|
0 commit comments