[pypy-svn] r53232 - in pypy/branch/jit-hotpath/pypy: jit/rainbow jit/rainbow/test jit/timeshifter rpython/ootypesystem translator

antocuni at codespeak.net antocuni at codespeak.net
Tue Apr 1 16:38:06 CEST 2008


Author: antocuni
Date: Tue Apr  1 16:38:05 2008
New Revision: 53232

Modified:
   pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vlist.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/oop.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/vlist.py
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/jit-hotpath/pypy/translator/exceptiontransform.py
Log:
port oopspec and vlist to ootype. First test passes



Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	Tue Apr  1 16:38:05 2008
@@ -5,6 +5,7 @@
 from pypy.objspace.flow import model as flowmodel
 from pypy.rpython.annlowlevel import cachedtype
 from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
 from pypy.jit.hintannotator.model import originalconcretetype
 from pypy.jit.hintannotator import model as hintmodel
 from pypy.jit.timeshifter import rtimeshift, rvalue, rcontainer, exception
@@ -732,13 +733,13 @@
         self.exceptioninstance_positions[exc_class] = result
         return result
 
-    def oopspecdesc_position(self, fnobj, canraise):
-        key = fnobj, canraise
+    def oopspecdesc_position(self, opname, oparg, canraise):
+        key = opname, oparg, canraise
         if key in self.oopspecdesc_positions:
             return self.oopspecdesc_positions[key]
         oopspecdesc = oop.OopSpecDesc(self.RGenOp, self.rtyper,
                                       self.exceptiondesc,
-                                      fnobj, canraise)
+                                      opname, oparg, canraise)
         result = len(self.oopspecdescs)
         self.oopspecdescs.append(oopspecdesc)
         self.oopspecdesc_positions[key] = result
@@ -1053,7 +1054,7 @@
     def handle_oopspec_call(self, op, withexc):
         from pypy.jit.timeshifter.oop import Index
         fnobj = get_funcobj(op.args[0].value)
-        oopspecdescindex = self.oopspecdesc_position(fnobj, withexc)
+        oopspecdescindex = self.oopspecdesc_position('call', fnobj, withexc)
         oopspecdesc = self.oopspecdescs[oopspecdescindex]
         opargs = op.args[1:]
         args_v = []
@@ -1591,10 +1592,55 @@
         return self.serialize_op_setfield_impl(op)
 
     def serialize_op_new(self, op):
+        TYPE = op.args[0].value
+        if TYPE.oopspec_name is not None:
+            # XXX: works only for List
+            oopspecdescindex = self.oopspecdesc_position('new', TYPE, False)
+            oopspecdesc = self.oopspecdescs[oopspecdescindex]
+            deepfrozen = False
+            index = self.serialize_oparg("red", flowmodel.Constant(0, lltype.Signed))
+            self.emit('red_oopspec_call_1')
+            self.emit(oopspecdescindex)
+            self.emit(deepfrozen)
+            self.emit(index)
+            self.register_redvar(op.result)
+            return
+
         index = self.structtypedesc_position(op.args[0].value)
         self.emit("red_new", index)
         self.register_redvar(op.result)
 
+    def serialize_op_oosend(self, op):
+        if self.hannotator.bookkeeper.is_green_call(op):
+            assert False, 'TODO'
+
+        withexc = self.can_raise(op)
+        name = op.args[0].value
+        opargs = op.args[1:]
+        SELFTYPE = opargs[0].concretetype
+        if SELFTYPE.oopspec_name is not None:
+            hasresult = op.result.concretetype != lltype.Void
+            _, meth = SELFTYPE._lookup(name)
+            oopspecdescindex = self.oopspecdesc_position('send', meth, withexc)
+            oopspecdesc = self.oopspecdescs[oopspecdescindex]
+            args_v = []
+            args = []
+            for v in opargs:
+                args_v.append(v)
+                args.append(self.serialize_oparg("red", v))
+
+            hs_self = self.hannotator.binding(opargs[0])
+            deepfrozen = hs_self.deepfrozen
+
+            self.emit("red_oopspec_call%s_%s" % ("_noresult" * (not hasresult),
+                                                 len(args)))
+            self.emit(oopspecdescindex)
+            self.emit(deepfrozen)
+            self.emit(*args)
+
+        else:
+            assert False, 'TODO'
+
 
 class GraphTransformer(object):
     def __init__(self, hannotator):

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vlist.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vlist.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vlist.py	Tue Apr  1 16:38:05 2008
@@ -5,7 +5,7 @@
 
 
 
