|
41 | 41 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__AND__;
|
42 | 42 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CONTAINS__;
|
43 | 43 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
| 44 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__GE__; |
| 45 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__GT__; |
44 | 46 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
|
45 | 47 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
|
| 48 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__LE__; |
| 49 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__LT__; |
| 50 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__NE__; |
46 | 51 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__OR__;
|
47 | 52 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SUB__;
|
48 | 53 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__XOR__;
|
|
65 | 70 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
66 | 71 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
67 | 72 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
| 73 | +import com.oracle.truffle.api.CompilerDirectives; |
68 | 74 | import com.oracle.truffle.api.dsl.Cached;
|
69 | 75 | import com.oracle.truffle.api.dsl.Fallback;
|
70 | 76 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
@@ -177,6 +183,36 @@ Object doGeneric(Object self, Object other) {
|
177 | 183 | }
|
178 | 184 | }
|
179 | 185 |
|
| 186 | + @Builtin(name = __NE__, fixedNumOfArguments = 2) |
| 187 | + @GenerateNodeFactory |
| 188 | + public abstract static class NeNode extends PythonBinaryBuiltinNode { |
| 189 | + @Child EqNode eqNode; |
| 190 | + |
| 191 | + private EqNode getEqNode() { |
| 192 | + if (eqNode == null) { |
| 193 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 194 | + eqNode = insert(DictViewBuiltinsFactory.EqNodeFactory.create()); |
| 195 | + } |
| 196 | + return eqNode; |
| 197 | + } |
| 198 | + |
| 199 | + @Specialization |
| 200 | + public boolean notEqual(PDictView self, PDictView other) { |
| 201 | + return !(Boolean) getEqNode().execute(self, other); |
| 202 | + } |
| 203 | + |
| 204 | + @Specialization |
| 205 | + public boolean notEqual(PDictView self, PBaseSet other) { |
| 206 | + return !(Boolean) getEqNode().execute(self, other); |
| 207 | + } |
| 208 | + |
| 209 | + @Fallback |
| 210 | + @SuppressWarnings("unused") |
| 211 | + Object doGeneric(Object self, Object other) { |
| 212 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 213 | + } |
| 214 | + } |
| 215 | + |
180 | 216 | @Builtin(name = __SUB__, fixedNumOfArguments = 2)
|
181 | 217 | @GenerateNodeFactory
|
182 | 218 | abstract static class SubNode extends PythonBinaryBuiltinNode {
|
@@ -316,4 +352,134 @@ PBaseSet doItemsView(PDictItemsView self, PDictItemsView other,
|
316 | 352 | return factory().createSet(xorNode.execute(selfSet.getDictStorage(), otherSet.getDictStorage()));
|
317 | 353 | }
|
318 | 354 | }
|
| 355 | + |
| 356 | + @Builtin(name = __LE__, fixedNumOfArguments = 2) |
| 357 | + @GenerateNodeFactory |
| 358 | + abstract static class LessEqualNode extends PythonBinaryBuiltinNode { |
| 359 | + @Specialization |
| 360 | + boolean lessEqual(PDictKeysView self, PBaseSet other, |
| 361 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode) { |
| 362 | + return isSubsetNode.execute(self.getDict().getDictStorage(), other.getDictStorage()); |
| 363 | + } |
| 364 | + |
| 365 | + @Specialization |
| 366 | + boolean lessEqual(PDictKeysView self, PDictKeysView other, |
| 367 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode) { |
| 368 | + return isSubsetNode.execute(self.getDict().getDictStorage(), other.getDict().getDictStorage()); |
| 369 | + } |
| 370 | + |
| 371 | + @Specialization |
| 372 | + boolean lessEqual(PDictItemsView self, PBaseSet other, |
| 373 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode, |
| 374 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode) { |
| 375 | + PSet selfSet = constructSetNode.executeWith(self); |
| 376 | + return isSubsetNode.execute(selfSet.getDictStorage(), other.getDictStorage()); |
| 377 | + } |
| 378 | + |
| 379 | + @Specialization |
| 380 | + boolean lessEqual(PDictItemsView self, PDictItemsView other, |
| 381 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode, |
| 382 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode) { |
| 383 | + PSet selfSet = constructSetNode.executeWith(self); |
| 384 | + PSet otherSet = constructSetNode.executeWith(other); |
| 385 | + return isSubsetNode.execute(selfSet.getDictStorage(), otherSet.getDictStorage()); |
| 386 | + } |
| 387 | + } |
| 388 | + |
| 389 | + @Builtin(name = __GE__, fixedNumOfArguments = 2) |
| 390 | + @GenerateNodeFactory |
| 391 | + abstract static class GreaterEqualNode extends PythonBinaryBuiltinNode { |
| 392 | + @Specialization |
| 393 | + boolean greaterEqual(PDictKeysView self, PBaseSet other, |
| 394 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) { |
| 395 | + return isSupersetNode.execute(self.getDict().getDictStorage(), other.getDictStorage()); |
| 396 | + } |
| 397 | + |
| 398 | + @Specialization |
| 399 | + boolean greaterEqual(PDictKeysView self, PDictKeysView other, |
| 400 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) { |
| 401 | + return isSupersetNode.execute(self.getDict().getDictStorage(), other.getDict().getDictStorage()); |
| 402 | + } |
| 403 | + |
| 404 | + @Specialization |
| 405 | + boolean greaterEqual(PDictItemsView self, PBaseSet other, |
| 406 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode, |
| 407 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode) { |
| 408 | + PSet selfSet = constructSetNode.executeWith(self); |
| 409 | + return isSupersetNode.execute(selfSet.getDictStorage(), other.getDictStorage()); |
| 410 | + } |
| 411 | + |
| 412 | + @Specialization |
| 413 | + boolean greaterEqual(PDictItemsView self, PDictItemsView other, |
| 414 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode, |
| 415 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode) { |
| 416 | + PSet selfSet = constructSetNode.executeWith(self); |
| 417 | + PSet otherSet = constructSetNode.executeWith(other); |
| 418 | + return isSupersetNode.execute(selfSet.getDictStorage(), otherSet.getDictStorage()); |
| 419 | + } |
| 420 | + } |
| 421 | + |
| 422 | + @Builtin(name = __LT__, fixedNumOfArguments = 2) |
| 423 | + @GenerateNodeFactory |
| 424 | + abstract static class LessThanNode extends PythonBinaryBuiltinNode { |
| 425 | + @Child LessEqualNode lessEqualNode; |
| 426 | + |
| 427 | + private LessEqualNode getLessEqualNode() { |
| 428 | + if (lessEqualNode == null) { |
| 429 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 430 | + lessEqualNode = insert(DictViewBuiltinsFactory.LessEqualNodeFactory.create()); |
| 431 | + } |
| 432 | + return lessEqualNode; |
| 433 | + } |
| 434 | + |
| 435 | + @Specialization |
| 436 | + boolean isLessThan(PDictView self, PBaseSet other, |
| 437 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 438 | + if (sizeProfile.profile(self.size() >= other.size())) { |
| 439 | + return false; |
| 440 | + } |
| 441 | + return (Boolean) getLessEqualNode().execute(self, other); |
| 442 | + } |
| 443 | + |
| 444 | + @Specialization |
| 445 | + boolean isLessThan(PDictView self, PDictView other, |
| 446 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 447 | + if (sizeProfile.profile(self.size() >= other.size())) { |
| 448 | + return false; |
| 449 | + } |
| 450 | + return (Boolean) getLessEqualNode().execute(self, other); |
| 451 | + } |
| 452 | + } |
| 453 | + |
| 454 | + @Builtin(name = __GT__, fixedNumOfArguments = 2) |
| 455 | + @GenerateNodeFactory |
| 456 | + abstract static class GreaterThanNode extends PythonBinaryBuiltinNode { |
| 457 | + @Child GreaterEqualNode greaterEqualNode; |
| 458 | + |
| 459 | + private GreaterEqualNode getGreaterEqualNode() { |
| 460 | + if (greaterEqualNode == null) { |
| 461 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 462 | + greaterEqualNode = insert(DictViewBuiltinsFactory.GreaterEqualNodeFactory.create()); |
| 463 | + } |
| 464 | + return greaterEqualNode; |
| 465 | + } |
| 466 | + |
| 467 | + @Specialization |
| 468 | + boolean isGreaterThan(PDictView self, PBaseSet other, |
| 469 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 470 | + if (sizeProfile.profile(self.size() <= other.size())) { |
| 471 | + return false; |
| 472 | + } |
| 473 | + return (Boolean) getGreaterEqualNode().execute(self, other); |
| 474 | + } |
| 475 | + |
| 476 | + @Specialization |
| 477 | + boolean isGreaterThan(PDictView self, PDictView other, |
| 478 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 479 | + if (sizeProfile.profile(self.size() <= other.size())) { |
| 480 | + return false; |
| 481 | + } |
| 482 | + return (Boolean) getGreaterEqualNode().execute(self, other); |
| 483 | + } |
| 484 | + } |
319 | 485 | }
|
0 commit comments