[pypy-svn] r25045 - pypy/dist/pypy/jit

arigo at codespeak.net arigo at codespeak.net
Mon Mar 27 18:21:29 CEST 2006


Author: arigo
Date: Mon Mar 27 18:21:28 2006
New Revision: 25045

Modified:
   pypy/dist/pypy/jit/hintrtyper.py
   pypy/dist/pypy/jit/rtimeshift.py
Log:
light refactorings, and support for directly calling methods
of frozen PBCs as mix-level helpers.



Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py	(original)
+++ pypy/dist/pypy/jit/hintrtyper.py	Mon Mar 27 18:21:28 2006
@@ -1,3 +1,4 @@
+import types
 from pypy.annotation import model as annmodel
 from pypy.annotation.pairtype import pair, pairtype
 from pypy.rpython import annlowlevel
@@ -218,11 +219,23 @@
     def genmixlevelhelpercall(self, function, args_s, args_v, s_result):
         # XXX first approximation, will likely need some fine controlled
         # specialisation for these helpers too
-        rtyper = self.timeshifter.rtyper
+
+        if isinstance(function, types.MethodType):
+            if function.im_self is not None:
+                # bound method => function and an extra first argument
+                bk = self.rtyper.annotator.bookkeeper
+                s_self = bk.immutablevalue(function.im_self)
+                r_self = self.rtyper.getrepr(s_self)
+                v_self = inputconst(r_self.lowleveltype,
+                                    r_self.convert_const(function.im_self))
+                args_s = [s_self] + args_s
+                args_v = [v_self] + args_v
+            function = function.im_func
 
         graph = self.timeshifter.annhelper.getgraph(function, args_s, s_result)
         self.record_extra_call(graph) # xxx
 
+        rtyper = self.timeshifter.rtyper
         ARGS = [rtyper.getrepr(s_arg).lowleveltype for s_arg in args_s]
         RESULT = rtyper.getrepr(s_result).lowleveltype
 
@@ -326,14 +339,14 @@
 
 
 class RedStructRepr(RedRepr):
-    ll_factory = None
+    typedesc = None
 
     def create(self, hop):
-        if self.ll_factory is None:
+        if self.typedesc is None:
             T = self.original_concretetype.TO
-            self.ll_factory = rtimeshift.make_virtualredbox_factory_for_struct(T)
+            self.typedesc = rtimeshift.ContainerTypeDesc(T)
         ts = self.timeshifter
-        return hop.llops.genmixlevelhelpercall(self.ll_factory,
+        return hop.llops.genmixlevelhelpercall(self.typedesc.ll_factory,
             [], [], ts.s_RedBox)
 
 

Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/rtimeshift.py	Mon Mar 27 18:21:28 2006
@@ -91,7 +91,6 @@
     "A red box that contains (for now) a virtual Struct."
 
     def __init__(self, typedesc):
-        # XXX pass a TypeDesc instead of these arguments
         self.content_boxes = typedesc.content_boxes[:]
         self.typedesc = typedesc
         self.genvar = rgenop.nullvar
@@ -122,19 +121,6 @@
         else:
             self.content_boxes[fielddesc.fieldindex] = valuebox
 
-def make_virtualredbox_factory_for_struct(T):
-    defls = []
-    for name in T._names:
-        FIELDTYPE = T._flds[name]
-        defaultvalue = FIELDTYPE._defl()
-        defaultbox = ConstRedBox.ll_fromvalue(defaultvalue)
-        defls.append(defaultbox)
-    desc = ContainerTypeDesc(T)
-    desc.content_boxes = defls
-    def ll_factory():
-        return VirtualRedBox(desc)
-    return ll_factory
-
 class ConstRedBox(RedBox):
     "A red box that contains a run-time constant."
 
@@ -278,6 +264,16 @@
         # XXX only for Struct so far
         self.fielddescs = [make_fielddesc(self.PTRTYPE, name)
                            for name in TYPE._names]
+        defls = []
+        for name in TYPE._names:
+            FIELDTYPE = TYPE._flds[name]
+            defaultvalue = FIELDTYPE._defl()
+            defaultbox = ConstRedBox.ll_fromvalue(defaultvalue)
+            defls.append(defaultbox)
+        self.content_boxes = defls
+
+    def ll_factory(self):
+        return VirtualRedBox(self)
 
     def _freeze_(self):
         return True



More information about the Pypy-commit mailing list