-class TestVList(InterpretationTest):
+class VListTest(InterpretationTest):
     type_system = "lltype"
 
     def test_vlist(self):
@@ -187,3 +187,24 @@
 
         res = self.interpret(f, [2], [0], policy=P_OOPSPEC)
         assert res == -7
+
+
+class TestLLType(VListTest):
+    type_system = "lltype"
+
+class TestOOType(VListTest):
+    type_system = "ootype"
+
+    def _skip(self):
+        py.test.skip('in progress')
+
+    test_enter_block = _skip
+    test_merge = _skip
+    test_replace = _skip
+    test_force = _skip
+    test_oop_vlist = _skip
+    test_alloc_and_set = _skip
+    test_lists_deepfreeze = _skip
+    test_frozen_list = _skip
+    test_frozen_list_indexerror = _skip
+    test_bogus_index_while_compiling = _skip

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/typesystem.py	Tue Apr  1 16:38:05 2008
@@ -4,7 +4,7 @@
 def deref(T):
     if isinstance(T, lltype.Ptr):
         return T.TO
-    assert isinstance(T, (ootype.Instance, ootype.Record))
+    assert isinstance(T, (ootype.Instance, ootype.BuiltinType))
     return T
 
 def fieldType(T, name):

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/oop.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/oop.py	Tue Apr  1 16:38:05 2008
@@ -5,98 +5,59 @@
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.ootypesystem import ootype
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.translator import exceptiontransform
 from pypy.translator.simplify import get_funcobj, get_functype
+from pypy.jit.rainbow.typesystem import deref
+
+def OopSpecDesc(RGenOp, rtyper, exceptiondesc, opname, oparg, can_raise):
+    if opname == 'new':
+        cls = NewOopSpecDesc
+    elif opname == 'send':
+        cls = SendOopSpecDesc
+    elif opname == 'call':
+        cls = CallOopSpecDesc
+    return cls(RGenOp, rtyper, exceptiondesc, oparg, can_raise)
 
 class Index:
     def __init__(self, n):
         self.n = n
 
-
-class OopSpecDesc:
+class AbstractOopSpecDesc:
     __metaclass__ = cachedtype
 
     def __init__(self, RGenOp, rtyper, exceptiondesc, fnobj, can_raise):
         self.rtyper = rtyper
-        ll_func = fnobj._callable
-        FUNCTYPE = lltype.typeOf(fnobj)
-        nb_args = len(FUNCTYPE.ARGS)
-
         self.can_raise = can_raise
+        self._setup_oopdesc(RGenOp, fnobj)
 
-        # parse the oopspec and fill in the arguments
-        operation_name, args = ll_func.oopspec.split('(', 1)
-        assert args.endswith(')')
-        args = args[:-1] + ','     # trailing comma to force tuple syntax
-        if args.strip() == ',':
-            args = '()'
-        argnames = ll_func.func_code.co_varnames[:nb_args]
-        argname2index = dict(zip(argnames, [Index(n) for n in range(nb_args)]))
-        self.argtuple = eval(args, argname2index)
-        # end of rather XXX'edly hackish parsing
-
-        OOPARGTYPES = []
-        arg_llsig_to_oopsig = {}
-        for i, obj in enumerate(self.argtuple):
-            if isinstance(obj, Index):
-                arg_llsig_to_oopsig[obj.n] = i
-                OOPARG = FUNCTYPE.ARGS[obj.n]
-            else:
-                OOPARG = lltype.typeOf(obj)
-            OOPARGTYPES.append(OOPARG)
-
-        self.residualargsources = []
-        for i in range(nb_args):
-            ARGTYPE = FUNCTYPE.ARGS[i]
-            if ARGTYPE is not lltype.Void:
-                self.residualargsources.append(arg_llsig_to_oopsig[i])
-
-        self.args_gv = [None] * nb_args
-        fnptr = fnobj._as_ptr()
-        self.gv_fnptr = RGenOp.constPrebuiltGlobal(fnptr)
-        result_kind = RGenOp.kindToken(FUNCTYPE.RESULT)
-        self.result_kind = result_kind
-        if FUNCTYPE.RESULT is lltype.Void:
+        if self.RESULT is lltype.Void:
             self.errorbox = None
             self.gv_whatever_return_value = None
         else:
