[pypy-svn] r54367 - in pypy/branch/oo-jit/pypy: jit/codegen/cli translator/cli

antocuni at codespeak.net antocuni at codespeak.net
Sat May 3 15:49:49 CEST 2008


Author: antocuni
Date: Sat May  3 15:49:48 2008
New Revision: 54367

Modified:
   pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py
   pypy/branch/oo-jit/pypy/translator/cli/cts.py
   pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py
   pypy/branch/oo-jit/pypy/translator/cli/opcodes.py
Log:
- store ObjectConst.value as ootype.Object instead of the CLI System.Object

- add support for char const

- add support for void return values

- remove some old code referencing llmemory.Address, which should never be seen here



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	Sat May  3 15:49:48 2008
@@ -1,13 +1,11 @@
 from pypy.tool.pairtype import extendabletype
 from pypy.rpython.ootypesystem import ootype
-from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rlib.objectmodel import specialize
 from pypy.jit.codegen.model import AbstractRGenOp, GenBuilder, GenLabel
 from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch
 from pypy.jit.codegen.cli import operation as ops
 from pypy.jit.codegen.cli.dumpgenerator import DumpGenerator
 from pypy.translator.cli.dotnet import CLR, typeof, new_array, box, unbox, clidowncast, classof
-from pypy.translator.cli.dotnet import cast_record_to_object, cast_object_to_record
 System = CLR.System
 Utils = CLR.pypy.runtime.Utils
 DelegateHolder = CLR.pypy.runtime.DelegateHolder
@@ -16,10 +14,13 @@
 DUMP_IL = False
 DEBUG = False
 
+cVoid = ootype.nullruntimeclass
 cInt32 = classof(System.Int32)
 cBoolean = classof(System.Boolean)
 cDouble = classof(System.Double)
 cObject = classof(System.Object)
+cString = classof(System.String)
+cChar = classof(System.Char)
 
 class SigToken:
     def __init__(self, args, res, funcclass):
@@ -29,7 +30,10 @@
 
 def class2type(cls):
     'Cast a PBC of type ootype.Class into a System.Type instance'
-    return clidowncast(box(cls), System.Type)
+    if cls is cVoid:
+        return None
+    else:
+        return clidowncast(box(cls), System.Type)
 
 class __extend__(GenVarOrConst):
     __metaclass__ = extendabletype
@@ -85,8 +89,9 @@
 
 class IntConst(GenConst):
 
-    def __init__(self, value):
+    def __init__(self, value, clitype):
         self.value = value
+        self.clitype = clitype
 
     @specialize.arg(1)
     def revealconst(self, T):
@@ -94,17 +99,19 @@
             return self.value
         elif T is ootype.Bool:
             return bool(self.value)
+        elif T is ootype.Char:
+            return chr(self.value)
         else:
             assert False
 
     def getCliType(self):
-        return typeof(System.Int32)
+        return self.clitype
 
     def load(self, builder):
         builder.il.Emit(OpCodes.Ldc_I4, self.value)
 
     def __repr__(self):
-        return "const=%s" % self.value
+        return "int const=%s" % self.value
 
 
 class FloatConst(GenConst):
@@ -115,8 +122,7 @@
     @specialize.arg(1)
     def revealconst(self, T):
         assert T is ootype.Float
-        if T is ootype.Float:
-            return self.value
+        return self.value
 
     def getCliType(self):
         return typeof(System.Double)
@@ -125,7 +131,7 @@
         builder.il.Emit(OpCodes.Ldc_R8, self.value)
 
     def __repr__(self):
-        return "const=%s" % self.value
+        return "float const=%s" % self.value
 
 class BaseConst(GenConst):
 
@@ -165,13 +171,7 @@
 
     @specialize.arg(1)
     def revealconst(self, T):
-        if T is llmemory.Address:
-            return unbox(self.obj, ootype.ROOT) # XXX
-        elif isinstance(T, ootype.Record):
-            return cast_object_to_record(T, self.obj)
-        else:
-            assert isinstance(T, ootype.OOType)
-            return unbox(self.obj, T)
+        return ootype.cast_from_object(T, self.obj)
 
 
 OBJECT = System.Object._INSTANCE
