[pypy-svn] r65431 - in pypy/branch/pyjitpl5-experiments/pypy: config jit/backend/cli jit/backend/cli/test jit/backend/test jit/metainterp/test rpython/ootypesystem translator/cli translator/cli/src translator/oosupport/test_template

antocuni at codespeak.net antocuni at codespeak.net
Tue May 26 21:04:22 CEST 2009


Author: antocuni
Date: Tue May 26 21:04:20 2009
New Revision: 65431

Added:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_loop.py
      - copied unchanged from r65430, pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_loop.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_vlist.py
      - copied unchanged from r65430, pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_vlist.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_loop.py
      - copied unchanged from r65430, pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_zrpy_loop.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_virtualizable.py
      - copied unchanged from r65430, pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_zrpy_virtualizable.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_vlist.py
      - copied unchanged from r65430, pypy/branch/pyjitpl5/pypy/jit/backend/cli/test/test_zrpy_vlist.py
Modified:
   pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/methodfactory.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_basic.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_basic.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_exception.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_send.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/support.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_loop.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_tl.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_virtualizable.py
   pypy/branch/pyjitpl5-experiments/pypy/rpython/ootypesystem/rpbc.py
   pypy/branch/pyjitpl5-experiments/pypy/translator/cli/opcodes.py
   pypy/branch/pyjitpl5-experiments/pypy/translator/cli/src/pypylib.cs
   pypy/branch/pyjitpl5-experiments/pypy/translator/oosupport/test_template/class_.py
Log:
merge changes from pyjitpl5 to pyjitpl5-experiments

        svn merge svn+ssh://codespeak.net/svn/pypy/branch/pyjitpl5/pypy -r65302:HEAD

        ------------------------------------------------------------------------
        r65304 | antocuni | 2009-05-19 10:31:13 +0200 (Tue, 19 May 2009) | 5 lines

        don't print stuff on stdout, as it breaks the minimal and cli backends
        (because the spawn an external process and read the result as printed on
        stdout)


        ------------------------------------------------------------------------
        r65314 | antocuni | 2009-05-19 17:28:40 +0200 (Tue, 19 May 2009) | 7 lines

        implement bridges; so far the implementation is very simple, just a tailcall
        to the method containing the next loop; hopefully, the speed penalty
        associated to the tail call is not too heavy, because we don't expect bridges
        to be so frequent (thanks cfbolz for the idea).  In the future, we might think
        of other techniques to avoid tail calls.


        ------------------------------------------------------------------------
        r65331 | antocuni | 2009-05-20 16:21:28 +0200 (Wed, 20 May 2009) | 10 lines

        the code to implement bridges was broken, fix it:

          - don't put a 'ret' in emit_store_opargs, else the jump is never taken

          - put the array of failing ops on the cpu, not on the method, else the
            "failed_op" index stored in inputargs is meaningless

          - add a bunch of debugging stuff


        ------------------------------------------------------------------------
        r65335 | antocuni | 2009-05-20 18:19:29 +0200 (Wed, 20 May 2009) | 3 lines

        update test status: two more tests pass, one fails only on mono but not on windows, another is not a translation test


        ------------------------------------------------------------------------
        r65336 | antocuni | 2009-05-20 18:32:07 +0200 (Wed, 20 May 2009) | 3 lines

        good, all these tests pass now


        ------------------------------------------------------------------------
        r65337 | antocuni | 2009-05-20 18:36:30 +0200 (Wed, 20 May 2009) | 4 lines

        more passing tests. test_int_lshift_ovf still fails because of a
        NotImplementedError (will investigate later)


        ------------------------------------------------------------------------
        r65338 | antocuni | 2009-05-20 18:42:01 +0200 (Wed, 20 May 2009) | 2 lines

        implement set_overflow_error to make test_int_lshift_ovf passing

        ------------------------------------------------------------------------
        r65339 | antocuni | 2009-05-20 18:51:57 +0200 (Wed, 20 May 2009) | 2 lines

        be explicit on which operation we don't expect in the cli backend. Only few "real" operations are left now

        ------------------------------------------------------------------------
        r65341 | antocuni | 2009-05-21 10:06:38 +0200 (Thu, 21 May 2009) | 3 lines

        add new tests (to be run directly through Python for .NET); most of them pass, a bunch can be run only after translation, only one seems to be related to a real failure


        ------------------------------------------------------------------------
        r65342 | antocuni | 2009-05-21 10:09:51 +0200 (Thu, 21 May 2009) | 2 lines

        I was wrong, this test also has no chances to pass without translation

        ------------------------------------------------------------------------
        r65343 | antocuni | 2009-05-21 10:19:59 +0200 (Thu, 21 May 2009) | 2 lines

        more tests, most of them pass :-)

        ------------------------------------------------------------------------
        r65344 | antocuni | 2009-05-21 11:46:23 +0200 (Thu, 21 May 2009) | 7 lines

        - add a new test to test_loop to test string operations

        - fix oosends to String and Unicode objects

        - test_loop_{string,unicode} pass


        ------------------------------------------------------------------------
        r65345 | antocuni | 2009-05-21 12:39:34 +0200 (Thu, 21 May 2009) | 2 lines

        port more tests, implement do_oonewarray; test_simple_array passes

        ------------------------------------------------------------------------
        r65346 | antocuni | 2009-05-21 13:55:06 +0200 (Thu, 21 May 2009) | 3 lines

        implement emit_op_new_arry, but comment it out as it cannot be tested without translation.


        ------------------------------------------------------------------------
        r65347 | antocuni | 2009-05-21 14:05:47 +0200 (Thu, 21 May 2009) | 2 lines

        implement emit_op_new_arry to make almost all these tests passing

        ------------------------------------------------------------------------
        r65348 | antocuni | 2009-05-21 14:12:41 +0200 (Thu, 21 May 2009) | 4 lines

        delay the call to get_concrete_calltable, so that the low level types of the
        methods arguments have been fully computed, much like r65288. test_ll_fixed_setitem_fast passes


        ------------------------------------------------------------------------
        r65349 | antocuni | 2009-05-21 14:31:03 +0200 (Thu, 21 May 2009) | 2 lines

        port more tests, ignore 'promote_virtualizable' in the normal cli backend.

        ------------------------------------------------------------------------
        r65350 | antocuni | 2009-05-21 14:50:55 +0200 (Thu, 21 May 2009) | 5 lines

        implement emit_op_instanceof, and all the remaining virtualizable tests pass.
        Moreover, add stubs for all the few still missing operations, so that we can
        kill the warning and put an assert instead


        ------------------------------------------------------------------------
        r65351 | antocuni | 2009-05-21 21:51:06 +0200 (Thu, 21 May 2009) | 2 lines

        use "boehm" as a dummy value, else it conflicts with tl/pypyjit.py

        ------------------------------------------------------------------------
        r65352 | antocuni | 2009-05-22 00:47:33 +0200 (Fri, 22 May 2009) | 3 lines

        implement sort_key() for all CLI descrs


        ------------------------------------------------------------------------
        r65358 | antocuni | 2009-05-22 13:56:38 +0200 (Fri, 22 May 2009) | 2 lines

        these two tests pass also on ootype nowadays

        ------------------------------------------------------------------------
        r65421 | antocuni | 2009-05-26 16:08:37 +0200 (Tue, 26 May 2009) | 2 lines

        skip this test, as it cannot really work after translation

        ------------------------------------------------------------------------



