diff options
author | Barry Warsaw <barry@python.org> | 2001-12-21 20:04:22 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-12-21 20:04:22 (GMT) |
commit | 52acb49298fd0aee8a2a2a352f0b2ab039649bde (patch) | |
tree | 8494a3378452f85b4b71a0e02bc6c63cc21f8bec /Lib | |
parent | 87fa3aa12cbb24c89cfb13c16d04f46a2dd9a9e1 (diff) | |
download | cpython-52acb49298fd0aee8a2a2a352f0b2ab039649bde.zip cpython-52acb49298fd0aee8a2a2a352f0b2ab039649bde.tar.gz cpython-52acb49298fd0aee8a2a2a352f0b2ab039649bde.tar.bz2 |
Merge of the release22 branch changes back into the trunk.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/compiler/ast.py | 15 | ||||
-rw-r--r-- | Lib/compiler/pycodegen.py | 12 | ||||
-rw-r--r-- | Lib/compiler/symbols.py | 2 | ||||
-rw-r--r-- | Lib/compiler/transformer.py | 2 | ||||
-rw-r--r-- | Lib/test/test_cpickle.py | 7 |
5 files changed, 34 insertions, 4 deletions
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py index 23c463b..680afee 100644 --- a/Lib/compiler/ast.py +++ b/Lib/compiler/ast.py @@ -282,6 +282,21 @@ class Module(Node): def __repr__(self): return "Module(%s, %s)" % (repr(self.doc), repr(self.node)) +class Expression(Node): + # Expression is an artifical node class to support "eval" + nodes["expression"] = "Expression" + def __init__(self, node): + self.node = node + + def getChildren(self): + return self.node, + + def getChildNodes(self): + return self.node, + + def __repr__(self): + return "Expression(%s)" % (repr(self.node)) + class UnaryAdd(Node): nodes["unaryadd"] = "UnaryAdd" def __init__(self, expr): diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index f526ae1..4194d27 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -34,6 +34,7 @@ EXCEPT = 2 TRY_FINALLY = 3 END_FINALLY = 4 +# XXX this doesn't seem to be used class BlockStack(misc.Stack): __super_init = misc.Stack.__init__ @@ -351,6 +352,13 @@ class CodeGenerator: self.emit('LOAD_CONST', None) self.emit('RETURN_VALUE') + def visitExpression(self, node): + self.set_lineno(node) + self.scopes = self.parseSymbols(node) + self.scope = self.scopes[node] + self.visit(node.node) + self.emit('RETURN_VALUE') + def visitFunction(self, node): self._visitFuncOrLambda(node, isLambda=0) if node.doc: @@ -1158,9 +1166,7 @@ class ExpressionCodeGenerator(NestedScopeMixin, CodeGenerator): def __init__(self, tree): self.graph = pyassem.PyFlowGraph("<expression>", tree.filename) self.__super_init() - self.set_lineno(tree) walk(tree, self) - self.emit('RETURN_VALUE') def get_module(self): return self @@ -1181,6 +1187,7 @@ class InteractiveCodeGenerator(NestedScopeMixin, CodeGenerator): def get_module(self): return self + def visitDiscard(self, node): # XXX Discard means it's an expression. Perhaps this is a bad # name. @@ -1299,7 +1306,6 @@ class ClassCodeGenerator(NestedScopeMixin, AbstractClassCode, CodeGenerator): self.__super_init(klass, scopes, module) self.graph.setFreeVars(self.scope.get_free_vars()) self.graph.setCellVars(self.scope.get_cell_vars()) -## self.graph.setFlag(CO_NESTED) def generateArgList(arglist): """Generate an arg list marking TupleArgs""" diff --git a/Lib/compiler/symbols.py b/Lib/compiler/symbols.py index 200341f..cd7bceb 100644 --- a/Lib/compiler/symbols.py +++ b/Lib/compiler/symbols.py @@ -206,6 +206,8 @@ class SymbolVisitor: scope = self.module = self.scopes[node] = ModuleScope() self.visit(node.node, scope) + visitExpression = visitModule + def visitFunction(self, node, parent): parent.add_def(node.name) for n in node.defaults: diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index 9875561..cd36aae 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -172,7 +172,7 @@ class Transformer: def eval_input(self, nodelist): # from the built-in function input() ### is this sufficient? - return self.com_node(nodelist[0]) + return Expression(self.com_node(nodelist[0])) def funcdef(self, nodelist): # funcdef: 'def' NAME parameters ':' suite diff --git a/Lib/test/test_cpickle.py b/Lib/test/test_cpickle.py index dda606f..874735b 100644 --- a/Lib/test/test_cpickle.py +++ b/Lib/test/test_cpickle.py @@ -80,6 +80,13 @@ class cPickleFastPicklerTests(AbstractPickleTests): AbstractPickleTests.test_recursive_multi, self) + def test_nonrecursive_deep(self): + a = [] + for i in range(100): + a = [a] + b = self.loads(self.dumps(a)) + self.assertEqual(a, b) + def test_main(): loader = unittest.TestLoader() suite = unittest.TestSuite() |