[pypy-svn] r62663 - in pypy/branch/pyjitpl5/pypy/jit/backend/x86: . test

fijal at codespeak.net fijal at codespeak.net
Fri Mar 6 20:02:35 CET 2009


Author: fijal
Date: Fri Mar  6 20:02:34 2009
New Revision: 62663

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
Log:
a bit of progress. still some weird failures though :(


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	Fri Mar  6 20:02:34 2009
@@ -7,7 +7,8 @@
 from pypy.annotation import model as annmodel
 from pypy.tool.uid import fixid
 from pypy.jit.backend.x86.regalloc import (RegAlloc, FRAMESIZE, WORD, REGS,
-                                      arg_pos, lower_byte, stack_pos, Perform)
+                                      arg_pos, lower_byte, stack_pos, Perform,
+                                      RETURN)
 from pypy.rlib.objectmodel import we_are_translated, specialize
 from pypy.jit.backend.x86 import codebuf
 from pypy.jit.backend.x86.support import gc_malloc_fnaddr
@@ -387,8 +388,14 @@
         base_loc, ofs_loc, value_loc, scale_loc, baseofs = arglocs
         assert isinstance(baseofs, IMM32)
         assert isinstance(scale_loc, IMM32)
-        self.mc.MOV(addr_add(base_loc, ofs_loc, baseofs.value, scale_loc.value),
-                    value_loc)
+        if scale_loc.value == 2:
+            self.mc.MOV(addr_add(base_loc, ofs_loc, baseofs.value,
+                                 scale_loc.value), value_loc)
+        elif scale_loc.value == 0:
+            self.mc.MOV(addr_add8(base_loc, ofs_loc, baseofs.value,
+                                 scale_loc.value), lower_byte(value_loc))
+        else:
+            raise NotImplementedError("scale = %d" % scale)
 
     def genop_strsetitem(self, op, arglocs):
         base_loc, ofs_loc, val_loc = arglocs
@@ -418,7 +425,7 @@
 
     genop_catch = genop_merge_point
 
-    def xxx_genop_return(self, op, locs):
+    def genop_return(self, op, locs):
         if op.args:
             loc = locs[0]
             if loc is not eax:
@@ -506,16 +513,14 @@
         arglocs = arglocs[1:]
         extra_on_stack = 0
         for i in range(len(op.args) - 1, 0, -1):
-            # op.args[1] is a calldesc
-            if i != 1:
-                v = op.args[i]
-                loc = arglocs[len(arglocs) - 1 - extra_on_stack]
-                if not isinstance(loc, MODRM):
-                    self.mc.PUSH(loc)
-                else:
-                    # we need to add a bit, ble
-                    self.mc.PUSH(stack_pos(loc.position + extra_on_stack))
-                extra_on_stack += 1
+            v = op.args[i]
+            loc = arglocs[i]
+            if not isinstance(loc, MODRM):
+                self.mc.PUSH(loc)
+            else:
+                # we need to add a bit, ble
+                self.mc.PUSH(stack_pos(loc.position + extra_on_stack))
+            extra_on_stack += 1
         if isinstance(op.args[0], Const):
             x = rel32(self.cpu.get_box_value_as_int(op.args[0]))
         else:
@@ -537,14 +542,17 @@
     #    self.gen_call(op, arglocs, resloc)
     #    self.mc.MOVZX(eax, eax)
 
-genop_discard_list = [None] * rop._LAST
+genop_discard_list = [None] * (RETURN + 1)
 genop_list = [None] * rop._LAST
 genop_guard_list = [None] * rop._LAST
 
 for name, value in Assembler386.__dict__.iteritems():
     if name.startswith('genop_'):
         opname = name[len('genop_'):]
-        num = getattr(rop, opname.upper())
+        if opname == 'return':
+            num = RETURN
+        else:
+            num = getattr(rop, opname.upper())
         if value.func_code.co_argcount == 3:
             genop_discard_list[num] = value
         elif value.func_code.co_argcount == 5:

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	Fri Mar  6 20:02:34 2009
@@ -17,6 +17,8 @@
 WORD = 4
 FRAMESIZE = 1024    # XXX should not be a constant at all!!
 
+RETURN = rop._LAST
+
 class TempBox(Box):
     def __init__(self):
         pass
@@ -578,7 +580,7 @@
         self.eventually_free_vars(op.liveboxes + op.args)
         return ops + [PerformDiscard(op, [x, y] + locs)]
 