-            error_value = exceptiontransform.error_value(FUNCTYPE.RESULT)
+            error_value = exceptiontransform.error_value(self.RESULT)
             self.errorbox = rvalue.redbox_from_prebuilt_value(RGenOp,
                                                               error_value)
             self.gv_whatever_return_value = self.errorbox.genvar
-        redboxbuilder = rvalue.ll_redboxbuilder(FUNCTYPE.RESULT)
+        redboxbuilder = rvalue.ll_redboxbuilder(self.RESULT)
         self.redboxbuilder = redboxbuilder
-        self.sigtoken = RGenOp.sigToken(FUNCTYPE)
-
-        if operation_name == 'newlist':
-            typename, method = 'list', 'oop_newlist'
-            SELFTYPE = FUNCTYPE.RESULT.TO
-            is_method = False
-        elif operation_name == 'newdict':
-            typename, method = 'dict', 'oop_newdict'
-            SELFTYPE = FUNCTYPE.RESULT.TO
-            is_method = False
-        else:
-            typename, method = operation_name.split('.')
-            method = 'oop_%s_%s' % (typename, method)
-            SELFTYPE = FUNCTYPE.ARGS[self.argtuple[0].n].TO
-            is_method = True
-        self.is_method = is_method
 
         # hack! to avoid confusion between the .typedesc attribute
         # of oopspecdescs of different types (lists, dicts, etc.)
         # let's use different subclasses for the oopspecdesc too.
-        self.__class__ = myrealclass = globals()['OopSpecDesc_%s' % typename]
+        thisclass = self.__class__.__name__
+        self.__class__ = myrealclass = globals()['%s_%s' % (thisclass, self.typename)]
 
-        vmodule = __import__('pypy.jit.timeshifter.v%s' % (typename,),
-                             None, None, [method])
+        vmodule = __import__('pypy.jit.timeshifter.v%s' % (self.typename,),
+                             None, None, [self.method])
         self.typedesc = vmodule.TypeDesc(RGenOp, rtyper, exceptiondesc,
-                                         SELFTYPE)
-        handler = getattr(vmodule, method)
+                                         self.SELFTYPE)
+        handler = getattr(vmodule, self.method)
 
         boxargcount_max = handler.func_code.co_argcount - 3
         boxargcount_min = boxargcount_max - len(handler.func_defaults or ())
+        is_method = self.is_method
 
         def ll_handler(jitstate, oopspecdesc, deepfrozen, *argboxes):
             # an indirection to support the fact that the handler() can
@@ -114,7 +75,7 @@
             assert isinstance(oopspecdesc, myrealclass)
             if is_method:
                 selfbox = argboxes[0]
-                assert isinstance(selfbox, rvalue.PtrRedBox)
+                assert isinstance(selfbox, rvalue.AbstractPtrRedBox)
                 return handler(jitstate, oopspecdesc, deepfrozen, selfbox,
                                *argboxes[1:])
             else:
@@ -124,21 +85,25 @@
         self.couldfold = getattr(handler, 'couldfold', False)
 
         if self.couldfold:
