[pypy-svn] r50603 - pypy/branch/fixed-list-ootype/pypy/translator/oosupport

atobe at codespeak.net atobe at codespeak.net
Mon Jan 14 16:34:30 CET 2008


Author: atobe
Date: Mon Jan 14 16:34:30 2008
New Revision: 50603

Modified:
   pypy/branch/fixed-list-ootype/pypy/translator/oosupport/constant.py
   pypy/branch/fixed-list-ootype/pypy/translator/oosupport/genoo.py
Log:
(cfbolz, atobe): In progress. Trying to get support for prebuilt arrays.

Modified: pypy/branch/fixed-list-ootype/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/oosupport/constant.py	(original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/oosupport/constant.py	Mon Jan 14 16:34:30 2008
@@ -203,6 +203,8 @@
             return genoo.ClassConst(self.db, value, uniq)
         elif isinstance(value, ootype._list):
             return genoo.ListConst(self.db, value, uniq)
+        elif isinstance(value, ootype._array):
+            return genoo.ArrayConst(self.db, value, uniq)
         elif isinstance(value, ootype._static_meth):
             return genoo.StaticMethodConst(self.db, value, uniq)
         elif isinstance(value, ootype._custom_dict):
@@ -395,7 +397,7 @@
         and any classes that are used are loaded.  Called when the
         constant object is created.
         """
-        raise NotImplementedException
+        raise NotImplementedError
     
     def create_pointer(self, gen):
         """
@@ -413,7 +415,7 @@
         the pointer from the stack in the process; otherwise, a pop
         is automatically inserted afterwards.
         """
-        raise NotImplementedException
+        raise NotImplementedError
 
     # ____________________________________________________________
     # Internal helpers
@@ -604,10 +606,6 @@
         The default is not to initialize if the list is a list of
         Void. """
         return self.value._TYPE.ITEM is ootype.Void
-        try:
-            return self.value._list == [0] * len(self.value._list)
-        except:
-            return False
 
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
@@ -628,6 +626,56 @@
             gen.call_method(SELFTYPE, 'll_setitem_fast')
 
 # ______________________________________________________________________
+# Array constants
+
+class ArrayConst(AbstractConst):
+    def __init__(self, db, list, count):
+        AbstractConst.__init__(self, db, list, count)
+        self.name = 'ARRAY__%d' % count
+
+    def record_dependencies(self):
+        if not self.value:
+            return
+        for item in self.value._array:
+            self._record_const_if_complex(self.value._TYPE.ITEM, item)
+
+    def create_pointer(self, gen):
+        from pypy.objspace.flow.model import Constant
+        assert not self.is_null()
+        SELFTYPE = self.value._TYPE
+
+        # Create the array
+        length = Constant(len(self.value._array), ootype.Signed)
+        gen.oonewarray(SELFTYPE, length)
+        
+    def _do_not_initialize(self):
+        """ Returns True if the array should not be initialized; this
+        can be overloaded by the backend if your conditions are wider.
+        The default is not to initialize if the array is a array of
+        Void. """
+        return self.value._TYPE.ITEM is ootype.Void
+
+    def initialize_data(self, constgen, gen):
+        assert not self.is_null()
+        SELFTYPE = self.value._TYPE
+        ITEM = self.value._TYPE.ITEM
+
+        # check for special cases and avoid initialization
+        if self._do_not_initialize():
+            return
+
+        # set each item in the list using the OOTYPE methods
+        for idx, item in enumerate(self.value._array):
+            constgen._consider_split_current_function(gen)
+            gen.dup(SELFTYPE)
+            push_constant(self.db, ootype.Signed, idx, gen)
+            push_constant(self.db, ITEM, item, gen)
+            gen.prepare_generic_argument(ITEM)
+            gen.call_method(SELFTYPE, 'll_setitem_fast')
+            print idx, item
+
+
+# ______________________________________________________________________
 # Dictionary constants
 
 class DictConst(AbstractConst):

Modified: pypy/branch/fixed-list-ootype/pypy/translator/oosupport/genoo.py
==============================================================================
--- pypy/branch/fixed-list-ootype/pypy/translator/oosupport/genoo.py	(original)
+++ pypy/branch/fixed-list-ootype/pypy/translator/oosupport/genoo.py	Mon Jan 14 16:34:30 2008
@@ -22,6 +22,7 @@
     RecordConst = ooconst.RecordConst
     ClassConst = ooconst.ClassConst
     ListConst = ooconst.ListConst
+    ArrayConst = ooconst.ArrayConst
     StaticMethodConst = ooconst.StaticMethodConst
     CustomDictConst = ooconst.CustomDictConst
     DictConst = ooconst.DictConst



More information about the Pypy-commit mailing list