-    def xxx_consider_return(self, op, ignored):
+    def consider_return(self, op, ignored):
         if op.args:
             arglocs = [self.loc(op.args[0])]
             self.eventually_free_var(op.args[0])
@@ -720,19 +722,19 @@
 
     def consider_call(self, op, ignored):
         from pypy.jit.backend.x86.runner import CPU386
-        args = [op.args[0]] + op.args[2:]
-        calldescr = op.args[1].getint()
-        _, size, _ = CPU386.unpack_calldescr(calldescr)
+        calldescr = op.descr
+        numargs, size, _ = CPU386.unpack_calldescr(calldescr)
+        assert numargs == len(op.args)
         return self._call(op, [imm(size)] +
-                          [self.loc(arg) for arg in args])
+                          [self.loc(arg) for arg in op.args])
 
     consider_call_pure = consider_call
 
     def consider_new(self, op, ignored):
-        return self._call(op, [self.loc(arg) for arg in op.args])
+        return self._call(op, [imm(op.descr)])
 
     def consider_new_with_vtable(self, op, ignored):
-        return self._call(op, [self.loc(arg) for arg in op.args])
+        return self._call(op, [imm(op.descr), self.loc(op.args[0])])
 
     def consider_newstr(self, op, ignored):
         ofs = symbolic.get_field_token(rstr.STR, 'chars')[0]
@@ -766,8 +768,8 @@
         return res
 
     def consider_new_array(self, op, ignored):
-        size_of_field, basesize = self._unpack_arraydescr(op.args[0].getint())
-        return self._malloc_varsize(0, basesize, 0, size_of_field, op.args[1],
+        size_of_field, basesize = self._unpack_arraydescr(op.descr)
+        return self._malloc_varsize(0, basesize, 0, size_of_field, op.args[0],
                                     op.result)
 
     def consider_oononnull(self, op, ignored):
@@ -788,9 +790,9 @@
 
     def consider_setfield_gc(self, op, ignored):
         base_loc, ops0  = self.make_sure_var_in_reg(op.args[0], op.args)
-        ofs_loc, size_loc = self._unpack_fielddescr(op.args[1].getint())
-        value_loc, ops2 = self.make_sure_var_in_reg(op.args[2], op.args)
-        self.eventually_free_vars([op.args[0], op.args[1], op.args[2]])
+        ofs_loc, size_loc = self._unpack_fielddescr(op.descr)
+        value_loc, ops2 = self.make_sure_var_in_reg(op.args[1], op.args)
+        self.eventually_free_vars(op.args)
         return (ops0 + ops2 +
                 [PerformDiscard(op, [base_loc, ofs_loc, size_loc, value_loc])])
 
@@ -803,21 +805,19 @@
                 [PerformDiscard(op, [base_loc, ofs_loc, value_loc])])
 
     def consider_setarrayitem_gc(self, op, ignored):
-        scale, ofs = self._unpack_arraydescr(op.args[1].getint())
-        assert scale == 2
-        args = [op.args[0], op.args[2], op.args[3]]
-        base_loc, ops0  = self.make_sure_var_in_reg(op.args[0], args)
-        ofs_loc, ops1 = self.make_sure_var_in_reg(op.args[2], args)
-        value_loc, ops2 = self.make_sure_var_in_reg(op.args[3], args)
+        scale, ofs = self._unpack_arraydescr(op.descr)
+        base_loc, ops0  = self.make_sure_var_in_reg(op.args[0], op.args)
+        ofs_loc, ops1 = self.make_sure_var_in_reg(op.args[1], op.args)
+        value_loc, ops2 = self.make_sure_var_in_reg(op.args[2], op.args)
         self.eventually_free_vars(op.args)
         return (ops0 + ops2 + ops1 +
                 [PerformDiscard(op, [base_loc, ofs_loc, value_loc,
                                      imm(scale), imm(ofs)])])
 
     def consider_getfield_gc(self, op, ignored):
-        ofs_loc, size_loc = self._unpack_fielddescr(op.args[1].getint())
+        ofs_loc, size_loc = self._unpack_fielddescr(op.descr)
         base_loc, ops0 = self.make_sure_var_in_reg(op.args[0], op.args)
-        self.eventually_free_vars([op.args[0], op.args[1]])
+        self.eventually_free_vars(op.args)
         result_loc, more_ops = self.force_allocate_reg(op.result, [])
         return (ops0 + more_ops +
                 [Perform(op, [base_loc, ofs_loc, size_loc], result_loc)])