+            # XXX: works only with lltype
+            ll_func = fnobj._callable
             oopargcheck = ll_func.oopargcheck    # required if couldfold=True
             # make a copy of the function, for specialization purposes
             oopargcheck = func_with_new_name(oopargcheck,
-                                             'argcheck_%s' % (method,))
+                                             'argcheck_%s' % (self.method,))
         else:
             oopargcheck = None
 
         if True:     # preserve indentation for svn history.
             # This used to be only if couldfold, but it is now
             # always required, for the fallback interp
-            ARGS = FUNCTYPE.ARGS
+            ARGS = self.ARGS
             residualargsources = self.residualargsources
             unrolling_ARGS = unrolling_iterable(ARGS)
-            unrolling_OOPARGS = unrolling_iterable(enumerate(OOPARGTYPES))
+            unrolling_OOPARGS = unrolling_iterable(enumerate(self.OOPARGTYPES))
 
+            RESULT = self.RESULT
+            fnptr = self.fnptr
             def do_call(rgenop, args_gv):
                 oopargs = ()
                 for i, ARG in unrolling_OOPARGS:
@@ -158,7 +123,7 @@
                         v = oopargs[argsrc]
                     args += (v,)
                 result = maybe_on_top_of_llinterp(exceptiondesc, fnptr)(*args)
-                if FUNCTYPE.RESULT == lltype.Void:
+                if RESULT == lltype.Void:
                     return None
                 return rgenop.genconst(result)
 
@@ -179,8 +144,7 @@
                 jitstate.residual_exception(e)
                 return self.errorbox
         else:
-            gv_result = builder.genop_call(self.sigtoken,
-                                           self.gv_fnptr, args_gv)
+            gv_result = self.generate_call(builder, args_gv)
             if self.can_raise:
                 jitstate.generated_oop_residual_can_raise = True
         return self.redboxbuilder(gv_result)
@@ -195,11 +159,127 @@
         return self.errorbox
     residual_exception._annspecialcase_ = 'specialize:arg(2)'
 
