1.1 --- a/simplified.py Sun Jul 23 23:56:11 2006 +0200
1.2 +++ b/simplified.py Sun Jul 23 23:57:13 2006 +0200
1.3 @@ -23,6 +23,29 @@
1.4
1.5 from compiler.visitor import ASTVisitor
1.6
1.7 +# Elementary visitor support.
1.8 +
1.9 +class Visitor(ASTVisitor):
1.10 +
1.11 + "A visitor base class."
1.12 +
1.13 + def __init__(self):
1.14 + ASTVisitor.__init__(self)
1.15 +
1.16 + def default(self, node, *args):
1.17 + raise ValueError, node.__class__
1.18 +
1.19 + def dispatch(self, node, *args):
1.20 + return ASTVisitor.dispatch(self, node, *args)
1.21 +
1.22 + def dispatches(self, nodes, *args):
1.23 + results = []
1.24 + for node in nodes:
1.25 + results.append(self.dispatch(node, *args))
1.26 + return results
1.27 +
1.28 +# Simplified program nodes.
1.29 +
1.30 class Node:
1.31
1.32 """
1.33 @@ -87,6 +110,12 @@
1.34 if hasattr(self, "params"):
1.35 for name, default in self.params:
1.36 self._pprint(indent + 2, "( ", "%s -> %s" % (name, default))
1.37 + if hasattr(self, "star") and self.star:
1.38 + name, default = self.star
1.39 + self._pprint(indent + 2, "( ", "%s -> %s" % (name, default))
1.40 + if hasattr(self, "dstar") and self.dstar:
1.41 + name, default = self.dstar
1.42 + self._pprint(indent + 2, "( ", "%s -> %s" % (name, default))
1.43 if getattr(self, "acquire_locals", 0):
1.44 self._pprint(indent + 2, "( ", "acquiring locals")
1.45 if getattr(self, "structure", 0):
1.46 @@ -111,10 +140,14 @@
1.47 if hasattr(self, "args"):
1.48 for arg in self.args:
1.49 arg.pprint(indent + 2, "( ")
1.50 + if hasattr(self, "star") and self.star:
1.51 + self.star.pprint(indent + 2, "( ")
1.52 + if hasattr(self, "dstar") and self.dstar:
1.53 + self.dstar.pprint(indent + 2, "( ")
1.54
1.55 class Module(Node): "A Python module."
1.56 class Subprogram(Node): "A subprogram: functions, methods and loops."
1.57 -class Class(Node): "A Python class."
1.58 +class Constant(Node): "A constant."
1.59 class Pass(Node): "A placeholder node corresponding to pass."
1.60 class Invoke(Node): "A function, method or loop invocation."
1.61 class Return(Node): "Return an evaluated expression."
1.62 @@ -126,7 +159,6 @@
1.63 class LoadName(Node): "Load a named object."
1.64 class LoadGlobal(Node): "Load a named global object."
1.65 class LoadAttr(Node): "Load an object attribute."
1.66 -class LoadConst(Node): "Load a constant."
1.67 class LoadRef(Node): "Load a reference, typically a subprogram."
1.68 class LoadExc(Node): "Load a handled exception."
1.69 class StoreTemp(Node): "Store a temporary value."
1.70 @@ -138,24 +170,6 @@
1.71 class Try(Node): "A try...except...else...finally grouping node."
1.72 class Raise(Node): "An exception raising node."
1.73 class Not(Node): "A negation of an expression."
1.74 -
1.75 -class Visitor(ASTVisitor):
1.76 -
1.77 - "A visitor base class."
1.78 -
1.79 - def __init__(self):
1.80 - ASTVisitor.__init__(self)
1.81 -
1.82 - def default(self, node, *args):
1.83 - raise ValueError, node.__class__
1.84 -
1.85 - def dispatch(self, node, *args):
1.86 - return ASTVisitor.dispatch(self, node, *args)
1.87 -
1.88 - def dispatches(self, nodes, *args):
1.89 - results = []
1.90 - for node in nodes:
1.91 - results.append(self.dispatch(node, *args))
1.92 - return results
1.93 +class Class(Node): "A Python class."
1.94
1.95 # vim: tabstop=4 expandtab shiftwidth=4