38
38
import static com .oracle .graal .python .nodes .SpecialMethodNames .__ITER__ ;
39
39
import static com .oracle .graal .python .nodes .SpecialMethodNames .__REVERSED__ ;
40
40
import static com .oracle .graal .python .nodes .SpecialMethodNames .__LEN__ ;
41
- import static com .oracle .graal .python .nodes .SpecialMethodNames .__MISSING__ ;
42
41
import static com .oracle .graal .python .nodes .SpecialMethodNames .__SETITEM__ ;
43
42
import static com .oracle .graal .python .runtime .exception .PythonErrorType .KeyError ;
44
43
import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
67
66
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
68
67
import com .oracle .graal .python .builtins .objects .mappingproxy .PMappingproxy ;
69
68
import com .oracle .graal .python .builtins .objects .method .PBuiltinMethod ;
69
+ import com .oracle .graal .python .builtins .objects .method .PMethod ;
70
70
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
71
71
import com .oracle .graal .python .builtins .objects .str .PString ;
72
72
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
73
73
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
74
74
import com .oracle .graal .python .nodes .ErrorMessages ;
75
- import com .oracle .graal .python .nodes .PGuards ;
76
75
import com .oracle .graal .python .nodes .PRaiseNode ;
76
+ import com .oracle .graal .python .nodes .SpecialMethodNames ;
77
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__MISSING__ ;
77
78
import com .oracle .graal .python .nodes .builtins .ListNodes ;
78
79
import com .oracle .graal .python .nodes .call .CallNode ;
79
80
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
96
97
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
97
98
import com .oracle .truffle .api .dsl .Fallback ;
98
99
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
100
+ import com .oracle .truffle .api .dsl .ImportStatic ;
99
101
import com .oracle .truffle .api .dsl .Specialization ;
100
102
import com .oracle .truffle .api .frame .VirtualFrame ;
101
103
import com .oracle .truffle .api .library .CachedLibrary ;
104
+ import com .oracle .truffle .api .nodes .Node ;
102
105
import com .oracle .truffle .api .profiles .BranchProfile ;
103
106
import com .oracle .truffle .api .profiles .ConditionProfile ;
104
107
@@ -274,18 +277,41 @@ public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
274
277
Object getItem (VirtualFrame frame , PDict self , Object key ,
275
278
@ CachedLibrary (value = "self.getDictStorage()" ) HashingStorageLibrary hlib ,
276
279
@ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile profile ,
277
- @ Cached ( "create(__MISSING__)" ) LookupAndCallBinaryNode specialNode ) {
280
+ @ Cached DispatchMissingNode missing ) {
278
281
final Object result = hlib .getItemWithFrame (self .getDictStorage (), key , profile , frame );
279
282
if (result == null ) {
280
- return specialNode . executeObject (frame , self , key );
283
+ return missing . execute (frame , self , key );
281
284
}
282
285
return result ;
283
286
}
284
287
}
285
288
286
- @ Builtin (name = __MISSING__ , minNumOfPositionalArgs = 2 )
287
- @ GenerateNodeFactory
288
- public abstract static class MissingNode extends PythonBinaryBuiltinNode {
289
+ @ ImportStatic (SpecialMethodNames .class )
290
+ protected abstract static class DispatchMissingNode extends Node {
291
+
292
+ protected abstract Object execute (VirtualFrame frame , Object self , Object key );
293
+
294
+ @ Specialization (guards = "hasMissing(self, lib)" , limit = "1" )
295
+ protected Object misssing (Object self , Object key ,
296
+ @ CachedLibrary ("self" ) PythonObjectLibrary lib ,
297
+ @ Exclusive @ Cached CallNode callNode ) {
298
+ return callNode .execute (lib .lookupAttribute (self , __MISSING__ ), key );
299
+ }
300
+
301
+ @ Specialization (guards = "!hasMissing(self, lib)" , limit = "1" )
302
+ protected Object misssing (VirtualFrame frame , Object self , Object key ,
303
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("self" ) PythonObjectLibrary lib ,
304
+ @ Exclusive @ Cached DefaultMissingNode missing ) {
305
+ return missing .execute (frame , self , key );
306
+ }
307
+
308
+ protected boolean hasMissing (Object self , PythonObjectLibrary lib ) {
309
+ Object missing = lib .lookupAttribute (self , __MISSING__ );
310
+ return missing != PNone .NO_VALUE && missing instanceof PMethod ;
311
+ }
312
+ }
313
+
314
+ protected abstract static class DefaultMissingNode extends PythonBinaryBuiltinNode {
289
315
@ SuppressWarnings ("unused" )
290
316
@ Specialization
291
317
Object run (Object self , PString key ,
@@ -301,13 +327,8 @@ Object run(Object self, String key) {
301
327
302
328
@ SuppressWarnings ("unused" )
303
329
@ Specialization (guards = "!isString(key)" )
304
- Object run (VirtualFrame frame , Object self , Object key ,
305
- @ Cached ("create(__REPR__)" ) LookupAndCallUnaryNode specialNode ) {
306
- Object name = specialNode .executeObject (frame , key );
307
- if (!PGuards .isString (name )) {
308
- throw raise (TypeError , ErrorMessages .RETURNED_NON_STRING , "__repr__" , name );
309
- }
310
- throw raise (KeyError , "%s" , name );
330
+ Object run (VirtualFrame frame , Object self , Object key ) {
331
+ throw raise (KeyError , new Object []{key });
311
332
}
312
333
}
313
334
0 commit comments