[pypy-svn] r57701 - in pypy/branch/oo-jit/pypy/jit/codegen/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Sun Aug 31 13:46:36 CEST 2008


Author: antocuni
Date: Sun Aug 31 13:46:36 2008
New Revision: 57701

Modified:
   pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py
   pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py
   pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py
Log:
implement genop_new; a modified version of test_degenerate_with_voids passes



Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py	Sun Aug 31 13:46:36 2008
@@ -1,7 +1,7 @@
 import py
 from pypy.rlib.objectmodel import specialize
 from pypy.rpython.ootypesystem import ootype
-from pypy.translator.cli.dotnet import CLR, typeof
+from pypy.translator.cli.dotnet import CLR, typeof, new_array
 from pypy.translator.cli import opcodes as cli_opcodes
 System = CLR.System
 OpCodes = System.Reflection.Emit.OpCodes
@@ -216,6 +216,20 @@
         self.gv_value.load(self.meth)
         self.meth.il.Emit(OpCodes.Stfld, self.fieldinfo)
 
+class New(Operation):
+
+    def __init__(self, meth, alloctoken):
+        self.meth = meth
+        self.clitype = alloctoken.getCliType()
+
+    def restype(self):
+        return self.clitype
+
+    def emit(self):
+        ctor = self.clitype.GetConstructor(new_array(System.Type, 0))
+        self.meth.il.Emit(OpCodes.Newobj, ctor)
+        self.storeResult()
+
 def mark(il, s):
     il.Emit(OpCodes.Ldstr, s)
     il.Emit(OpCodes.Pop)

Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py	Sun Aug 31 13:46:36 2008
@@ -39,6 +39,13 @@
         self.cls = cls
         self.name = name
 
+class AllocToken:
+    def __init__(self, ooclass):
+        self.ooclass = ooclass
+
+    def getCliType(self):
+        return class2type(self.ooclass)
+
 def class2type(cls):
     'Cast a PBC of type ootype.Class into a System.Type instance'
     if cls is cVoid:
@@ -337,7 +344,7 @@
     @staticmethod
     @specialize.memo()
     def allocToken(T):
-        return RCliGenOp.kindToken(T)
+        return AllocToken(ootype.runtimeClass(T))
 
     def check_no_open_mc(self):
         pass
@@ -641,8 +648,10 @@
     def genop_ooisnull(self, gv_obj):
         raise NotImplementedError
 
-    def genop_new(self, gv_obj):
-        raise NotImplementedError
+    def genop_new(self, alloctoken):
+        op = ops.New(self.meth, alloctoken)
+        self.appendop(op)
+        return op.gv_res()
 
     def enter_next_block(self, args_gv):
         seen = {}

Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py	Sun Aug 31 13:46:36 2008
@@ -1,4 +1,5 @@
 import py
+from pypy.rpython.lltypesystem import lltype
 from pypy.jit.codegen.cli.rgenop import RCliGenOp
 from pypy.jit.rainbow.test.test_interpreter import TestOOType as RainbowTest
 from pypy.translator.cli.test.runtest import compile_graph, get_annotation
@@ -62,8 +63,20 @@
         res = self.interpret(ll_function, ["xx"], [])
         assert res == 42
 
+    def test_degenerate_with_voids(self):
+        # the original test can't be executed when compiled because we can't
+        # inspect the content of an instance return an instance as a result;
+        # instead, we just check the class name
+        S = self.GcStruct('S', ('y', lltype.Void),
+                               ('x', lltype.Signed))
+        malloc = self.malloc
+        def ll_function():
+            s = malloc(S)
+            s.x = 123
+            return s
+        res = self.interpret(ll_function, [], [])
+        assert res.class_name == 'S'
 
-    test_degenerate_with_voids = skip
     test_arith_plus_minus = skip
     test_plus_minus = skip
     test_red_virtual_container = skip



More information about the Pypy-commit mailing list