@@ -825,10 +825,9 @@
     consider_getfield_gc_pure = consider_getfield_gc
 
     def consider_getarrayitem_gc(self, op, ignored):
-        scale, ofs = self._unpack_arraydescr(op.args[1].getint())
-        args = [op.args[0], op.args[2]]
-        base_loc, ops0  = self.make_sure_var_in_reg(op.args[0], args)
-        ofs_loc, ops1 = self.make_sure_var_in_reg(op.args[2], args)
+        scale, ofs = self._unpack_arraydescr(op.descr)
+        base_loc, ops0  = self.make_sure_var_in_reg(op.args[0], op.args)
+        ofs_loc, ops1 = self.make_sure_var_in_reg(op.args[1], op.args)
         self.eventually_free_vars(op.args)
         result_loc, more_ops = self.force_allocate_reg(op.result, [])
         return (ops0 + ops1 + more_ops +
@@ -953,12 +952,15 @@
         self.eventually_free_vars(op.args)
         return ops + laterops + [PerformDiscard(op, [])]
 
-oplist = [None] * rop._LAST
+oplist = [None] * (RETURN + 1)
 
 for name, value in RegAlloc.__dict__.iteritems():
     if name.startswith('consider_'):
         name = name[len('consider_'):]
-        num = getattr(rop, name.upper())
+        if name == 'return':
+            num = RETURN
+        else:
+            num = getattr(rop, name.upper())
         oplist[num] = value
 
 def arg_pos(i):

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	Fri Mar  6 20:02:34 2009
@@ -11,7 +11,7 @@
 from pypy.jit.metainterp import history
 from pypy.jit.metainterp.history import (ResOperation, Box, Const,
      ConstInt, ConstPtr, BoxInt, BoxPtr, ConstAddr)
-from pypy.jit.backend.x86.assembler import Assembler386, WORD
+from pypy.jit.backend.x86.assembler import Assembler386, WORD, RETURN
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.backend.x86.executor import execute
@@ -30,7 +30,7 @@
                                     lltype.Ptr(rffi.CArray(lltype.Signed))],
                                    lltype.Signed)
 
-    return_value_box = None
+    return_value_type = 0
 
     def __init__(self, rtyper, stats, translate_support_code=False,
                  mixlevelann=None):
@@ -123,7 +123,7 @@
                                  guard_op, 'to the jit')
             gf = GuardFailed(self, frame_addr, guard_op)
             self.metainterp.handle_guard_failure(gf)
-            self.return_value_box = gf.return_value_box
+            self.return_value_type = gf.return_value_type
             if self.debug:
                 if gf.return_addr == self.assembler.generic_return_addr:
                     llop.debug_print(lltype.Void, 'continuing at generic return address')
@@ -141,12 +141,12 @@
     def set_meta_interp(self, metainterp):
         self.metainterp = metainterp
 
-    def get_exception(self, frame):
+    def get_exception(self):
         res = self.assembler._exception_data[0]
         self.assembler._exception_data[0] = 0
         return res
 
-    def get_exc_value(self, frame):
+    def get_exc_value(self):
         return self.cast_int_to_gcref(self.assembler._exception_data[1])
 
 #     def execute_operation(self, opnum, valueboxes, result_type):
@@ -271,14 +271,12 @@
             return self.generated_mps[calldescr]
         except KeyError:
             pass
-        args = [BoxInt(0) for i in range(argnum + 3)]
-        args[1].value = calldescr
+        args = [BoxInt(0) for i in range(argnum)]
         result = BoxInt(0)
         operations = [
             ResOperation(rop.MERGE_POINT, args, None),
-            ResOperation(rop.CALL, args[:-1], result),
-            ResOperation(rop.GUARD_FALSE, [args[-1]], None)]
-        operations[-1].liveboxes = [result]
+            ResOperation(rop.CALL, args, result, calldescr),
+            ResOperation(RETURN, [result], None)]
         self.compile_operations(operations)
         self.generated_mps[calldescr] = operations
         return operations
@@ -302,16 +300,18 @@
 
         self.keepalives_index = len(self.keepalives)
         res = self.execute_call(startmp, func, values_as_int)
-        if self.return_value_box is None:
+        if self.return_value_type == VOID:
             if self.debug:
                 llop.debug_print(lltype.Void, " => void result")
+            res = None
         else:
             if self.debug:
                 llop.debug_print(lltype.Void, " => ", res)
+            res = self.get_valuebox_from_int(self.return_value_type, res)
         keepalive_until_here(valueboxes)
         self.keepalives_index = oldindex
         del self.keepalives[oldindex:]