Modified: pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/config/translationoption.py	Tue May 26 21:04:20 2009
@@ -30,7 +30,7 @@
                                 ("translation.backendopt.heap2stack", False),
                                 ("translation.backendopt.clever_malloc_removal", False),
                                 ("translation.list_comprehension_operations", False),
-                                ("translation.gc", "generation"), # it's not really used, but some jit code expects a value here
+                                ("translation.gc", "boehm"), # it's not really used, but some jit code expects a value here
                                 ]
                      }),
     ChoiceOption("backend", "Backend to use for code generation",

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	Tue May 26 21:04:20 2009
@@ -14,6 +14,7 @@
 System = CLR.System
 OpCodes = System.Reflection.Emit.OpCodes
 LoopDelegate = CLR.pypy.runtime.LoopDelegate
+DelegateHolder = CLR.pypy.runtime.DelegateHolder
 InputArgs = CLR.pypy.runtime.InputArgs
 
 cVoid = ootype.nullruntimeclass
@@ -51,12 +52,40 @@
     def store(self, meth):
         assert False, 'cannot store() to Constant'
 
+    def get_cliobj(self):
+        return dotnet.cast_to_native_object(self.getobj())
+
 class __extend__(ConstInt):
     __metaclass__ = extendabletype
 
     def load(self, meth):
         meth.il.Emit(OpCodes.Ldc_I4, self.value)
 
+
+class ConstFunction(Const):
+
+    def __init__(self, name):
+        self.name = name
+        self.holder = DelegateHolder()
+
+    def get_cliobj(self):
+        return dotnet.cliupcast(self.holder, System.Object)
+
+    def load(self, meth):
+        holdertype = self.holder.GetType()
+        funcfield = holdertype.GetField('func')
+        Const.load(self, meth)
+        meth.il.Emit(OpCodes.Castclass, holdertype)
+        meth.il.Emit(OpCodes.Ldfld, funcfield)
+        meth.il.Emit(OpCodes.Castclass, dotnet.typeof(LoopDelegate))
+
+    def _getrepr_(self):
+        return '<ConstFunction %s>' % self.name
+
+    def __hash__(self):
+        return hash(self.holder)
+
+
 class MethodArgument(AbstractValue):
     def __init__(self, index, cliType):
         self.index = index
@@ -87,6 +116,7 @@
 class Method(object):
 
     operations = [] # overwritten at the end of the module
+    tailcall = True
     debug = False
 
     def __init__(self, cpu, name, loop):
@@ -94,7 +124,6 @@
         self.name = name
         self.loop = loop
         self.boxes = {}       # box --> local var
-        self.failing_ops = [] # index --> op
         self.branches = []
         self.branchlabels = []
         self.consts = {}      # object --> index
@@ -124,10 +153,12 @@
         # initialize the array of genconsts
         consts = dotnet.new_array(System.Object, len(self.consts))
         for av_const, i in self.consts.iteritems():
-            consts[i] = dotnet.cast_to_native_object(av_const.getobj())
+            #consts[i] = dotnet.cast_to_native_object(av_const.getobj())
+            consts[i] = av_const.get_cliobj()
         # build the delegate
         func = self.meth_wrapper.create_delegate(delegatetype, consts)
-        self.func = dotnet.clidowncast(func, LoopDelegate)
+        func = dotnet.clidowncast(func, LoopDelegate)
+        self.loop._cli_funcbox.holder.SetFunc(func)
 
     def _get_meth_wrapper(self):
         restype = dotnet.class2type(cVoid)
@@ -151,10 +182,10 @@
 
     def get_index_for_failing_op(self, op):
         try:
-            return self.failing_ops.index(op)
+            return self.cpu.failing_ops.index(op)
         except ValueError:
-            self.failing_ops.append(op)
-            return len(self.failing_ops)-1
+            self.cpu.failing_ops.append(op)
+            return len(self.cpu.failing_ops)-1
 
     def get_index_for_constant(self, obj):
         try:
@@ -199,6 +230,7 @@
         self.il.Emit(OpCodes.Stelem, clitype)
 
     def emit_load_inputargs(self):
+        self.emit_debug("executing: " + self.name)
         i = 0
         for box in self.loop.inputargs:
             self.load_inputarg(i, box.type, box.getCliType())
@@ -211,8 +243,7 @@
 
     def emit_operations(self, operations):
         for op in operations:
-            if self.debug:
-                self.il.EmitWriteLine(op.repr())
+            self.emit_debug(op.repr())
             func = self.operations[op.opnum]
             assert func is not None
             func(self, op)
@@ -246,6 +277,10 @@
     def store_result(self, op):
         op.result.store(self)
 
+    def emit_debug(self, msg):
+        if self.debug:
+            self.il.EmitWriteLine(msg)
+
     def emit_clear_exception(self):
         self.av_inputargs.load(self)
         self.il.Emit(OpCodes.Ldnull)
@@ -282,12 +317,15 @@
         self.il.Emit(OpCodes.Ldc_I4, index_op)
         field = dotnet.typeof(InputArgs).GetField('failed_op')
         self.il.Emit(OpCodes.Stfld, field)
-        # store the lates values
+        self.emit_store_opargs(op)
+        self.il.Emit(OpCodes.Ret)
+
+    def emit_store_opargs(self, op):
+        # store the latest values
         i = 0
         for box in op.args:
             self.store_inputarg(i, box.type, box.getCliType(), box)
             i+=1
-        self.il.Emit(OpCodes.Ret)
 
     def emit_guard_bool(self, op, opcode):
         assert op.suboperations
@@ -344,13 +382,24 @@
 
     def emit_op_jump(self, op):
         target = op.jump_target
-        assert target is self.loop, 'TODO'
         assert len(op.args) == len(target.inputargs)
-        i = 0
-        for i in range(len(op.args)):
-            op.args[i].load(self)
-            target.inputargs[i].store(self)
-        self.il.Emit(OpCodes.Br, self.il_loop_start)
+        if target is self.loop:
+            i = 0
+            for i in range(len(op.args)):
+                op.args[i].load(self)
+                target.inputargs[i].store(self)
+            self.il.Emit(OpCodes.Br, self.il_loop_start)
+        else:
+            # it's a real bridge
+            self.emit_debug('jumping to ' + target.name)
+            self.emit_store_opargs(op)
+            target._cli_funcbox.load(self)
+            self.av_inputargs.load(self)
+            methinfo = dotnet.typeof(LoopDelegate).GetMethod('Invoke')
+            if self.tailcall:
+                self.il.Emit(OpCodes.Tailcall)
+            self.il.Emit(OpCodes.Callvirt, methinfo)
+            self.il.Emit(OpCodes.Ret)
 
     def emit_op_new_with_vtable(self, op):
         assert isinstance(op.args[0], ConstObj) # ignored, using the descr instead
@@ -361,6 +410,19 @@
         self.il.Emit(OpCodes.Newobj, ctor_info)
         self.store_result(op)
 
+    def emit_op_runtimenew(self, op):
+        raise NotImplementedError
+
+    def emit_op_instanceof(self, op):
+        descr = op.descr
+        assert isinstance(descr, runner.TypeDescr)
+        clitype = descr.get_clitype()
+        op.args[0].load(self)
+        self.il.Emit(OpCodes.Isinst, clitype)
+        self.il.Emit(OpCodes.Ldnull)
+        self.il.Emit(OpCodes.Cgt_Un)
+        self.store_result(op)
+
     def emit_op_ooidentityhash(self, op):
         raise NotImplementedError
 
@@ -369,7 +431,8 @@
         assert isinstance(descr, runner.StaticMethDescr)
         delegate_type = descr.get_delegate_clitype()
         meth_invoke = descr.get_meth_info()
-        self._emit_call(op, delegate_type, meth_invoke, descr.has_result)
+        self._emit_call(op, OpCodes.Callvirt, delegate_type,
+                        meth_invoke, descr.has_result)
 
     def emit_op_call(self, op):
         emit_op = Method.emit_op_call_impl.im_func
@@ -383,17 +446,18 @@
         assert isinstance(descr, runner.MethDescr)
         clitype = descr.get_self_clitype()
         methinfo = descr.get_meth_info()
-        self._emit_call(op, clitype, methinfo, descr.has_result)
+        opcode = descr.get_call_opcode()
+        self._emit_call(op, opcode, clitype, methinfo, descr.has_result)
 
     emit_op_oosend_pure = emit_op_oosend
 
-    def _emit_call(self, op, clitype, methinfo, has_result):
+    def _emit_call(self, op, opcode, clitype, methinfo, has_result):
         av_sm, args_av = op.args[0], op.args[1:]
         av_sm.load(self)
         self.il.Emit(OpCodes.Castclass, clitype)
         for av_arg in args_av:
             av_arg.load(self)
-        self.il.Emit(OpCodes.Callvirt, methinfo)
+        self.il.Emit(opcode, methinfo)
         if has_result:
             self.store_result(op)
 
@@ -451,25 +515,36 @@
         self.il.Emit(OpCodes.Castclass, clitype)
         self.il.Emit(OpCodes.Ldlen)
         self.store_result(op)
-        
-    def not_implemented(self, op):
+
+    def emit_op_new_array(self, op):
+        descr = op.descr
+        assert isinstance(descr, runner.TypeDescr)
+        item_clitype = descr.get_clitype()
+        op.args[0].load(self)
+        self.il.Emit(OpCodes.Newarr, item_clitype)
+        self.store_result(op)        
+
+    def emit_op_guard_nonvirtualized(self, op):
+        raise NotImplementedError
+
+    def lltype_only(self, op):
+        print 'Operation %s is lltype specific, should not get here!' % op.getopname()
         raise NotImplementedError
 
-    emit_op_cast_int_to_ptr = not_implemented
-    emit_op_guard_nonvirtualized = not_implemented
-    emit_op_unicodelen = not_implemented
-    emit_op_setfield_raw = not_implemented
-    emit_op_cast_ptr_to_int = not_implemented
-    emit_op_newunicode = not_implemented
-    emit_op_new_array = not_implemented
-    emit_op_unicodegetitem = not_implemented
-    emit_op_strgetitem = not_implemented
-    emit_op_getfield_raw = not_implemented
-    emit_op_unicodesetitem = not_implemented
-    emit_op_getfield_raw_pure = not_implemented
-    emit_op_strlen = not_implemented
-    emit_op_newstr = not_implemented
-    emit_op_strsetitem = not_implemented
+    emit_op_new = lltype_only
+    emit_op_setfield_raw = lltype_only
+    emit_op_getfield_raw = lltype_only
+    emit_op_getfield_raw_pure = lltype_only
+    emit_op_strsetitem = lltype_only
+    emit_op_unicodesetitem = lltype_only
+    emit_op_cast_int_to_ptr = lltype_only
+    emit_op_cast_ptr_to_int = lltype_only
+    emit_op_newstr = lltype_only
+    emit_op_strlen = lltype_only
+    emit_op_strgetitem = lltype_only
+    emit_op_newunicode = lltype_only    
+    emit_op_unicodelen = lltype_only
+    emit_op_unicodegetitem = lltype_only
 
 
 # --------------------------------------------------------------------
@@ -507,10 +582,7 @@
         elif isinstance(instr, opcodes.PushArg):
             lines.append('self.push_arg(op, %d)' % instr.n)
         else:
-            if not isinstance(instr, str):
-                print 'WARNING: unknown instruction %s' % instr
-                return
-
+            assert isinstance(instr, str), 'unknown instruction %s' % instr
             if instr.startswith('call '):
                 signature = instr[len('call '):]
                 renderCall(lines, signature)

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/methodfactory.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/methodfactory.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/methodfactory.py	Tue May 26 21:04:20 2009
@@ -71,7 +71,7 @@
     def create_delegate(self, delegatetype, consts):
         t = self.typeBuilder.CreateType()
         methinfo = t.GetMethod("invoke")
-##         if self.name == 'generated_case_1':
+##         if self.name == 'Loop #0(r1)_2':
 ##             assemblyData.auto_save_assembly.Save()
         return System.Delegate.CreateDelegate(delegatetype,
                                               consts,

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/runner.py	Tue May 26 21:04:20 2009
@@ -1,6 +1,9 @@
+from pypy.tool.pairtype import extendabletype
 from pypy.rpython.ootypesystem import ootype
+from pypy.rlib.objectmodel import we_are_translated
 from pypy.jit.metainterp.history import AbstractDescr, AbstractMethDescr
-from pypy.jit.metainterp.history import Box, BoxInt, BoxObj
+from pypy.jit.metainterp.history import Box, BoxInt, BoxObj, ConstObj, Const
+from pypy.jit.metainterp.history import TreeLoop
 from pypy.jit.metainterp import executor
 from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.backend import model
@@ -10,7 +13,19 @@
 from pypy.translator.cli.dotnet import CLR
 
 System = CLR.System
+OpCodes = System.Reflection.Emit.OpCodes
 InputArgs = CLR.pypy.runtime.InputArgs
+cpypyString = dotnet.classof(CLR.pypy.runtime.String)
+
+class __extend__(TreeLoop):
+    __metaclass__ = extendabletype
+
+    _cli_funcbox = None
+    _cli_meth = None
+    _cli_count = 0
+
+    def _get_cli_name(self):
+        return '%s(r%d)' % (self.name, self._cli_count)
 
 
 class CliCPU(model.AbstractCPU):
@@ -25,6 +40,7 @@
         self.stats = stats
         self.translate_support_code = translate_support_code
         self.inputargs = None
+        self.failing_ops = [] # index --> op
         self.ll_ovf_exc = self._get_prebuilt_exc(OverflowError)
         self.ll_zero_exc = self._get_prebuilt_exc(ZeroDivisionError)
 
@@ -48,6 +64,8 @@
 
     @cached_method('_methcache')
     def methdescrof(self, SELFTYPE, methname):
+        if SELFTYPE in (ootype.String, ootype.Unicode):
+            return StringMethDescr(SELFTYPE, methname)
         return MethDescr(SELFTYPE, methname)
 
     @cached_method('_typecache')
@@ -67,14 +85,19 @@
     # ----------------------
 
     def compile_operations(self, loop):
-        from pypy.jit.backend.cli.method import Method
-        meth = Method(self, loop.name, loop)
-        loop._cli_meth = meth
+        from pypy.jit.backend.cli.method import Method, ConstFunction
+        if loop._cli_funcbox is None:
+            loop._cli_funcbox = ConstFunction(loop.name)
+        else:
+            # discard previously compiled loop
+            loop._cli_funcbox.holder.SetFunc(None)
+        loop._cli_meth = Method(self, loop._get_cli_name(), loop)
+        loop._cli_count += 1
 
     def execute_operations(self, loop):
-        meth = loop._cli_meth
-        meth.func(self.get_inputargs())
-        return meth.failing_ops[self.inputargs.get_failed_op()]
+        func = loop._cli_funcbox.holder.GetFunc()
+        func(self.get_inputargs())
+        return self.failing_ops[self.inputargs.get_failed_op()]
 
     def set_future_value_int(self, index, intvalue):
         self.get_inputargs().set_int(index, intvalue)
@@ -110,10 +133,14 @@
         self.get_inputargs().set_exc_value(None)
 
     def set_overflow_error(self):
-        raise NotImplementedError
+        exc_obj = ootype.cast_to_object(self.ll_ovf_exc)
+        exc_value = dotnet.cast_to_native_object(exc_obj)
+        self.get_inputargs().set_exc_value(exc_value)
 
     def set_zero_division_error(self):
-        raise NotImplementedError
+        exc_obj = ootype.cast_to_object(self.ll_zero_exc)
+        exc_value = dotnet.cast_to_native_object(exc_obj)
+        self.get_inputargs().set_exc_value(exc_value)
 
     # ----------------------
 
@@ -122,6 +149,11 @@
         assert len(args) == 1 # but we don't need it, so ignore
         return typedescr.create()
 
+    def do_new_array(self, args, typedescr):
+        assert isinstance(typedescr, TypeDescr)
+        assert len(args) == 1
+        return typedescr.create_array(args[0])
+
     def do_runtimenew(self, args, descr):
         classbox = args[0]
         classobj = ootype.cast_from_object(ootype.Class, classbox.getobj())
@@ -188,6 +220,16 @@
 # ----------------------------------------------------------------------
 key_manager = KeyManager()
 
+class DescrWithKey(AbstractDescr):
+    key = -1
+
+    def __init__(self, key):
+        self.key = key_manager.getkey(key)
+
+    def sort_key(self):
+        return self.key
+
+
 def get_class_for_type(T):
     if T is ootype.Void:
         return ootype.nullruntimeclass
@@ -206,10 +248,10 @@
     else:
         assert False
 
-
-class TypeDescr(AbstractDescr):
+class TypeDescr(DescrWithKey):
 
     def __init__(self, TYPE):
+        DescrWithKey.__init__(self, TYPE)
         from pypy.jit.backend.llgraph.runner import boxresult
         from pypy.jit.metainterp.warmspot import unwrap
         ARRAY = ootype.Array(TYPE)
@@ -245,25 +287,25 @@
         self.getarraylength = getarraylength
         self.instanceof = instanceof
         self.ooclass = get_class_for_type(TYPE)
-        self.ooarrayclass = get_class_for_type(ARRAY)
 
     def get_clitype(self):
         return dotnet.class2type(self.ooclass)
 
     def get_array_clitype(self):
-        return dotnet.class2type(self.ooarrayclass)
+        return self.get_clitype().MakeArrayType()
 
     def get_constructor_info(self):
         clitype = self.get_clitype()
         return clitype.GetConstructor(dotnet.new_array(System.Type, 0))
 
-class StaticMethDescr(AbstractDescr):
+class StaticMethDescr(DescrWithKey):
 
     callfunc = None
     funcclass = ootype.nullruntimeclass
     has_result = False
 
     def __init__(self, FUNC, ARGS, RESULT):
+        DescrWithKey.__init__(self, (FUNC, ARGS, RESULT))
         from pypy.jit.backend.llgraph.runner import boxresult, make_getargs
         getargs = make_getargs(FUNC.ARGS)
         def callfunc(funcbox, argboxes):
@@ -300,6 +342,7 @@
     selfclass = ootype.nullruntimeclass
     methname = ''
     has_result = False
+    key = -1
     
     def __init__(self, SELFTYPE, methname):
         from pypy.jit.backend.llgraph.runner import boxresult, make_getargs
@@ -317,6 +360,10 @@
         self.selfclass = ootype.runtimeClass(SELFTYPE)
         self.methname = methname
         self.has_result = (METH.RESULT != ootype.Void)
+        self.key = key_manager.getkey((SELFTYPE, methname))
+
+    def sort_key(self):
+        return self.key
 
     def get_self_clitype(self):
         return dotnet.class2type(self.selfclass)
@@ -325,16 +372,29 @@
         clitype = self.get_self_clitype()
         return clitype.GetMethod(self.methname+'')
 
+    def get_call_opcode(self):
+        return OpCodes.Callvirt
 
-class FieldDescr(AbstractDescr):
+
+class StringMethDescr(MethDescr):
+
+    def get_meth_info(self):
+        clitype = dotnet.class2type(cpypyString)
+        return clitype.GetMethod(self.methname+'')
+
+    def get_call_opcode(self):
+        return OpCodes.Call
+        
+
+class FieldDescr(DescrWithKey):
 
     getfield = None
     setfield = None
     selfclass = ootype.nullruntimeclass
     fieldname = ''
-    key = -1
 
     def __init__(self, TYPE, fieldname):
+        DescrWithKey.__init__(self, (TYPE, fieldname))
         from pypy.jit.backend.llgraph.runner import boxresult
         from pypy.jit.metainterp.warmspot import unwrap
         _, T = TYPE._lookup_field(fieldname)
@@ -353,9 +413,6 @@
         self.fieldname = fieldname
         self.key = key_manager.getkey((TYPE, fieldname))
 
-    def sort_key(self):
-        return self.key
-
     def equals(self, other):
         assert isinstance(other, FieldDescr)
         return self.key == other.key

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_basic.py	Tue May 26 21:04:20 2009
@@ -37,7 +37,4 @@
     test_oostring_instance = skip
     test_long_long = skip
     test_free_object = skip
-    
-    test_stopatxpolicy = _skip
-    test_bridge_from_interpreter = _skip
-    test_bridge_from_interpreter_4 = _skip
+    test_stopatxpolicy = skip

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_basic.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_basic.py	Tue May 26 21:04:20 2009
@@ -16,17 +16,21 @@
     # for the individual tests see
     # ====> ../../../metainterp/test/test_basic.py
 
+    def mono_bug(self):
+        py.test.skip('mono bug?')
+
     def skip(self):
         py.test.skip('in-progress')
 
-    test_stopatxpolicy = skip
+    test_stopatxpolicy = mono_bug
+
     test_print = skip
     test_bridge_from_interpreter = skip
     test_bridge_from_interpreter_2 = skip
-    test_bridge_from_interpreter_3 = skip
-    test_bridge_from_interpreter_4 = skip
-    test_bridge_leaving_interpreter_5 = skip
     test_free_object = skip
 
+    def test_bridge_from_interpreter_4(self):
+        pass # not a translation test
+    
     def test_we_are_jitted(self):
         py.test.skip("it seems to fail even with the x86 backend, didn't investigate the problem")

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_exception.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_exception.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_exception.py	Tue May 26 21:04:20 2009
@@ -7,17 +7,5 @@
     # for the individual tests see
     # ====> ../../../metainterp/test/test_exception.py
 
-    def skip_loop(self):
-        py.test.skip('jump across loops not implemented yet')
-
-    def skip(self):
-        py.test.skip('in-progress')
-
-    test_bridge_from_guard_exception = skip_loop
-    test_exception_four_cases = skip_loop
-    test_bridge_from_interpreter_exc = skip_loop
-    test_bridge_from_interpreter_exc_2 = skip_loop
-    test_int_lshift_ovf = skip_loop
-
-
+    pass
 

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_send.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_send.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_zrpy_send.py	Tue May 26 21:04:20 2009
@@ -7,12 +7,6 @@
     # for the individual tests see
     # ====> ../../../metainterp/test/test_send.py
 
-    def skip_loop(self):
-        py.test.skip('jump across loops not implemented yet')
-
-    test_three_receivers = skip_loop
-    test_three_classes = skip_loop
-    test_recursive_call_to_portal_from_blackhole = skip_loop
-    test_indirect_call_unknown_object_1 = skip_loop
-    test_three_cases = skip_loop
+    def test_recursive_call_to_portal_from_blackhole(self):
+        py.test.skip('string return values are not supported')
 

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/support.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/support.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/test/support.py	Tue May 26 21:04:20 2009
@@ -104,3 +104,9 @@
         from pypy.translator.cli.test.runtest import compile_graph
         func = compile_graph(entry_point_graph, t, nowrap=True, standalone=True)
         return func(*args)
+
+    def run_directly(self, fn, args):
+        from pypy.translator.cli.test.runtest import compile_function, get_annotation
+        ann = [get_annotation(x) for x in args]
+        clifunc = compile_function(fn, ann)
+        return clifunc(*args)

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_loop.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_loop.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_loop.py	Tue May 26 21:04:20 2009
@@ -16,6 +16,9 @@
                               CPUClass=self.CPUClass,
                               type_system=self.type_system)
 
+    def run_directly(self, f, args):
+        return f(*args)
+
     def test_simple_loop(self):
         myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
         def f(x, y):
@@ -348,7 +351,21 @@
                 x += unichr(n)
                 n -= 1
             return hash(x)
-        expected = f(100)
+        expected = self.run_directly(f, [100])
+        res = self.meta_interp(f, [100])
+        assert res == expected
+
+    def test_loop_string(self):
+        myjitdriver = JitDriver(greens = [], reds = ['x', 'n'])
+        def f(n):
+            x = ''
+            while n > 13:
+                myjitdriver.can_enter_jit(n=n, x=x)
+                myjitdriver.jit_merge_point(n=n, x=x)
+                x += chr(n)
+                n -= 1
+            return hash(x)
+        expected = self.run_directly(f, [100])
         res = self.meta_interp(f, [100])
         assert res == expected
 

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_tl.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_tl.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_tl.py	Tue May 26 21:04:20 2009
@@ -95,8 +95,6 @@
     def test_tl_base(self):
         res = self.meta_interp(self.main.im_func, [0, 6], listops=True)
         assert res == 5040
-        if self.type_system == 'ootype':
-            py.test.skip('optimizing problem')
         self.check_loops({'int_mul':1, 'jump':1,
                           'int_sub':1, 'int_is_true':1, 'int_le':1,
                           'guard_false':1, 'guard_value':1})
@@ -104,8 +102,6 @@
     def test_tl_2(self):
         res = self.meta_interp(self.main.im_func, [1, 10], listops=True)
         assert res == self.main.im_func(1, 10)
-        if self.type_system == 'ootype':
-            py.test.skip('optimizing problem')
         self.check_loops({'int_sub':1, 'int_le':1,
                          'int_is_true':1, 'guard_false':1, 'jump':1,
                           'guard_value':1})

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_virtualizable.py	Tue May 26 21:04:20 2009
@@ -617,3 +617,11 @@
                  ImplicitVirtualizableTests,
                  LLJitMixin):
     pass
