27
27
package com .oracle .graal .python .builtins .objects .type ;
28
28
29
29
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__BASES__ ;
30
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__BASICSIZE__ ;
30
31
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__CLASS__ ;
32
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICTOFFSET__ ;
31
33
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICT__ ;
34
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__ITEMSIZE__ ;
32
35
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__MODULE__ ;
33
36
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__MRO__ ;
34
37
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__NAME__ ;
95
98
import com .oracle .graal .python .nodes .object .GetClassNode ;
96
99
import com .oracle .graal .python .nodes .object .GetLazyClassNode ;
97
100
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
101
+ import com .oracle .graal .python .nodes .truffle .PythonTypes ;
98
102
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
99
103
import com .oracle .truffle .api .CompilerAsserts ;
100
104
import com .oracle .truffle .api .CompilerDirectives ;
105
109
import com .oracle .truffle .api .dsl .ImportStatic ;
106
110
import com .oracle .truffle .api .dsl .NodeFactory ;
107
111
import com .oracle .truffle .api .dsl .Specialization ;
112
+ import com .oracle .truffle .api .dsl .TypeSystemReference ;
108
113
import com .oracle .truffle .api .frame .VirtualFrame ;
109
114
import com .oracle .truffle .api .profiles .BranchProfile ;
110
115
import com .oracle .truffle .api .profiles .ConditionProfile ;
@@ -542,10 +547,14 @@ private static <T> Object[] toArray(Set<T> subclasses) {
542
547
}
543
548
}
544
549
545
- @ Builtin (name = __NAME__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
546
550
@ GenerateNodeFactory
547
551
@ ImportStatic (NativeMemberNames .class )
548
- static abstract class NameNode extends PythonBinaryBuiltinNode {
552
+ @ TypeSystemReference (PythonTypes .class )
553
+ static abstract class AbstractSlotNode extends PythonBinaryBuiltinNode {
554
+ }
555
+
556
+ @ Builtin (name = __NAME__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
557
+ static abstract class NameNode extends AbstractSlotNode {
549
558
@ Specialization (guards = "isNoValue(value)" )
550
559
String getName (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
551
560
return cls .getName ();
@@ -593,9 +602,7 @@ private static String getQualName(String fqname) {
593
602
}
594
603
595
604
@ Builtin (name = __MODULE__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
596
- @ GenerateNodeFactory
597
- @ ImportStatic (NativeMemberNames .class )
598
- static abstract class ModuleNode extends PythonBinaryBuiltinNode {
605
+ static abstract class ModuleNode extends AbstractSlotNode {
599
606
600
607
@ Specialization (guards = "isNoValue(value)" )
601
608
Object getModule (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
@@ -621,15 +628,15 @@ Object setModule(PythonClass cls, Object value,
621
628
}
622
629
623
630
@ Specialization (guards = "isNoValue(value)" )
624
- Object getModule (PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) PNone value ,
631
+ Object getModule (PythonNativeClass cls , @ SuppressWarnings ("unused" ) PNone value ,
625
632
@ Cached ("create(TP_NAME)" ) GetTypeMemberNode getTpNameNode ) {
626
633
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
627
634
String tpName = (String ) getTpNameNode .execute (cls );
628
635
return getModuleName (tpName );
629
636
}
630
637
631
638
@ Specialization (guards = "!isNoValue(value)" )
632
- Object getModule (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) Object value ) {
639
+ Object setNative (@ SuppressWarnings ("unused" ) PythonNativeClass cls , @ SuppressWarnings ("unused" ) Object value ) {
633
640
throw raise (PythonErrorType .RuntimeError , "can't set attributes of native type" );
634
641
}
635
642
@@ -648,9 +655,7 @@ protected String getBuiltinsName() {
648
655
}
649
656
650
657
@ Builtin (name = __QUALNAME__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
651
- @ GenerateNodeFactory
652
- @ ImportStatic (NativeMemberNames .class )
653
- static abstract class QualNameNode extends PythonBinaryBuiltinNode {
658
+ static abstract class QualNameNode extends AbstractSlotNode {
654
659
@ Specialization (guards = "isNoValue(value)" )
655
660
String getName (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
656
661
return cls .getName ();
@@ -674,15 +679,15 @@ Object setName(PythonClass cls, Object value,
674
679
}
675
680
676
681
@ Specialization (guards = "isNoValue(value)" )
677
- String getNative (PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) PNone value ,
682
+ String getNative (PythonNativeClass cls , @ SuppressWarnings ("unused" ) PNone value ,
678
683
@ Cached ("create(TP_NAME)" ) GetTypeMemberNode getTpNameNode ) {
679
684
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
680
685
String tpName = (String ) getTpNameNode .execute (cls );
681
686
return getQualName (tpName );
682
687
}
683
688
684
689
@ Specialization (guards = "!isNoValue(value)" )
685
- Object getModule (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) Object value ) {
690
+ Object setNative (@ SuppressWarnings ("unused" ) PythonNativeClass cls , @ SuppressWarnings ("unused" ) Object value ) {
686
691
throw raise (PythonErrorType .RuntimeError , "can't set attributes of native type" );
687
692
}
688
693
@@ -694,6 +699,113 @@ private static String getQualName(String fqname) {
694
699
}
695
700
return fqname ;
696
701
}
702
+ }
703
+
704
+ @ Builtin (name = __DICTOFFSET__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
705
+ static abstract class DictoffsetNode extends AbstractSlotNode {
706
+ @ Specialization (guards = "isNoValue(value)" )
707
+ String getName (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
708
+ return cls .getName ();
709
+ }
710
+
711
+ @ Specialization (guards = {"isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
712
+ Object getName (PythonClass cls , @ SuppressWarnings ("unused" ) PNone value ,
713
+ @ Cached ("create()" ) ReadAttributeFromObjectNode getName ) {
714
+ return getName .execute (cls , __DICTOFFSET__ );
715
+ }
716
+
717
+ @ Specialization (guards = "!isNoValue(value)" )
718
+ Object setName (@ SuppressWarnings ("unused" ) PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) Object value ) {
719
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of built-in/extension 'type'" );
720
+ }
721
+
722
+ @ Specialization (guards = {"!isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
723
+ Object setName (PythonClass cls , Object value ,
724
+ @ Cached ("create()" ) WriteAttributeToObjectNode setName ) {
725
+ return setName .execute (cls , __DICTOFFSET__ , value );
726
+ }
727
+
728
+ @ Specialization (guards = "isNoValue(value)" )
729
+ Object getNative (PythonNativeClass cls , @ SuppressWarnings ("unused" ) PNone value ,
730
+ @ Cached ("create(TP_DICTOFFSET)" ) GetTypeMemberNode getTpDictoffsetNode ) {
731
+ return getTpDictoffsetNode .execute (cls );
732
+ }
733
+
734
+ @ Specialization (guards = "!isNoValue(value)" )
735
+ Object setNative (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) Object value ) {
736
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of native type" );
737
+ }
738
+ }
739
+
740
+ @ Builtin (name = __ITEMSIZE__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
741
+ static abstract class ItemsizeNode extends AbstractSlotNode {
742
+ @ Specialization (guards = "isNoValue(value)" )
743
+ String getName (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
744
+ return cls .getName ();
745
+ }
746
+
747
+ @ Specialization (guards = {"isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
748
+ Object getName (PythonClass cls , @ SuppressWarnings ("unused" ) PNone value ,
749
+ @ Cached ("create()" ) ReadAttributeFromObjectNode getName ) {
750
+ return getName .execute (cls , __ITEMSIZE__ );
751
+ }
752
+
753
+ @ Specialization (guards = "!isNoValue(value)" )
754
+ Object setName (@ SuppressWarnings ("unused" ) PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) Object value ) {
755
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of built-in/extension 'type'" );
756
+ }
757
+
758
+ @ Specialization (guards = {"!isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
759
+ Object setName (PythonClass cls , Object value ,
760
+ @ Cached ("create()" ) WriteAttributeToObjectNode setName ) {
761
+ return setName .execute (cls , __ITEMSIZE__ , value );
762
+ }
763
+
764
+ @ Specialization (guards = "isNoValue(value)" )
765
+ Object getNative (PythonNativeClass cls , @ SuppressWarnings ("unused" ) PNone value ,
766
+ @ Cached ("create(TP_ITEMSIZE)" ) GetTypeMemberNode getTpDictoffsetNode ) {
767
+ return getTpDictoffsetNode .execute (cls );
768
+ }
769
+
770
+ @ Specialization (guards = "!isNoValue(value)" )
771
+ Object setNative (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) Object value ) {
772
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of native type" );
773
+ }
774
+ }
697
775
776
+ @ Builtin (name = __BASICSIZE__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
777
+ static abstract class BasicsizeNode extends AbstractSlotNode {
778
+ @ Specialization (guards = "isNoValue(value)" )
779
+ String getName (PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) PNone value ) {
780
+ return cls .getName ();
781
+ }
782
+
783
+ @ Specialization (guards = {"isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
784
+ Object getName (PythonClass cls , @ SuppressWarnings ("unused" ) PNone value ,
785
+ @ Cached ("create()" ) ReadAttributeFromObjectNode getName ) {
786
+ return getName .execute (cls , __BASICSIZE__ );
787
+ }
788
+
789
+ @ Specialization (guards = "!isNoValue(value)" )
790
+ Object setName (@ SuppressWarnings ("unused" ) PythonBuiltinClass cls , @ SuppressWarnings ("unused" ) Object value ) {
791
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of built-in/extension 'type'" );
792
+ }
793
+
794
+ @ Specialization (guards = {"!isNoValue(value)" , "!isPythonBuiltinClass(cls)" })
795
+ Object setName (PythonClass cls , Object value ,
796
+ @ Cached ("create()" ) WriteAttributeToObjectNode setName ) {
797
+ return setName .execute (cls , __BASICSIZE__ , value );
798
+ }
799
+
800
+ @ Specialization (guards = "isNoValue(value)" )
801
+ Object getNative (PythonNativeClass cls , @ SuppressWarnings ("unused" ) PNone value ,
802
+ @ Cached ("create(TP_BASICSIZE)" ) GetTypeMemberNode getTpDictoffsetNode ) {
803
+ return getTpDictoffsetNode .execute (cls );
804
+ }
805
+
806
+ @ Specialization (guards = "!isNoValue(value)" )
807
+ Object setNative (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject cls , @ SuppressWarnings ("unused" ) Object value ) {
808
+ throw raise (PythonErrorType .RuntimeError , "can't set attributes of native type" );
809
+ }
698
810
}
699
811
}
0 commit comments