[pypy-svn] r16294 - in pypy/dist/pypy: fakecompiler interpreter lib/_stablecompiler

tismer at codespeak.net tismer at codespeak.net
Tue Aug 23 17:32:41 CEST 2005


Author: tismer
Date: Tue Aug 23 17:32:39 2005
New Revision: 16294

Modified:
   pypy/dist/pypy/fakecompiler/fakecompiler.py
   pypy/dist/pypy/interpreter/pycompiler.py
   pypy/dist/pypy/lib/_stablecompiler/apphook.py
Log:
had to change the way to build the compilers.
Everything is done at initialization time.
When compiling, we check which compiler to use.

Modified: pypy/dist/pypy/fakecompiler/fakecompiler.py
==============================================================================
--- pypy/dist/pypy/fakecompiler/fakecompiler.py	(original)
+++ pypy/dist/pypy/fakecompiler/fakecompiler.py	Tue Aug 23 17:32:39 2005
@@ -2,17 +2,6 @@
 
 DUMPFILE = 'this_is_the_marshal_file'
 
-def fakeapplevelcompile(tuples, filename, mode):
-    done = False
-    data = marshal.dumps( (tuples, filename, mode, done) )
-    file(DUMPFILE, "wb").write(data)
-    os.system('%s fakecompiler.py' % get_python())
-    data = file(DUMPFILE, "rb").read()
-    code, filename, mode, done = marshal.loads(data)
-    if not done:
-        raise ValueError, "could not fake compile!"
-    return code
-
 def reallycompile(tuples, filename, mode):
     return parser.compileast(parser.tuple2ast(tuples), filename)
 

Modified: pypy/dist/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycompiler.py	(original)
+++ pypy/dist/pypy/interpreter/pycompiler.py	Tue Aug 23 17:32:39 2005
@@ -244,25 +244,23 @@
         debug_print(" done")
 
     def _load_compilers(self):
-        compile1 = self.space.appexec([], r'''():
+        self.w_compileapp = self.space.appexec([], r'''():
             from _stablecompiler import apphook
             return apphook.applevelcompile
         ''')
-        compile2 = self.w_applevelcompile = self.space.appexec([], r'''():
-            import os
+        self.w_compilefake = self.space.appexec([], r'''():
             from _stablecompiler import apphook
-            if os.path.exists('fakecompiler.py'):
-                print "faking compiler, because fakecompiler.py is in the current dir"
-                import fakecompiler
-                return fakecompiler.fakeapplevelcompile
-            else:
-                return apphook.applevelcompile
+            return apphook.fakeapplevelcompile
         ''')
-        self.applevelcompile_w = {
-            'single': compile1,
-            'eval': compile2,
-            'exec': compile2,
-            }
+
+    def _get_compiler(self, mode):
+        from pypy.interpreter.error import debug_print
+        import os
+        if os.path.exists('fakecompiler.py') and mode != 'single':
+            debug_print("faking compiler, because fakecompiler.py is in the current dir")
+            return self.w_compilefake
+        else:
+            return self.w_compileapp
 
     def compile_parse_result(self, parse_result, filename, mode):
         space = self.space
@@ -282,7 +280,7 @@
                 w_nested_tuples,
                 space.wrap(source_encoding)])
 
-        w_code = space.call_function(self.applevelcompile_w[mode],
+        w_code = space.call_function(self._get_compiler(mode),
                                      w_nested_tuples,
                                      space.wrap(filename),
                                      space.wrap(mode))

Modified: pypy/dist/pypy/lib/_stablecompiler/apphook.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/apphook.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/apphook.py	Tue Aug 23 17:32:39 2005
@@ -20,3 +20,20 @@
     else: # mode == 'eval':
         codegenerator = ExpressionCodeGenerator(tree)
     return codegenerator.getCode()
+
+# temporary fake stuff, to allow to use the translated
+# PyPy for testing.
+
+DUMPFILE = 'this_is_the_marshal_file'
+
+def fakeapplevelcompile(tuples, filename, mode):
+    import os, marshal
+    done = False
+    data = marshal.dumps( (tuples, filename, mode, done) )
+    file(DUMPFILE, "wb").write(data)
+    os.system('%s fakecompiler.py' % get_python())
+    data = file(DUMPFILE, "rb").read()
+    code, filename, mode, done = marshal.loads(data)
+    if not done:
+        raise ValueError, "could not fake compile!"
+    return code



More information about the Pypy-commit mailing list