56
56
import com .oracle .graal .python .builtins .objects .PNone ;
57
57
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
58
58
import com .oracle .graal .python .builtins .objects .str .StringUtils .SimpleTruffleStringFormatNode ;
59
+ import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetIndexedSlotsCountNode ;
59
60
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
60
61
import com .oracle .graal .python .nodes .ErrorMessages ;
61
- import com .oracle .graal .python .nodes .HiddenAttr ;
62
62
import com .oracle .graal .python .nodes .PRaiseNode ;
63
63
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetFixedAttributeNode ;
64
64
import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
@@ -106,10 +106,10 @@ static TruffleString doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor sel
106
106
}
107
107
108
108
@ Specialization
109
- static TruffleString doHiddenAttrDescriptor (VirtualFrame frame , HiddenAttrDescriptor self ,
109
+ static TruffleString doIndexedSlotDescriptor (VirtualFrame frame , IndexedSlotDescriptor self ,
110
110
@ Shared @ Cached ("create(T___QUALNAME__)" ) GetFixedAttributeNode readQualNameNode ,
111
111
@ Shared ("formatter" ) @ Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode ) {
112
- return simpleTruffleStringFormatNode .format ("%s.%s" , toStr (readQualNameNode .executeObject (frame , self .getType ())), self .getAttr (). getName ());
112
+ return simpleTruffleStringFormatNode .format ("%s.%s" , toStr (readQualNameNode .executeObject (frame , self .getType ())), self .getName ());
113
113
}
114
114
115
115
@ TruffleBoundary
@@ -128,9 +128,8 @@ static TruffleString doGetSetDescriptor(GetSetDescriptor self) {
128
128
}
129
129
130
130
@ Specialization
131
- static TruffleString doHiddenAttrDescriptor (HiddenAttrDescriptor self ,
132
- @ Cached TruffleString .FromJavaStringNode fromJavaStringNode ) {
133
- return fromJavaStringNode .execute (self .getAttr ().getName (), TS_ENCODING );
131
+ static TruffleString doIndexedSlotDescriptor (IndexedSlotDescriptor self ) {
132
+ return self .getName ();
134
133
}
135
134
}
136
135
@@ -172,15 +171,16 @@ Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj
172
171
}
173
172
174
173
@ Specialization
175
- Object doHiddenAttrDescriptor ( HiddenAttrDescriptor descr , PythonAbstractObject obj ,
174
+ Object doIndexedSlotDescriptor ( IndexedSlotDescriptor descr , PythonAbstractObject obj ,
176
175
@ Bind ("this" ) Node inliningTarget ,
177
176
@ Exclusive @ Cached PRaiseNode .Lazy raiseNode ,
178
- @ Cached HiddenAttr .ReadNode readNode ) {
179
- Object val = readNode .execute (inliningTarget , obj , descr .getAttr (), PNone .NO_VALUE );
180
- if (val != PNone .NO_VALUE ) {
177
+ @ Cached GetOrCreateIndexedSlots getSlotsNode ) {
178
+ Object [] slots = getSlotsNode .execute (inliningTarget , obj );
179
+ Object val = slots [descr .getIndex ()];
180
+ if (val != null ) {
181
181
return val ;
182
182
}
183
- throw raiseNode .get (inliningTarget ).raise (AttributeError , ErrorMessages .OBJ_N_HAS_NO_ATTR_S , descr .getType (), descr .getAttr (). getName ());
183
+ throw raiseNode .get (inliningTarget ).raise (AttributeError , ErrorMessages .OBJ_N_HAS_NO_ATTR_S , descr .getType (), descr .getName ());
184
184
}
185
185
}
186
186
@@ -202,10 +202,10 @@ Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj
202
202
}
203
203
204
204
@ Specialization
205
- static Object doHiddenAttrDescriptor ( HiddenAttrDescriptor descr , PythonAbstractObject obj , Object value ,
205
+ static Object doIndexedSlotDescriptor ( IndexedSlotDescriptor descr , PythonAbstractObject obj , Object value ,
206
206
@ Bind ("this" ) Node inliningTarget ,
207
- @ Cached HiddenAttr . WriteNode writeNode ) {
208
- writeNode .execute (inliningTarget , obj , descr .getAttr (), value ) ;
207
+ @ Cached GetOrCreateIndexedSlots getSlotsNode ) {
208
+ getSlotsNode .execute (inliningTarget , obj )[ descr .getIndex ()] = value ;
209
209
return true ;
210
210
}
211
211
}
@@ -239,18 +239,41 @@ Object doGetSetDescriptor(VirtualFrame frame, GetSetDescriptor descr, Object obj
239
239
}
240
240
241
241
@ Specialization
242
- Object doHiddenAttrDescriptor ( HiddenAttrDescriptor descr , PythonAbstractObject obj ,
242
+ Object doIndexedSlotDescriptor ( IndexedSlotDescriptor descr , PythonAbstractObject obj ,
243
243
@ Bind ("this" ) Node inliningTarget ,
244
244
@ Exclusive @ Cached PRaiseNode .Lazy raiseNode ,
245
- @ Cached HiddenAttr .WriteNode writeNode ,
246
- @ Cached HiddenAttr .ReadNode readNode ,
245
+ @ Cached GetOrCreateIndexedSlots getSlotsNode ,
247
246
@ Cached InlinedConditionProfile profile ) {
248
247
// PyMember_SetOne - Check if the attribute is set.
249
- if (profile .profile (inliningTarget , readNode .execute (inliningTarget , obj , descr .getAttr (), PNone .NO_VALUE ) != PNone .NO_VALUE )) {
250
- writeNode .execute (inliningTarget , obj , descr .getAttr (), PNone .NO_VALUE );
248
+ Object [] slots = getSlotsNode .execute (inliningTarget , obj );
249
+ if (profile .profile (inliningTarget , slots [descr .getIndex ()] != null )) {
250
+ slots [descr .getIndex ()] = null ;
251
251
return PNone .NONE ;
252
252
}
253
- throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .AttributeError , ErrorMessages .S , descr .getAttr ().getName ());
253
+ throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .AttributeError , ErrorMessages .S , descr .getName ());
254
+ }
255
+ }
256
+
257
+ @ GenerateInline
258
+ @ GenerateCached (false )
259
+ @ GenerateUncached
260
+ abstract static class GetOrCreateIndexedSlots extends Node {
261
+ abstract Object [] execute (Node inliningTarget , PythonAbstractObject object );
262
+
263
+ @ Specialization (guards = "object.getIndexedSlots() != null" )
264
+ static Object [] doGet (PythonAbstractObject object ) {
265
+ return object .getIndexedSlots ();
266
+ }
267
+
268
+ @ Specialization (guards = "object.getIndexedSlots() == null" )
269
+ static Object [] doCreate (Node inliningTarget , PythonAbstractObject object ,
270
+ @ Cached GetIndexedSlotsCountNode getIndexedSlotsCountNode ,
271
+ @ Cached GetClassNode getClassNode ) {
272
+ Object cls = getClassNode .execute (inliningTarget , object );
273
+ int slotCount = getIndexedSlotsCountNode .execute (inliningTarget , cls );
274
+ Object [] slots = new Object [slotCount ];
275
+ object .setIndexedSlots (slots );
276
+ return slots ;
254
277
}
255
278
}
256
279
}
0 commit comments