[pypy-svn] r35682 - in pypy/dist/pypy: objspace/std translator/goal

antocuni at codespeak.net antocuni at codespeak.net
Wed Dec 13 17:17:49 CET 2006


Author: antocuni
Date: Wed Dec 13 17:17:47 2006
New Revision: 35682

Modified:
   pypy/dist/pypy/objspace/std/multimethod.py
   pypy/dist/pypy/translator/goal/targetpypystandalone.py
Log:
(antocuni, fed by arigo and pedronis)

Select the multimethod installer depending on the typesystem. Added a
sanity check to be sure not to mix the two installers.



Modified: pypy/dist/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/dist/pypy/objspace/std/multimethod.py	(original)
+++ pypy/dist/pypy/objspace/std/multimethod.py	Wed Dec 13 17:17:47 2006
@@ -101,12 +101,15 @@
 class InstallerVersion1:
     """NOT_RPYTHON"""
 
+    instance_counter = 0
+
     mmfunccache = {}
 
     prefix_memo = {}
 
     def __init__(self, multimethod, prefix, list_of_typeorders,
                  baked_perform_call=True, base_typeorder=None):
+        self.__class__.instance_counter += 1
         self.multimethod = multimethod
         # avoid prefix clashes, user code should supply different prefixes
         # itself for nice names in tracebacks
@@ -602,11 +605,13 @@
 class InstallerVersion2(object):
     """NOT_RPYTHON"""
 
+    instance_counter = 0
     mrdtables = {}
 
     def __init__(self, multimethod, prefix, list_of_typeorders,
                  baked_perform_call=True, base_typeorder=None):
         #print 'InstallerVersion2:', prefix
+        self.__class__.instance_counter += 1
         self.multimethod = multimethod
         self.prefix = prefix
         self.list_of_typeorders = list_of_typeorders

Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py	Wed Dec 13 17:17:47 2006
@@ -2,13 +2,6 @@
 
 import os, sys
 
-# as of revision 27081, multimethod.py uses the InstallerVersion1 by default
-# because it is much faster both to initialize and run on top of CPython.
-# The InstallerVersion2 is optimized for making a translator-friendly
-# structure.  So we patch here...
-from pypy.objspace.std import multimethod
-multimethod.Installer = multimethod.InstallerVersion2
-
 from pypy.objspace.std.objspace import StdObjSpace
 from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
@@ -88,7 +81,21 @@
         return parser
 
     def handle_config(self, config):
-        pass
+        # as of revision 27081, multimethod.py uses the InstallerVersion1 by default
+        # because it is much faster both to initialize and run on top of CPython.
+        # The InstallerVersion2 is optimized for making a translator-friendly
+        # structure for low level backends. However, InstallerVersion1 is still
+        # preferable for high level backends, so we patch here.
+        from pypy.objspace.std import multimethod
+        if config.translation.type_system == 'lltype':
+            assert multimethod.InstallerVersion1.instance_counter == 0,\
+                   'The wrong Installer version has already been instatiated'
+            multimethod.Installer = multimethod.InstallerVersion2
+        else:
+            # don't rely on the default, set again here
+            assert multimethod.InstallerVersion2.instance_counter == 0,\
+                   'The wrong Installer version has already been instatiated'
+            multimethod.Installer = multimethod.InstallerVersion1
 
     def handle_translate_config(self, translateconfig):
         pass



More information about the Pypy-commit mailing list