[pypy-svn] r51313 - in pypy/dist/pypy: jit/codegen/cli jit/codegen/cli/test translator/cli/src

antocuni at codespeak.net antocuni at codespeak.net
Wed Feb 6 16:32:19 CET 2008


Author: antocuni
Date: Wed Feb  6 16:32:19 2008
New Revision: 51313

Modified:
   pypy/dist/pypy/jit/codegen/cli/operation.py
   pypy/dist/pypy/jit/codegen/cli/rgenop.py
   pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py
   pypy/dist/pypy/translator/cli/src/pypylib.cs
Log:
- test_largedummy would work out of the box, if only .maxstack were
  big enough to fit it.

- implemented branching



Modified: pypy/dist/pypy/jit/codegen/cli/operation.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/cli/operation.py	(original)
+++ pypy/dist/pypy/jit/codegen/cli/operation.py	Wed Feb  6 16:32:19 2008
@@ -1,29 +1,71 @@
-from pypy.translator.cli.dotnet import CLR
-OpCodes = CLR.System.Reflection.Emit.OpCodes
+from pypy.rpython.ootypesystem import ootype
+from pypy.translator.cli.dotnet import CLR, typeof
+System = CLR.System
+OpCodes = System.Reflection.Emit.OpCodes
 
 class Operation:
-    restype = None
     _gv_res = None
 
+    def restype(self):
+        return self.gv_x.getCliType()
+
     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)
+            restype = self.restype()
+            if restype is not None:
+                loc = self.il.DeclareLocal(restype)
+                self._gv_res = GenLocalVar(loc)
         return self._gv_res
 
     def emit(self):
         raise NotImplementedError
 
 
+class Branch(Operation):
+    
+    def __init__(self, il, label):
+        self.il = il
+        self.label = label
+
+    def emit(self):
+        self.il.emit(OpCodes.Br, self.label)
+
+
 class UnaryOp(Operation):
     def __init__(self, il, gv_x):
         self.il = il
         self.gv_x = gv_x
 
 
+class AbstractBranchIf(UnaryOp):
+
+    def __init__(self, il, gv_x, label):
+        self.il = il
+        self.gv_x = gv_x
+        self.label = label
+
+    def restype(self):
+        return None
+
+    def emit(self):
+        self.il.emit(self.getOpCode(), self.label)
+
+    def getOpCode(self):
+        return OpCodes.Brtrue
+
+
+class BrFalse(AbstractBranchIf):
+
+    def getOpCode(self):
+        return OpCodes.Brfalse
+
+class BrTrue(AbstractBranchIf):
+
+    def getOpCode(self):
+        return OpCodes.Brtrue
+
+
 class SameAs(UnaryOp):
     def emit(self):
         gv_res = self.gv_res()
@@ -55,3 +97,10 @@
 class Sub(BinaryOp):
     def getOpCode(self):
         return OpCodes.Sub
+
+class Gt(BinaryOp):
+    def restype(self):
+        return typeof(System.Boolean)
+
+    def getOpCode(self):
+        return OpCodes.Cgt

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	Wed Feb  6 16:32:19 2008
@@ -20,6 +20,8 @@
         return typeof(CLR.pypy.runtime.DelegateType_int__int)
     elif tok == (['<Signed>', '<Signed>'], '<Signed>'):
         return typeof(CLR.pypy.runtime.DelegateType_int__int_int)
+    elif tok == (['<Signed>'] * 100, '<Signed>'):
+        return typeof(CLR.pypy.runtime.DelegateType_int__int_100)
     else:
         assert False
 
@@ -85,6 +87,9 @@
         assert T is ootype.Signed
         return self.value
 
+    def getCliType(self):
+        return typeof(System.Int32)
+
     def load(self, il):
         il.Emit(OpCodes.Ldc_I4, self.value)
 
@@ -93,6 +98,7 @@
 
 SM_INT__INT = ootype.StaticMethod([ootype.Signed], ootype.Signed)
 SM_INT__INT_INT = ootype.StaticMethod([ootype.Signed, ootype.Signed], ootype.Signed)
+SM_INT__INT_100 = ootype.StaticMethod([ootype.Signed] * 100, ootype.Signed)
 
 class ObjectConst(GenConst):
 
@@ -108,6 +114,9 @@
         elif T == SM_INT__INT_INT:
             DelegateType = CLR.pypy.runtime.DelegateType_int__int_int
             return clidowncast(DelegateType, self.obj)