+    def __repr__(self):
+        return '<%s(%s)>' % (self.__class__.__name__, self.method)
+
+class CallOopSpecDesc(AbstractOopSpecDesc):
+
+    def _setup_oopdesc(self, RGenOp, fnobj):
+        FUNCTYPE = lltype.typeOf(fnobj)
+        self.ARGS = FUNCTYPE.ARGS
+        self.RESULT = FUNCTYPE.RESULT
+        ll_func = fnobj._callable
+        nb_args = len(FUNCTYPE.ARGS)
+
+        # parse the oopspec and fill in the arguments
+        operation_name, args = ll_func.oopspec.split('(', 1)
+        assert args.endswith(')')
+        args = args[:-1] + ','     # trailing comma to force tuple syntax
+        if args.strip() == ',':
+            args = '()'
+        argnames = ll_func.func_code.co_varnames[:nb_args]
+        argname2index = dict(zip(argnames, [Index(n) for n in range(nb_args)]))
+        self.argtuple = eval(args, argname2index)
+        # end of rather XXX'edly hackish parsing
+
+        self.OOPARGTYPES = []
+        arg_llsig_to_oopsig = {}
+        for i, obj in enumerate(self.argtuple):
+            if isinstance(obj, Index):
+                arg_llsig_to_oopsig[obj.n] = i
+                OOPARG = FUNCTYPE.ARGS[obj.n]
+            else:
+                OOPARG = lltype.typeOf(obj)
+            self.OOPARGTYPES.append(OOPARG)
+
+        self.residualargsources = []
+        for i in range(nb_args):
+            ARGTYPE = FUNCTYPE.ARGS[i]
+            if ARGTYPE is not lltype.Void:
+                self.residualargsources.append(arg_llsig_to_oopsig[i])
+
+        if operation_name == 'newlist':
+            self.typename = 'list'
+            self.method = 'oop_newlist'
+            self.SELFTYPE = deref(FUNCTYPE.RESULT)
+            self.is_method = False
+        elif operation_name == 'newdict':
+            self.typename = 'dict'
+            self.method = 'oop_newdict'
+            self.SELFTYPE = deref(FUNCTYPE.RESULT)
+            is_method = False
+        else:
+            self.typename, method = operation_name.split('.')
+            self.method = 'oop_%s_%s' % (self.typename, method)
+            self.SELFTYPE = deref(FUNCTYPE.ARGS[self.argtuple[0].n])
+            self.is_method = True
+
+        self.fnptr = fnobj._as_ptr()
+        self.gv_fnptr = RGenOp.constPrebuiltGlobal(self.fnptr)
+        self.sigtoken = RGenOp.sigToken(FUNCTYPE)
+
+        # the following attributes seem to be unused
+##        result_kind = RGenOp.kindToken(FUNCTYPE.RESULT)
+##        self.result_kind = result_kind
+##        self.args_gv = [None] * nb_args
+
+    def generate_call(self, builder, args_gv):
+        return builder.genop_call(self.sigtoken, self.gv_fnptr, args_gv)
+
+
+class CallOopSpecDesc_list(CallOopSpecDesc):
+    pass
+
+class CallOopSpecDesc_dict(CallOopSpecDesc):
+    pass
+
+
+class NewOopSpecDesc(AbstractOopSpecDesc):
+    def _setup_oopdesc(self, RGenOp, TYPE):
+        self.SELFTYPE = TYPE
+        self.ARGS = []
+        self.RESULT = TYPE
+        self.OOPARGTYPES = []
+        self.residualargsources = []
+        self.typename = TYPE.oopspec_name
+        self.method = 'oop_new%s' % self.typename
+        self.is_method = False
+
+        def allocate():
+            return ootype.new(TYPE)
+        self.fnptr = self.rtyper.annotate_helper_fn(allocate, [])
+
+class NewOopSpecDesc_list(NewOopSpecDesc):
+    pass
+
+class NewOopSpecDesc_dict(NewOopSpecDesc):
+    pass
+
+
+class SendOopSpecDesc(AbstractOopSpecDesc):
+    def _setup_oopdesc(self, RGenOp, meth):
+        METH = ootype.typeOf(meth)
+        assert METH.SELFTYPE is not None, 'fix ootype'
+        self.SELFTYPE = METH.SELFTYPE
+        self.ARGS = METH.ARGS
+        self.RESULT = METH.RESULT
+
+        # we assume the number and position of the arguments are the
+        # same as in the original oosend
+        self.OOPARGTYPES = [self.SELFTYPE] + list(METH.ARGS)
+        self.residualargsources = range(len(self.OOPARGTYPES))
+        self.typename = self.SELFTYPE.oopspec_name
+        methname = meth._name.lstrip('_')
+        methname = methname.lstrip('ll_')
+        self.method = 'oop_%s_method_%s' % (self.typename, methname)
+        self.is_method = True
+        self.fnptr = meth
+
 
-class OopSpecDesc_list(OopSpecDesc):
+class SendOopSpecDesc_list(SendOopSpecDesc):
     pass
 
-class OopSpecDesc_dict(OopSpecDesc):
+class SendOopSpecDesc_dict(SendOopSpecDesc):
     pass
 
 

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	Tue Apr  1 16:38:05 2008
@@ -86,8 +86,9 @@
         self.name = self._get_type_name(TYPE)
         self.ptrkind = RGenOp.kindToken(self.PTRTYPE)
 
-        self.immutable = TYPE._hints.get('immutable', False)
-        self.noidentity = TYPE._hints.get('noidentity', False)
+        hints = getattr(TYPE, '_hints', {})
+        self.immutable = hints.get('immutable', False)
+        self.noidentity = hints.get('noidentity', False)
 
         fixsize = not TYPE._is_varsize()
 
@@ -260,14 +261,19 @@
         pass
 
     def _iter_fields(self, TYPE):
-        for name, (FIELDTYPE, defl) in TYPE._fields.iteritems():
+        try:
+            fields = TYPE._fields
+        except AttributeError:
+            return
+        for name, (FIELDTYPE, defl) in fields.iteritems():
             yield name, FIELDTYPE
 
     def _get_type_name(self, TYPE):
-        if isinstance(TYPE, ootype.Record):
-            return TYPE._short_name()
-        else:
+        try:
             return TYPE._name
