[pypy-svn] r73517 - in pypy/branch/decouple-host-opcodes/pypy: interpreter interpreter/test translator

fijal at codespeak.net fijal at codespeak.net
Wed Apr 7 21:02:40 CEST 2010


Author: fijal
Date: Wed Apr  7 21:02:24 2010
New Revision: 73517

Modified:
   pypy/branch/decouple-host-opcodes/pypy/interpreter/baseobjspace.py
   pypy/branch/decouple-host-opcodes/pypy/interpreter/gateway.py
   pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_code.py
   pypy/branch/decouple-host-opcodes/pypy/translator/geninterplevel.py
Log:
Hack around so we don't actually create cpython objects from source, but
instead we pass source around and compile it with our own compiler.

Does not really solve the issue of calling "for internal debugging" space.exec_
for the translation


Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/baseobjspace.py	Wed Apr  7 21:02:24 2010
@@ -13,7 +13,7 @@
 from pypy.rlib.timer import DummyTimer, Timer
 from pypy.rlib.rarithmetic import r_uint
 from pypy.rlib import jit
-import os, sys
+import os, sys, py
 
 __all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
 
@@ -948,12 +948,15 @@
             raise TypeError, 'space.eval(): expected a string, code or PyCode object'
         return expression.exec_code(self, w_globals, w_locals)
 
-    def exec_(self, statement, w_globals, w_locals, hidden_applevel=False):
+    def exec_(self, statement, w_globals, w_locals, hidden_applevel=False,
+              filename=None):
         "NOT_RPYTHON: For internal debugging."
         import types
+        if filename is None:
+            filename = '?'
         from pypy.interpreter.pycode import PyCode
         if isinstance(statement, str):
-            statement = compile(statement, '?', 'exec')
+            statement = py.code.Source(statement).compile()
         if isinstance(statement, types.CodeType):
             statement = PyCode._from_code(self, statement,
                                           hidden_applevel=hidden_applevel)

Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/gateway.py	Wed Apr  7 21:02:24 2010
@@ -821,12 +821,9 @@
 
     hidden_applevel = True
 
-    def __init__(self, source, filename = None, modname = '__builtin__'):
+    def __init__(self, source, filename=None, modname='__builtin__'):
         self.filename = filename
-        if self.filename is None:
-            self.code = py.code.Source(source).compile()
-        else:
-            self.code = NiceCompile(self.filename)(source)
+        self.source = str(py.code.Source(source).deindent())
         self.modname = modname
         # look at the first three lines for a NOT_RPYTHON tag
         first = "\n".join(source.split("\n", 3)[:3])
@@ -910,8 +907,9 @@
     from pypy.interpreter.pycode import PyCode
     w_glob = space.newdict(module=True)
     space.setitem(w_glob, space.wrap('__name__'), space.wrap(self.modname))
-    space.exec_(self.code, w_glob, w_glob,
-                hidden_applevel=self.hidden_applevel)
+    space.exec_(self.source, w_glob, w_glob,
+                hidden_applevel=self.hidden_applevel,
+                filename=self.filename)
     return w_glob
 
 # __________ geninterplevel version __________
@@ -931,7 +929,7 @@
         from pypy.translator.geninterplevel import translate_as_module
         import marshal
         scramble = md5(cls.seed)
-        scramble.update(marshal.dumps(self.code))
+        scramble.update(marshal.dumps(self.source))
         key = scramble.hexdigest()
         initfunc = cls.known_code.get(key)
         if not initfunc:
@@ -952,7 +950,7 @@
         if not initfunc:
             # build it and put it into a file
             initfunc, newsrc = translate_as_module(
-                self.code, self.filename, self.modname)
+                self.source, self.filename, self.modname)
             fname = cls.cache_path.join(name+".py").strpath
             f = file(get_tmp_file_name(fname), "w")
             print >> f, """\

Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_code.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_code.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_code.py	Wed Apr  7 21:02:24 2010
@@ -1,5 +1,6 @@
 from pypy.conftest import gettestobjspace
 from pypy.interpreter import gateway
+from pypy.interpreter import baseobjspace
 import py
 
 class AppTestCodeIntrospection:
@@ -9,7 +10,7 @@
         if py.test.config.option.runappdirect:
             filename = __file__
         else:
-            filename = gateway.__file__
+            filename = baseobjspace.__file__
 
         if filename[-3:] != '.py':
             filename = filename[:-1]

Modified: pypy/branch/decouple-host-opcodes/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/translator/geninterplevel.py	Wed Apr  7 21:02:24 2010
@@ -71,7 +71,7 @@
 log = py.log.Producer("geninterp")
 py.log.setconsumer("geninterp", ansi_log)
 
-GI_VERSION = '1.2.7'  # bump this for substantial changes
+GI_VERSION = '1.2.8'  # bump this for substantial changes
 # ____________________________________________________________
 
 try:
@@ -1475,10 +1475,7 @@
     """
     # create something like a module
     if type(sourcetext) is str:
-        if filename is None: 
-            code = py.code.Source(sourcetext).compile()
-        else: 
-            code = NiceCompile(filename)(sourcetext)
+        code = py.code.Source(sourcetext).compile()
     else:
         # assume we got an already compiled source
         code = sourcetext



More information about the Pypy-commit mailing list