-        return self.return_value_box
+        return res
 
     def execute_call(self, startmp, func, values_as_int):
         # help flow objspace
@@ -396,13 +396,12 @@
 
     # ------------------- backend-specific ops ------------------------
 
-    def do_arraylen_gc(self, args):
+    def do_arraylen_gc(self, args, arraydescr):
         gcref = args[0].getptr(llmemory.GCREF)
         return BoxInt(rffi.cast(rffi.CArrayPtr(lltype.Signed), gcref)[0])
 
-    def do_getarrayitem_gc(self, args):
-        arraydescr = args[1].getint()
-        field = args[2].getint()
+    def do_getarrayitem_gc(self, args, arraydescr):
+        field = args[1].getint()
         gcref = args[0].getptr(llmemory.GCREF)
         if arraydescr < 0:
             ptr = True
@@ -423,9 +422,8 @@
         else:
             raise NotImplementedError("size = %d" % size)
 
-    def do_setarrayitem_gc(self, args):
-        arraydescr = args[1].getint()
-        field = args[2].getint()
+    def do_setarrayitem_gc(self, args, arraydescr):
+        field = args[1].getint()
         gcref = args[0].getptr(llmemory.GCREF)
         if arraydescr < 0:
             ptr = True
@@ -434,25 +432,25 @@
         shift, ofs = self.unpack_arraydescr(arraydescr)
         size = 1 << shift
         if size == 1:
-            v = args[3].getint()
+            v = args[2].getint()
             rffi.cast(rffi.CArrayPtr(lltype.Char), gcref)[ofs + field] = chr(v)
         elif size == WORD:
             a = rffi.cast(rffi.CArrayPtr(lltype.Signed), gcref)
             if not ptr:
-                a[ofs/WORD + field] = args[3].getint()
+                a[ofs/WORD + field] = args[2].getint()
             else:
-                p = args[3].getptr(llmemory.GCREF)
+                p = args[2].getptr(llmemory.GCREF)
                 a[ofs/WORD + field] = self.cast_gcref_to_int(p)
         else:
             raise NotImplementedError("size = %d" % size)
 
-    def do_strlen(self, args):
+    def do_strlen(self, args, descr=0):
         basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR)
         gcref = args[0].getptr(llmemory.GCREF)
         v = rffi.cast(rffi.CArrayPtr(lltype.Signed), gcref)[ofs_length/WORD]
         return BoxInt(v)
 
-    def do_strgetitem(self, args):
+    def do_strgetitem(self, args, descr=0):
         basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR)
         gcref = args[0].getptr(llmemory.GCREF)
         i = args[1].getint()
@@ -474,13 +472,11 @@
             raise NotImplementedError("size = %d" % size)
         return BoxInt(v)
 
-    def do_getfield_gc(self, args):
-        fielddescr = args[1].getint()
+    def do_getfield_gc(self, args, fielddescr):
         gcref = args[0].getptr(llmemory.GCREF)
         return self._base_do_getfield(gcref, fielddescr)
 
-    def do_getfield_raw(self, args):
-        fielddescr = args[1].getint()
+    def do_getfield_raw(self, args, fielddescr):
         return self._base_do_getfield(args[0].getint(), fielddescr)
 
     @specialize.argtype(2)
@@ -502,33 +498,31 @@
         else:
             raise NotImplementedError("size = %d" % size)
 
-    def do_setfield_gc(self, args):
-        fielddescr = args[1].getint()
+    def do_setfield_gc(self, args, fielddescr):
         gcref = args[0].getptr(llmemory.GCREF)
-        self._base_do_setfield(fielddescr, gcref, args[2])
+        self._base_do_setfield(fielddescr, gcref, args[1])
 
-    def do_setfield_raw(self, args):
-        fielddescr = args[1].getint()
-        self._base_do_setfield(fielddescr, args[0].getint(), args[2])
+    def do_setfield_raw(self, args, fielddescr):
+        self._base_do_setfield(fielddescr, args[0].getint(), args[1])
 
-    def do_new(self, args):
-        res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(args[0].getint())
+    def do_new(self, args, descrsize):
+        res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(descrsize)
         return BoxPtr(self.cast_int_to_gcref(res))
 
-    def do_new_with_vtable(self, args):
-        res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(args[0].getint())
-        rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = args[1].getint()
+    def do_new_with_vtable(self, args, descrsize):
+        res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(descrsize)
+        rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = args[0].getint()
         return BoxPtr(self.cast_int_to_gcref(res))
 
