40
40
*/
41
41
package com .oracle .graal .python .builtins .objects .getsetdescriptor ;
42
42
43
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
43
44
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___DELETE__ ;
44
45
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___GET__ ;
45
46
import static com .oracle .graal .python .nodes .SpecialMethodNames .J___OBJCLASS__ ;
52
53
import com .oracle .graal .python .builtins .CoreFunctions ;
53
54
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
54
55
import com .oracle .graal .python .builtins .PythonBuiltins ;
56
+ import com .oracle .graal .python .builtins .objects .PNone ;
55
57
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorBuiltins .DescrDeleteNode ;
56
58
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorBuiltins .DescrGetNode ;
57
59
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorBuiltins .DescrSetNode ;
58
60
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorBuiltins .DescriptorCheckNode ;
59
61
import com .oracle .graal .python .builtins .objects .str .StringUtils .SimpleTruffleStringFormatNode ;
60
62
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
63
+ import com .oracle .graal .python .nodes .ErrorMessages ;
64
+ import com .oracle .graal .python .nodes .PRaiseNode ;
61
65
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
62
66
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
63
67
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
64
68
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
69
+ import com .oracle .truffle .api .dsl .Bind ;
65
70
import com .oracle .truffle .api .dsl .Cached ;
66
71
import com .oracle .truffle .api .dsl .Cached .Shared ;
67
72
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
68
73
import com .oracle .truffle .api .dsl .NodeFactory ;
69
74
import com .oracle .truffle .api .dsl .Specialization ;
70
75
import com .oracle .truffle .api .frame .VirtualFrame ;
76
+ import com .oracle .truffle .api .nodes .Node ;
71
77
import com .oracle .truffle .api .strings .TruffleString ;
72
78
73
79
/**
@@ -115,24 +121,33 @@ TruffleString repr(HiddenKeyDescriptor descr,
115
121
@ Builtin (name = J___GET__ , minNumOfPositionalArgs = 2 , maxNumOfPositionalArgs = 3 )
116
122
@ GenerateNodeFactory
117
123
abstract static class GetSetGetNode extends PythonTernaryBuiltinNode {
124
+ @ Specialization (guards = {"isNone(obj)" , "!isPNone(type)" })
125
+ static Object doNone (@ SuppressWarnings ("unused" ) Object descr , @ SuppressWarnings ("unused" ) PNone obj , @ SuppressWarnings ("unused" ) Object type ) {
126
+ return descr ;
127
+ }
128
+
129
+ @ Specialization (guards = "isNone(obj)" )
130
+ static Object doNoneNone (@ SuppressWarnings ("unused" ) Object descr , @ SuppressWarnings ("unused" ) PNone obj , @ SuppressWarnings ("unused" ) PNone type ,
131
+ @ Cached PRaiseNode raiseNode ) {
132
+ throw raiseNode .raise (TypeError , ErrorMessages .GET_NONE_NONE_IS_INVALID );
133
+ }
134
+
118
135
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L149
119
- @ Specialization
136
+ @ Specialization ( guards = "!isNone(obj)" )
120
137
static Object doGetSetDescriptor (VirtualFrame frame , GetSetDescriptor descr , Object obj , @ SuppressWarnings ("unused" ) Object type ,
138
+ @ Bind ("this" ) Node inliningTarget ,
121
139
@ Cached DescriptorCheckNode descriptorCheckNode ,
122
140
@ Cached DescrGetNode getNode ) {
123
- if (descriptorCheckNode .execute (descr .getType (), descr .getName (), obj )) {
124
- return descr ;
125
- }
141
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getName (), obj );
126
142
return getNode .execute (frame , descr , obj );
127
143
}
128
144
129
- @ Specialization
145
+ @ Specialization ( guards = "!isNone(obj)" )
130
146
static Object doHiddenKeyDescriptor (VirtualFrame frame , HiddenKeyDescriptor descr , Object obj , @ SuppressWarnings ("unused" ) Object type ,
147
+ @ Bind ("this" ) Node inliningTarget ,
131
148
@ Cached DescriptorCheckNode descriptorCheckNode ,
132
149
@ Cached DescrGetNode getNode ) {
133
- if (descriptorCheckNode .execute (descr .getType (), descr .getKey (), obj )) {
134
- return descr ;
135
- }
150
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getKey (), obj );
136
151
return getNode .execute (frame , descr , obj );
137
152
}
138
153
}
@@ -142,21 +157,19 @@ static Object doHiddenKeyDescriptor(VirtualFrame frame, HiddenKeyDescriptor desc
142
157
abstract static class GetSetSetNode extends PythonTernaryBuiltinNode {
143
158
@ Specialization
144
159
static Object doGetSetDescriptor (VirtualFrame frame , GetSetDescriptor descr , Object obj , Object value ,
160
+ @ Bind ("this" ) Node inliningTarget ,
145
161
@ Cached DescriptorCheckNode descriptorCheckNode ,
146
162
@ Cached DescrSetNode setNode ) {
147
- if (descriptorCheckNode .execute (descr .getType (), descr .getName (), obj )) {
148
- return descr ;
149
- }
163
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getName (), obj );
150
164
return setNode .execute (frame , descr , obj , value );
151
165
}
152
166
153
167
@ Specialization
154
168
static Object doHiddenKeyDescriptor (VirtualFrame frame , HiddenKeyDescriptor descr , Object obj , Object value ,
169
+ @ Bind ("this" ) Node inliningTarget ,
155
170
@ Cached DescriptorCheckNode descriptorCheckNode ,
156
171
@ Cached DescrSetNode setNode ) {
157
- if (descriptorCheckNode .execute (descr .getType (), descr .getKey (), obj )) {
158
- return descr ;
159
- }
172
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getKey (), obj );
160
173
return setNode .execute (frame , descr , obj , value );
161
174
}
162
175
}
@@ -167,21 +180,19 @@ abstract static class GetSetDeleteNode extends PythonBinaryBuiltinNode {
167
180
168
181
@ Specialization
169
182
static Object doGetSetDescriptor (VirtualFrame frame , GetSetDescriptor descr , Object obj ,
183
+ @ Bind ("this" ) Node inliningTarget ,
170
184
@ Cached DescriptorCheckNode descriptorCheckNode ,
171
185
@ Cached DescrDeleteNode deleteNode ) {
172
- if (descriptorCheckNode .execute (descr .getType (), descr .getName (), obj )) {
173
- return descr ;
174
- }
186
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getName (), obj );
175
187
return deleteNode .execute (frame , descr , obj );
176
188
}
177
189
178
190
@ Specialization
179
191
static Object doHiddenKeyDescriptor (VirtualFrame frame , HiddenKeyDescriptor descr , Object obj ,
192
+ @ Bind ("this" ) Node inliningTarget ,
180
193
@ Cached DescriptorCheckNode descriptorCheckNode ,
181
194
@ Cached DescrDeleteNode deleteNode ) {
182
- if (descriptorCheckNode .execute (descr .getType (), descr .getKey (), obj )) {
183
- return descr ;
184
- }
195
+ descriptorCheckNode .execute (inliningTarget , descr .getType (), descr .getKey (), obj );
185
196
return deleteNode .execute (frame , descr , obj );
186
197
}
187
198
}
0 commit comments