[pypy-commit] pypy HopArg: store HighLevelOp data as a list of HopArgs

rlamy noreply at buildbot.pypy.org
Wed May 14 05:08:17 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: HopArg
Changeset: r71503:d8d5f7833dcc
Date: 2014-05-14 04:07 +0100
http://bitbucket.org/pypy/pypy/changeset/d8d5f7833dcc/

Log:	store HighLevelOp data as a list of HopArgs

diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -1,6 +1,7 @@
 from rpython.annotator import model as annmodel
 from rpython.flowspace.model import Constant
 from rpython.rlib import rarithmetic, objectmodel
+from rpython.rtyper.rtyper import HopArg
 from rpython.rtyper import raddress, rptr, extregistry, rrange
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.lltypesystem import lltype, llmemory, rclass
@@ -47,23 +48,19 @@
     hop = hop.copy()
     from rpython.annotator.argument import ArgumentsForTranslation
     arguments = ArgumentsForTranslation.fromshape(
-            hop.args_s[1].const, # shape
+            hop.args[1].s.const, # shape
             range(hop.nb_args-2))
     if arguments.w_stararg is not None:
         # expand the *arg in-place -- it must be a tuple
         from rpython.rtyper.rtuple import TupleRepr
         if arguments.w_stararg != hop.nb_args - 3:
             raise TyperError("call pattern too complex")
-        v_tuple = hop.args_v.pop()
-        s_tuple = hop.args_s.pop()
-        r_tuple = hop.args_r.pop()
-        if not isinstance(r_tuple, TupleRepr):
+        tup = hop.args.pop()
+        if not isinstance(tup.r, TupleRepr):
             raise TyperError("*arg must be a tuple")
-        for i in range(len(r_tuple.items_r)):
-            v_item = r_tuple.getitem_internal(hop.llops, v_tuple, i)
-            hop.args_v.append(v_item)
-            hop.args_s.append(s_tuple.items[i])
-            hop.args_r.append(r_tuple.items_r[i])
+        for i in range(len(tup.r.items_r)):
+            v_item = tup.r.getitem_internal(hop.llops, tup.v, i)
+            hop.args.append(HopArg(v_item, tup.s.items[i], tup.r.items_r[i]))
 
     keywords = arguments.keywords
     if not takes_kwds and keywords:
@@ -143,13 +140,15 @@
                 self.self_repr.__class__.__name__, name))
         # hack based on the fact that 'lowleveltype == self_repr.lowleveltype'
         hop2 = hop.copy()
-        assert hop2.args_r[0] is self
-        if isinstance(hop2.args_v[0], Constant):
-            c = hop2.args_v[0].value    # get object from bound method
+        assert hop2.args[0].r is self
+        if isinstance(hop2.args[0].v, Constant):
+            c = hop2.args[0].v.value    # get object from bound method
             c = get_builtin_method_self(c)
-            hop2.args_v[0] = Constant(c)
-        hop2.args_s[0] = self.s_self
-        hop2.args_r[0] = self.self_repr
+            v_self = Constant(c)
+        else:
+            v_self = hop2.args[0].v
+        h_self = HopArg(v_self, self.s_self, self.self_repr)
+        hop2.args[0] = h_self
         return bltintyper(hop2)
 
 class __extend__(pairtype(BuiltinMethodRepr, BuiltinMethodRepr)):
@@ -175,7 +174,7 @@
             result.append(hop.inputarg(r, arg=i))
         else:
             result.append(None)
-    del hop.args_v[hop.nb_args - len(lst):]
+    del hop.args[hop.nb_args - len(lst):]
     return result
 
 def get_builtin_method_self(x):
@@ -316,8 +315,9 @@
     for i in range(len(new_args_r)):
         assert hop.args_r[i].lowleveltype == new_args_r[i].lowleveltype
 
-    hop.args_r = new_args_r
-    hop.args_s = [s_callable] + args_s
+    new_args = [HopArg(v, s, r) for v, s, r in
+            zip(hop.args_v, [s_callable] + args_s, new_args_r)]
+    hop.args = new_args
 
     hop.s_result = s_ret
     assert hop.r_result.lowleveltype == rresult.lowleveltype
diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py
--- a/rpython/rtyper/rclass.py
+++ b/rpython/rtyper/rclass.py
@@ -390,6 +390,7 @@
         raise NotImplementedError
 
     def _emulate_call(self, hop, meth_name):
+        from rpython.rtyper.rtyper import HopArg
         vinst, = hop.inputargs(self)
         clsdef = hop.args_s[0].classdef
         s_unbound_attr = clsdef.find_attribute(meth_name).getvalue()
@@ -402,10 +403,10 @@
         r_method = self.rtyper.getrepr(s_attr)
         r_method.get_method_from_instance(self, vinst, hop.llops)
         hop2 = hop.copy()
-        hop2.spaceop = op.simple_call(hop.spaceop.args[0])
+        v = hop.args[0].v
+        hop2.spaceop = op.simple_call(v)
         hop2.spaceop.result = hop.spaceop.result
-        hop2.args_r = [r_method]
-        hop2.args_s = [s_attr]
+        hop2.args = [HopArg(v, s_attr, r_method)]
         return hop2.dispatch()
 
     def rtype_iter(self, hop):
diff --git a/rpython/rtyper/rcontrollerentry.py b/rpython/rtyper/rcontrollerentry.py
--- a/rpython/rtyper/rcontrollerentry.py
+++ b/rpython/rtyper/rcontrollerentry.py
@@ -1,5 +1,6 @@
 from rpython.flowspace.model import Constant
 from rpython.rtyper.error import TyperError
+from rpython.rtyper.rtyper import HopArg
 from rpython.rtyper.rmodel import Repr
 from rpython.tool.pairtype import pairtype
 
@@ -58,11 +59,11 @@
             raise TyperError("args_r[%d] = %r, expected ControlledInstanceRepr"
                              % (index, r_controlled))
         s_new, r_new = r_controlled.s_real_obj, r_controlled.r_real_obj
-        hop2.args_s[index], hop2.args_r[index] = s_new, r_new
         v = hop2.args_v[index]
         if isinstance(v, Constant):
             real_value = r_controlled.controller.convert(v.value)
-            hop2.args_v[index] = Constant(real_value)
+            v = Constant(real_value)
+        hop2.args[index] = HopArg(v, s_new, r_new)
     if revealresult:
         r_controlled = hop2.r_result
         if not isinstance(r_controlled, ControlledInstanceRepr):
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -2,6 +2,7 @@
 
 from rpython.annotator import model as annmodel, description
 from rpython.flowspace.model import Constant
+from rpython.rtyper.rtyper import HopArg
 from rpython.rtyper import rclass, callparse
 from rpython.rtyper.annlowlevel import llstr
 from rpython.rtyper.error import TyperError
@@ -563,11 +564,15 @@
         # XXX obscure, try to refactor...
         s_function = annmodel.SomePBC([self.funcdesc])
         hop2 = hop.copy()
-        hop2.args_s[0] = self.s_im_self   # make the 1st arg stand for 'im_self'
-        hop2.args_r[0] = self.r_im_self   # (same lowleveltype as 'self')
+
+        # make the 1st arg stand for 'im_self'
         if isinstance(hop2.args_v[0], Constant):
             boundmethod = hop2.args_v[0].value
-            hop2.args_v[0] = Constant(boundmethod.im_self)
+            v_im_self = Constant(boundmethod.im_self)
+        else:
+            v_im_self = hop2.args[0].v
+        hop2.args[0] = HopArg(v_im_self, self.s_im_self, self.r_im_self)
+
         if call_args:
             hop2.swap_fst_snd_args()
             _, s_shape = hop2.r_s_popfirstarg() # temporarely remove shape
@@ -854,8 +859,8 @@
 
     def add_instance_arg_to_hop(self, hop, call_args):
         hop2 = hop.copy()
-        hop2.args_s[0] = self.s_im_self   # make the 1st arg stand for 'im_self'
-        hop2.args_r[0] = self.r_im_self   # (same lowleveltype as 'self')
+        hop2.args[0].s = self.s_im_self   # make the 1st arg stand for 'im_self'
+        hop2.args[0].r = self.r_im_self   # (same lowleveltype as 'self')
 
         if call_args:
             hop2.swap_fst_snd_args()
diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py
--- a/rpython/rtyper/rrange.py
+++ b/rpython/rtyper/rrange.py
@@ -1,5 +1,6 @@
 from rpython.flowspace.model import Constant
 from rpython.rtyper.error import TyperError
+from rpython.rtyper.rtyper import HopArg
 from rpython.rtyper.lltypesystem.lltype import Signed, Void, Ptr
 from rpython.rtyper.rlist import dum_nocheck, dum_checkidx
 from rpython.rtyper.rmodel import Repr, IteratorRepr
@@ -207,7 +208,7 @@
         v_enumerate, = hop.inputargs(self)
         v_index = hop.gendirectcall(self.ll_getnextindex, v_enumerate)
         hop2 = hop.copy()
-        hop2.args_r = [self.r_baseiter]
+        hop2.args = [HopArg(hop.args[0].v, hop.args[0].s, self.r_baseiter)]
         r_item_src = self.r_baseiter.external_item_repr
         r_item_dst = hop.r_result.items_r[1]
         v_item = self.r_baseiter.rtype_next(hop2)
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -676,10 +676,12 @@
     def setup(self):
         rtyper = self.rtyper
         spaceop = self.spaceop
-        self.args_v   = list(spaceop.args)
-        self.args_s   = [rtyper.binding(a) for a in spaceop.args]
+        args_v   = spaceop.args
+        args_s   = [rtyper.binding(a) for a in args_v]
+        args_r   = [rtyper.getrepr(s_a) for s_a in args_s]
+        self.args = [HopArg(v, s, r) for v, s, r in
+                zip(args_v, args_s, args_r)]
         self.s_result = rtyper.binding(spaceop.result)
-        self.args_r   = [rtyper.getrepr(s_a) for s_a in self.args_s]
         self.r_result = rtyper.getrepr(self.s_result)
         rtyper.call_all_setups()  # compute ForwardReferences now
 
@@ -688,9 +690,16 @@
         return len(self.args_v)
 
     @property
-    def args(self):
-        return [HopArg(v, s, r) for v, s, r in
-                zip(self.args_v, self.args_s, self.args_r)]
+    def args_v(self):
+        return [arg.v for arg in self.args]
+
+    @property
+    def args_s(self):
+        return [arg.s for arg in self.args]
+
+    @property
+    def args_r(self):
+        return [arg.r for arg in self.args]
 
     def copy(self):
         result = HighLevelOp(self.rtyper, self.spaceop,
@@ -741,8 +750,8 @@
 
     def r_s_pop(self, index=-1):
         "Return and discard the argument with index position."
-        self.args_v.pop(index)
-        return self.args_r.pop(index), self.args_s.pop(index)
+        arg = self.args.pop(index)
+        return arg.r, arg.s
 
     def r_s_popfirstarg(self):
         "Return and discard the first argument."
@@ -750,14 +759,11 @@
 
     def v_s_insertfirstarg(self, v_newfirstarg, s_newfirstarg):
         r_newfirstarg = self.rtyper.getrepr(s_newfirstarg)
-        self.args_v.insert(0, v_newfirstarg)
-        self.args_r.insert(0, r_newfirstarg)
-        self.args_s.insert(0, s_newfirstarg)
+        newarg = HopArg(v_newfirstarg, s_newfirstarg, r_newfirstarg)
+        self.args.insert(0, newarg)
 
     def swap_fst_snd_args(self):
-        self.args_v[0], self.args_v[1] = self.args_v[1], self.args_v[0]
-        self.args_s[0], self.args_s[1] = self.args_s[1], self.args_s[0]
-        self.args_r[0], self.args_r[1] = self.args_r[1], self.args_r[0]
+        self.args[0], self.args[1] = self.args[1], self.args[0]
 
     def has_implicit_exception(self, exc_cls):
         if self.llops.llop_raising_exceptions is not None:


More information about the pypy-commit mailing list