+        elif T == SM_INT__INT_100:
+            DelegateType = CLR.pypy.runtime.DelegateType_int__int_100
+            return clidowncast(DelegateType, self.obj)
         else:
             assert isinstance(T, ootype.OOType)
             return ootype.oodowncast(T, self.obj)
@@ -149,14 +158,14 @@
         for i in range(len(argtoks)):
             args[i] = token2clitype(argtoks[i])
         res = token2clitype(restok)
-        builder = Builder(self, name, res, args)
+        builder = Builder(self, name, res, args, sigtoken)
         return builder, builder.gv_entrypoint, builder.inputargs_gv[:]
 
 
 
 class Builder(GenBuilder):
 
-    def __init__(self, rgenop, name, res, args):
+    def __init__(self, rgenop, name, res, args, sigtoken):
         self.rgenop = rgenop
         self.meth = Utils.CreateDynamicMethod(name, res, args)
         self.il = self.meth.GetILGenerator()
@@ -164,6 +173,8 @@
         for i in range(len(args)):
             self.inputargs_gv.append(GenArgVar(i, args[i]))
         self.gv_entrypoint = ObjectConst(None) # XXX?
+        self.sigtoken = sigtoken
+        self.isOpen = False
  
     @specialize.arg(1)
     def genop2(self, opname, gv_arg1, gv_arg2):
@@ -171,26 +182,59 @@
             op = ops.Add(self.il, gv_arg1, gv_arg2)
         elif opname == 'int_sub':
             op = ops.Sub(self.il, gv_arg1, gv_arg2)
+        elif opname == 'int_gt':
+            op = ops.Gt(self.il, gv_arg1, gv_arg2)
         else:
             assert False
-        op.emit()
+        self.emit(op)
         return op.gv_res()
 
+    def emit(self, op):
+        op.emit()
+
+    def start_writing(self):
+        self.isOpen = True
+
     def finish_and_return(self, sigtoken, gv_returnvar):
         gv_returnvar.load(self.il)
         self.il.Emit(OpCodes.Ret)
-        delegate_type = sigtoken2clitype(sigtoken)
-        myfunc = self.meth.CreateDelegate(delegate_type)
-        self.gv_entrypoint.obj = myfunc
+        self.isOpen = False
 
     def end(self):
-        pass
+        delegate_type = sigtoken2clitype(self.sigtoken)
+        myfunc = self.meth.CreateDelegate(delegate_type)
+        self.gv_entrypoint.obj = myfunc
 
     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
+        label = self.il.DefineLabel()
+        self.il.MarkLabel(label)
+        return label
+
+    def _jump_if(self, gv_condition, opcode):
+        label = self.il.DefineLabel()
+        gv_condition.load(self.il)
+        self.il.Emit(opcode, label)
+        return BranchBuilder(self, label)
+
+    def jump_if_false(self, gv_condition, args_for_jump_gv):
+        return self._jump_if(gv_condition, OpCodes.Brfalse)
+
+    def jump_if_true(self, gv_condition, args_for_jump_gv):
+        return self._jump_if(gv_condition, OpCodes.Brtrue)
+
+class BranchBuilder(Builder):
+
+    def __init__(self, parent, label):
+        self.parent = parent
+        self.label = label
+        self.il = parent.il
+        self.isOpen = False
+
+    def start_writing(self):
+        assert not self.parent.isOpen
+        self.isOpen = True
+        self.il.MarkLabel(self.label)

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	Wed Feb  6 16:32:19 2008
@@ -11,6 +11,8 @@
         'test_dummy',
         'test_hide_and_reveal',
         'test_hide_and_reveal_p',
+        'test_largedummy_direct', # _compile works if we set a higher maxstack
+        'test_branching',
         ]
 
     for p in prefixes:

Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs	Wed Feb  6 16:32:19 2008
@@ -55,6 +55,7 @@
 {
     public delegate int DelegateType_int__int(int a);
     public delegate int DelegateType_int__int_int(int a, int b);
+    public delegate int DelegateType_int__int_100(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, int a56, int a57, int a58, int a59, int a60, int a61, int a62, int a63, int a64, int a65, int a66, int a67, int a68, int a69, int a70, int a71, int a72, int a73, int a74, int a75, int a76, int a77, int a78, int a79, int a80, int a81, int a82, int a83, int a84, int a85, int a86, int a87, int a88, int a89, int a90, int a91, int a92, int a93, int a94, int a95, int a96, int a97, int a98, int a99);
 
     public class Utils
     {



More information about the Pypy-commit mailing list