-    def do_new_array(self, args):
-        size_of_field, ofs = self.unpack_arraydescr(args[0].getint())
-        num_elem = args[1].getint()
+    def do_new_array(self, args, arraydescr):
+        size_of_field, ofs = self.unpack_arraydescr(arraydescr)
+        num_elem = args[0].getint()
         size = ofs + (1 << size_of_field) * num_elem
         res = rffi.cast(GC_MALLOC, gc_malloc_fnaddr())(size)
         rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = num_elem
         return BoxPtr(self.cast_int_to_gcref(res))
 
-    def do_newstr(self, args):
+    def do_newstr(self, args, descr=0):
         basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR)
         assert itemsize == 1
         num_elem = args[0].getint()
@@ -537,18 +531,23 @@
         rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
         return BoxPtr(self.cast_int_to_gcref(res))
 
-    def do_strsetitem(self, args):
+    def do_strsetitem(self, args, descr=0):
         basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR)
         index = args[1].getint()
         v = args[2].getint()
         a = args[0].getptr(llmemory.GCREF)
         rffi.cast(rffi.CArrayPtr(lltype.Char), a)[index + basesize] = chr(v)
 
-    def do_call(self, args):
-        calldescr = args[1].getint()
+    def do_call(self, args, calldescr):
         num_args, size, ptr = self.unpack_calldescr(calldescr)
         mp = self._get_mp_for_call(num_args, calldescr)
-        return self.execute_operations_in_new_frame('call', mp, args + [BoxInt(1)])
+        if size == 0:
+            self.return_value_type = VOID
+        elif ptr:
+            self.return_value_type = PTR
+        else:
+            self.return_value_type = INT
+        return self.execute_operations_in_new_frame('call', mp, args)
 
     # ------------------- helpers and descriptions --------------------
 
@@ -654,7 +653,7 @@
         return hex(x)
 
 class GuardFailed(object):
-    return_value_box = None
+    return_value_type = 0
     
     def __init__(self, cpu, frame, guard_op):
         self.cpu = cpu
@@ -666,7 +665,13 @@
         if return_value_box is not None:
             frame = getframe(self.frame)
             frame[0] = self.cpu.convert_box_to_int(return_value_box)
-            self.return_value_box = return_value_box
+            if (isinstance(return_value_box, ConstInt) or
+                isinstance(return_value_box, BoxInt)):
+                self.return_value_type = INT
+            else:
+                self.return_value_type = PTR
+        else:
+            self.return_value_type = VOID
         self.return_addr = self.cpu.assembler.generic_return_addr
 
     def make_ready_for_continuing_at(self, merge_point):

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	Fri Mar  6 20:02:34 2009
@@ -45,15 +45,17 @@
         cls.cpu = CPU(rtyper=None, stats=FakeStats())
         cls.cpu.set_meta_interp(FakeMetaInterp())
 
-    def execute_operation(self, opname, valueboxes, result_type):
+    def execute_operation(self, opname, valueboxes, result_type, descr=0):
         key = [opname, result_type]
-        mp = self.get_compiled_single_operation(opname, result_type, valueboxes)
+        mp = self.get_compiled_single_operation(opname, result_type, valueboxes,
+                                                descr)
         boxes = [box for box in valueboxes if isinstance(box, Box)]
         res = self.cpu.execute_operations_in_new_frame(opname, mp, boxes +
                                                        [BoxInt(1)])
         return res
 
-    def get_compiled_single_operation(self, opnum, result_type, valueboxes):
+    def get_compiled_single_operation(self, opnum, result_type, valueboxes,
+                                      descr):
         livevarlist = []
         for box in valueboxes:
             if isinstance(box, Box):
@@ -78,6 +80,7 @@
         operations = [mp,
                       ResOperation(opnum, livevarlist, result),
                       ResOperation(rop.GUARD_FALSE, [checker], None)]
+        operations[1].descr = descr
         operations[-1].liveboxes = results
         if operations[1].is_guard():
             operations[1].liveboxes = []
@@ -114,13 +117,13 @@
         cpu = self.cpu
         u = lltype.malloc(U)
         u_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, u))
-        ofs_box = ConstInt(cpu.fielddescrof(S, 'value'))
+        ofs = cpu.fielddescrof(S, 'value')
         assert self.execute_operation(rop.SETFIELD_GC,
-                                      [u_box, ofs_box, BoxInt(3)],
-                                     'void') == None
+                                      [u_box, BoxInt(3)],
+                                     'void', ofs) == None
         assert u.parent.parent.value == 3
         u.parent.parent.value += 100
