[pypy-svn] r8707 - in pypy/dist/pypy: interpreter module
ac at codespeak.net
ac at codespeak.net
Sat Jan 29 14:12:42 CET 2005
Author: ac
Date: Sat Jan 29 14:12:42 2005
New Revision: 8707
Modified:
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/module/__builtin__interp.py
Log:
Properly inherit effects of future statements into eval(), exec and compile().
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Sat Jan 29 14:12:42 2005
@@ -6,6 +6,11 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter import pytraceback
+import __future__
+compiler_flags = 0
+for fname in __future__.all_feature_names:
+ compiler_flags |= getattr(__future__, fname).compiler_flag
+
class PyFrame(eval.Frame):
"""Represents a frame for a regular Python function
@@ -50,6 +55,9 @@
def getclosure(self):
return None
+ def get_compile_flags(self):
+ return self.code.co_flags & compiler_flags
+
def eval(self, executioncontext):
"Interpreter main loop!"
try:
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Sat Jan 29 14:12:42 2005
@@ -344,7 +344,9 @@
w_locals = f.valuestack.pop()
w_globals = f.valuestack.pop()
w_prog = f.valuestack.pop()
- w_resulttuple = f.prepare_exec(w_prog, w_globals, w_locals)
+ w_compile_flags = f.space.wrap(f.get_compile_flags())
+ w_resulttuple = f.prepare_exec(w_prog, w_globals, w_locals,
+ w_compile_flags)
w_prog, w_globals, w_locals = f.space.unpacktuple(w_resulttuple, 3)
plain = f.space.is_true(f.space.is_(w_locals, f.w_locals))
@@ -355,7 +357,7 @@
if plain:
f.setdictscope(w_locals)
- def app_prepare_exec(f, prog, globals, locals):
+ def app_prepare_exec(f, prog, globals, locals, compile_flags):
"""Manipulate parameters to exec statement to (codeobject, dict, dict).
"""
# XXX INCOMPLETE
@@ -387,14 +389,10 @@
## isinstance(prog, types.FileType)):
raise TypeError("exec: arg 1 must be a string, file, or code object")
## if isinstance(prog, types.FileType):
- ## flags = 0
- ## ## XXX add in parent flag merging
- ## co = compile(prog.read(),prog.name,'exec',flags,1)
+ ## co = compile(prog.read(),prog.name,'exec',comple_flags,1)
## return (co,globals,locals)
else: # prog is a string
- flags = 0
- ## XXX add in parent flag merging
- co = compile(prog,'<string>','exec',flags,1)
+ co = compile(prog,'<string>','exec', compile_flags, 1)
return (co, globals, locals)
def POP_BLOCK(f):
Modified: pypy/dist/pypy/module/__builtin__interp.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__interp.py (original)
+++ pypy/dist/pypy/module/__builtin__interp.py Sat Jan 29 14:12:42 2005
@@ -196,14 +196,21 @@
w_exc = space.call_function(space.w_ImportError, w_failing)
raise OperationError(space.w_ImportError, w_exc)
-
def compile(str_, filename, startstr,
supplied_flags=0, dont_inherit=0):
#print (str_, filename, startstr, supplied_flags, dont_inherit)
# XXX we additionally allow GENERATORS because compiling some builtins
# requires it. doesn't feel quite right to do that here.
+ supplied_flags |= 4096
+ if not dont_inherit:
+ try:
+ frame = _actframe()
+ except IndexError:
+ pass
+ else:
+ supplied_flags |= frame.get_compile_flags()
try:
- c = cpy_builtin.compile(str_, filename, startstr, supplied_flags|4096, dont_inherit)
+ c = cpy_builtin.compile(str_, filename, startstr, supplied_flags, 1)
# It would be nice to propagate all exceptions to app level,
# but here we only propagate the 'usual' ones, until we figure
# out how to do it generically.
More information about the Pypy-commit
mailing list