[pypy-svn] r29466 - in pypy/dist/pypy/jit: hintannotator timeshifter timeshifter/test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 28 20:38:49 CEST 2006


Author: arigo
Date: Wed Jun 28 20:38:47 2006
New Revision: 29466

Added:
   pypy/dist/pypy/jit/timeshifter/vlist.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/timeshifter/rtyper.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
(pedronis, arre, arigo)
Started working on the next test: redboxed virtual lists.
Intermediate check-in.


Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Wed Jun 28 20:38:47 2006
@@ -411,6 +411,14 @@
 # ____________________________________________________________
 
 def handle_highlevel_operation(bookkeeper, ll_func, *args_hs):
+    if getattr(bookkeeper.annotator.policy, 'novirtualcontainer', False):
+        # "blue variables" disabled, we just return a red var all the time.
+        RESULT = bookkeeper.current_op_concretetype()
+        if RESULT is lltype.Void:
+            return None
+        else:
+            return SomeLLAbstractVariable(RESULT)
+
     # parse the oopspec and fill in the arguments
     operation_name, args = ll_func.oopspec.split('(', 1)
     assert args.endswith(')')

Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py	Wed Jun 28 20:38:47 2006
@@ -1,4 +1,5 @@
 import types
+from pypy.objspace.flow import model as flowmodel
 from pypy.annotation import model as annmodel
 from pypy.annotation.pairtype import pair, pairtype
 from pypy.rpython import annlowlevel
@@ -196,6 +197,63 @@
         r_result = hop.r_result
         return r_result.create(hop)
 
+    def translate_op_direct_call(self, hop):
+        c_func = hop.args_v[0]
+        assert isinstance(c_func, flowmodel.Constant)
+        fnobj = c_func.value._obj
+        if hasattr(fnobj._callable, 'oopspec'):
+            hop.r_s_popfirstarg()
+            return self.handle_highlevel_operation(fnobj._callable, hop)
+        else:
+            raise NotImplementedError("direct_call")
+
+    def handle_highlevel_operation(self, ll_func, hop):
+        # parse the oopspec and fill in the arguments
+        class Index:
+            def __init__(self, n):
+                self.n = n
+        operation_name, args = ll_func.oopspec.split('(', 1)
+        assert args.endswith(')')
+        args = args[:-1] + ','     # trailing comma to force tuple syntax
+        argnames = ll_func.func_code.co_varnames[:hop.nb_args]
+        d = dict(zip(argnames, [Index(n) for n in range(hop.nb_args)]))
+        argtuple = eval(args, d)
+        args_v = []
+        for obj in argtuple:
+            if isinstance(obj, Index):
+                hs = hop.args_s[obj.n]
+                r_arg = self.getredrepr(originalconcretetype(hs))
+                v = hop.inputarg(r_arg, arg=obj.n)
+            else:
+                v = hop.inputconst(self.getredrepr(lltype.typeOf(obj)), obj)
+            args_v.append(v)
+        # end of rather XXX'edly hackish parsing
+
+        ts = self.timeshifter
+        args_s = [ts.s_RedBox] * len(args_v)
+        RESULT = originalconcretetype(hop.s_result)
+        if RESULT is lltype.Void:
+            s_result = annmodel.s_None
+        else:
+            s_result = ts.s_RedBox
+
+        if operation_name == 'newlist':
+            from pypy.jit.timeshifter.vlist import ListTypeDesc, oop_newlist
+            typedesc = ListTypeDesc(RESULT.TO)
+            c_typedesc = inputconst(lltype.Void, typedesc)
+            s_typedesc = ts.rtyper.annotator.bookkeeper.immutablevalue(typedesc)
+            args_v.insert(0, c_typedesc)
+            args_s.insert(0, s_typedesc)
+            ll_handler = oop_newlist
+        else:
+            XXX - Later
+
+        v_jitstate = hop.llops.getjitstate()
+        return hop.llops.genmixlevelhelpercall(ll_handler,
+                                               [ts.s_JITState] + args_s,
+                                               [v_jitstate] + args_v,
+                                               s_result)
+
 
 class HintLowLevelOpList(LowLevelOpList):
     """Warning: the HintLowLevelOpList's rtyper is the *original*

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Wed Jun 28 20:38:47 2006
@@ -20,6 +20,7 @@
 
 P_NOVIRTUAL = AnnotatorPolicy()
 P_NOVIRTUAL.novirtualcontainer = True
+P_NOVIRTUAL.oopspec = True
 
 def getargtypes(annotator, values):
     return [annotation(annotator, x) for x in values]
@@ -559,3 +560,13 @@
     insns, res = timeshift(ll_function, [1], [], policy=P_NOVIRTUAL)
     assert res == 1 + 2
     assert insns == {'int_is_true': 1, 'int_add': 1}
+
+def test_vlist():
+    py.test.skip("in-progress")
+    def ll_function():
+        lst = []
+        lst.append(12)
+        return lst[0]
+    insns, res = timeshift(ll_function, [], [], policy=P_NOVIRTUAL)
+    assert res == 12
+    assert insns == {}

Added: pypy/dist/pypy/jit/timeshifter/vlist.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/timeshifter/vlist.py	Wed Jun 28 20:38:47 2006
@@ -0,0 +1,34 @@
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython import rgenop
+from pypy.jit.timeshifter.rcontainer import AbstractContainer, cachedtype
+from pypy.jit.timeshifter import rvalue
+
+
+class ListTypeDesc(object):
+    __metaclass__ = cachedtype
+
+    def __init__(self, LIST):
+        self.LIST = LIST
+        self.LISTPTR = lltype.Ptr(LIST)
+        self.gv_type = rgenop.constTYPE(self.LIST)
+        self.gv_ptrtype = rgenop.constTYPE(self.LISTPTR)
+
+    def _freeze_(self):
+        return True
+
+
+class VirtualList(AbstractContainer):
+
+    def __init__(self, typedesc):
+        self.typedesc = typedesc
+        self.item_boxes = []
+
+
+def oop_newlist(jitstate, typedesc, lengthbox):
+    assert lengthbox.is_constant()
+    length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
+    assert length == 0
+    vlist = VirtualList(typedesc)
+    box = rvalue.PtrRedBox(typedesc.gv_ptrtype)
+    box.content = vlist
+    return box



More information about the Pypy-commit mailing list