+        except AttributeError:
+            return TYPE._short_name()
+
 
 def create_varsize(jitstate, contdesc, sizebox):
     gv_size = sizebox.getgenvar(jitstate)

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/vlist.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/vlist.py	Tue Apr  1 16:38:05 2008
@@ -6,6 +6,12 @@
 from pypy.rpython.lltypesystem import lloperation
 debug_print = lloperation.llop.debug_print
 
+def TypeDesc(RGenOp, rtyper, exceptiondesc, LIST):
+    if rtyper.type_system.name == 'lltypesystem':
+        return LLTypeListTypeDesc(RGenOp, rtyper, exceptiondesc, LIST)
+    else:
+        return OOTypeListTypeDesc(RGenOp, rtyper, exceptiondesc, LIST)
+
 
 class ItemDesc(object):
     __metaclass__ = cachedtype
@@ -24,17 +30,59 @@
                 if not T._is_varsize():
                     self.canbevirtual = True
 
-class ListTypeDesc(object):
+class AbstractListTypeDesc(object):
     __metaclass__ = cachedtype
 
     def __init__(self, RGenOp, rtyper, exceptiondesc, LIST):
         self.LIST = LIST
-        self.LISTPTR = lltype.Ptr(LIST)
+        self.LISTPTR = self.Ptr(LIST)
         self.ptrkind = RGenOp.kindToken(self.LISTPTR)
         self.null = self.LISTPTR._defl()
         self.gv_null = RGenOp.constPrebuiltGlobal(self.null)
         self.exceptiondesc = exceptiondesc
 
+        self._setup(RGenOp, rtyper, LIST)
+        self._define_devirtualize()
+        self._define_allocate()
+
+    def _define_allocate(self):
+        LIST = self.LIST
+        LISTPTR = self.LISTPTR
+
+        def allocate(rgenop, n):
+            l = LIST.ll_newlist(n)
+            return rgenop.genconst(l)
+
+        def populate(item_boxes, gv_lst, box_gv_reader):
+            l = gv_lst.revealconst(LISTPTR)
+            # NB. len(item_boxes) may be l.ll_length()+1 if need_reshaping :-(
+            for i in range(l.ll_length()):
+                box = item_boxes[i]
+                if box is not None:
+                    gv_value = box_gv_reader(box)
+                    v = gv_value.revealconst(LIST.ITEM)
+                    l.ll_setitem_fast(i, v)
+
+        self.allocate = allocate
+        self.populate = populate
+
+    def _freeze_(self):
+        return True
+
+    def factory(self, length, itembox):
+        vlist = VirtualList(self, length, itembox)
+        box = self.PtrRedBox(known_nonzero=True)
+        box.content = vlist
+        vlist.ownbox = box
+        return box
+
+
+class LLTypeListTypeDesc(AbstractListTypeDesc):
+
+    Ptr = staticmethod(lltype.Ptr)
+    PtrRedBox = rvalue.PtrRedBox
+
+    def _setup(self, RGenOp, rtyper, LIST):
         argtypes = [lltype.Signed]
         ll_newlist_ptr = rtyper.annotate_helper_fn(LIST.ll_newlist,
                                                    argtypes)
@@ -48,9 +96,6 @@
         self.tok_ll_setitem_fast = RGenOp.sigToken(
             lltype.typeOf(ll_setitem_fast).TO)
 
-        self._define_devirtualize()
-        self._define_allocate()
-
     def _define_devirtualize(self):
         LIST = self.LIST
         LISTPTR = self.LISTPTR
@@ -70,39 +115,18 @@
 
         self.devirtualize = make, fill_into
 
