|
33 | 33 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
34 | 34 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
|
35 | 35 | import com.oracle.graal.python.nodes.BuiltinNames;
|
| 36 | +import com.oracle.graal.python.nodes.ErrorMessages; |
| 37 | +import com.oracle.graal.python.nodes.PRaiseNode; |
36 | 38 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
|
37 | 39 | import com.oracle.graal.python.runtime.PythonContext;
|
38 | 40 | import com.oracle.truffle.api.CompilerAsserts;
|
39 | 41 | import com.oracle.truffle.api.CompilerDirectives;
|
40 | 42 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
41 | 43 | import com.oracle.truffle.api.dsl.Cached;
|
| 44 | +import com.oracle.truffle.api.dsl.Cached.Shared; |
42 | 45 | import com.oracle.truffle.api.dsl.CachedContext;
|
43 | 46 | import com.oracle.truffle.api.dsl.Fallback;
|
44 | 47 | import com.oracle.truffle.api.dsl.Specialization;
|
@@ -414,116 +417,137 @@ public boolean hasMembers() {
|
414 | 417 |
|
415 | 418 | @ExportMessage
|
416 | 419 | public Object getMembers(boolean includeInternal,
|
417 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 420 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
418 | 421 | @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException {
|
419 | 422 | return lib.getMembers(context.getCore().lookupType(this), includeInternal);
|
420 | 423 | }
|
421 | 424 |
|
422 | 425 | @ExportMessage
|
423 | 426 | public boolean isMemberReadable(String key,
|
424 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 427 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
425 | 428 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
426 | 429 | return lib.isMemberReadable(context.getCore().lookupType(this), key);
|
427 | 430 | }
|
428 | 431 |
|
429 | 432 | @ExportMessage
|
430 | 433 | public Object readMember(String key,
|
431 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 434 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
432 | 435 | @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException, UnknownIdentifierException {
|
433 | 436 | return lib.readMember(context.getCore().lookupType(this), key);
|
434 | 437 | }
|
435 | 438 |
|
436 | 439 | @ExportMessage
|
437 | 440 | public boolean isMemberModifiable(String key,
|
438 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 441 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
439 | 442 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
440 | 443 | return lib.isMemberModifiable(context.getCore().lookupType(this), key);
|
441 | 444 | }
|
442 | 445 |
|
443 | 446 | @ExportMessage
|
444 | 447 | public boolean isMemberInsertable(String key,
|
445 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 448 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
446 | 449 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
447 | 450 | return lib.isMemberInsertable(context.getCore().lookupType(this), key);
|
448 | 451 | }
|
449 | 452 |
|
450 | 453 | @ExportMessage
|
451 | 454 | public void writeMember(String key, Object value,
|
452 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 455 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
453 | 456 | @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException, UnknownIdentifierException, UnsupportedTypeException {
|
454 | 457 | lib.writeMember(context.getCore().lookupType(this), key, value);
|
455 | 458 | }
|
456 | 459 |
|
457 | 460 | @ExportMessage
|
458 | 461 | public boolean isMemberRemovable(String key,
|
459 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 462 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
460 | 463 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
461 | 464 | return lib.isMemberRemovable(context.getCore().lookupType(this), key);
|
462 | 465 | }
|
463 | 466 |
|
464 | 467 | @ExportMessage
|
465 | 468 | public void removeMember(String key,
|
466 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 469 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
467 | 470 | @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException, UnknownIdentifierException {
|
468 | 471 | lib.removeMember(context.getCore().lookupType(this), key);
|
469 | 472 | }
|
470 | 473 |
|
471 | 474 | @ExportMessage
|
472 | 475 | public boolean isMemberInvocable(String key,
|
473 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 476 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
474 | 477 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
475 | 478 | return lib.isMemberInvocable(context.getCore().lookupType(this), key);
|
476 | 479 | }
|
477 | 480 |
|
478 | 481 | @ExportMessage
|
479 | 482 | public Object invokeMember(String key, Object[] arguments,
|
480 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 483 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
481 | 484 | @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException {
|
482 | 485 | return lib.invokeMember(context.getCore().lookupType(this), key, arguments);
|
483 | 486 | }
|
484 | 487 |
|
485 | 488 | @ExportMessage
|
486 | 489 | public boolean isMemberInternal(String key,
|
487 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 490 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
488 | 491 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
489 | 492 | return lib.isMemberInternal(context.getCore().lookupType(this), key);
|
490 | 493 | }
|
491 | 494 |
|
492 | 495 | @ExportMessage
|
493 | 496 | public boolean hasMemberReadSideEffects(String key,
|
494 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 497 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
495 | 498 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
496 | 499 | return lib.hasMemberReadSideEffects(context.getCore().lookupType(this), key);
|
497 | 500 | }
|
498 | 501 |
|
499 | 502 | @ExportMessage
|
500 | 503 | public boolean hasMemberWriteSideEffects(String key,
|
501 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
| 504 | + @Shared("interop") @CachedLibrary(limit = "1") InteropLibrary lib, |
502 | 505 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
503 | 506 | return lib.hasMemberWriteSideEffects(context.getCore().lookupType(this), key);
|
504 | 507 | }
|
505 | 508 |
|
506 | 509 | @ExportMessage
|
507 | 510 | static boolean isSequenceType(PythonBuiltinClassType type,
|
508 | 511 | @CachedContext(PythonLanguage.class) PythonContext context,
|
509 |
| - @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
| 512 | + @Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
510 | 513 | return lib.isSequenceType(context.getCore().lookupType(type));
|
511 | 514 | }
|
512 | 515 |
|
513 | 516 | @ExportMessage
|
514 | 517 | static boolean isMappingType(PythonBuiltinClassType type,
|
515 | 518 | @CachedContext(PythonLanguage.class) PythonContext context,
|
516 |
| - @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
| 519 | + @Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
517 | 520 | return lib.isMappingType(context.getCore().lookupType(type));
|
518 | 521 | }
|
519 | 522 |
|
520 | 523 | @ExportMessage
|
521 | 524 | static long hashWithState(PythonBuiltinClassType type, ThreadState state,
|
522 | 525 | @CachedContext(PythonLanguage.class) PythonContext context,
|
523 |
| - @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
| 526 | + @Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary lib) { |
524 | 527 | return lib.hashWithState(context.getCore().lookupType(type), state);
|
525 | 528 | }
|
526 | 529 |
|
| 530 | + @ExportMessage |
| 531 | + @SuppressWarnings("unused") |
| 532 | + static double asJavaDoubleWithState(PythonBuiltinClassType type, ThreadState state, |
| 533 | + @Shared("raise") @Cached PRaiseNode raiseNode) { |
| 534 | + throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_REAL_NUMBER, type); |
| 535 | + } |
| 536 | + |
| 537 | + @ExportMessage |
| 538 | + @SuppressWarnings("unused") |
| 539 | + static Object asPIntWithState(PythonBuiltinClassType type, ThreadState state, |
| 540 | + @Shared("raise") @Cached PRaiseNode raiseNode) { |
| 541 | + throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, type); |
| 542 | + } |
| 543 | + |
| 544 | + @ExportMessage |
| 545 | + @SuppressWarnings("unused") |
| 546 | + static long asJavaLongWithState(PythonBuiltinClassType type, ThreadState state, |
| 547 | + @Shared("raise") @Cached PRaiseNode raiseNode) { |
| 548 | + throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_NUMERIC, type); |
| 549 | + } |
| 550 | + |
527 | 551 | @ExportMessage
|
528 | 552 | static Object getLazyPythonClass(@SuppressWarnings("unused") PythonBuiltinClassType type) {
|
529 | 553 | return PythonClass;
|
@@ -610,13 +634,8 @@ public static boolean isExceptionType(PythonBuiltinClassType type) {
|
610 | 634 | * {@link com.oracle.graal.python.builtins.objects.type.TypeBuiltins.ReprNode
|
611 | 635 | * TypeBuiltins.ReprNode}
|
612 | 636 | */
|
613 |
| - @ExportMessage |
614 |
| - String asPString() { |
615 |
| - return getQualifiedName(); |
616 |
| - } |
617 |
| - |
618 | 637 | @ExportMessage
|
619 | 638 | String asPStringWithState(@SuppressWarnings("unused") ThreadState state) {
|
620 |
| - return asPString(); |
| 639 | + return getQualifiedName(); |
621 | 640 | }
|
622 | 641 | }
|
0 commit comments