[pypy-svn] r12697 - in pypy/dist/pypy: objspace/flow translator
tismer at codespeak.net
tismer at codespeak.net
Sat May 21 05:20:23 CEST 2005
Author: tismer
Date: Sat May 21 05:20:22 2005
New Revision: 12697
Modified:
pypy/dist/pypy/objspace/flow/specialcase.py
pypy/dist/pypy/translator/geninterplevel.py
Log:
made the decision of whether to do imports immediately
configurable. Special-casing still applies, since
we don't want to expose our globals during an import.
I had a very funny side-effect, after the last panic-checkin.
Somehow, a reference to _formatting is kept around, even
after we used _formatting globally.
Changed geninterp in a way that it checks whether a module
can be imported. If not, pypy/lib is temporarily added
to sys.path during the import.
Anyway, I guess our deliverable suffers from this problem
and it will crash every time people are running code twice,
requiring the _formatting module. The cached version
will fail to resolve the import. :-(
Modified: pypy/dist/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/specialcase.py (original)
+++ pypy/dist/pypy/objspace/flow/specialcase.py Sat May 21 05:20:22 2005
@@ -9,20 +9,18 @@
from pypy.tool.cache import Cache
from pypy.tool.sourcetools import NiceCompile, compile2
-EAGER_IMPORTS = True
-
def sc_import(space, fn, args):
w_name, w_glob, w_loc, w_frm = args.fixedunpack(4)
try:
- mod = __import__(space.unwrap(w_name), space.unwrap(w_glob),
- space.unwrap(w_loc), space.unwrap(w_frm))
+ name, glob, loc, frm = (space.unwrap(w_name), space.unwrap(w_glob),
+ space.unwrap(w_loc), space.unwrap(w_frm))
except UnwrapException:
# import * in a function gives us the locals as Variable
# we forbid it as a SyntaxError
raise SyntaxError, "RPython: import * is not allowed in functions"
- if EAGER_IMPORTS:
- return space.wrap(mod)
- # redirect it, but avoid showing the globals
+ if space.do_imports_immediately:
+ return space.wrap(__import__(name, glob, loc, frm))
+ # redirect it, but avoid exposing the globals
w_glob = Constant({})
return space.do_operation('simple_call', Constant(__import__),
w_name, w_glob, w_loc, w_frm)
@@ -86,8 +84,7 @@
# fn = pyframe.normalize_exception.get_function(space)
# this is now routed through the objspace, directly.
# space.specialcases[fn] = sc_normalize_exception
- if space.do_imports_immediately:
- space.specialcases[__import__] = sc_import
+ space.specialcases[__import__] = sc_import
# redirect ApplevelClass for print et al.
space.specialcases[ApplevelClass] = sc_applevel
# turn calls to built-in functions to the corresponding operation,
Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py (original)
+++ pypy/dist/pypy/translator/geninterplevel.py Sat May 21 05:20:22 2005
@@ -77,7 +77,7 @@
import pypy # __path__
import py.path
-GI_VERSION = '1.0.9' # bump this for substantial changes
+GI_VERSION = '1.1.0' # bump this for substantial changes
# ____________________________________________________________
def eval_helper(self, typename, expr):
@@ -406,8 +406,26 @@
value.__file__.endswith('.py') or
value.__file__.endswith('.pyo')) :
return bltinmod_helper(self, value)
+ # we might have createda reference to a module
+ # that is non-standard.
+ # check whether we can import
+ try:
+ import value
+ need_extra_path = False
+ except ImportError:
+ need_extra_path = True
name = self.uniquename('mod_%s' % value.__name__)
- self.initcode.append1('import %s as _tmp' % value.__name__)
+ if need_extra_path:
+ self.initcode.append1('import pypy')
+ self.initcode.append1('import sys')
+ self.initcode.append1('import os')
+ self.initcode.append1('libdir = os.path.join(pypy.__path__[0], "lib")\n'
+ 'hold = sys.path[:]\n'
+ 'sys.path.insert(0, libdir)\n'
+ 'import %s as _tmp\n'
+ 'sys.path[:] = hold\n' % value.__name__)
+ else:
+ self.initcode.append1('import %s as _tmp' % value.__name__)
self.initcode.append1('%s = space.wrap(_tmp)' % (name))
return name
@@ -1285,7 +1303,7 @@
pass
def translate_as_module(sourcetext, filename=None, modname="app2interpexec",
- tmpname=None):
+ do_imports_immediately=False, tmpname=None):
""" compile sourcetext as a module, translating to interp level.
The result is the init function that creates the wrapped module dict,
together with the generated source text.
@@ -1320,7 +1338,7 @@
entrypoint = dic
t = Translator(None, verbose=False, simplifying=needed_passes,
- do_imports_immediately=False,
+ do_imports_immediately=do_imports_immediately,
builtins_can_raise_exceptions=True)
gen = GenRpy(t, entrypoint, modname, dic)
if tmpname:
More information about the Pypy-commit
mailing list