11/*
2- * Copyright (c) 2017, 2018 , Oracle and/or its affiliates.
2+ * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
33 * Copyright (c) 2013, Regents of the University of California
44 *
55 * All rights reserved.
3232import com .oracle .graal .python .nodes .expression .ExpressionNode ;
3333import com .oracle .graal .python .nodes .frame .ReadNode ;
3434import 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 ;
3637import com .oracle .truffle .api .dsl .Specialization ;
3738import com .oracle .truffle .api .frame .VirtualFrame ;
3839import com .oracle .truffle .api .nodes .NodeInfo ;
3940
4041@ NodeInfo (shortName = __GETITEM__ )
4142public abstract class GetItemNode extends BinaryOpNode implements ReadNode {
4243
44+ @ Child private LookupAndCallBinaryNode callGetitemNode ;
45+
4346 public ExpressionNode getPrimary () {
4447 return getLeftNode ();
4548 }
@@ -53,8 +56,16 @@ public ExpressionNode getSlice() {
5356 public abstract Object execute (Object primary , Object slice );
5457
5558 @ 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+ }
5869 return callGetitemNode .executeObject (primary , index );
5970 }
6071
0 commit comments