[pypy-svn] r24674 - pypy/dist/pypy/translator/squeak

nik at codespeak.net nik at codespeak.net
Tue Mar 21 11:46:16 CET 2006


Author: nik
Date: Tue Mar 21 11:45:53 2006
New Revision: 24674

Modified:
   pypy/dist/pypy/translator/squeak/codeformatter.py
   pypy/dist/pypy/translator/squeak/node.py
Log:
fix initialization of constant instances, broken due to the new static
ootype model. it seems like i will need to get the dynamic type out of
instances/views a few times, does it make sense to have a method for
this on instances/views?


Modified: pypy/dist/pypy/translator/squeak/codeformatter.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/codeformatter.py	(original)
+++ pypy/dist/pypy/translator/squeak/codeformatter.py	Tue Mar 21 11:45:53 2006
@@ -104,7 +104,7 @@
             return str(value)
         elif isinstance(value, ootype._class):
             return self.format_Instance(value._INSTANCE)
-        elif isinstance(value, ootype._instance):
+        elif isinstance(value, (ootype._instance, ootype._view)):
             return self.format_Instance(value._TYPE)
         elif isinstance(value, ootype._static_meth):
             return self.gen.unique_func_name(value.graph)

Modified: pypy/dist/pypy/translator/squeak/node.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/node.py	(original)
+++ pypy/dist/pypy/translator/squeak/node.py	Tue Mar 21 11:45:53 2006
@@ -3,7 +3,7 @@
 from pypy.translator.squeak.opformatter import OpFormatter
 from pypy.translator.squeak.codeformatter import CodeFormatter, Message
 from pypy.translator.squeak.codeformatter import Field, Assignment, CustomVariable
-from pypy.rpython.ootypesystem.ootype import Instance, Class, ROOT
+from pypy.rpython.ootypesystem.ootype import Instance, Class, ROOT, _view
 
 class CodeNode:
 
@@ -341,10 +341,17 @@
 
     def dependencies(self):
         # Important: Field initializers for the *runtime* type
-        return [FieldInitializerNode(self.gen, c.value._TYPE)
+        return [FieldInitializerNode(self.gen, self._dynamic_type(c.value))
             for c in self.constants.iterkeys()] + \
             [ClassNode(self.gen, self.CONSTANTS, class_vars=["Constants"])]
 
+    def _dynamic_type(self, instance):
+        # XXX move this to ootype?
+        if isinstance(instance, _view):
+            return instance._inst._TYPE
+        else:
+            return instance._TYPE
+
     def render(self):
         codef = CodeFormatter(self.gen)
         # XXX use CodeFormatter throughout here
@@ -354,9 +361,10 @@
         yield codef.format(message.with_args([]))
         yield "    Constants := Dictionary new."
         for const, const_id in self.constants.iteritems():
-            INST = const.value._TYPE
+            INST = self._dynamic_type(const.value)
+            inst = const.value._downcast(INST)
             field_names = INST._allfields().keys()
-            field_values = [getattr(const.value, f) for f in field_names]
+            field_values = [getattr(inst, f) for f in field_names]
             new = Message("new").send_to(INST, [])
             init_message = Message("fieldInit").send_to(new, field_values)
             yield "    Constants at: '%s' put: %s." \



More information about the Pypy-commit mailing list