@@ -217,19 +217,15 @@
     def genconst(self, llvalue):
         T = ootype.typeOf(llvalue)
         if T is ootype.Signed:
-            return IntConst(llvalue)
+            return IntConst(llvalue, typeof(System.Int32))
         elif T is ootype.Bool:
-            return IntConst(int(llvalue))
+            return IntConst(int(llvalue), typeof(System.Boolean))
+        elif T is ootype.Char:
+            return IntConst(ord(llvalue), typeof(System.Char))
         elif T is ootype.Float:
             return FloatConst(llvalue)
-        elif T is llmemory.Address:
-            assert llvalue is llmemory.NULL
-            return zero_const
-        elif isinstance(T, ootype.Record):
-            obj = cast_record_to_object(llvalue)
-            return ObjectConst(obj)
         elif isinstance(T, ootype.OOType):
-            obj = box(llvalue)
+            obj = ootype.cast_to_object(llvalue)
             return ObjectConst(obj)
         else:
             assert False, "XXX not implemented"
@@ -237,7 +233,7 @@
     @staticmethod
     def genzeroconst(kind):
         if kind is cInt32:
-            return IntConst(0)
+            return IntConst(0, typeof(System.Int32))
         else:
             return zero_const # ???
 
@@ -245,8 +241,6 @@
     @specialize.memo()
     def sigToken(FUNCTYPE):
         """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 = [RCliGenOp.kindToken(T) for T in FUNCTYPE.ARGS]
         res = RCliGenOp.kindToken(FUNCTYPE.RESULT)
         funcclass = classof(FUNCTYPE)
@@ -256,13 +250,17 @@
     @specialize.memo()
     def kindToken(T):
         if T is ootype.Void:
-            return None
+            return cVoid
         elif T is ootype.Signed:
             return cInt32
         elif T is ootype.Bool:
             return cBoolean
         elif T is ootype.Float:
             return cDouble
+        elif T is ootype.String:
+            return cString
+        elif T is ootype.Char:
+            return cChar
         elif isinstance(T, ootype.Instance):
             return cObject # XXX?
         else:
@@ -469,5 +467,4 @@
 
 global_rgenop = RCliGenOp()
 RCliGenOp.constPrebuiltGlobal = global_rgenop.genconst
-NULL = ootype.null(System.Object._INSTANCE)
-zero_const = ObjectConst(NULL)
+zero_const = ObjectConst(ootype.NULL)

Modified: pypy/branch/oo-jit/pypy/translator/cli/cts.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/cts.py	(original)
+++ pypy/branch/oo-jit/pypy/translator/cli/cts.py	Sat May  3 15:49:48 2008
@@ -147,6 +147,7 @@
     ootype.Unicode: types.string,
     ootype.UnicodeBuilder: types.string_builder,
     ootype.WeakReference: types.weakref,
+    ootype.Object: types.object,
 
     # maps generic types to their ordinal
     ootype.List.SELFTYPE_T: types.list,

Modified: pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py	(original)
+++ pypy/branch/oo-jit/pypy/translator/cli/ilgenerator.py	Sat May  3 15:49:48 2008
@@ -418,6 +418,9 @@
     def dup(self, TYPE):
         self.ilasm.opcode('dup')
 
+    def push_null(self, TYPE):
+        self.ilasm.opcode('ldnull')
+
     def oonewarray(self, TYPE, length):
         if TYPE.ITEM is ootype.Void:
             self.new(TYPE)

Modified: pypy/branch/oo-jit/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/opcodes.py	(original)
+++ pypy/branch/oo-jit/pypy/translator/cli/opcodes.py	Sat May  3 15:49:48 2008
@@ -36,6 +36,8 @@
     'oosend':                   [CallMethod],
     'ooupcast':                 DoNothing,
     'oodowncast':               [DownCast],
+    'cast_to_object':           DoNothing,
+    'cast_from_object':         [DownCast],
     'clibox':                   [Box],
     'cliunbox':                 [Unbox],
     'cli_newarray':             [NewArray],



More information about the Pypy-commit mailing list