[pypy-svn] r57775 - in pypy/branch/oo-jit/pypy: annotation jit/codegen/cli jit/codegen/cli/test translator/cli

antocuni at codespeak.net antocuni at codespeak.net
Tue Sep 2 21:57:30 CEST 2008


Author: antocuni
Date: Tue Sep  2 21:57:23 2008
New Revision: 57775

Modified:
   pypy/branch/oo-jit/pypy/annotation/binaryop.py
   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
   pypy/branch/oo-jit/pypy/translator/cli/database.py
Log:
a bit of refactoring of {Field,Method}Token and ObjectConst; fix some weird
bugs; skip a failing test



Modified: pypy/branch/oo-jit/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/annotation/binaryop.py	(original)
+++ pypy/branch/oo-jit/pypy/annotation/binaryop.py	Tue Sep  2 21:57:23 2008
@@ -951,14 +951,12 @@
             common = r2.ootype
         elif r2.ootype is None:
             common = r1.ootype
-        elif r1.ootype is ootype.Object or r2.ootype is ootype.Object:
-            common = ootype.Object
-        elif isinstance(r1.ootype, ootype.BuiltinType) or isinstance(r2.ootype, ootype.BuiltinType):
-            common = ootype.Object
-        else:
+        elif isinstance(r1.ootype, ootype.Instance) and isinstance(r2.ootype, ootype.Instance):
             common = ootype.commonBaseclass(r1.ootype, r2.ootype)
             assert common is not None, ('Mixing of incompatible classes %r, %r'
                                         % (r1.ootype, r2.ootype))
+        else:
+            common = ootype.Object
         return SomeOOClass(common)
 
 class __extend__(pairtype(SomeOOInstance, SomeObject)):

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	Tue Sep  2 21:57:23 2008
@@ -6,7 +6,7 @@
 System = CLR.System
 OpCodes = System.Reflection.Emit.OpCodes
 
-class Operation:
+class Operation(object):
     _gv_res = None
 
     def restype(self):
@@ -177,11 +177,9 @@
 class GetField(Operation):
 
     def __init__(self, meth, gv_obj, fieldtoken):
-        from pypy.jit.codegen.cli.rgenop import class2type
         self.meth = meth
         self.gv_obj = gv_obj
-        clitype = class2type(fieldtoken.ooclass)
-        self.fieldinfo = clitype.GetField(str(fieldtoken.name))
+        self.fieldinfo = fieldtoken.getFieldInfo()
 
     def restype(self):
         return self.fieldinfo.get_FieldType()
@@ -195,12 +193,10 @@
 class SetField(Operation):
 
     def __init__(self, meth, gv_obj, gv_value, fieldtoken):
-        from pypy.jit.codegen.cli.rgenop import class2type
         self.meth = meth
         self.gv_obj = gv_obj
         self.gv_value = gv_value
-        clitype = class2type(fieldtoken.ooclass)
-        self.fieldinfo = clitype.GetField(str(fieldtoken.name))
+        self.fieldinfo = fieldtoken.getFieldInfo()
 
     def restype(self):
         return None
@@ -224,6 +220,28 @@
         self.meth.il.Emit(OpCodes.Newobj, ctor)
         self.storeResult()
 
+class OOSend(Operation):
+
+    def __init__(self, meth, gv_self, args_gv, methtoken):
+        self.meth = meth
+        self.gv_self = gv_self
+        self.args_gv = args_gv
+        self.methodinfo = methtoken.getMethodInfo()
+
+    def restype(self):
+        clitype = self.methodinfo.get_ReturnType()
+        if clitype is typeof(System.Void):
+            return None
+        return clitype
+
+    def emit(self):
+        self.gv_self.load(self.meth)
+        for gv_arg in self.args_gv:
+            gv_arg.load(self.meth)
+        self.meth.il.Emit(OpCodes.Callvirt, self.methodinfo)
+        if self.restype() is not None:
+            self.storeResult()
+
 def mark(il, s):
     il.Emit(OpCodes.Ldstr, s)
     il.Emit(OpCodes.Pop)
@@ -308,7 +326,9 @@
             code = source.compile()
             exec code in globals(), out
         elif value is cli_opcodes.DoNothing:
-            out[opname] = SameAs
+            # create a new subclass of SameAs; we can't use SameAs directly
+            # because its restype could be patched later
+            out[opname] = type(opname, (SameAs,), {})
         else:
             renderCustomOp(opname, baseclass, value, out)
 

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	Tue Sep  2 21:57:23 2008
@@ -39,6 +39,19 @@
         self.ooclass = ooclass
         self.name = name
 
+    def getFieldInfo(self):
+        clitype = class2type(self.ooclass)
+        return clitype.GetField(str(self.name))
+
+class MethToken:
+    def __init__(self, ooclass, name):
+        self.ooclass = ooclass
+        self.name = name
+
+    def getMethodInfo(self):
+        clitype = class2type(self.ooclass)
+        return clitype.GetMethod(str(self.name))
+
 class AllocToken:
     def __init__(self, ooclass):
         self.ooclass = ooclass
@@ -171,14 +184,12 @@
 
 class ObjectConst(BaseConst):
 
-    def __init__(self, obj):
+    def __init__(self, ooclass, obj):
+        self.ooclass = ooclass
         self.obj = obj
 
     def getCliType(self):
-        if self.obj == ootype.NULL:
-            return class2type(cObject)
-        cliobj = dotnet.cast_to_native_object(self.obj)
-        return cliobj.GetType()
+        return class2type(self.ooclass)
 
     def getobj(self):
         return dotnet.cast_to_native_object(self.obj)
@@ -246,7 +257,6 @@
         self.inputargs_gv = inputargs_gv
 
     def emit_trampoline(self, meth):
-        from pypy.jit.codegen.cli.operation import mark
         il = meth.il
         args_manager = meth.graphinfo.args_manager
         il.MarkLabel(self.il_trampoline_label)
@@ -272,8 +282,9 @@
         elif T is ootype.Float:
             return FloatConst(llvalue)
         elif isinstance(T, ootype.OOType):
+            ooclass = ootype.runtimeClass(T)
             obj = ootype.cast_to_object(llvalue)
-            return ObjectConst(obj)
+            return ObjectConst(ooclass, obj)
         else:
             assert False, "XXX not implemented"
 
@@ -305,7 +316,8 @@
     @staticmethod
     @specialize.memo()
     def methToken(TYPE, methname):
-        return methname #XXX
+        ooclass = ootype.runtimeClass(TYPE)
+        return MethToken(ooclass, methname)
 
     @staticmethod
     @specialize.memo()
@@ -632,7 +644,9 @@
         self.appendop(op)
 
     def genop_oosend(self, methtoken, gv_self, args_gv):
-        raise NotImplementedError
+        op = ops.OOSend(self.meth, gv_self, args_gv, methtoken)
+        self.appendop(op)
+        return op.gv_res()
 
     def genop_oononnull(self, gv_obj):
         raise NotImplementedError
@@ -724,4 +738,4 @@
 
 global_rgenop = RCliGenOp()
 RCliGenOp.constPrebuiltGlobal = global_rgenop.genconst
-zero_const = ObjectConst(ootype.NULL)
+zero_const = ObjectConst(cObject, ootype.NULL)

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	Tue Sep  2 21:57:23 2008
@@ -80,7 +80,9 @@
     def test_arith_plus_minus(self):
         py.test.skip("Cannot work unless we add support for constant arguments in compiled tests")
 
-    test_compile_time_const_tuple = skip
+    def test_compile_time_const_tuple(self):
+        py.test.skip("Fails, and it seems to be related to missing support for constant arguments")
+
     test_green_deepfrozen_oosend = skip
     test_direct_oosend_with_green_self = skip
     test_builtin_oosend_with_green_args = skip

Modified: pypy/branch/oo-jit/pypy/translator/cli/database.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/database.py	(original)
+++ pypy/branch/oo-jit/pypy/translator/cli/database.py	Tue Sep  2 21:57:23 2008
@@ -134,6 +134,8 @@
             return self.class_name(TYPE)
         elif isinstance(TYPE, ootype.Record):
             return self.get_record_name(TYPE)
+        elif isinstance(TYPE, ootype.OOType):
+            return self.cts.lltype_to_cts(TYPE)
         else:
             assert False
 



More information about the Pypy-commit mailing list