[pypy-svn] r50609 - pypy/branch/fixed-list-ootype/pypy/translator/jvm

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 14 18:16:20 CET 2008


Author: cfbolz
Date: Mon Jan 14 18:16:19 2008
New Revision: 50609

Modified:
   pypy/branch/fixed-list-ootype/pypy/translator/jvm/database.py
   pypy/branch/fixed-list-ootype/pypy/translator/jvm/generator.py
   pypy/branch/fixed-list-ootype/pypy/translator/jvm/typesystem.py
Log:
implement void arrays as just integers (the only information they have is there
length)


Modified: pypy/branch/fixed-list-ootype/pypy/translator/jvm/database.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/jvm/database.py	(original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/jvm/database.py	Mon Jan 14 18:16:19 2008
@@ -542,6 +542,7 @@
         ootype.Bool     : jvmtype.jByteArray,
         ootype.UniChar  : jvmtype.jCharArray,
         ootype.String   : jvmtype.jStringArray,
+        ootype.Void     : jvmtype.jVoidArray,
     }
 
     def _array_type(self, ITEM):

Modified: pypy/branch/fixed-list-ootype/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/jvm/generator.py	(original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/jvm/generator.py	Mon Jan 14 18:16:19 2008
@@ -19,7 +19,8 @@
      jObject, jByteArray, jPyPyExcWrap, jIntegerClass, jLongClass, \
      jDoubleClass, jCharClass, jStringBuilder, JvmScalarType, jArrayList, \
      jObjectArray, jPyPyInterlink, jPyPyCustomDict, jPyPyEquals, \
-     jPyPyHashCode, jMap, jPyPyWeakRef, jSystem, jll_os, jPyPyInterlink
+     jPyPyHashCode, jMap, jPyPyWeakRef, jSystem, jll_os, jPyPyInterlink, \
+     jVoidArray
 
 
 # ___________________________________________________________________________
@@ -139,7 +140,10 @@
 
 class NewArrayOpcodeFamily(object):
     def __init__(self):
-        self.cache = {}
+        # a void array is just an int, therefore oonewarray does not need to
+        # do anything, because it the new can just use the int argument that is
+        # already on the stack
+        self.cache = {jVoidArray: None}
 
     def for_type(self, arraytype):
         try:
@@ -475,7 +479,32 @@
             gen._instr(ARRSTORE.for_type(self.arraytype.element_type))
         else:
             assert 0, "unknown array method"
-        
+
+class VoidArrayMethod(ArrayMethod):
+    def _argtypes(self):
+        if self.ootype_methodname == "ll_length":
+            return []
+        elif self.ootype_methodname == "ll_getitem_fast":
+            return [jInt]
+        elif self.ootype_methodname == "ll_setitem_fast":
+            return [jInt]
+        else:
+            assert 0, "unknown array method"
+
+    def _rettype(self):
+        if self.ootype_methodname == "ll_length":
+            return jInt
+        return jVoid
+
+    def invoke(self, gen):
+        if self.ootype_methodname == "ll_length":
+            pass
+        elif self.ootype_methodname == "ll_getitem_fast":
+            gen.emit(POP); gen.emit(POP)
+        elif self.ootype_methodname == "ll_setitem_fast":
+            gen.emit(POP); gen.emit(POP)
+        else:
+            assert 0, "unknown array method"
 
 # ___________________________________________________________________________
 # Fields
@@ -997,6 +1026,9 @@
         it is the name of a method to invoke, or an Opcode/Method
         object (defined above)."""
 
+        if instr is None:
+            return
+
         if isinstance(instr, str):
             return getattr(self, instr)(*args)
 

Modified: pypy/branch/fixed-list-ootype/pypy/translator/jvm/typesystem.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/jvm/typesystem.py	(original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/jvm/typesystem.py	Mon Jan 14 18:16:19 2008
@@ -239,6 +239,16 @@
         # Arrays don't have methods in Java, but they do in the ootype system
         from pypy.translator.jvm.generator import ArrayMethod
         return ArrayMethod(self, methodnm)
+
+class JvmVoidArrayType(JvmArrayType):
+    def __init__(self):
+        JvmType.__init__(self, JvmTypeDescriptor("I"))
+        self.element_type = jVoid
+    def lookup_method(self, methodnm):
+        # Arrays don't have methods in Java, but they do in the ootype system
+        from pypy.translator.jvm.generator import VoidArrayMethod
+        return VoidArrayMethod(self, methodnm)
+
         
 jByteArray = JvmArrayType(jByte)
 jObjectArray = JvmArrayType(jObject)
@@ -246,6 +256,7 @@
 jDoubleArray = JvmArrayType(jDouble)
 jCharArray = JvmArrayType(jChar)
 jIntArray = JvmArrayType(jInt)
+jVoidArray = JvmVoidArrayType()
 
 class Generifier(object):
 



More information about the Pypy-commit mailing list