46
46
47
47
import com .oracle .graal .python .builtins .objects .PNone ;
48
48
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
49
- import com .oracle .graal .python .nodes .attributes .GetAttributeNodeGen .GetAnyAttributeNodeGen ;
50
- import com .oracle .graal .python .nodes .attributes .GetAttributeNodeGen .GetFixedAttributeNodeGen ;
51
49
import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
52
50
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
53
51
import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodNode ;
58
56
import com .oracle .graal .python .runtime .exception .PException ;
59
57
import com .oracle .truffle .api .CompilerDirectives ;
60
58
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
61
- import com .oracle .truffle .api .dsl .NodeChild ;
62
- import com .oracle .truffle .api .dsl .Specialization ;
63
59
import com .oracle .truffle .api .frame .VirtualFrame ;
64
60
import com .oracle .truffle .api .nodes .Node ;
65
- import com .oracle .truffle .api .nodes .UnexpectedResultException ;
66
61
import com .oracle .truffle .api .profiles .ConditionProfile ;
67
62
68
- @ NodeChild (value = "object" , type = ExpressionNode .class )
69
- public abstract class GetAttributeNode extends ExpressionNode implements ReadNode {
63
+ public final class GetAttributeNode extends ExpressionNode implements ReadNode {
70
64
71
65
@ Child private GetFixedAttributeNode getFixedAttributeNode ;
66
+ @ Child private ExpressionNode objectExpression ;
72
67
73
- public abstract int executeInt (VirtualFrame frame , Object object );
74
-
75
- public abstract boolean executeBoolean (VirtualFrame frame , Object object );
76
-
77
- public abstract Object executeObject (VirtualFrame frame , Object object );
78
-
79
- protected GetAttributeNode (String key ) {
80
- getFixedAttributeNode = GetFixedAttributeNode .create (key );
68
+ @ Override
69
+ public Object execute (VirtualFrame frame ) {
70
+ return executeObject (frame , objectExpression .execute (frame ));
81
71
}
82
72
83
- @ Specialization (rewriteOn = UnexpectedResultException .class )
84
- protected int doItInt (VirtualFrame frame , Object object ) throws UnexpectedResultException {
85
- return getFixedAttributeNode .executeInt (frame , object );
86
- }
87
-
88
- @ Specialization (rewriteOn = UnexpectedResultException .class )
89
- protected boolean doItBoolean (VirtualFrame frame , Object object ) throws UnexpectedResultException {
90
- return getFixedAttributeNode .executeBoolean (frame , object );
73
+ public Object executeObject (VirtualFrame frame , Object object ) {
74
+ return getFixedAttributeNode .executeObject (frame , object );
91
75
}
92
76
93
- @ Specialization ( replaces = { "doItInt" , "doItBoolean" })
94
- protected Object doIt ( VirtualFrame frame , Object object ) {
95
- return getFixedAttributeNode . executeObject ( frame , object ) ;
77
+ protected GetAttributeNode ( String key , ExpressionNode object ) {
78
+ getFixedAttributeNode = GetFixedAttributeNode . create ( key );
79
+ objectExpression = object ;
96
80
}
97
81
98
82
public final String getKey () {
99
83
return getFixedAttributeNode .key ;
100
84
}
101
85
102
86
public static GetAttributeNode create (String key , ExpressionNode object ) {
103
- return GetAttributeNodeGen . create (key , object );
87
+ return new GetAttributeNode (key , object );
104
88
}
105
89
106
90
public static GetAttributeNode create (String key ) {
107
- return GetAttributeNodeGen . create (key , null );
91
+ return new GetAttributeNode (key , null );
108
92
}
109
93
94
+ @ Override
110
95
public final StatementNode makeWriteNode (ExpressionNode rhs ) {
111
96
return SetAttributeNode .create (getFixedAttributeNode .key , getObject (), rhs );
112
97
}
113
98
114
- public abstract ExpressionNode getObject ();
99
+ public ExpressionNode getObject () {
100
+ return objectExpression ;
101
+ }
115
102
116
103
abstract static class GetAttributeBaseNode extends Node {
117
104
105
+ @ Child protected LookupAndCallBinaryNode dispatchNode = LookupAndCallBinaryNode .create (__GETATTRIBUTE__ );
106
+ @ Child protected IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile .create ();
107
+
118
108
@ Child private LookupSpecialMethodNode lookupGetattrNode ;
119
109
@ Child private CallBinaryMethodNode callBinaryMethodNode ;
120
- @ Child private PythonObjectLibrary lib = PythonObjectLibrary . getFactory (). createDispatched ( 1 ) ;
110
+ @ Child private PythonObjectLibrary lib ;
121
111
122
112
@ CompilationFinal private ConditionProfile hasGetattrProfile ;
123
113
124
- int dispatchGetAttrOrRethrowInt (VirtualFrame frame , Object object , Object key , PException pe ) throws UnexpectedResultException {
125
- return ensureCallGetattrNode ().executeInt (frame , lookupGetattrOrRethrow (frame , object , pe ), object , key );
126
- }
127
-
128
- long dispatchGetAttrOrRethrowLong (VirtualFrame frame , Object object , Object key , PException pe ) throws UnexpectedResultException {
129
- return ensureCallGetattrNode ().executeLong (frame , lookupGetattrOrRethrow (frame , object , pe ), object , key );
130
- }
131
-
132
- boolean dispatchGetAttrOrRethrowBool (VirtualFrame frame , Object object , Object key , PException pe ) throws UnexpectedResultException {
133
- return ensureCallGetattrNode ().executeBool (frame , lookupGetattrOrRethrow (frame , object , pe ), object , key );
134
- }
135
-
136
114
Object dispatchGetAttrOrRethrowObject (VirtualFrame frame , Object object , Object key , PException pe ) {
137
115
return ensureCallGetattrNode ().executeObject (frame , lookupGetattrOrRethrow (frame , object , pe ), object , key );
138
116
}
139
117
140
118
/** Lookup {@code __getattr__} or rethrow {@code pe} if it does not exist. */
141
119
private Object lookupGetattrOrRethrow (VirtualFrame frame , Object object , PException pe ) {
142
- Object getattrAttribute = ensureLookupGetattrNode ().execute (frame , lib .getLazyPythonClass (object ), object );
120
+ Object getattrAttribute = ensureLookupGetattrNode ().execute (frame , ensurePythonObjLib () .getLazyPythonClass (object ), object );
143
121
if (ensureHasGetattrProfile ().profile (getattrAttribute == PNone .NO_VALUE )) {
144
122
throw pe ;
145
123
}
@@ -169,15 +147,19 @@ private ConditionProfile ensureHasGetattrProfile() {
169
147
}
170
148
return hasGetattrProfile ;
171
149
}
172
- }
173
150
174
- public abstract static class GetFixedAttributeNode extends GetAttributeBaseNode {
151
+ public PythonObjectLibrary ensurePythonObjLib () {
152
+ if (lib == null ) {
153
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
154
+ lib = insert (PythonObjectLibrary .getFactory ().createDispatched (1 ));
155
+ }
156
+ return lib ;
157
+ }
158
+ }
175
159
160
+ public static final class GetFixedAttributeNode extends GetAttributeBaseNode {
176
161
private final String key ;
177
162
178
- @ Child private LookupAndCallBinaryNode dispatchNode = LookupAndCallBinaryNode .create (__GETATTRIBUTE__ );
179
- @ Child private IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile .create ();
180
-
181
163
public GetFixedAttributeNode (String key ) {
182
164
this .key = key ;
183
165
}
@@ -186,46 +168,7 @@ public final String getKey() {
186
168
return key ;
187
169
}
188
170
189
- public abstract int executeInt (VirtualFrame frame , Object object ) throws UnexpectedResultException ;
190
-
191
- public abstract long executeLong (VirtualFrame frame , Object object ) throws UnexpectedResultException ;
192
-
193
- public abstract boolean executeBoolean (VirtualFrame frame , Object object ) throws UnexpectedResultException ;
194
-
195
- public abstract Object executeObject (VirtualFrame frame , Object object );
196
-
197
- @ Specialization (rewriteOn = UnexpectedResultException .class )
198
- protected int doItInt (VirtualFrame frame , Object object ) throws UnexpectedResultException {
199
- try {
200
- return dispatchNode .executeInt (frame , object , key );
201
- } catch (PException pe ) {
202
- pe .expect (AttributeError , isBuiltinClassProfile );
203
- return dispatchGetAttrOrRethrowInt (frame , object , key , pe );
204
- }
205
- }
206
-
207
- @ Specialization (rewriteOn = UnexpectedResultException .class )
208
- protected long doItLong (VirtualFrame frame , Object object ) throws UnexpectedResultException {
209
- try {
210
- return dispatchNode .executeLong (frame , object , key );
211
- } catch (PException pe ) {
212
- pe .expect (AttributeError , isBuiltinClassProfile );
213
- return dispatchGetAttrOrRethrowLong (frame , object , key , pe );
214
- }
215
- }
216
-
217
- @ Specialization (rewriteOn = UnexpectedResultException .class )
218
- protected boolean doItBoolean (VirtualFrame frame , Object object ) throws UnexpectedResultException {
219
- try {
220
- return dispatchNode .executeBool (frame , object , key );
221
- } catch (PException pe ) {
222
- pe .expect (AttributeError , isBuiltinClassProfile );
223
- return dispatchGetAttrOrRethrowBool (frame , object , key , pe );
224
- }
225
- }
226
-
227
- @ Specialization (replaces = {"doItInt" , "doItBoolean" })
228
- protected Object doIt (VirtualFrame frame , Object object ) {
171
+ public Object executeObject (VirtualFrame frame , Object object ) {
229
172
try {
230
173
return dispatchNode .executeObject (frame , object , key );
231
174
} catch (PException pe ) {
@@ -235,55 +178,13 @@ protected Object doIt(VirtualFrame frame, Object object) {
235
178
}
236
179
237
180
public static GetFixedAttributeNode create (String key ) {
238
- return GetFixedAttributeNodeGen . create (key );
181
+ return new GetFixedAttributeNode (key );
239
182
}
240
183
}
241
184
242
- public abstract static class GetAnyAttributeNode extends GetAttributeBaseNode {
243
-
244
- @ Child private LookupAndCallBinaryNode dispatchNode = LookupAndCallBinaryNode .create (__GETATTRIBUTE__ );
245
- @ Child private IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile .create ();
246
-
247
- public abstract int executeInt (VirtualFrame frame , Object object , Object key ) throws UnexpectedResultException ;
248
-
249
- public abstract long executeLong (VirtualFrame frame , Object object , Object key ) throws UnexpectedResultException ;
250
-
251
- public abstract boolean executeBoolean (VirtualFrame frame , Object object , Object key ) throws UnexpectedResultException ;
252
-
253
- public abstract Object executeObject (VirtualFrame frame , Object object , Object key );
254
-
255
- @ Specialization (rewriteOn = UnexpectedResultException .class )
256
- protected int doItInt (VirtualFrame frame , Object object , String key ) throws UnexpectedResultException {
257
- try {
258
- return dispatchNode .executeInt (frame , object , key );
259
- } catch (PException pe ) {
260
- pe .expect (AttributeError , isBuiltinClassProfile );
261
- return dispatchGetAttrOrRethrowInt (frame , object , key , pe );
262
- }
263
- }
264
-
265
- @ Specialization (rewriteOn = UnexpectedResultException .class )
266
- protected long doItLong (VirtualFrame frame , Object object , Object key ) throws UnexpectedResultException {
267
- try {
268
- return dispatchNode .executeLong (frame , object , key );
269
- } catch (PException pe ) {
270
- pe .expect (AttributeError , isBuiltinClassProfile );
271
- return dispatchGetAttrOrRethrowLong (frame , object , key , pe );
272
- }
273
- }
274
-
275
- @ Specialization (rewriteOn = UnexpectedResultException .class )
276
- protected boolean doItBoolean (VirtualFrame frame , Object object , Object key ) throws UnexpectedResultException {
277
- try {
278
- return dispatchNode .executeBool (frame , object , key );
279
- } catch (PException pe ) {
280
- pe .expect (AttributeError , isBuiltinClassProfile );
281
- return dispatchGetAttrOrRethrowBool (frame , object , key , pe );
282
- }
283
- }
185
+ public static final class GetAnyAttributeNode extends GetAttributeBaseNode {
284
186
285
- @ Specialization (replaces = {"doItInt" , "doItBoolean" })
286
- protected Object doIt (VirtualFrame frame , Object object , Object key ) {
187
+ public Object executeObject (VirtualFrame frame , Object object , Object key ) {
287
188
try {
288
189
return dispatchNode .executeObject (frame , object , key );
289
190
} catch (PException pe ) {
@@ -293,7 +194,7 @@ protected Object doIt(VirtualFrame frame, Object object, Object key) {
293
194
}
294
195
295
196
public static GetAnyAttributeNode create () {
296
- return GetAnyAttributeNodeGen . create ();
197
+ return new GetAnyAttributeNode ();
297
198
}
298
199
}
299
200
}
0 commit comments