-    def _define_allocate(self):
-        LIST = self.LIST
-        LISTPTR = self.LISTPTR
-
-        def allocate(rgenop, n):
-            l = LIST.ll_newlist(n)
-            return rgenop.genconst(l)
-
-        def populate(item_boxes, gv_lst, box_gv_reader):
-            l = gv_lst.revealconst(LISTPTR)
-            # NB. len(item_boxes) may be l.ll_length()+1 if need_reshaping :-(
-            for i in range(l.ll_length()):
-                box = item_boxes[i]
-                if box is not None:
-                    gv_value = box_gv_reader(box)
-                    v = gv_value.revealconst(LIST.ITEM)
-                    l.ll_setitem_fast(i, v)
+        
 
-        self.allocate = allocate
-        self.populate = populate
+class OOTypeListTypeDesc(AbstractListTypeDesc):
 
-    def _freeze_(self):
-        return True
-
-    def factory(self, length, itembox):
-        vlist = VirtualList(self, length, itembox)
-        box = rvalue.PtrRedBox(known_nonzero=True)
-        box.content = vlist
-        vlist.ownbox = box
-        return box
+    Ptr = staticmethod(lambda T: T)
+    PtrRedBox = rvalue.InstanceRedBox
 
-TypeDesc = ListTypeDesc
+    def _setup(self, RGenOp, rtyper, LIST):
+        pass
 
+    def _define_devirtualize(self):
+        pass # XXX
 
 class FrozenVirtualList(FrozenContainer):
 
@@ -163,6 +187,7 @@
 
     def __init__(self, typedesc, length=0, itembox=None):
         self.typedesc = typedesc
+        self.itembox = itembox
         self.item_boxes = [itembox] * length
         # self.ownbox = ...    set in factory()
 
@@ -355,6 +380,18 @@
                                          deepfrozen=deepfrozen)
 oop_list_nonzero.couldfold = True
 
+def oop_list_method_resize(jitstate, oopspecdesc, deepfrozen, selfbox, lengthbox):
+    content = selfbox.content
+    if isinstance(content, VirtualList):
+        item_boxes = content.item_boxes
+        length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
+        if len(item_boxes) < length:
+            diff = length - len(item_boxes)
+            item_boxes += [itembox] * diff
+    else:
+        oopspecdesc.residual_call(jitstate, [selfbox],
+                                  deepfrozen=deepfrozen)
+
 def oop_list_append(jitstate, oopspecdesc, deepfrozen, selfbox, itembox):
     content = selfbox.content
     if isinstance(content, VirtualList):

Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/ootype.py	Tue Apr  1 16:38:05 2008
@@ -13,6 +13,8 @@
 
 class OOType(LowLevelType):
 
+    oopspec_name = None
+
     def _is_compatible(TYPE1, TYPE2):
         if TYPE1 == TYPE2:
             return True
@@ -476,6 +478,7 @@
     # placeholder, because we want backends to distinguish that.
     SELFTYPE_T = object()
     ITEMTYPE_T = object()
+    oopspec_name = 'list'
 
     def __init__(self, ITEMTYPE=None):
         self._ITEMTYPE = ITEMTYPE
@@ -564,6 +567,7 @@
     SELFTYPE_T = object()
     KEYTYPE_T = object()
     VALUETYPE_T = object()
+    oopspec_name = 'dict'
 
     def __init__(self, KEYTYPE=None, VALUETYPE=None):
         self._KEYTYPE = KEYTYPE
@@ -1016,6 +1020,9 @@
    def __repr__(self):
        return 'sm %s' % self._name
 
+   def _as_ptr(self):
+       return self
+
 class _forward_static_meth(_static_meth):
    allowed_types = (StaticMethod, ForwardReference)
 

Modified: pypy/branch/jit-hotpath/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/translator/exceptiontransform.py	(original)
+++ pypy/branch/jit-hotpath/pypy/translator/exceptiontransform.py	Tue Apr  1 16:38:05 2008
@@ -473,8 +473,11 @@
         return obj1 is obj2
 
     def check_for_alloc_shortcut(self, spaceop):
+##        if spaceop.opname in ('new', 'runtimenew', 'oonewcustomdict'):
+##            return True
         return False
 
+
 def ExceptionTransformer(translator):
     type_system = translator.rtyper.type_system.name
     if type_system == 'lltypesystem':



More information about the Pypy-commit mailing list