52
52
import com .oracle .graal .python .builtins .objects .type .SpecialMethodSlot ;
53
53
import com .oracle .graal .python .nodes .ErrorMessages ;
54
54
import com .oracle .graal .python .nodes .PRaiseNode ;
55
- import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
56
- import com .oracle .graal .python .nodes .interop .PForeignToPTypeNode ;
57
55
import com .oracle .graal .python .runtime .GilNode ;
58
56
import com .oracle .graal .python .runtime .PythonContext ;
57
+ import com .oracle .graal .python .util .PythonUtils ;
59
58
import com .oracle .truffle .api .CompilerAsserts ;
60
59
import com .oracle .truffle .api .CompilerDirectives ;
61
60
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
66
65
import com .oracle .truffle .api .dsl .Fallback ;
67
66
import com .oracle .truffle .api .dsl .Specialization ;
68
67
import com .oracle .truffle .api .frame .VirtualFrame ;
69
- import com .oracle .truffle .api .interop .ArityException ;
70
- import com .oracle .truffle .api .interop .InteropLibrary ;
71
68
import com .oracle .truffle .api .interop .TruffleObject ;
72
- import com .oracle .truffle .api .interop .UnknownIdentifierException ;
73
- import com .oracle .truffle .api .interop .UnsupportedMessageException ;
74
- import com .oracle .truffle .api .interop .UnsupportedTypeException ;
75
69
import com .oracle .truffle .api .library .CachedLibrary ;
76
70
import com .oracle .truffle .api .library .ExportLibrary ;
77
71
import com .oracle .truffle .api .library .ExportMessage ;
72
+ import com .oracle .truffle .api .library .Message ;
73
+ import com .oracle .truffle .api .library .ReflectionLibrary ;
78
74
import com .oracle .truffle .api .object .Shape ;
79
75
import com .oracle .truffle .api .profiles .ConditionProfile ;
80
76
81
- @ ExportLibrary (InteropLibrary .class )
82
77
@ ExportLibrary (PythonObjectLibrary .class )
78
+ // InteropLibrary is proxied through ReflectionLibrary
79
+ @ ExportLibrary (ReflectionLibrary .class )
83
80
public enum PythonBuiltinClassType implements TruffleObject {
84
81
85
82
ForeignObject (FOREIGN , Flags .PRIVATE_DERIVED_WODICT ),
@@ -601,137 +598,12 @@ public final Shape getInstanceShape(PythonLanguage lang) {
601
598
PStringIO .base = PTextIOBase ;
602
599
}
603
600
604
- /* InteropLibrary messages */
605
- @ SuppressWarnings ("static-method" )
606
- @ ExportMessage
607
- public boolean isExecutable () {
608
- return true ;
609
- }
610
-
611
- @ ExportMessage
612
- public Object execute (Object [] arguments ,
613
- @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
614
- @ CachedContext (PythonLanguage .class ) PythonContext context ) throws UnsupportedTypeException , ArityException , UnsupportedMessageException {
615
- return lib .execute (context .getCore ().lookupType (this ), arguments );
616
- }
617
-
618
- @ SuppressWarnings ("static-method" )
619
- @ ExportMessage
620
- public boolean isInstantiable () {
621
- return true ;
622
- }
623
-
624
- @ ExportMessage
625
- public Object instantiate (Object [] arguments ,
626
- @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
627
- @ CachedContext (PythonLanguage .class ) PythonContext context ) throws UnsupportedTypeException , ArityException , UnsupportedMessageException {
628
- return lib .instantiate (context .getCore ().lookupType (this ), arguments );
629
- }
630
-
631
- @ SuppressWarnings ("static-method" )
632
- @ ExportMessage
633
- public boolean hasMembers () {
634
- return true ;
635
- }
636
-
637
- @ ExportMessage
638
- public Object getMembers (boolean includeInternal ,
639
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
640
- @ CachedContext (PythonLanguage .class ) PythonContext context ) throws UnsupportedMessageException {
641
- return lib .getMembers (context .getCore ().lookupType (this ), includeInternal );
642
- }
643
-
644
- @ ExportMessage
645
- public boolean isMemberReadable (String key ,
646
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
647
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
648
- return lib .isMemberReadable (context .getCore ().lookupType (this ), key );
649
- }
650
-
651
- @ ExportMessage
652
- public Object readMember (String key ,
653
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
654
- @ CachedContext (PythonLanguage .class ) PythonContext context ) throws UnsupportedMessageException , UnknownIdentifierException {
655
- return lib .readMember (context .getCore ().lookupType (this ), key );
656
- }
657
-
658
- @ ExportMessage
659
- public boolean isMemberModifiable (String key ,
660
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
661
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
662
- return lib .isMemberModifiable (context .getCore ().lookupType (this ), key );
663
- }
664
-
601
+ // Proxy InteropLibrary messages to the PythonBuiltinClass
665
602
@ ExportMessage
666
- public boolean isMemberInsertable (String key ,
667
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
668
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
669
- return lib .isMemberInsertable (context .getCore ().lookupType (this ), key );
670
- }
671
-
672
- @ ExportMessage
673
- public void writeMember (String key , Object value ,
674
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
675
- @ CachedContext (PythonLanguage .class ) PythonContext context )
676
- throws UnsupportedMessageException , UnknownIdentifierException , UnsupportedTypeException {
677
- lib .writeMember (context .getCore ().lookupType (this ), key , value );
678
- }
679
-
680
- @ ExportMessage
681
- public boolean isMemberRemovable (String key ,
682
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
683
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
684
- return lib .isMemberRemovable (context .getCore ().lookupType (this ), key );
685
- }
686
-
687
- @ ExportMessage
688
- public void removeMember (String key ,
689
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
690
- @ CachedContext (PythonLanguage .class ) PythonContext context ) throws UnsupportedMessageException , UnknownIdentifierException {
691
- lib .removeMember (context .getCore ().lookupType (this ), key );
692
- }
693
-
694
- @ ExportMessage
695
- public boolean isMemberInvocable (String key ,
696
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
697
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
698
- return lib .isMemberInvocable (context .getCore ().lookupType (this ), key );
699
- }
700
-
701
- @ ExportMessage
702
- public Object invokeMember (String key , Object [] arguments ,
703
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
704
- @ CachedContext (PythonLanguage .class ) PythonContext context )
705
- throws UnsupportedMessageException , ArityException , UnknownIdentifierException , UnsupportedTypeException {
706
- return lib .invokeMember (context .getCore ().lookupType (this ), key , arguments );
707
- }
708
-
709
- @ ExportMessage
710
- public boolean isMemberInternal (String key ,
711
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
712
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
713
- return lib .isMemberInternal (context .getCore ().lookupType (this ), key );
714
- }
715
-
716
- @ ExportMessage
717
- public boolean hasMemberReadSideEffects (String key ,
718
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
719
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
720
- return lib .hasMemberReadSideEffects (context .getCore ().lookupType (this ), key );
721
- }
722
-
723
- @ ExportMessage
724
- public boolean hasMemberWriteSideEffects (String key ,
725
- @ Shared ("interop" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
726
- @ CachedContext (PythonLanguage .class ) PythonContext context ) {
727
- return lib .hasMemberWriteSideEffects (context .getCore ().lookupType (this ), key );
728
- }
729
-
730
- @ ExportMessage
731
- static boolean isSequenceType (PythonBuiltinClassType type ,
732
- @ CachedContext (PythonLanguage .class ) PythonContext context ,
733
- @ Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
734
- return lib .isSequenceType (context .getCore ().lookupType (type ));
603
+ public Object send (Message message , Object [] args ,
604
+ @ CachedLibrary (limit = "1" ) ReflectionLibrary lib ,
605
+ @ CachedContext (PythonLanguage .class ) PythonContext context ) throws Exception {
606
+ return lib .send (context .getCore ().lookupType (this ), message , args );
735
607
}
736
608
737
609
@ ExportMessage
@@ -842,35 +714,6 @@ public boolean isLazyPythonClass() {
842
714
return true ;
843
715
}
844
716
845
- @ ExportMessage
846
- static boolean isMetaObject (@ SuppressWarnings ("unused" ) PythonBuiltinClassType self ) {
847
- return true ;
848
- }
849
-
850
- @ ExportMessage
851
- static boolean isMetaInstance (PythonBuiltinClassType self , Object instance ,
852
- @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
853
- @ Cached PForeignToPTypeNode convert ,
854
- @ Cached IsSubtypeNode isSubtype ,
855
- @ Cached .Exclusive @ Cached GilNode gil ) {
856
- boolean mustRelease = gil .acquire ();
857
- try {
858
- return isSubtype .execute (lib .getLazyPythonClass (convert .executeConvert (instance )), self );
859
- } finally {
860
- gil .release (mustRelease );
861
- }
862
- }
863
-
864
- @ ExportMessage
865
- static String getMetaSimpleName (PythonBuiltinClassType self ) {
866
- return self .getName ();
867
- }
868
-
869
- @ ExportMessage
870
- static String getMetaQualifiedName (PythonBuiltinClassType self ) {
871
- return self .getPrintName ();
872
- }
873
-
874
717
public static boolean isExceptionType (PythonBuiltinClassType type ) {
875
718
return type .isException ;
876
719
}
@@ -880,6 +723,22 @@ public static boolean isExceptionType(PythonBuiltinClassType type) {
880
723
*/
881
724
@ ExportMessage
882
725
String asPStringWithState (@ SuppressWarnings ("unused" ) ThreadState state ) {
883
- return getPrintName ();
726
+ return PythonUtils .format ("<class '%s'>" , getPrintName ());
727
+ }
728
+
729
+ @ ExportMessage
730
+ public Object lookupAndCallSpecialMethodWithState (ThreadState state , String methodName , Object [] arguments ,
731
+ @ CachedLibrary ("this" ) PythonObjectLibrary plib ,
732
+ @ Shared ("methodLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ) {
733
+ Object method = plib .lookupAttributeOnTypeStrict (this , methodName );
734
+ return methodLib .callUnboundMethodWithState (method , state , this , arguments );
735
+ }
736
+
737
+ @ ExportMessage
738
+ public Object lookupAndCallRegularMethodWithState (ThreadState state , String methodName , Object [] arguments ,
739
+ @ CachedLibrary ("this" ) PythonObjectLibrary plib ,
740
+ @ Shared ("methodLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ) {
741
+ Object method = plib .lookupAttributeStrictWithState (this , state , methodName );
742
+ return methodLib .callObjectWithState (method , state , arguments );
884
743
}
885
744
}
0 commit comments