[pypy-svn] r16435 - in pypy/dist/pypy: interpreter interpreter/stablecompiler interpreter/test objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Aug 24 21:43:57 CEST 2005


Author: arigo
Date: Wed Aug 24 21:43:55 2005
New Revision: 16435

Modified:
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/interpreter/stablecompiler/consts.py
   pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
   pypy/dist/pypy/interpreter/stablecompiler/symbols.py
   pypy/dist/pypy/interpreter/test/test_exec.py
   pypy/dist/pypy/objspace/std/typeobject.py
Log:
Temporarily moved away the scope changes of the "stablecompiler".
Crashing example:

   def f(a):
     exec ""
     return a

See CPython's dis.dis(f) to see what it does there...

svn merge -r16434:16433 .
svn merge -r16416:16415 .



Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Wed Aug 24 21:43:55 2005
@@ -442,8 +442,6 @@
         f.space.delitem(f.w_globals, w_varname)
 
     def LOAD_NAME(f, nameindex):
-        assert f.w_locals is not None, (
-               "compiler probably wrongly assumes optimized scopes")
         if f.w_locals is not f.w_globals:
             w_varname = f.getname_w(nameindex)
             try:

Modified: pypy/dist/pypy/interpreter/stablecompiler/consts.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/consts.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/consts.py	Wed Aug 24 21:43:55 2005
@@ -8,7 +8,6 @@
 SC_FREE = 3
 SC_CELL = 4
 SC_UNKNOWN = 5
-SC_DEFAULT = 6
 
 CO_OPTIMIZED = 0x0001
 CO_NEWLOCALS = 0x0002

Modified: pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	Wed Aug 24 21:43:55 2005
@@ -9,7 +9,7 @@
 from pypy.interpreter.stablecompiler import ast, parse, walk, syntax
 from pypy.interpreter.stablecompiler import pyassem, misc, future, symbols
 from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL, \
-    SC_FREE, SC_CELL, SC_DEFAULT
+    SC_FREE, SC_CELL
 from pypy.interpreter.stablecompiler.consts import CO_VARARGS, CO_VARKEYWORDS, \
     CO_NEWLOCALS, CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION
 from pypy.interpreter.stablecompiler.pyassem import TupleArg
@@ -280,14 +280,12 @@
             else:
                 self.emit(prefix + '_FAST', name)
         elif scope == SC_GLOBAL:
-            self.emit(prefix + '_GLOBAL', name)
+            if not self.optimized:
+                self.emit(prefix + '_NAME', name)
+            else:
+                self.emit(prefix + '_GLOBAL', name)
         elif scope == SC_FREE or scope == SC_CELL:
             self.emit(prefix + '_DEREF', name)
-        elif scope == SC_DEFAULT: 
-            if self.optimized:
-                self.emit(prefix + '_GLOBAL', name)
-            else:
-                self.emit(prefix + '_NAME', name)
         else:
             raise RuntimeError, "unsupported scope for var %s: %d" % \
                   (name, scope)
@@ -1290,7 +1288,7 @@
 
         args, hasTupleArg = generateArgList(func.argnames)
         self.graph = pyassem.PyFlowGraph(name, func.filename, args,
-                                         self.optimized)
+                                         optimized=1)
         self.isLambda = isLambda
         self.super_init()
 
@@ -1346,7 +1344,6 @@
     def __init__(self, func, scopes, isLambda, class_name, mod):
         self.scopes = scopes
         self.scope = scopes[func]
-        self.optimized = self.scope.optimized
         self.__super_init(func, scopes, isLambda, class_name, mod)
         self.graph.setFreeVars(self.scope.get_free_vars())
         self.graph.setCellVars(self.scope.get_cell_vars())

Modified: pypy/dist/pypy/interpreter/stablecompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/symbols.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/symbols.py	Wed Aug 24 21:43:55 2005
@@ -2,7 +2,7 @@
 
 from pypy.interpreter.stablecompiler import ast
 from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL, \
-    SC_FREE, SC_CELL, SC_UNKNOWN, SC_DEFAULT
+    SC_FREE, SC_CELL, SC_UNKNOWN
 from pypy.interpreter.stablecompiler.misc import mangle
 import types
 
@@ -12,7 +12,6 @@
 MANGLE_LEN = 256
 
 class Scope:
-    optimized = False
     # XXX how much information do I need about each name?
     def __init__(self, name, module, klass=None):
         self.name = name
@@ -102,7 +101,7 @@
         if self.nested:
             return SC_UNKNOWN
         else:
-            return SC_DEFAULT
+            return SC_GLOBAL
 
     def get_free_vars(self):
         if not self.nested:
@@ -135,8 +134,7 @@
         Be careful to stop if a child does not think the name is
         free.
         """
-        if name not in self.defs: 
-            self.globals[name] = 1
+        self.globals[name] = 1
         if self.frees.has_key(name):
             del self.frees[name]
         for child in self.children:
@@ -180,7 +178,6 @@
         self.__super_init("global", self)
 
 class FunctionScope(Scope):
-    optimized = True
     pass
 
 class GenExprScope(Scope):
@@ -241,12 +238,6 @@
         self.visit(node.code, scope)
         self.handle_free_vars(scope, parent)
 
-    def visitExec(self, node, parent): 
-        if not (node.globals or node.locals):
-            parent.optimized = 0   # bare exec statement
-        for child in node.getChildNodes():
-            self.visit(child, parent)
-    
     def visitGenExpr(self, node, parent):
         scope = GenExprScope(self.module, self.klass);
         if parent.nested or isinstance(parent, FunctionScope) \
@@ -341,7 +332,6 @@
     def visitFrom(self, node, scope):
         for name, asname in node.names:
             if name == "*":
-                scope.optimized = False
                 continue
             scope.add_def(asname or name)
 

Modified: pypy/dist/pypy/interpreter/test/test_exec.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_exec.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_exec.py	Wed Aug 24 21:43:55 2005
@@ -78,47 +78,6 @@
     def test_global_stmt(self):
         g = {}
         l = {}
-        co = compile("global a; a=5", '', 'exec')
-        #import dis
-        #dis.dis(co)
-        exec co in g, l
+        exec "global a; a=5" in g, l
         assert l == {}
         assert g['a'] == 5
-
-    def test_specialcase_free_load(self):
-        exec """if 1:
-            def f():
-                exec 'a=3'
-                return a
-            x = f()
-        """
-        assert x == 3
-
-    def test_specialcase_free_load2(self):
-        exec """if 1:
-            def f():
-                a = 2
-                exec 'a=3'
-                return a
-            x = f()
-        """
-        assert x == 3
-
-    def test_nested_names_are_not_confused(self):
-        def get_nested_class():
-            method_and_var = "var"
-            class Test:
-                def method_and_var(self):
-                    return "method"
-                def test(self):
-                    return method_and_var
-                def actual_global(self):
-                    return str("global")
-                def str(self):
-                    return str(self)
-            return Test()
-        t = get_nested_class()
-        assert t.actual_global() == "global" 
-        assert t.test() == 'var'
-        assert t.method_and_var() == 'method'
-

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Wed Aug 24 21:43:55 2005
@@ -52,6 +52,10 @@
         w_self.nslots = 0
         w_self.w_bestbase = None
 
+        # make sure there is a __doc__ in dict_w
+        if '__doc__' not in dict_w:
+            dict_w['__doc__'] = space.w_None
+
         if overridetypedef is not None:
             w_self.instancetypedef = overridetypedef
             w_self.hasdict = overridetypedef.hasdict



More information about the Pypy-commit mailing list