[pypy-svn] r12693 - in pypy/dist/pypy: annotation interpreter objspace/flow objspace/flow/test translator/test

tismer at codespeak.net tismer at codespeak.net
Sat May 21 00:02:01 CEST 2005


Author: tismer
Date: Sat May 21 00:02:01 2005
New Revision: 12693

Modified:
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/interpreter/eval.py
   pypy/dist/pypy/objspace/flow/specialcase.py
   pypy/dist/pypy/objspace/flow/test/test_objspace.py
   pypy/dist/pypy/translator/test/rpystone.py
Log:
added the option to switch eager
imports on and off.
If it is off, then it is handled via an
entry in builtin and still a little
special-casing in specialcase.py, see that file.

Note that I had to change a line in test_objspace,
because lazy importing

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Sat May 21 00:02:01 2005
@@ -198,6 +198,8 @@
 def time_func():
     return SomeFloat()
 
+def import_func(*args):
+    return SomeObject()
 
 # collect all functions
 import __builtin__
@@ -236,6 +238,9 @@
 BUILTIN_ANALYZERS[time.time] = time_func
 BUILTIN_ANALYZERS[time.clock] = time_func
 
+# import
+BUILTIN_ANALYZERS[__import__] = import_func
+
 # annotation of low-level types
 from pypy.annotation.model import SomePtr
 from pypy.rpython import lltypes

Modified: pypy/dist/pypy/interpreter/eval.py
==============================================================================
--- pypy/dist/pypy/interpreter/eval.py	(original)
+++ pypy/dist/pypy/interpreter/eval.py	Sat May 21 00:02:01 2005
@@ -100,7 +100,7 @@
     def setfastscope(self, scope_w):
         """Abstract. Initialize the fast locals from a list of values,
         where the order is according to self.code.signature()."""
-        raise TypeError, "abstract"        
+        raise TypeError, "abstract"
 
     def fast2locals(self):
         # Copy values from self.fastlocals_w to self.w_locals

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 00:02:01 2005
@@ -9,6 +9,8 @@
 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:
@@ -18,7 +20,12 @@
         # 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"
-    return space.wrap(mod)
+    if EAGER_IMPORTS:
+        return space.wrap(mod)
+    # redirect it, but avoid showing the globals
+    w_glob = Constant({})
+    return space.do_operation('simple_call', Constant(__import__),
+                              w_name, w_glob, w_loc, w_frm)
 
 def sc_operator(space, fn, args):
     args_w, kwds_w = args.unpack()

Modified: pypy/dist/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/test/test_objspace.py	Sat May 21 00:02:01 2005
@@ -379,7 +379,6 @@
     #__________________________________________________________
     
     def specialcases(x):
-        import operator
         operator.lt(x,3)
         operator.le(x,3)
         operator.eq(x,3)

Modified: pypy/dist/pypy/translator/test/rpystone.py
==============================================================================
--- pypy/dist/pypy/translator/test/rpystone.py	(original)
+++ pypy/dist/pypy/translator/test/rpystone.py	Sat May 21 00:02:01 2005
@@ -279,6 +279,8 @@
     sys.exit(100)
 
 def entrypoint(loops=None):
+    import string # just a little test
+    print string.replace("import works", "s", "x")
     if loops is None:
         loops = LOOPS  # initialize early, for slow space
         nargs = len(sys.argv) - 1



More information about the Pypy-commit mailing list