|
6 | 6 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
|
7 | 7 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELITEM__;
|
8 | 8 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ENTER__;
|
| 9 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__; |
9 | 10 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EXIT__;
|
10 | 11 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
|
11 | 12 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
|
|
25 | 26 | import com.oracle.graal.python.builtins.modules.BuiltinConstructors;
|
26 | 27 | import com.oracle.graal.python.builtins.objects.PEllipsis;
|
27 | 28 | import com.oracle.graal.python.builtins.objects.PNone;
|
| 29 | +import com.oracle.graal.python.builtins.objects.PNotImplemented; |
28 | 30 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
|
29 | 31 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins.ExpectIntNode;
|
30 | 32 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins.SepExpectByteNode;
|
|
50 | 52 | import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
|
51 | 53 | import com.oracle.graal.python.nodes.subscript.SliceLiteralNode;
|
52 | 54 | import com.oracle.graal.python.runtime.AsyncHandler;
|
| 55 | +import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext; |
53 | 56 | import com.oracle.graal.python.runtime.PythonContext;
|
54 | 57 | import com.oracle.graal.python.runtime.PythonCore;
|
55 |
| -import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext; |
| 58 | +import com.oracle.graal.python.runtime.exception.PException; |
56 | 59 | import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
|
57 | 60 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
|
58 | 61 | import com.oracle.graal.python.util.PythonUtils;
|
59 | 62 | import com.oracle.truffle.api.CompilerDirectives;
|
60 | 63 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
61 | 64 | import com.oracle.truffle.api.dsl.Cached;
|
| 65 | +import com.oracle.truffle.api.dsl.Cached.Shared; |
| 66 | +import com.oracle.truffle.api.dsl.Fallback; |
62 | 67 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
63 | 68 | import com.oracle.truffle.api.dsl.NodeFactory;
|
64 | 69 | import com.oracle.truffle.api.dsl.Specialization;
|
65 |
| -import com.oracle.truffle.api.dsl.Cached.Shared; |
66 | 70 | import com.oracle.truffle.api.frame.VirtualFrame;
|
67 | 71 | import com.oracle.truffle.api.interop.ArityException;
|
68 | 72 | import com.oracle.truffle.api.interop.InteropLibrary;
|
@@ -218,7 +222,7 @@ Object setitem(VirtualFrame frame, IntrinsifiedPMemoryView self, PSlice slice, O
|
218 | 222 | if (self.getDimensions() != 1) {
|
219 | 223 | throw raise(NotImplementedError, ErrorMessages.MEMORYVIEW_SLICE_ASSIGNMENT_RESTRICTED_TO_DIM_1);
|
220 | 224 | }
|
221 |
| - IntrinsifiedPMemoryView srcView = createMemoryView.create(object); |
| 225 | + IntrinsifiedPMemoryView srcView = createMemoryView.execute(object); |
222 | 226 | IntrinsifiedPMemoryView destView = (IntrinsifiedPMemoryView) getItemNode.execute(frame, self, slice);
|
223 | 227 | // TODO format skip @
|
224 | 228 | if (srcView.getDimensions() != destView.getDimensions() || srcView.getBufferShape()[0] != destView.getBufferShape()[0] || !srcView.getFormatString().equals(destView.getFormatString())) {
|
@@ -257,6 +261,110 @@ private void checkReadonly(IntrinsifiedPMemoryView self) {
|
257 | 261 | }
|
258 | 262 | }
|
259 | 263 |
|
| 264 | + @Builtin(name = __EQ__, minNumOfPositionalArgs = 2) |
| 265 | + @GenerateNodeFactory |
| 266 | + public static abstract class EqNode extends PythonBinaryBuiltinNode { |
| 267 | + @Child private CExtNodes.PCallCapiFunction callCapiFunction; |
| 268 | + |
| 269 | + @Specialization |
| 270 | + boolean eq(VirtualFrame frame, IntrinsifiedPMemoryView self, IntrinsifiedPMemoryView other, |
| 271 | + @CachedLibrary(limit = "3") PythonObjectLibrary lib, |
| 272 | + @Cached MemoryViewNodes.ReadItemAtNode readSelf, |
| 273 | + @Cached MemoryViewNodes.ReadItemAtNode readOther) { |
| 274 | + if (self.isReleased() || other.isReleased()) { |
| 275 | + return self == other; |
| 276 | + } |
| 277 | + |
| 278 | + int ndim = self.getDimensions(); |
| 279 | + if (ndim != other.getDimensions()) { |
| 280 | + return false; |
| 281 | + } |
| 282 | + |
| 283 | + for (int i = 0; i < ndim; i++) { |
| 284 | + if (self.getBufferShape()[i] != other.getBufferShape()[i]) { |
| 285 | + return false; |
| 286 | + } |
| 287 | + if (self.getBufferShape()[i] == 0) { |
| 288 | + break; |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + // TODO CPython supports only limited set of typed for reading and writing, but |
| 293 | + // for equality comparisons, it supports all the struct module formats. Implement that |
| 294 | + |
| 295 | + if (ndim == 0) { |
| 296 | + Object selfItem = readSelf.execute(self, self.getBufferPointer(), 0); |
| 297 | + Object otherItem = readOther.execute(other, other.getBufferPointer(), 0); |
| 298 | + return lib.equalsWithFrame(selfItem, otherItem, lib, frame); |
| 299 | + } |
| 300 | + |
| 301 | + return recursive(lib, self, other, readSelf, readOther, 0, ndim, |
| 302 | + self.getBufferPointer(), self.getOffset(), other.getBufferPointer(), other.getOffset()); |
| 303 | + } |
| 304 | + |
| 305 | + @Specialization(guards = "!isMemoryView(other)") |
| 306 | + Object eq(VirtualFrame frame, IntrinsifiedPMemoryView self, Object other, |
| 307 | + @Cached BuiltinConstructors.MemoryViewNode memoryViewNode, |
| 308 | + @CachedLibrary(limit = "3") PythonObjectLibrary lib, |
| 309 | + @Cached MemoryViewNodes.ReadItemAtNode readSelf, |
| 310 | + @Cached MemoryViewNodes.ReadItemAtNode readOther) { |
| 311 | + IntrinsifiedPMemoryView memoryView; |
| 312 | + try { |
| 313 | + memoryView = memoryViewNode.execute(other); |
| 314 | + } catch (PException e) { |
| 315 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 316 | + } |
| 317 | + return eq(frame, self, memoryView, lib, readSelf, readOther); |
| 318 | + } |
| 319 | + |
| 320 | + @Fallback |
| 321 | + @SuppressWarnings("unused") |
| 322 | + static Object eq(Object self, Object other) { |
| 323 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 324 | + } |
| 325 | + |
| 326 | + private boolean recursive(PythonObjectLibrary lib, IntrinsifiedPMemoryView self, IntrinsifiedPMemoryView other, |
| 327 | + MemoryViewNodes.ReadItemAtNode readSelf, MemoryViewNodes.ReadItemAtNode readOther, |
| 328 | + int dim, int ndim, Object selfPtr, int selfOffset, Object otherPtr, int otherOffset) { |
| 329 | + for (int i = 0; i < self.getBufferShape()[dim]; i++) { |
| 330 | + Object selfXPtr = selfPtr; |
| 331 | + int selfXOffset = selfOffset; |
| 332 | + Object otherXPtr = otherPtr; |
| 333 | + int otherXOffset = otherOffset; |
| 334 | + if (self.getBufferSuboffsets() != null && self.getBufferSuboffsets()[dim] >= 0) { |
| 335 | + selfXPtr = getCallCapiFunction().call(NativeCAPISymbols.FUN_TRUFFLE_ADD_SUBOFFSET, selfPtr, selfOffset, self.getBufferSuboffsets()[dim], self.getLength()); |
| 336 | + selfXOffset = 0; |
| 337 | + } |
| 338 | + if (other.getBufferSuboffsets() != null && other.getBufferSuboffsets()[dim] >= 0) { |
| 339 | + otherXPtr = getCallCapiFunction().call(NativeCAPISymbols.FUN_TRUFFLE_ADD_SUBOFFSET, otherPtr, otherOffset, other.getBufferSuboffsets()[dim], other.getLength()); |
| 340 | + otherXOffset = 0; |
| 341 | + } |
| 342 | + if (dim == ndim - 1) { |
| 343 | + Object selfItem = readSelf.execute(self, selfXPtr, selfXOffset); |
| 344 | + Object otherItem = readOther.execute(other, otherXPtr, otherXOffset); |
| 345 | + if (!lib.equals(selfItem, otherItem, lib)) { |
| 346 | + return false; |
| 347 | + } |
| 348 | + } else { |
| 349 | + if (!recursive(lib, self, other, readSelf, readOther, dim + 1, ndim, selfXPtr, selfXOffset, otherXPtr, otherXOffset)) { |
| 350 | + return false; |
| 351 | + } |
| 352 | + } |
| 353 | + selfOffset += self.getBufferStrides()[dim]; |
| 354 | + otherOffset += other.getBufferStrides()[dim]; |
| 355 | + } |
| 356 | + return true; |
| 357 | + } |
| 358 | + |
| 359 | + private CExtNodes.PCallCapiFunction getCallCapiFunction() { |
| 360 | + if (callCapiFunction == null) { |
| 361 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 362 | + callCapiFunction = insert(CExtNodes.PCallCapiFunction.create()); |
| 363 | + } |
| 364 | + return callCapiFunction; |
| 365 | + } |
| 366 | + } |
| 367 | + |
260 | 368 | @Builtin(name = __DELITEM__, minNumOfPositionalArgs = 1)
|
261 | 369 | @GenerateNodeFactory
|
262 | 370 | public static abstract class DelItemNode extends PythonUnaryBuiltinNode {
|
|
0 commit comments