[pypy-svn] r51275 - in pypy/dist/pypy: jit/codegen/cli jit/codegen/cli/test jit/codegen/test translator/c/test

antocuni at codespeak.net antocuni at codespeak.net
Mon Feb 4 23:30:50 CET 2008


Author: antocuni
Date: Mon Feb  4 23:30:49 2008
New Revision: 51275

Added:
   pypy/dist/pypy/jit/codegen/cli/operation.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/codegen/cli/rgenop.py
   pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py
   pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
   pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
more tests pass



Added: pypy/dist/pypy/jit/codegen/cli/operation.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/cli/operation.py	Mon Feb  4 23:30:49 2008
@@ -0,0 +1,57 @@
+from pypy.translator.cli.dotnet import CLR
+OpCodes = CLR.System.Reflection.Emit.OpCodes
+
+class Operation:
+    restype = None
+    _gv_res = None
+
+    def gv_res(self):
+        from pypy.jit.codegen.cli.rgenop import GenLocalVar
+        if self._gv_res is None:
+            # if restype is None, assume it's the same as the first arg
+            t = self.restype or self.gv_x.getCliType()
+            loc = self.il.DeclareLocal(t)
+            self._gv_res = GenLocalVar(loc)
+        return self._gv_res
+
+    def emit(self):
+        raise NotImplementedError
+
+
+class UnaryOp(Operation):
+    def __init__(self, il, gv_x):
+        self.il = il
+        self.gv_x = gv_x
+
+
+class SameAs(UnaryOp):
+    def emit(self):
+        gv_res = self.gv_res()
+        self.gv_x.load(self.il)
+        self.gv_res().store(self.il)
+
+
+class BinaryOp(Operation):
+    def __init__(self, il, gv_x, gv_y):
+        self.il = il
+        self.gv_x = gv_x
+        self.gv_y = gv_y
+
+    def emit(self):
+        self.gv_x.load(self.il)
+        self.gv_y.load(self.il)
+        self.il.Emit(self.getOpCode())
+        self.gv_res().store(self.il)
+
+    def getOpCode(self):
+        raise NotImplementedError
+
+
+class Add(BinaryOp):
+    def getOpCode(self):
+        return OpCodes.Add
+
+
+class Sub(BinaryOp):
+    def getOpCode(self):
+        return OpCodes.Sub

Modified: pypy/dist/pypy/jit/codegen/cli/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/cli/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/cli/rgenop.py	Mon Feb  4 23:30:49 2008
@@ -1,8 +1,9 @@
 from pypy.tool.pairtype import extendabletype
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import specialize
-from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
+from pypy.jit.codegen.model import AbstractRGenOp, GenBuilder
 from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch
+from pypy.jit.codegen.cli import operation as ops
 from pypy.translator.cli.dotnet import CLR, typeof, new_array, clidowncast
 System = CLR.System
 Utils = CLR.pypy.runtime.Utils
@@ -14,8 +15,19 @@
     else:
         assert False
 
+def sigtoken2clitype(tok):
+    if tok == (['<Signed>'], '<Signed>'):
+        return typeof(CLR.pypy.runtime.DelegateType_int__int)
+    elif tok == (['<Signed>', '<Signed>'], '<Signed>'):
+        return typeof(CLR.pypy.runtime.DelegateType_int__int_int)
+    else:
+        assert False
+
 class __extend__(GenVarOrConst):
     __metaclass__ = extendabletype
+
+    def getCliType(self):
+        raise NotImplementedError
     
     def load(self, il):
         raise NotImplementedError
@@ -24,9 +36,12 @@
         raise NotImplementedError
 
 class GenArgVar(GenVar):
-    def __init__(self, index):
+    def __init__(self, index, cliType):
         self.index = index
-        # XXX maybe we need to store also the type?
+        self.cliType = cliType
+
+    def getCliType(self):
+        return self.cliType
 
     def load(self, il):
         if self.index == 0:
@@ -50,12 +65,16 @@
     def __init__(self, v):
         self.v = v
 
