1
1
/*
2
- * Copyright (c) 2017, 2018 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2013, Regents of the University of California
4
4
*
5
5
* All rights reserved.
32
32
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
33
33
import com .oracle .graal .python .nodes .frame .ReadNode ;
34
34
import com .oracle .graal .python .nodes .statement .StatementNode ;
35
- import com .oracle .truffle .api .dsl .Cached ;
35
+ import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
36
+ import com .oracle .truffle .api .CompilerDirectives ;
36
37
import com .oracle .truffle .api .dsl .Specialization ;
37
38
import com .oracle .truffle .api .frame .VirtualFrame ;
38
39
import com .oracle .truffle .api .nodes .NodeInfo ;
39
40
40
41
@ NodeInfo (shortName = __GETITEM__ )
41
42
public abstract class GetItemNode extends BinaryOpNode implements ReadNode {
42
43
44
+ @ Child private LookupAndCallBinaryNode callGetitemNode ;
45
+
43
46
public ExpressionNode getPrimary () {
44
47
return getLeftNode ();
45
48
}
@@ -53,8 +56,16 @@ public ExpressionNode getSlice() {
53
56
public abstract Object execute (Object primary , Object slice );
54
57
55
58
@ Specialization
56
- public Object doSpecialObject (Object primary , Object index ,
57
- @ Cached ("create(__GETITEM__)" ) LookupAndCallBinaryNode callGetitemNode ) {
59
+ public Object doSpecialObject (Object primary , Object index ) {
60
+ if (callGetitemNode == null ) {
61
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
62
+ callGetitemNode = insert (LookupAndCallBinaryNode .create (__GETITEM__ , null , () -> new LookupAndCallBinaryNode .NotImplementedHandler () {
63
+ @ Override
64
+ public Object execute (Object arg , @ SuppressWarnings ("unused" ) Object arg2 ) {
65
+ throw raise (TypeError , "'%p' object is not subscriptable" , arg );
66
+ }
67
+ }));
68
+ }
58
69
return callGetitemNode .executeObject (primary , index );
59
70
}
60
71
0 commit comments