[pypy-commit] pypy online-transforms-2: handle __getitem__, __setitem__ with online transforms

rlamy noreply at buildbot.pypy.org
Thu Feb 19 19:44:21 CET 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: online-transforms-2
Changeset: r76003:d2d5da95e062
Date: 2014-10-15 23:28 +0100
http://bitbucket.org/pypy/pypy/changeset/d2d5da95e062/

Log:	handle __getitem__, __setitem__ with online transforms

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -2,7 +2,6 @@
 Binary operations between SomeValues.
 """
 
-import operator
 from rpython.tool.pairtype import pair, pairtype
 from rpython.annotator.model import (
     SomeObject, SomeInteger, SomeBool, s_Bool, SomeString, SomeChar, SomeList,
@@ -14,7 +13,7 @@
     read_can_only_throw, add_knowntypedata,
     merge_knowntypedata,)
 from rpython.annotator.bookkeeper import immutablevalue
-from rpython.flowspace.model import Variable, Constant
+from rpython.flowspace.model import Variable, Constant, const
 from rpython.flowspace.operation import op
 from rpython.rlib import rarithmetic
 from rpython.annotator.model import AnnotatorError
@@ -689,12 +688,16 @@
             return super(thistype, pair(ins1, ins2)).improve()
 
 
-class __extend__(pairtype(SomeInstance, SomeObject)):
-    def getitem((s_ins, s_idx)):
-        return s_ins._emulate_call("__getitem__", s_idx)
+ at op.getitem.register_transform(SomeInstance, SomeObject)
+def getitem_SomeInstance(annotator, v_ins, v_idx):
+    get_getitem = op.getattr(v_ins, const('__getitem__'))
+    return [get_getitem, op.simple_call(get_getitem.result, v_idx)]
 
-    def setitem((s_ins, s_idx), s_value):
-        return s_ins._emulate_call("__setitem__", s_idx, s_value)
+ at op.setitem.register_transform(SomeInstance, SomeObject)
+def setitem_SomeInstance(annotator, v_ins, v_idx, v_value):
+    get_setitem = op.getattr(v_ins, const('__setitem__'))
+    return [get_setitem,
+            op.simple_call(get_setitem.result, v_idx, v_value)]
 
 
 class __extend__(pairtype(SomeIterator, SomeIterator)):
diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py
--- a/rpython/rtyper/rclass.py
+++ b/rpython/rtyper/rclass.py
@@ -1008,14 +1008,6 @@
             return hop.gendirectcall(ll_isinstance, v_obj, v_cls)
 
 
-class __extend__(pairtype(InstanceRepr, Repr)):
-    def rtype_getitem((r_ins, r_obj), hop):
-        return r_ins._emulate_call(hop, "__getitem__")
-
-    def rtype_setitem((r_ins, r_obj), hop):
-        return r_ins._emulate_call(hop, "__setitem__")
-
-
 class __extend__(pairtype(InstanceRepr, InstanceRepr)):
     def convert_from_to((r_ins1, r_ins2), v, llops):
         # which is a subclass of which?


More information about the pypy-commit mailing list