-        assert (self.execute_operation(rop.GETFIELD_GC, [u_box, ofs_box], 'int')
+        assert (self.execute_operation(rop.GETFIELD_GC, [u_box], 'int', ofs)
                 .value == 103)
 
     def test_execute_operations_in_env(self):
@@ -250,18 +253,18 @@
 
             TP = lltype.GcArray(lltype.Signed)
             ofs = symbolic.get_field_token(TP, 'length')[0]
-            descr = ConstInt(self.cpu.arraydescrof(TP))
+            descr = self.cpu.arraydescrof(TP)
 
-            res = self.execute_operation(rop.NEW_ARRAY, [descr, ConstInt(10)],
-                                             'ptr')
+            res = self.execute_operation(rop.NEW_ARRAY, [ConstInt(10)],
+                                             'ptr', descr)
             assert allocs[0] == 10*WORD + ofs + WORD
             resbuf = ctypes.cast(res.value.intval, ctypes.POINTER(ctypes.c_int))
             assert resbuf[ofs/WORD] == 10
 
             # ------------------------------------------------------------
 
-            res = self.execute_operation(rop.NEW_ARRAY, [descr, BoxInt(10)],
-                                             'ptr')
+            res = self.execute_operation(rop.NEW_ARRAY, [BoxInt(10)],
+                                             'ptr', descr)
             assert allocs[0] == 10*WORD + ofs + WORD
             resbuf = ctypes.cast(res.value.intval, ctypes.POINTER(ctypes.c_int))
             assert resbuf[ofs/WORD] == 10
@@ -287,26 +290,26 @@
         TP = lltype.GcArray(lltype.Signed)
         ofs = symbolic.get_field_token(TP, 'length')[0]
         itemsofs = symbolic.get_field_token(TP, 'items')[0]
-        descr = ConstInt(self.cpu.arraydescrof(TP))
-        res = self.execute_operation(rop.NEW_ARRAY, [descr, ConstInt(10)],
-                                     'ptr')
+        descr = self.cpu.arraydescrof(TP)
+        res = self.execute_operation(rop.NEW_ARRAY, [ConstInt(10)],
+                                     'ptr', descr)
         resbuf = ctypes.cast(res.value.intval, ctypes.POINTER(ctypes.c_int))
         assert resbuf[ofs/WORD] == 10
-        self.execute_operation(rop.SETARRAYITEM_GC, [res, descr,
+        self.execute_operation(rop.SETARRAYITEM_GC, [res,
                                                      ConstInt(2), BoxInt(38)],
-                               'void')
+                               'void', descr)
         assert resbuf[itemsofs/WORD + 2] == 38
         
-        self.execute_operation(rop.SETARRAYITEM_GC, [res, descr,
+        self.execute_operation(rop.SETARRAYITEM_GC, [res,
                                                      BoxInt(3), BoxInt(42)],
-                               'void')
+                               'void', descr)
         assert resbuf[itemsofs/WORD + 3] == 42
 
-        r = self.execute_operation(rop.GETARRAYITEM_GC, [res, descr,
-                                                         ConstInt(2)], 'int')
+        r = self.execute_operation(rop.GETARRAYITEM_GC, [res, ConstInt(2)],
+                                   'int', descr)
         assert r.value == 38
-        r = self.execute_operation(rop.GETARRAYITEM_GC, [res, descr,
-                                                         BoxInt(3)], 'int')
+        r = self.execute_operation(rop.GETARRAYITEM_GC, [res, BoxInt(3)],
+                                   'int', descr)
         assert r.value == 42
 
     def test_getfield_setfield(self):
@@ -316,34 +319,39 @@
                              ('c1', lltype.Char),
                              ('c2', lltype.Char),
                              ('c3', lltype.Char))
-        res = self.execute_operation(rop.NEW, [ConstInt(self.cpu.sizeof(TP))],
-                                     'ptr')
-        ofs_s = ConstInt(self.cpu.fielddescrof(TP, 's'))
-        ofs_f = ConstInt(self.cpu.fielddescrof(TP, 'f'))
-        ofs_u = ConstInt(self.cpu.fielddescrof(TP, 'u'))
-        ofsc1 = ConstInt(self.cpu.fielddescrof(TP, 'c1'))
-        ofsc2 = ConstInt(self.cpu.fielddescrof(TP, 'c2'))
-        ofsc3 = ConstInt(self.cpu.fielddescrof(TP, 'c3'))
-        self.execute_operation(rop.SETFIELD_GC, [res, ofs_s, ConstInt(3)], 'void')
+        res = self.execute_operation(rop.NEW, [],
+                                     'ptr', self.cpu.sizeof(TP))
+        ofs_s = self.cpu.fielddescrof(TP, 's')
+        ofs_f = self.cpu.fielddescrof(TP, 'f')
+        ofs_u = self.cpu.fielddescrof(TP, 'u')
+        ofsc1 = self.cpu.fielddescrof(TP, 'c1')
+        ofsc2 = self.cpu.fielddescrof(TP, 'c2')
+        ofsc3 = self.cpu.fielddescrof(TP, 'c3')
+        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(3)], 'void',
+                               ofs_s)
         # XXX ConstFloat
         #self.execute_operation(rop.SETFIELD_GC, [res, ofs_f, 1e100], 'void')
         # XXX we don't support shorts (at all)
         #self.execute_operation(rop.SETFIELD_GC, [res, ofs_u, ConstInt(5)], 'void')
-        s = self.execute_operation(rop.GETFIELD_GC, [res, ofs_s], 'int')
+        s = self.execute_operation(rop.GETFIELD_GC, [res], 'int', ofs_s)
         assert s.value == 3
-        self.execute_operation(rop.SETFIELD_GC, [res, ofs_s, BoxInt(3)], 'void')
-        s = self.execute_operation(rop.GETFIELD_GC, [res, ofs_s], 'int')
+        self.execute_operation(rop.SETFIELD_GC, [res, BoxInt(3)], 'void',
+                               ofs_s)
+        s = self.execute_operation(rop.GETFIELD_GC, [res], 'int', ofs_s)
         assert s.value == 3
         #u = self.execute_operation(rop.GETFIELD_GC, [res, ofs_u], 'int')
         #assert u.value == 5
-        self.execute_operation(rop.SETFIELD_GC, [res, ofsc1, ConstInt(1)], 'void')
-        self.execute_operation(rop.SETFIELD_GC, [res, ofsc2, ConstInt(2)], 'void')
-        self.execute_operation(rop.SETFIELD_GC, [res, ofsc3, ConstInt(3)], 'void')
-        c = self.execute_operation(rop.GETFIELD_GC, [res, ofsc1], 'int')
+        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(1)], 'void',
+                               ofsc1)
+        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(2)], 'void',
+                               ofsc2)
+        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(3)], 'void',
+                               ofsc3)
+        c = self.execute_operation(rop.GETFIELD_GC, [res], 'int', ofsc1)
         assert c.value == 1
-        c = self.execute_operation(rop.GETFIELD_GC, [res, ofsc2], 'int')
+        c = self.execute_operation(rop.GETFIELD_GC, [res], 'int', ofsc2)
         assert c.value == 2
-        c = self.execute_operation(rop.GETFIELD_GC, [res, ofsc3], 'int')
+        c = self.execute_operation(rop.GETFIELD_GC, [res], 'int', ofsc3)
         assert c.value == 3
         
     def test_ovf_ops(self):
@@ -381,25 +389,26 @@
         cpu = self.cpu
         #
         A = lltype.GcArray(lltype.Char)
-        descrbox_A = ConstInt(cpu.arraydescrof(A))
+        descr_A = cpu.arraydescrof(A)
         a = lltype.malloc(A, 5)
         x = cpu.do_arraylen_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox_A])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a))],
+            descr_A)
         assert x.value == 5
         #
         a[2] = 'Y'
         x = cpu.do_getarrayitem_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox_A,
-             BoxInt(2)])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), BoxInt(2)],
+            descr_A)
         assert x.value == ord('Y')
         #
         B = lltype.GcArray(lltype.Ptr(A))
-        descrbox_B = ConstInt(cpu.arraydescrof(B))
+        descr_B = cpu.arraydescrof(B)
         b = lltype.malloc(B, 4)
         b[3] = a
         x = cpu.do_getarrayitem_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)), descrbox_B,
-             BoxInt(3)])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)), BoxInt(3)],
+            descr_B)
         assert isinstance(x, BoxPtr)
         assert x.getptr(lltype.Ptr(A)) == a
         #
@@ -418,29 +427,28 @@
         s = lltype.malloc(S)
         s.x = 'Z'
         x = cpu.do_getfield_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
-             BoxInt(descrfld_x)])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))],
+            descrfld_x)
         assert x.value == ord('Z')
         #
         cpu.do_setfield_gc(
             [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
-             BoxInt(descrfld_x),
-             BoxInt(ord('4'))])
+             BoxInt(ord('4'))],
+            descrfld_x)
         assert s.x == '4'
         #
         descrfld_y = cpu.fielddescrof(S, 'y')
         s.y = a
         x = cpu.do_getfield_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
-             BoxInt(descrfld_y)])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))],
+            descrfld_y)
         assert isinstance(x, BoxPtr)
         assert x.getptr(lltype.Ptr(A)) == a
         #
         s.y = lltype.nullptr(A)
         cpu.do_setfield_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
-             BoxInt(descrfld_y),
-             x])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)), x],
+            descrfld_y)
         assert s.y == a
         #
         RS = lltype.Struct('S', ('x', lltype.Char), ('y', lltype.Ptr(A)))
@@ -448,61 +456,57 @@
         rs = lltype.malloc(RS, immortal=True)
         rs.x = '?'
         x = cpu.do_getfield_raw(
-            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs))),
-             BoxInt(descrfld_rx)])
+            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs)))],
+            descrfld_rx)
         assert x.value == ord('?')
         #
         cpu.do_setfield_raw(
             [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs))),
-             BoxInt(descrfld_rx),
-             BoxInt(ord('!'))])
+             BoxInt(ord('!'))],
+            descrfld_rx)
         assert rs.x == '!'
         #
         descrfld_ry = cpu.fielddescrof(RS, 'y')
         rs.y = a
         x = cpu.do_getfield_raw(
-            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs))),
-             BoxInt(descrfld_ry)])
+            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs)))],
+            descrfld_ry)
         assert isinstance(x, BoxPtr)
         assert x.getptr(lltype.Ptr(A)) == a
         #
         rs.y = lltype.nullptr(A)
         cpu.do_setfield_raw(
-            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs))),
-             BoxInt(descrfld_ry),
-             x])
+            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs))), x],
+            descrfld_ry)
         assert rs.y == a
         #
         descrsize = cpu.sizeof(S)
-        x = cpu.do_new(
-            [BoxInt(descrsize)])
+        x = cpu.do_new([], descrsize)
         assert isinstance(x, BoxPtr)
         x.getptr(lltype.Ptr(S))
         #
         descrsize2 = cpu.sizeof(rclass.OBJECT)
         vtable2 = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
         x = cpu.do_new_with_vtable(
-            [BoxInt(descrsize2),
-             BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(vtable2)))])
+            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(vtable2)))],
+            descrsize2)
         assert isinstance(x, BoxPtr)
-        # well....
-        assert (rffi.cast(rffi.CArrayPtr(lltype.Signed),
-                         x.getptr(llmemory.GCREF))[0])
+        # well...
         #assert x.getptr(rclass.OBJECTPTR).typeptr == vtable2
         #
         arraydescr = cpu.arraydescrof(A)
-        x = cpu.do_new_array(
-            [BoxInt(arraydescr), BoxInt(7)])
+        x = cpu.do_new_array([BoxInt(7)], arraydescr)
         assert isinstance(x, BoxPtr)
         assert len(x.getptr(lltype.Ptr(A))) == 7
         #
         cpu.do_setarrayitem_gc(
-            [x, descrbox_A, BoxInt(5), BoxInt(ord('*'))])
+            [x, BoxInt(5), BoxInt(ord('*'))], descr_A)
         assert x.getptr(lltype.Ptr(A))[5] == '*'
         #
         cpu.do_setarrayitem_gc(
-            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)), descrbox_B,
-             BoxInt(1), x])
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)),
+             BoxInt(1), x],
+            descr_B)
         assert b[1] == x.getptr(lltype.Ptr(A))
         #
         x = cpu.do_newstr([BoxInt(5)])
@@ -520,11 +524,11 @@
             return chr(ord(c) + 1)
         FPTR = lltype.Ptr(lltype.FuncType([lltype.Char], lltype.Char))
         func_ptr = llhelper(FPTR, func)
-        calldescr = cpu.calldescrof([lltype.Char], lltype.Char)
+        calldescr = cpu.calldescrof([FPTR, lltype.Char], lltype.Char)
         x = cpu.do_call(
             [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(func_ptr))),
-             ConstInt(calldescr),
-             BoxInt(ord('A'))])
+             BoxInt(ord('A'))],
+            calldescr)
         assert x.value == ord('B')
 
     def test_executor(self):



More information about the Pypy-commit mailing list