[pypy-svn] r73527 - in pypy/branch/decouple-host-opcodes/pypy: interpreter interpreter/test tool/pytest

fijal at codespeak.net fijal at codespeak.net
Wed Apr 7 23:50:51 CEST 2010


Author: fijal
Date: Wed Apr  7 23:50:49 2010
New Revision: 73527

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_appinterp.py
   pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_code.py
   pypy/branch/decouple-host-opcodes/pypy/tool/pytest/appsupport.py
Log:
Try slightly harder to compile our own code with our own compiler. Fail at
geninterp so far


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 23:50:49 2010
@@ -956,7 +956,8 @@
             filename = '?'
         from pypy.interpreter.pycode import PyCode
         if isinstance(statement, str):
-            statement = py.code.Source(statement).compile()
+            compiler = self.createcompiler()
+            statement = compiler.compile(statement, filename, 'exec', 0)
         if isinstance(statement, types.CodeType):
             statement = PyCode._from_code(self, statement,
                                           hidden_applevel=hidden_applevel)
@@ -1177,7 +1178,7 @@
         assert source.startswith('('), "incorrect header in:\n%s" % (source,)
         source = py.code.Source("def anonymous%s\n" % source)
         w_glob = space.newdict()
-        space.exec_(source.compile(), w_glob, w_glob)
+        space.exec_(str(source), w_glob, w_glob)
         return space.getitem(w_glob, space.wrap('anonymous'))
 
 class DummyLock(object):

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 23:50:49 2010
@@ -812,6 +812,9 @@
 # and now for something completely different ... 
 #
 
+class MyStr(str):
+    pass
+
 class ApplevelClass:
     """NOT_RPYTHON
     A container for app-level source code that should be executed
@@ -822,6 +825,11 @@
     hidden_applevel = True
 
     def __init__(self, source, filename=None, modname='__builtin__'):
+        # HAAACK (but a good one)
+        if filename is None:
+            f = sys._getframe(2)
+            filename = MyStr('<%s:%d>' % (f.f_code.co_filename, f.f_lineno))
+            filename.__source__ = py.code.Source(source)
         self.filename = filename
         self.source = str(py.code.Source(source).deindent())
         self.modname = modname

Modified: pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_appinterp.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/interpreter/test/test_appinterp.py	Wed Apr  7 23:50:49 2010
@@ -1,6 +1,7 @@
 
 import py
 from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp, applevelinterp_temp
+from pypy.interpreter.error import OperationError
 
 def test_execwith_novars(space): 
     val = space.appexec([], """ 
@@ -18,11 +19,11 @@
     assert space.eq_w(val, space.wrap(42))
 
 def test_execwith_compile_error(space): 
-    excinfo = py.test.raises(SyntaxError, space.appexec, [], """
+    excinfo = py.test.raises(OperationError, space.appexec, [], """
     (): 
         y y 
     """)
-    assert str(excinfo.value).find('y y') != -1 
+    assert str(excinfo.value.errorstr(space)).find('y y') != -1 
 
 def test_simple_applevel(space):
     app = appdef("""app(x,y): 

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 23:50:49 2010
@@ -10,7 +10,7 @@
         if py.test.config.option.runappdirect:
             filename = __file__
         else:
-            filename = baseobjspace.__file__
+            filename = gateway.__file__
 
         if filename[-3:] != '.py':
             filename = filename[:-1]

Modified: pypy/branch/decouple-host-opcodes/pypy/tool/pytest/appsupport.py
==============================================================================
--- pypy/branch/decouple-host-opcodes/pypy/tool/pytest/appsupport.py	(original)
+++ pypy/branch/decouple-host-opcodes/pypy/tool/pytest/appsupport.py	Wed Apr  7 23:50:49 2010
@@ -87,7 +87,7 @@
         if debug_excs:
             self._excinfo = debug_excs[0]
 
-    def exconly(self, tryshort=True): 
+    def exconly(self, tryshort=True):
         return '(application-level) ' + self.operr.errorstr(self.space)
 
     def errisinstance(self, exc): 



More information about the Pypy-commit mailing list