+    def getCliType(self):
+        return self.v.get_LocalType()
+
     def load(self, il):
         il.Emit(OpCodes.Ldloc, self.v)
 
     def store(self, il):
         il.Emit(OpCodes.Stloc, self.v)
 
+
 class IntConst(GenConst):
 
     def __init__(self, value):
@@ -70,9 +89,11 @@
         il.Emit(OpCodes.Ldc_I4, self.value)
 
     def __repr__(self):
-        "NOT_RPYTHON"
         return "const=%s" % self.value
 
+SM_INT__INT = ootype.StaticMethod([ootype.Signed], ootype.Signed)
+SM_INT__INT_INT = ootype.StaticMethod([ootype.Signed, ootype.Signed], ootype.Signed)
+
 class ObjectConst(GenConst):
 
     def __init__(self, obj):
@@ -80,9 +101,16 @@
 
     @specialize.arg(1)
     def revealconst(self, T):
-        DelegateType = CLR.pypy.runtime.DelegateType_int__int # XXX use T
-        return clidowncast(DelegateType, self.obj)
-
+        # XXX: probably you can't mix StaticMethod and others OOTypes
+        if T == SM_INT__INT:
+            DelegateType = CLR.pypy.runtime.DelegateType_int__int
+            return clidowncast(DelegateType, self.obj)
+        elif T == SM_INT__INT_INT:
+            DelegateType = CLR.pypy.runtime.DelegateType_int__int_int
+            return clidowncast(DelegateType, self.obj)
+        else:
+            assert isinstance(T, ootype.OOType)
+            return ootype.oodowncast(T, self.obj)
 
 class RCliGenOp(AbstractRGenOp):
 
@@ -95,6 +123,8 @@
         T = ootype.typeOf(llvalue)
         if T is ootype.Signed:
             return IntConst(llvalue)
+        elif isinstance(T, ootype.OOType):
+            return ObjectConst(llvalue)
         else:
             assert False, "XXX not implemented"
 
@@ -104,10 +134,15 @@
         """Return a token describing the signature of FUNCTYPE."""
         # XXX: the right thing to do would be to have a way to
         # represent typeof(t) as a pbc
-        args = [repr(T) for T in FUNCTYPE.ARGS]
-        res = repr(FUNCTYPE.RESULT)
+        args = [RCliGenOp.kindToken(T) for T in FUNCTYPE.ARGS]
+        res = RCliGenOp.kindToken(FUNCTYPE.RESULT)
         return args, res
 
+    @staticmethod
+    @specialize.memo()
+    def kindToken(T):
+        return repr(T)
+
     def newgraph(self, sigtoken, name):
         argtoks, restok = sigtoken
         args = new_array(System.Type, len(argtoks))
@@ -127,26 +162,35 @@
         self.il = self.meth.GetILGenerator()
         self.inputargs_gv = []
         for i in range(len(args)):
-            self.inputargs_gv.append(GenArgVar(i))
+            self.inputargs_gv.append(GenArgVar(i, args[i]))
         self.gv_entrypoint = ObjectConst(None) # XXX?
  
     @specialize.arg(1)
     def genop2(self, opname, gv_arg1, gv_arg2):
-        assert opname == 'int_add'
-        res = self.il.DeclareLocal(typeof(System.Int32))
-        gv_res = GenLocalVar(res)
-        gv_arg1.load(self.il)
-        gv_arg2.load(self.il)
-        self.il.Emit(OpCodes.Add)
-        gv_res.store(self.il)
-        return gv_res
+        if opname == 'int_add':
+            op = ops.Add(self.il, gv_arg1, gv_arg2)
+        elif opname == 'int_sub':
+            op = ops.Sub(self.il, gv_arg1, gv_arg2)
+        else:
+            assert False
+        op.emit()
+        return op.gv_res()
 
     def finish_and_return(self, sigtoken, gv_returnvar):
         gv_returnvar.load(self.il)
         self.il.Emit(OpCodes.Ret)
