Kaydet (Commit) 46cc7c0f authored tarafından Thomas Wouters's avatar Thomas Wouters

Bring Tools/compiler almost up to date. Specifically:

- fix tab space issues (SF patch #101167 by Neil Schemenauer)
- fix co_flags for classes to include CO_NEWLOCALS (SF patch #101145 by Neil)
- fix for merger of UNPACK_LIST and UNPACK_TUPLE into UNPACK_SEQUENCE,
  (SF patch #101168 by, well, Neil :)
- Adjust bytecode MAGIC to current bytecode.

TODO: teach compile.py about list comprehensions.
üst 81f7eb6c
This diff is collapsed.
This diff is collapsed.
...@@ -38,7 +38,7 @@ class ASTVisitor: ...@@ -38,7 +38,7 @@ class ASTVisitor:
def __init__(self): def __init__(self):
self.node = None self.node = None
self._cache = {} self._cache = {}
def preorder(self, tree, visitor): def preorder(self, tree, visitor):
"""Do preorder walk of tree using visitor""" """Do preorder walk of tree using visitor"""
...@@ -47,7 +47,7 @@ class ASTVisitor: ...@@ -47,7 +47,7 @@ class ASTVisitor:
self._preorder(tree) self._preorder(tree)
def _preorder(self, node, *args): def _preorder(self, node, *args):
return apply(self.dispatch, (node,) + args) return apply(self.dispatch, (node,) + args)
def default(self, node, *args): def default(self, node, *args):
for child in node.getChildren(): for child in node.getChildren():
...@@ -56,18 +56,18 @@ class ASTVisitor: ...@@ -56,18 +56,18 @@ class ASTVisitor:
def dispatch(self, node, *args): def dispatch(self, node, *args):
self.node = node self.node = node
meth = self._cache.get(node.__class__, None) meth = self._cache.get(node.__class__, None)
className = node.__class__.__name__ className = node.__class__.__name__
if meth is None: if meth is None:
meth = getattr(self.visitor, 'visit' + className, self.default) meth = getattr(self.visitor, 'visit' + className, self.default)
self._cache[node.__class__] = meth self._cache[node.__class__] = meth
if self.VERBOSE > 0: if self.VERBOSE > 0:
if self.VERBOSE == 1: if self.VERBOSE == 1:
if meth == 0: if meth == 0:
print "dispatch", className print "dispatch", className
else: else:
print "dispatch", className, (meth and meth.__name__ or '') print "dispatch", className, (meth and meth.__name__ or '')
return apply(meth, (node,) + args) return apply(meth, (node,) + args)
class ExampleASTVisitor(ASTVisitor): class ExampleASTVisitor(ASTVisitor):
"""Prints examples of the nodes that aren't visited """Prints examples of the nodes that aren't visited
...@@ -80,11 +80,11 @@ class ExampleASTVisitor(ASTVisitor): ...@@ -80,11 +80,11 @@ class ExampleASTVisitor(ASTVisitor):
def dispatch(self, node, *args): def dispatch(self, node, *args):
self.node = node self.node = node
meth = self._cache.get(node.__class__, None) meth = self._cache.get(node.__class__, None)
className = node.__class__.__name__ className = node.__class__.__name__
if meth is None: if meth is None:
meth = getattr(self.visitor, 'visit' + className, 0) meth = getattr(self.visitor, 'visit' + className, 0)
self._cache[node.__class__] = meth self._cache[node.__class__] = meth
if self.VERBOSE > 1: if self.VERBOSE > 1:
print "dispatch", className, (meth and meth.__name__ or '') print "dispatch", className, (meth and meth.__name__ or '')
if meth: if meth:
...@@ -92,15 +92,15 @@ class ExampleASTVisitor(ASTVisitor): ...@@ -92,15 +92,15 @@ class ExampleASTVisitor(ASTVisitor):
elif self.VERBOSE > 0: elif self.VERBOSE > 0:
klass = node.__class__ klass = node.__class__
if not self.examples.has_key(klass): if not self.examples.has_key(klass):
self.examples[klass] = klass self.examples[klass] = klass
print print
print self.visitor print self.visitor
print klass print klass
for attr in dir(node): for attr in dir(node):
if attr[0] != '_': if attr[0] != '_':
print "\t", "%-12.12s" % attr, getattr(node, attr) print "\t", "%-12.12s" % attr, getattr(node, attr)
print print
return apply(self.default, (node,) + args) return apply(self.default, (node,) + args)
_walker = ASTVisitor _walker = ASTVisitor
def walk(tree, visitor, verbose=None): def walk(tree, visitor, verbose=None):
......
...@@ -38,7 +38,7 @@ class ASTVisitor: ...@@ -38,7 +38,7 @@ class ASTVisitor:
def __init__(self): def __init__(self):
self.node = None self.node = None
self._cache = {} self._cache = {}
def preorder(self, tree, visitor): def preorder(self, tree, visitor):
"""Do preorder walk of tree using visitor""" """Do preorder walk of tree using visitor"""
...@@ -47,7 +47,7 @@ class ASTVisitor: ...@@ -47,7 +47,7 @@ class ASTVisitor:
self._preorder(tree) self._preorder(tree)
def _preorder(self, node, *args): def _preorder(self, node, *args):
return apply(self.dispatch, (node,) + args) return apply(self.dispatch, (node,) + args)
def default(self, node, *args): def default(self, node, *args):
for child in node.getChildren(): for child in node.getChildren():
...@@ -56,18 +56,18 @@ class ASTVisitor: ...@@ -56,18 +56,18 @@ class ASTVisitor:
def dispatch(self, node, *args): def dispatch(self, node, *args):
self.node = node self.node = node
meth = self._cache.get(node.__class__, None) meth = self._cache.get(node.__class__, None)
className = node.__class__.__name__ className = node.__class__.__name__
if meth is None: if meth is None:
meth = getattr(self.visitor, 'visit' + className, self.default) meth = getattr(self.visitor, 'visit' + className, self.default)
self._cache[node.__class__] = meth self._cache[node.__class__] = meth
if self.VERBOSE > 0: if self.VERBOSE > 0:
if self.VERBOSE == 1: if self.VERBOSE == 1:
if meth == 0: if meth == 0:
print "dispatch", className print "dispatch", className
else: else:
print "dispatch", className, (meth and meth.__name__ or '') print "dispatch", className, (meth and meth.__name__ or '')
return apply(meth, (node,) + args) return apply(meth, (node,) + args)
class ExampleASTVisitor(ASTVisitor): class ExampleASTVisitor(ASTVisitor):
"""Prints examples of the nodes that aren't visited """Prints examples of the nodes that aren't visited
...@@ -80,11 +80,11 @@ class ExampleASTVisitor(ASTVisitor): ...@@ -80,11 +80,11 @@ class ExampleASTVisitor(ASTVisitor):
def dispatch(self, node, *args): def dispatch(self, node, *args):
self.node = node self.node = node
meth = self._cache.get(node.__class__, None) meth = self._cache.get(node.__class__, None)
className = node.__class__.__name__ className = node.__class__.__name__
if meth is None: if meth is None:
meth = getattr(self.visitor, 'visit' + className, 0) meth = getattr(self.visitor, 'visit' + className, 0)
self._cache[node.__class__] = meth self._cache[node.__class__] = meth
if self.VERBOSE > 1: if self.VERBOSE > 1:
print "dispatch", className, (meth and meth.__name__ or '') print "dispatch", className, (meth and meth.__name__ or '')
if meth: if meth:
...@@ -92,15 +92,15 @@ class ExampleASTVisitor(ASTVisitor): ...@@ -92,15 +92,15 @@ class ExampleASTVisitor(ASTVisitor):
elif self.VERBOSE > 0: elif self.VERBOSE > 0:
klass = node.__class__ klass = node.__class__
if not self.examples.has_key(klass): if not self.examples.has_key(klass):
self.examples[klass] = klass self.examples[klass] = klass
print print
print self.visitor print self.visitor
print klass print klass
for attr in dir(node): for attr in dir(node):
if attr[0] != '_': if attr[0] != '_':
print "\t", "%-12.12s" % attr, getattr(node, attr) print "\t", "%-12.12s" % attr, getattr(node, attr)
print print
return apply(self.default, (node,) + args) return apply(self.default, (node,) + args)
_walker = ASTVisitor _walker = ASTVisitor
def walk(tree, visitor, verbose=None): def walk(tree, visitor, verbose=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment