Commits

Maciej Fijalkowski  committed f60dbf4

work more on resoperation

  • Participants
  • Parent commits 3b467df
  • Branches result-in-resops

Comments (0)

Files changed (4)

File pypy/jit/metainterp/executor.py

     if func.resulttype not in ('i', 'r', 'f', None):
         return None
     argtypes = unrolling_iterable(func.argtypes)
+    if len(func.argtypes) <= 3:
+        create_resop_func = getattr(resoperation,
+                                    'create_resop_%d' % len(func.argtypes))
     #
-    def do(cpu, _, *args):
-        newargs = ()
-        orig_args = args
-        for argtype in argtypes:
-            if argtype == 'cpu':
-                value = cpu
-            elif argtype == 'd':
-                value = args[-1]
-                assert isinstance(value, AbstractDescr)
-                args = args[:-1]
-            else:
-                arg = args[0]
-                args = args[1:]
-                if argtype == 'i':   value = arg.getint()
-                elif argtype == 'r': value = arg.getref_base()
-                elif argtype == 'f': value = arg.getfloatstorage()
-            newargs = newargs + (value,)
-        assert not args
+        def do(cpu, _, *args):
+            newargs = ()
+            orig_args = args
+            for argtype in argtypes:
+                if argtype == 'cpu':
+                    value = cpu
+                elif argtype == 'd':
+                    value = args[-1]
+                    assert isinstance(value, AbstractDescr)
+                    args = args[:-1]
+                else:
+                    arg = args[0]
+                    args = args[1:]
+                    if argtype == 'i':   value = arg.getint()
+                    elif argtype == 'r': value = arg.getref_base()
+                    elif argtype == 'f': value = arg.getfloatstorage()
+                newargs = newargs + (value,)
+            assert not args
+            #
+            result = func(*newargs)
+            return create_resop_func(opnum, result, *orig_args)
+            #
         #
-        result = func(*newargs)
-        if has_descr:
-            return create_resop(opnum, orig_args[:-1], result, orig_args[-1])
-        else:
-            return create_resop(opnum, orig_args, result)
-        #
-    #
+    else:
+        def do(*args):
+            xxx
     do.func_name = 'do_' + name
     return do
 

File pypy/jit/metainterp/pyjitpl.py

         # FIXME: kill TerminatingLoopToken?
         # FIXME: can we call compile_trace?
         token = loop_tokens[0].finishdescr
-        self.history.record(create_resop(rop.FINISH, exits, None, descr=token))
+        self.history.record(create_resop(rop.FINISH, None, exits, descr=token))
         target_token = compile.compile_trace(self, self.resumekey)
         if target_token is not token:
             compile.giveup()

File pypy/jit/metainterp/resoperation.py

 VOID  = 'v'
 
 @specialize.arg(0)
-def create_resop(opnum, args, result, descr=None):
+def create_resop(opnum, result, args, descr=None):
     cls = opclasses[opnum]
     assert cls.NUMARGS == -1
     if cls.is_always_pure():
     return op
 
 @specialize.arg(0)
-def create_resop_1(opnum, arg0, result, descr=None):
+def create_resop_1(opnum, result, arg0, descr=None):
     cls = opclasses[opnum]
     assert cls.NUMARGS == 1
     if cls.is_always_pure():
     return op
 
 @specialize.arg(0)
-def create_resop_2(opnum, arg0, arg1, result, descr=None):
+def create_resop_2(opnum, result, arg0, arg1, descr=None):
     cls = opclasses[opnum]
     assert cls.NUMARGS == 2
     if cls.is_always_pure():
     return op
 
 @specialize.arg(0)
-def create_resop_3(opnum, arg0, arg1, arg2, result, descr=None):
+def create_resop_3(opnum, result, arg0, arg1, arg2, descr=None):
     cls = opclasses[opnum]
     assert cls.NUMARGS == 3
     if cls.is_always_pure():
 
     def repr(self, graytext=False):
         # RPython-friendly version
-        if self.result is not None:
-            sres = '%s = ' % (self.result,)
+        resultrepr = self.getresultrepr()
+        if resultrepr is not None:
+            sres = '%s = ' % (resultrepr,)
         else:
             sres = ''
         if self.name:
     def getresult(self):
         return None
 
+    def getresultrepr(self):
+        return None
+
 class ResOpInt(object):
     _mixin_ = True
     type = INT
         return self.intval
     getresult = getint
 
+    def getresultrepr(self):
+        return str(self.intval)
+
     @staticmethod
     def wrap_constant(intval):
         from pypy.jit.metainterp.history import ConstInt
         # XXX not sure between float or float storage
         self.floatval = floatval
 
+    def getresultrepr(self):
+        return str(self.floatval)
+
     def getfloatstorage(self):
         return self.floatval
     getresult = getfloatstorage
         return self.pval
     getresult = getref_base
 
+    def getresultrepr(self):
+        # XXX what do we want to put in here?
+        return str(self.pval)
+
     @staticmethod
     def wrap_constant(pval):
         from pypy.jit.metainterp.history import ConstPtr
         func(self.getopnum(), 0, self._arg0)
 
     def clone(self):
-        r = create_resop_1(self.opnum, self._arg0, self.getresult(),
+        r = create_resop_1(self.opnum, self.getresult(), self._arg0,
                               self.getdescrclone())
         if self.is_guard():
             r.setfailargs(self.getfailargs())
         func(self.getopnum(), 1, self._arg1)
 
     def clone(self):
-        r = create_resop_2(self.opnum, self._arg0, self._arg1,
-                           self.getresult(),  self.getdescrclone())
+        r = create_resop_2(self.opnum, self.getresult(), self._arg0, self._arg1,
+                           self.getdescrclone())
         if self.is_guard():
             r.setfailargs(self.getfailargs())
         return r
 
     def clone(self):
         assert not self.is_guard()
-        return create_resop_3(self.opnum, self._arg0, self._arg1, self._arg2,
-                              self.getresult(), self.getdescrclone())
+        return create_resop_3(self.opnum, self.getresult(), self._arg0,
+                              self._arg1, self._arg2, self.getdescrclone())
     
 
 class N_aryOp(object):
 
     def clone(self):
         assert not self.is_guard()
-        return create_resop(self.opnum, self._args[:], self.getresult(),
+        return create_resop(self.opnum, self.getresult(), self._args[:],
                               self.getdescrclone())
 
 

File pypy/jit/metainterp/test/test_resoperation.py

 
     def __ne__(self, other):
         return not self == other
-    
+
+    def __str__(self):
+        return self.v
+
     def is_constant(self):
         return False
 
+class FakeDescr(AbstractDescr):
+    def __repr__(self):
+        return 'descr'
+
 def test_arity_mixins():
     cases = [
         (0, rop.NullaryOp),
 def test_instantiate():
     from pypy.rpython.lltypesystem import lltype, llmemory
     
-    op = rop.create_resop_2(rop.rop.INT_ADD, FakeBox('a'), FakeBox('b'), 15)
+    op = rop.create_resop_2(rop.rop.INT_ADD, 15, FakeBox('a'), FakeBox('b'))
     assert op.getarglist() == [FakeBox('a'), FakeBox('b')]
     assert op.getint() == 15
 
     mydescr = AbstractDescr()
-    op = rop.create_resop(rop.rop.CALL_f, [FakeBox('a'),
-                                           FakeBox('b')], 15.5, descr=mydescr)
+    op = rop.create_resop(rop.rop.CALL_f, 15.5, [FakeBox('a'),
+                                           FakeBox('b')], descr=mydescr)
     assert op.getarglist() == [FakeBox('a'), FakeBox('b')]
     assert op.getfloat() == 15.5
     assert op.getdescr() is mydescr
 
-    op = rop.create_resop(rop.rop.CALL_p, [FakeBox('a'), FakeBox('b')],
-                          lltype.nullptr(llmemory.GCREF.TO), descr=mydescr)
+    op = rop.create_resop(rop.rop.CALL_p, lltype.nullptr(llmemory.GCREF.TO),
+                          [FakeBox('a'), FakeBox('b')], descr=mydescr)
     assert op.getarglist() == [FakeBox('a'), FakeBox('b')]
     assert not op.getref_base()
     assert op.getdescr() is mydescr    
     mydescr = AbstractDescr()
     p = lltype.malloc(llmemory.GCREF.TO)
     assert rop.create_resop_0(rop.rop.NEW, p).can_malloc()
-    call = rop.create_resop(rop.rop.CALL_i, [FakeBox('a'),
-                                             FakeBox('b')], 3, descr=mydescr)
+    call = rop.create_resop(rop.rop.CALL_i, 3, [FakeBox('a'),
+                                                FakeBox('b')], descr=mydescr)
     assert call.can_malloc()
-    assert not rop.create_resop_2(rop.rop.INT_ADD, FakeBox('a'),
-                                  FakeBox('b'), 3).can_malloc()
+    assert not rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox('a'),
+                                  FakeBox('b')).can_malloc()
 
 def test_get_deep_immutable_oplist():
-    ops = [rop.create_resop_2(rop.rop.INT_ADD, FakeBox('a'), FakeBox('b'), 3)]
+    ops = [rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox('a'), FakeBox('b'))]
     newops = rop.get_deep_immutable_oplist(ops)
     py.test.raises(TypeError, "newops.append('foobar')")
     py.test.raises(TypeError, "newops[0] = 'foobar'")
     assert not op2 is op
     assert op2.getresult() is None
     assert op2.getfailargs() is op.getfailargs()
-    op = rop.create_resop_1(rop.rop.INT_IS_ZERO, FakeBox('a'), 1)
+    op = rop.create_resop_1(rop.rop.INT_IS_ZERO, 1, FakeBox('a'))
     op2 = op.clone()
     assert op2 is not op
     assert op2._arg0 == FakeBox('a')
     assert op2.getint() == 1
-    op = rop.create_resop_2(rop.rop.INT_ADD, FakeBox('a'), FakeBox('b'), 1)
+    op = rop.create_resop_2(rop.rop.INT_ADD, 1, FakeBox('a'), FakeBox('b'))
     op2 = op.clone()
     assert op2 is not op
     assert op2._arg0 == FakeBox('a')
     assert op2._arg1 == FakeBox('b')
     assert op2.getint() == 1
-    op = rop.create_resop_3(rop.rop.STRSETITEM, FakeBox('a'), FakeBox('b'),
-                            FakeBox('c'), None)
+    op = rop.create_resop_3(rop.rop.STRSETITEM, None, FakeBox('a'),
+                            FakeBox('b'), FakeBox('c'))
     op2 = op.clone()
     assert op2 is not op
     assert op2._arg0 == FakeBox('a')
     assert op2._arg1 == FakeBox('b')
     assert op2._arg2 == FakeBox('c')
     assert op2.getresult() is None
-    op = rop.create_resop(rop.rop.CALL_i, [FakeBox('a'), FakeBox('b'),
-                            FakeBox('c')], 13, descr=mydescr)
+    op = rop.create_resop(rop.rop.CALL_i, 13, [FakeBox('a'), FakeBox('b'),
+                            FakeBox('c')], descr=mydescr)
     op2 = op.clone()
     assert op2 is not op
     assert op2._args == [FakeBox('a'), FakeBox('b'), FakeBox('c')]
     assert op2.getint() == 13
+
+def test_repr():
+    mydescr = FakeDescr()
+    op = rop.create_resop_0(rop.rop.GUARD_NO_EXCEPTION, None, descr=mydescr)
+    assert repr(op) == 'guard_no_exception(, descr=descr)'
+    op = rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox("a"), FakeBox("b"))
+    assert repr(op) == '3 = int_add(a, b)'