-        DelegateType = CLR.pypy.runtime.DelegateType_int__int # XXX use sigtoken
-        myfunc = self.meth.CreateDelegate(typeof(DelegateType))
+        delegate_type = sigtoken2clitype(sigtoken)
+        myfunc = self.meth.CreateDelegate(delegate_type)
         self.gv_entrypoint.obj = myfunc
 
     def end(self):
         pass
+
+    def enter_next_block(self, kinds, args_gv):
+        for i in range(len(args_gv)):
+            op = ops.SameAs(self.il, args_gv[i])
+            op.emit()
+            args_gv[i] = op.gv_res()
+        lbl = self.il.DefineLabel()
+        self.il.MarkLabel(lbl)
+        return lbl

Modified: pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py	Mon Feb  4 23:30:49 2008
@@ -4,8 +4,23 @@
 from pypy.jit.codegen.test.rgenop_tests import AbstractRGenOpTests, OOType
 from pypy.translator.cli.test.runtest import compile_function
 
-# test disabled, only two pass
-class xTestRCliGenop(AbstractRGenOpTests):
+passing = set()
+def fn():
+    prefixes = [
+        'test_adder',
+        'test_dummy',
+        'test_hide_and_reveal',
+        'test_hide_and_reveal_p',
+        ]
+
+    for p in prefixes:
+        passing.add(p)
+        passing.add(p + '_direct')
+        passing.add(p + '_compile')
+fn()
+del fn
+
+class TestRCliGenop(AbstractRGenOpTests):
     RGenOp = RCliGenOp
     T = OOType
 
@@ -26,3 +41,10 @@
     def directtesthelper(self, FUNCTYPE, func):
         py.test.skip('???')
 
+    def __getattribute__(self, name):
+        if name.startswith('test_') and name not in passing:
+            def fn():
+                py.test.skip("doesn't work yet")
+            return fn
+        else:
+            return object.__getattribute__(self, name)

Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	(original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	Mon Feb  4 23:30:49 2008
@@ -20,8 +20,17 @@
     FUNC100 = lltype.FuncType([lltype.Signed]*100, lltype.Signed)
 
     @staticmethod
-    def Ptr(FUNC):
-        return lltype.Ptr(FUNC)
+    def Ptr(T):
+        return lltype.Ptr(T)
+
+    @staticmethod
+    def Struct(name, *fields):
+        S = lltype.GcStruct(name, *fields)
+        return S
+
+    @staticmethod
+    def malloc(S):
+        return lltype.malloc(S)
 
 
 class OOType(object):
@@ -33,8 +42,17 @@
     FUNC100 = ootype.StaticMethod([lltype.Signed]*100, lltype.Signed)
 
     @staticmethod
-    def Ptr(FUNC):
-        return FUNC
+    def Ptr(T):
+        return T
+
+    @staticmethod
+    def Struct(name, *fields):
+        I = ootype.Instance(name, ootype.ROOT, dict(fields))
+        return I
+
+    @staticmethod
+    def malloc(I):
+        return ootype.new(I)
 
 
 def make_adder(T, rgenop, n):
@@ -944,11 +962,11 @@
 
     def test_hide_and_reveal_p(self):
         RGenOp = self.RGenOp
-        S = lltype.GcStruct('s', ('x', lltype.Signed))
+        S = self.T.Struct('s', ('x', lltype.Signed))
         S_PTR = self.T.Ptr(S)
-        s1 = lltype.malloc(S)
+        s1 = self.T.malloc(S)
         s1.x = 8111
-        s2 = lltype.malloc(S)
+        s2 = self.T.malloc(S)
         s2.x = 8222
         def hide_and_reveal_p(n):
             rgenop = RGenOp()

Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Mon Feb  4 23:30:49 2008
@@ -9,7 +9,7 @@
     if not check_boehm_presence():
         py.test.skip("Boehm GC not present")
 
-class AbstractGCTestClass:
+class AbstractGCTestClass(object):
     gcpolicy = "boehm"
     stacklessgc = False
    



More information about the Pypy-commit mailing list