+
+
+class TestOptimize2(ImplicitVirtualizableTests, LLJitMixin):
+
+    def meta_interp(self, *args, **kwds):
+        from pypy.jit.metainterp.optimize2 import Optimizer
+        kwds['optimizer'] = Optimizer
+        return LLJitMixin.meta_interp(self, *args, **kwds)

Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/ootypesystem/rpbc.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/ootypesystem/rpbc.py	Tue May 26 21:04:20 2009
@@ -116,10 +116,11 @@
 
 class MethodsPBCRepr(AbstractMethodsPBCRepr):
 
-    def __init__(self, rtyper, s_pbc):
-        AbstractMethodsPBCRepr.__init__(self, rtyper, s_pbc)
-        sampledesc = s_pbc.descriptions.iterkeys().next()
-        self.concretetable, _ = get_concrete_calltable(rtyper,
+    concretetable = None # set by _setup_repr_final
+
+    def _setup_repr_final(self):
+        sampledesc = self.s_pbc.descriptions.iterkeys().next()
+        self.concretetable, _ = get_concrete_calltable(self.rtyper,
                                              sampledesc.funcdesc.getcallfamily())
 
     def rtype_simple_call(self, hop):

Modified: pypy/branch/pyjitpl5-experiments/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/translator/cli/opcodes.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/translator/cli/opcodes.py	Tue May 26 21:04:20 2009
@@ -80,6 +80,7 @@
     'keepalive':                Ignore,
     'is_early_constant':        [PushPrimitive(ootype.Bool, False)],
     'jit_marker':               Ignore,
+    'promote_virtualizable':    Ignore,
     }
 
 # __________ numeric operations __________

Modified: pypy/branch/pyjitpl5-experiments/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/translator/cli/src/pypylib.cs	Tue May 26 21:04:20 2009
@@ -291,24 +291,25 @@
             return default_blockid;
         }
     }
+  */
         
     public class DelegateHolder
     {
-        public Delegate func;
+        public LoopDelegate func;
 
         // we need getter and setter because we can't directly access fields from RPython
-        public void SetFunc(Delegate func)
+        public void SetFunc(LoopDelegate func)
         {
             this.func = func;
         }
 
-        public Delegate GetFunc()
+        public LoopDelegate GetFunc()
         {
             return this.func;
         }
     }
 
-  */
+
 
     public class AutoSaveAssembly
     {

Modified: pypy/branch/pyjitpl5-experiments/pypy/translator/oosupport/test_template/class_.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/translator/oosupport/test_template/class_.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/translator/oosupport/test_template/class_.py	Tue May 26 21:04:20 2009
@@ -64,5 +64,8 @@
             return a.x + b.x
         assert self.interpret(fn, [1, 2]) == 3
 
+    def test_cast_object_mix_null(self):
+        py.test.skip('cannot return ootype.NULL from translated functions')
+
 class BaseTestSpecialcase(BaseTestRspecialcase):
     pass



More information about the Pypy-commit mailing list