paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paulb@24 | 4 | Simplify AST structures for easier type propagation and analysis. The code in |
paulb@24 | 5 | this module processes AST trees originating from the compiler module and |
paulb@24 | 6 | produces a result tree consisting of instruction-oriented program nodes. |
paul@0 | 7 | |
paul@0 | 8 | Copyright (C) 2006 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 9 | |
paul@0 | 10 | This software is free software; you can redistribute it and/or |
paul@0 | 11 | modify it under the terms of the GNU General Public License as |
paul@0 | 12 | published by the Free Software Foundation; either version 2 of |
paul@0 | 13 | the License, or (at your option) any later version. |
paul@0 | 14 | |
paul@0 | 15 | This software is distributed in the hope that it will be useful, |
paul@0 | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 18 | GNU General Public License for more details. |
paul@0 | 19 | |
paul@0 | 20 | You should have received a copy of the GNU General Public |
paul@0 | 21 | License along with this library; see the file LICENCE.txt |
paul@0 | 22 | If not, write to the Free Software Foundation, Inc., |
paul@0 | 23 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paul@0 | 24 | """ |
paul@0 | 25 | |
paulb@19 | 26 | from simplified import * |
paul@0 | 27 | import compiler.ast |
paul@0 | 28 | |
paulb@19 | 29 | class Simplifier(Visitor): |
paul@0 | 30 | |
paul@0 | 31 | """ |
paul@0 | 32 | A simplifying visitor for AST nodes. |
paul@0 | 33 | |
paul@5 | 34 | Covered: And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break, |
paulb@13 | 35 | CallFunc, Class, Compare, Const, Continue, Dict, Discard, For, |
paulb@13 | 36 | From, Function, Getattr, Global, If, Import, Invert, Keyword, |
paulb@13 | 37 | Lambda, List, Module, Name, Not, Or, Pass, Raise, Return, Slice, |
paulb@13 | 38 | Stmt, Subscript, TryExcept, TryFinally, Tuple, While, UnaryAdd, |
paulb@13 | 39 | UnarySub. |
paul@0 | 40 | |
paulb@13 | 41 | Missing: Add, Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div, |
paulb@13 | 42 | Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor, |
paulb@13 | 43 | ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift, Sliceobj, |
paulb@13 | 44 | Sub, Yield. |
paul@0 | 45 | """ |
paul@0 | 46 | |
paul@0 | 47 | def __init__(self): |
paulb@19 | 48 | Visitor.__init__(self) |
paul@1 | 49 | self.result = None # The resulting tree. |
paul@1 | 50 | self.subprograms = [] # Subprograms outside the tree. |
paulb@24 | 51 | self.structures = [] # Structures/classes. |
paulb@24 | 52 | self.constants = {} # Constants. |
paul@1 | 53 | self.current_subprograms = [] # Current subprograms being processed. |
paul@0 | 54 | |
paulb@20 | 55 | def process(self, node): |
paulb@20 | 56 | self.visitor = self |
paulb@20 | 57 | return self.dispatch(node) |
paulb@20 | 58 | |
paulb@6 | 59 | def dispatch_or_none(self, node, *args): |
paulb@6 | 60 | if node is not None: |
paulb@6 | 61 | return self.dispatch(node, *args) |
paulb@6 | 62 | else: |
paulb@6 | 63 | return LoadName(name="None") |
paulb@6 | 64 | |
paul@0 | 65 | # Placeholder or deletion transformations. |
paul@0 | 66 | |
paul@0 | 67 | def visitStmt(self, stmt): |
paul@0 | 68 | return self.dispatches(stmt.nodes) |
paul@0 | 69 | |
paul@0 | 70 | def visitPass(self, pass_): |
paul@0 | 71 | return Pass(pass_) |
paul@0 | 72 | |
paul@0 | 73 | def visitDiscard(self, discard): |
paul@0 | 74 | return self.dispatch(discard.expr) |
paul@0 | 75 | |
paul@0 | 76 | # Relatively trivial transformations. |
paul@0 | 77 | |
paul@0 | 78 | def visitModule(self, module): |
paul@0 | 79 | self.result = Module(module) |
paul@0 | 80 | self.result.code = self.dispatch(module.node) |
paul@0 | 81 | return self.result |
paul@0 | 82 | |
paul@0 | 83 | def visitGetattr(self, getattr): |
paul@0 | 84 | result = LoadAttr(getattr, name=getattr.attrname) |
paul@0 | 85 | result.expr = self.dispatch(getattr.expr) |
paul@0 | 86 | return result |
paul@0 | 87 | |
paul@0 | 88 | def visitKeyword(self, keyword): |
paul@0 | 89 | result = Keyword(keyword, name=keyword.name) |
paul@0 | 90 | result.expr = self.dispatch(keyword.expr) |
paul@0 | 91 | return result |
paul@0 | 92 | |
paul@1 | 93 | def visitGlobal(self, global_): |
paul@1 | 94 | result = Global(global_, names=global_.names) |
paul@1 | 95 | return result |
paul@1 | 96 | |
paul@3 | 97 | def visitImport(self, import_): |
paul@3 | 98 | result = Assign(import_) |
paul@3 | 99 | code = [] |
paul@3 | 100 | for path, alias in import_.names: |
paul@3 | 101 | importer = Import(name=path) |
paul@3 | 102 | top = alias or path.split(".")[0] |
paul@3 | 103 | code.append(StoreName(expr=importer, name=top)) |
paul@3 | 104 | result.code = code |
paul@3 | 105 | return result |
paul@3 | 106 | |
paul@3 | 107 | def visitFrom(self, from_): |
paul@3 | 108 | result = Assign(from_) |
paul@3 | 109 | code = [] |
paul@3 | 110 | code.append(StoreTemp(expr=Import(name=from_.modname))) |
paul@3 | 111 | for name, alias in from_.names: |
paul@3 | 112 | code.append(StoreName(expr=LoadAttr(expr=LoadTemp(), name=name), name=(alias or name))) |
paul@3 | 113 | result.code = code |
paul@3 | 114 | return result |
paul@3 | 115 | |
paul@0 | 116 | def visitName(self, name): |
paul@0 | 117 | result = LoadName(name, name=name.name) |
paul@0 | 118 | return result |
paul@0 | 119 | |
paul@0 | 120 | def visitConst(self, const): |
paulb@24 | 121 | if not self.constants.has_key(const.value): |
paulb@24 | 122 | self.constants[const.value] = Constant(name=repr(const.value), value=const.value) |
paulb@24 | 123 | result = LoadRef(ref=self.constants[const.value]) |
paul@0 | 124 | return result |
paul@0 | 125 | |
paul@0 | 126 | def visitReturn(self, return_): |
paul@0 | 127 | result = Return(return_) |
paul@0 | 128 | result.expr = self.dispatch(return_.value) |
paul@0 | 129 | return result |
paul@0 | 130 | |
paul@0 | 131 | def visitBreak(self, break_): |
paul@0 | 132 | result = Return(break_) |
paul@0 | 133 | return result |
paul@0 | 134 | |
paul@0 | 135 | def visitContinue(self, continue_): |
paulb@7 | 136 | result = Invoke(continue_, same_frame=1, produces_result=0, star=None, dstar=None, args=[]) |
paul@0 | 137 | result.expr = LoadRef(ref=self.current_subprograms[-1]) |
paul@0 | 138 | return result |
paul@0 | 139 | |
paul@5 | 140 | def visitRaise(self, raise_): |
paul@5 | 141 | result = Raise(raise_, expr=self.dispatch(raise_.expr1), traceback=None) |
paul@5 | 142 | if raise_.expr2 is not None: |
paul@5 | 143 | result.args = [self.dispatch(raise_.expr2)] |
paul@5 | 144 | if raise_.expr3 is not None: |
paul@5 | 145 | result.traceback = self.dispatch(raise_.expr3) |
paul@5 | 146 | return result |
paul@5 | 147 | |
paul@0 | 148 | def _visitBuiltin(self, builtin, name): |
paul@1 | 149 | result = Invoke(builtin, expr=LoadName(name=name)) |
paul@1 | 150 | result.args = self.dispatches(builtin.nodes) |
paul@0 | 151 | return result |
paul@0 | 152 | |
paul@0 | 153 | def visitTuple(self, tuple): |
paulb@24 | 154 | return self._visitBuiltin(tuple, "tuple") |
paul@0 | 155 | |
paul@0 | 156 | def visitList(self, list): |
paulb@24 | 157 | return self._visitBuiltin(list, "list") |
paul@0 | 158 | |
paul@0 | 159 | def visitDict(self, dict): |
paulb@24 | 160 | result = Invoke(dict, expr=LoadName(name="dict")) |
paul@0 | 161 | args = [] |
paul@0 | 162 | for key, value in dict.items: |
paulb@24 | 163 | tuple = Invoke(expr=LoadName(name="tuple"), star=None, dstar=None) |
paul@0 | 164 | tuple.args = [self.dispatch(key), self.dispatch(value)] |
paul@0 | 165 | args.append(tuple) |
paul@0 | 166 | result.args = args |
paul@0 | 167 | return result |
paul@0 | 168 | |
paulb@17 | 169 | # Logical and comparison operations plus chained statements. |
paulb@17 | 170 | |
paulb@17 | 171 | def visitIf(self, if_): |
paulb@17 | 172 | |
paulb@26 | 173 | """ |
paulb@26 | 174 | Convert If(tests=..., else_=...) to: |
paulb@26 | 175 | |
paulb@26 | 176 | Invoke -> Subprogram |
paulb@26 | 177 | Conditional (test) -> Invoke -> Subprogram (body) |
paulb@26 | 178 | Return |
paulb@26 | 179 | Conditional (test) -> Invoke -> Subprogram (body) |
paulb@26 | 180 | Return |
paulb@26 | 181 | ... |
paulb@26 | 182 | """ |
paulb@26 | 183 | |
paulb@17 | 184 | # Make a subprogram for the statement and record it outside the main tree. |
paulb@17 | 185 | |
paulb@28 | 186 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paulb@17 | 187 | self.current_subprograms.append(subprogram) |
paulb@17 | 188 | |
paulb@17 | 189 | # In the subprogram, make conditionals for each test plus statement, |
paulb@17 | 190 | # adding a return onto the end of each statement block. |
paulb@17 | 191 | |
paulb@17 | 192 | nodes = [] |
paulb@17 | 193 | for compare, stmt in if_.tests: |
paulb@17 | 194 | # Produce something like... |
paulb@17 | 195 | # expr.__true__() ? body |
paulb@17 | 196 | test = Conditional(else_=[], test=Invoke( |
paulb@17 | 197 | expr=LoadAttr(expr=self.dispatch(compare), name="__true__"), |
paulb@17 | 198 | args=[], star=None, dstar=None)) |
paulb@26 | 199 | |
paulb@28 | 200 | body_subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paulb@26 | 201 | self.current_subprograms.append(body_subprogram) |
paulb@26 | 202 | |
paulb@26 | 203 | body_subprogram.code = self.dispatch(stmt) + [Return()] |
paulb@26 | 204 | |
paulb@26 | 205 | self.current_subprograms.pop() |
paulb@26 | 206 | self.subprograms.append(body_subprogram) |
paulb@26 | 207 | |
paulb@26 | 208 | test.body = [Invoke(stmt, expr=LoadRef(ref=body_subprogram), same_frame=1, star=None, dstar=None, args=[]), Return()] |
paulb@17 | 209 | nodes.append(test) |
paulb@17 | 210 | |
paulb@17 | 211 | # Add the compound statement from any else clause to the end. |
paulb@17 | 212 | |
paulb@17 | 213 | if if_.else_ is not None: |
paulb@28 | 214 | else_subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paulb@26 | 215 | self.current_subprograms.append(else_subprogram) |
paulb@26 | 216 | |
paulb@26 | 217 | else_subprogram.code = self.dispatch(if_.else_) + [Return()] |
paulb@26 | 218 | |
paulb@26 | 219 | self.current_subprograms.pop() |
paulb@26 | 220 | self.subprograms.append(else_subprogram) |
paulb@26 | 221 | |
paulb@26 | 222 | nodes.append(Invoke(stmt, expr=LoadRef(ref=else_subprogram), same_frame=1, star=None, dstar=None, args=[])) |
paulb@17 | 223 | |
paulb@17 | 224 | subprogram.code = nodes |
paulb@17 | 225 | |
paulb@17 | 226 | self.current_subprograms.pop() |
paulb@17 | 227 | self.subprograms.append(subprogram) |
paulb@17 | 228 | |
paulb@17 | 229 | # Make an invocation of the subprogram. |
paulb@17 | 230 | |
paulb@17 | 231 | result = Invoke(compare, same_frame=1, star=None, dstar=None, args=[]) |
paulb@17 | 232 | result.expr = LoadRef(ref=subprogram) |
paulb@17 | 233 | return result |
paulb@17 | 234 | |
paulb@17 | 235 | def _visitTryExcept(self, tryexcept): |
paulb@17 | 236 | |
paulb@17 | 237 | # Make a subprogram for the statement and record it outside the main tree. |
paulb@17 | 238 | |
paulb@28 | 239 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paulb@17 | 240 | self.current_subprograms.append(subprogram) |
paulb@17 | 241 | |
paulb@17 | 242 | # In the subprogram, make conditionals for each test plus statement, |
paulb@17 | 243 | # adding a return onto the end of each statement block. |
paulb@17 | 244 | |
paulb@17 | 245 | nodes = [] |
paulb@17 | 246 | for spec, assign, stmt in tryexcept.handlers: |
paulb@17 | 247 | |
paulb@17 | 248 | # If no specification exists, produce an unconditional block. |
paulb@17 | 249 | |
paulb@17 | 250 | if spec is None: |
paulb@17 | 251 | nodes += self.dispatch(stmt) |
paulb@17 | 252 | |
paulb@17 | 253 | # Produce something like... |
paulb@17 | 254 | # isinstance(<exc>, <spec>) |
paulb@17 | 255 | |
paulb@17 | 256 | else: |
paulb@17 | 257 | new_spec = self.dispatch(spec) |
paulb@17 | 258 | test = Conditional(body=[], else_=[], test=Invoke(expr=LoadName(name="isinstance"), args=[LoadExc(), new_spec], star=None, dstar=None)) |
paulb@17 | 259 | if assign is not None: |
paulb@17 | 260 | test.body.append(Assign(code=[StoreTemp(expr=LoadExc()), self.dispatch(assign), ReleaseTemp()])) |
paulb@17 | 261 | test.body += self.dispatch(stmt) + [Return()] |
paulb@17 | 262 | nodes.append(test) |
paulb@17 | 263 | |
paulb@17 | 264 | # Add a raise operation to deal with unhandled exceptions. |
paulb@17 | 265 | |
paulb@17 | 266 | nodes.append(Raise(expr=LoadExc())) |
paulb@17 | 267 | subprogram.code = nodes |
paulb@17 | 268 | |
paulb@17 | 269 | self.current_subprograms.pop() |
paulb@17 | 270 | self.subprograms.append(subprogram) |
paulb@17 | 271 | |
paulb@17 | 272 | # Make an invocation of the subprogram. |
paulb@17 | 273 | |
paulb@17 | 274 | result = Invoke(same_frame=1, star=None, dstar=None, args=[]) |
paulb@17 | 275 | result.expr = LoadRef(ref=subprogram) |
paulb@17 | 276 | return result |
paulb@17 | 277 | |
paulb@17 | 278 | def visitTryExcept(self, tryexcept): |
paulb@17 | 279 | result = Try(tryexcept, body=[], else_=[], finally_=[]) |
paulb@17 | 280 | if tryexcept.body is not None: |
paulb@17 | 281 | result.body = self.dispatch(tryexcept.body) |
paulb@17 | 282 | if tryexcept.else_ is not None: |
paulb@17 | 283 | result.else_ = self.dispatch(tryexcept.else_) |
paulb@17 | 284 | result.handler = self._visitTryExcept(tryexcept) |
paulb@17 | 285 | return result |
paulb@13 | 286 | |
paulb@13 | 287 | comparison_methods = { |
paulb@13 | 288 | "==" : "__eq__", "!=" : "__ne__", "<" : "__lt__", "<=" : "__le__", |
paulb@13 | 289 | ">=" : "__ge__", ">" : "__gt__", "is" : None, "is not" : None |
paulb@13 | 290 | } |
paulb@13 | 291 | |
paulb@13 | 292 | def visitCompare(self, compare): |
paulb@13 | 293 | |
paulb@13 | 294 | # Make a subprogram for the expression and record it outside the main tree. |
paulb@13 | 295 | |
paulb@28 | 296 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) |
paulb@13 | 297 | self.current_subprograms.append(subprogram) |
paulb@13 | 298 | |
paulb@13 | 299 | # In the subprogram, make instructions which invoke a method on the |
paulb@13 | 300 | # first operand of each operand pair and, if appropriate, return with |
paulb@13 | 301 | # the value from that method. |
paulb@13 | 302 | |
paulb@13 | 303 | nodes = [] |
paulb@13 | 304 | last = compare.ops[-1] |
paulb@13 | 305 | previous = self.dispatch(compare.expr) |
paulb@13 | 306 | for op in compare.ops: |
paulb@13 | 307 | op_name, node = op |
paulb@13 | 308 | expr = self.dispatch(node) |
paulb@13 | 309 | method_name = self.comparison_methods[op_name] |
paulb@13 | 310 | if method_name: |
paulb@15 | 311 | invocation = Invoke(expr=LoadAttr(expr=previous, name=method_name), args=[expr], star=None, dstar=None) |
paulb@13 | 312 | elif op_name == "is": |
paulb@15 | 313 | invocation = Invoke(expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None) |
paulb@13 | 314 | elif op_name == "is not": |
paulb@15 | 315 | invocation = Not(expr=Invoke(expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None)) |
paulb@13 | 316 | else: |
paulb@13 | 317 | raise NotImplementedError, op_name |
paulb@13 | 318 | nodes.append(StoreTemp(expr=invocation)) |
paulb@13 | 319 | if op is not last: |
paulb@13 | 320 | nodes.append(Conditional(test=Not(expr=LoadTemp()), body=[Return(expr=LoadTemp())])) |
paulb@13 | 321 | nodes.append(ReleaseTemp()) |
paulb@13 | 322 | else: |
paulb@13 | 323 | nodes.append(Return(expr=LoadTemp())) |
paulb@15 | 324 | previous = expr |
paulb@13 | 325 | subprogram.code = nodes |
paulb@13 | 326 | |
paulb@13 | 327 | self.current_subprograms.pop() |
paulb@13 | 328 | self.subprograms.append(subprogram) |
paulb@13 | 329 | |
paulb@13 | 330 | # Make an invocation of the subprogram. |
paulb@13 | 331 | |
paulb@13 | 332 | result = Invoke(compare, same_frame=1, star=None, dstar=None, args=[]) |
paulb@13 | 333 | result.expr = LoadRef(ref=subprogram) |
paulb@13 | 334 | return result |
paul@1 | 335 | |
paul@1 | 336 | def visitAnd(self, and_): |
paulb@7 | 337 | |
paulb@7 | 338 | # Make a subprogram for the expression and record it outside the main tree. |
paulb@7 | 339 | |
paulb@28 | 340 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) |
paulb@7 | 341 | self.current_subprograms.append(subprogram) |
paulb@7 | 342 | |
paulb@12 | 343 | # In the subprogram, make instructions which store each operand, test |
paulb@12 | 344 | # for each operand's truth status, and if appropriate return from the |
paulb@12 | 345 | # subprogram with the value of the operand. |
paulb@12 | 346 | |
paul@1 | 347 | nodes = [] |
paulb@7 | 348 | last = and_.nodes[-1] |
paul@1 | 349 | for node in and_.nodes: |
paulb@7 | 350 | expr = self.dispatch(node) |
paulb@7 | 351 | if node is not last: |
paulb@12 | 352 | nodes.append(StoreTemp(expr=expr)) |
paulb@15 | 353 | invocation = Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) |
paulb@13 | 354 | nodes.append(Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())])) |
paulb@7 | 355 | nodes.append(ReleaseTemp()) |
paulb@7 | 356 | else: |
paulb@7 | 357 | nodes.append(Return(expr=expr)) |
paulb@7 | 358 | subprogram.code = nodes |
paulb@7 | 359 | |
paulb@7 | 360 | self.current_subprograms.pop() |
paulb@7 | 361 | self.subprograms.append(subprogram) |
paulb@7 | 362 | |
paulb@7 | 363 | # Make an invocation of the subprogram. |
paulb@7 | 364 | |
paulb@7 | 365 | result = Invoke(and_, same_frame=1, star=None, dstar=None, args=[]) |
paulb@7 | 366 | result.expr = LoadRef(ref=subprogram) |
paul@1 | 367 | return result |
paul@1 | 368 | |
paul@1 | 369 | def visitOr(self, or_): |
paulb@7 | 370 | |
paulb@7 | 371 | # Make a subprogram for the expression and record it outside the main tree. |
paulb@7 | 372 | |
paulb@28 | 373 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) |
paulb@7 | 374 | self.current_subprograms.append(subprogram) |
paulb@7 | 375 | |
paulb@12 | 376 | # In the subprogram, make instructions which store each operand, test |
paulb@12 | 377 | # for each operand's truth status, and if appropriate return from the |
paulb@12 | 378 | # subprogram with the value of the operand. |
paulb@12 | 379 | |
paul@1 | 380 | nodes = [] |
paulb@7 | 381 | last = or_.nodes[-1] |
paul@1 | 382 | for node in or_.nodes: |
paulb@7 | 383 | expr = self.dispatch(node) |
paulb@7 | 384 | if node is not last: |
paulb@12 | 385 | nodes.append(StoreTemp(expr=expr)) |
paulb@15 | 386 | invocation = Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) |
paulb@7 | 387 | nodes.append(Conditional(test=invocation, body=[Return(expr=LoadTemp())])) |
paulb@7 | 388 | nodes.append(ReleaseTemp()) |
paulb@7 | 389 | else: |
paulb@7 | 390 | nodes.append(Return(expr=expr)) |
paulb@7 | 391 | subprogram.code = nodes |
paulb@7 | 392 | |
paulb@7 | 393 | self.current_subprograms.pop() |
paulb@7 | 394 | self.subprograms.append(subprogram) |
paulb@7 | 395 | |
paulb@7 | 396 | # Make an invocation of the subprogram. |
paulb@7 | 397 | |
paulb@7 | 398 | result = Invoke(or_, same_frame=1, star=None, dstar=None, args=[]) |
paulb@7 | 399 | result.expr = LoadRef(ref=subprogram) |
paul@1 | 400 | return result |
paul@1 | 401 | |
paul@1 | 402 | def visitNot(self, not_): |
paul@1 | 403 | result = Not(not_, expr=Invoke(expr=LoadAttr(expr=self.dispatch(not_.expr), name="__true__"), |
paulb@15 | 404 | args=[], star=None, dstar=None)) |
paul@1 | 405 | return result |
paul@1 | 406 | |
paul@4 | 407 | # Operators. |
paul@4 | 408 | |
paul@4 | 409 | def visitUnaryAdd(self, unaryadd): |
paulb@11 | 410 | return Invoke(unaryadd, expr=LoadAttr(expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[]) |
paul@4 | 411 | |
paul@4 | 412 | def visitUnarySub(self, unarysub): |
paulb@11 | 413 | return Invoke(unarysub, expr=LoadAttr(expr=self.dispatch(unarysub.expr), name="__neg__"), args=[]) |
paul@4 | 414 | |
paul@4 | 415 | def visitInvert(self, invert): |
paulb@11 | 416 | return Invoke(invert, expr=LoadAttr(expr=self.dispatch(invert.expr), name="__invert__"), args=[]) |
paul@4 | 417 | |
paul@0 | 418 | # Assignments. |
paul@0 | 419 | |
paul@2 | 420 | augassign_methods = { |
paulb@9 | 421 | "+=" : "__iadd__", "-=" : "__isub__", "*=" : "__imul__", "/=" : "__idiv__", |
paulb@9 | 422 | "%=" : "__imod__", "**=" : "__ipow__", "<<=" : "__ilshift__", ">>=" : "__irshift__", |
paulb@9 | 423 | "&=" : "__iand__", "^=" : "__ixor__", "|=" : "__ior__" |
paul@2 | 424 | } |
paul@2 | 425 | |
paul@2 | 426 | def visitAugAssign(self, augassign): |
paul@2 | 427 | result = Assign(augassign) |
paul@2 | 428 | expr = self.dispatch(augassign.expr) |
paul@2 | 429 | |
paul@2 | 430 | # Simple augmented assignment: name += expr |
paul@2 | 431 | |
paul@2 | 432 | if isinstance(augassign.node, compiler.ast.Name): |
paulb@6 | 433 | name = augassign.node |
paulb@6 | 434 | node = self.dispatch(name) |
paul@2 | 435 | get_incremented = StoreTemp( |
paul@2 | 436 | expr=Invoke(expr=LoadAttr(expr=node, name=self.augassign_methods[augassign.op]), args=[expr]) |
paul@2 | 437 | ) |
paulb@6 | 438 | store = StoreName(expr=LoadTemp(), name=name.name) |
paul@2 | 439 | result.code = [get_incremented, store, ReleaseTemp()] |
paul@2 | 440 | |
paulb@9 | 441 | # Complicated augmented assignment: lvalue.attr += expr |
paul@2 | 442 | |
paul@2 | 443 | elif isinstance(augassign.node, compiler.ast.Getattr): |
paulb@6 | 444 | |
paulb@9 | 445 | # <lvalue> -> setattr(<lvalue>, getattr(<lvalue>, "attr").__xxx__(expr)) |
paulb@6 | 446 | |
paulb@6 | 447 | getattr = augassign.node |
paulb@6 | 448 | store_expr = StoreTemp(index="expr", expr=self.dispatch(getattr.expr)) |
paulb@6 | 449 | node_attr = LoadAttr(expr=LoadTemp(index="expr"), name=getattr.attrname) |
paul@2 | 450 | get_incremented = StoreTemp( |
paul@2 | 451 | expr=Invoke(expr=LoadAttr(expr=node_attr, name=self.augassign_methods[augassign.op]), args=[expr]) |
paul@2 | 452 | ) |
paulb@6 | 453 | store = StoreAttr(expr=LoadTemp(), lvalue=LoadTemp(index="expr"), name=getattr.attrname) |
paulb@6 | 454 | result.code = [store_expr, get_incremented, store, ReleaseTemp(index="expr"), ReleaseTemp()] |
paulb@6 | 455 | |
paulb@9 | 456 | # Complicated augassign using slices: lvalue[lower:upper] += expr |
paulb@6 | 457 | |
paulb@6 | 458 | elif isinstance(augassign.node, compiler.ast.Slice): |
paulb@9 | 459 | |
paulb@9 | 460 | # <lvalue>, <lower>, <upper> -> <lvalue>.__setslice__(<lower>, <upper>, <lvalue>.__getslice__(<lower>, <upper>).__xxx__(expr)) |
paulb@9 | 461 | |
paulb@6 | 462 | slice = augassign.node |
paulb@6 | 463 | store_expr = StoreTemp(index="expr", expr=self.dispatch(slice.expr)) |
paulb@6 | 464 | store_lower = StoreTemp(index="lower", expr=self.dispatch_or_none(slice.lower)) |
paulb@6 | 465 | store_upper = StoreTemp(index="upper", expr=self.dispatch_or_none(slice.upper)) |
paulb@11 | 466 | node_slice = self._visitSlice(slice, LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_APPLY") |
paulb@6 | 467 | get_incremented = StoreTemp( |
paulb@6 | 468 | expr=Invoke(expr=LoadAttr(expr=node_slice, name=self.augassign_methods[augassign.op]), args=[expr]) |
paulb@6 | 469 | ) |
paulb@11 | 470 | store = self._visitSlice(slice, LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_ASSIGN", LoadTemp()) |
paulb@6 | 471 | result.code = [store_expr, store_lower, store_upper, get_incremented, store, |
paulb@6 | 472 | ReleaseTemp(index="expr"), ReleaseTemp(index="lower"), ReleaseTemp(index="upper"), ReleaseTemp()] |
paul@2 | 473 | |
paulb@10 | 474 | # Complicated augassign using subscripts: lvalue[subs] += expr |
paulb@10 | 475 | |
paulb@10 | 476 | elif isinstance(augassign.node, compiler.ast.Subscript): |
paulb@10 | 477 | |
paulb@10 | 478 | # <lvalue>, <subs> -> <lvalue>.__setitem__(<subs>, <lvalue>.__getitem__(<subs>).__xxx__(expr)) |
paulb@10 | 479 | |
paulb@10 | 480 | subscript = augassign.node |
paulb@10 | 481 | store_expr = StoreTemp(index="expr", expr=self.dispatch(subscript.expr)) |
paulb@10 | 482 | subs = self._visitSubscriptSubs(subscript.subs) |
paulb@10 | 483 | store_subs = StoreTemp(index="subs", expr=subs) |
paulb@11 | 484 | node_subscript = self._visitSubscript(subscript, LoadTemp(index="expr"), LoadTemp(index="subs"), "OP_APPLY") |
paulb@10 | 485 | get_incremented = StoreTemp( |
paulb@10 | 486 | expr=Invoke(expr=LoadAttr(expr=node_subscript, name=self.augassign_methods[augassign.op]), args=[expr]) |
paulb@10 | 487 | ) |
paulb@11 | 488 | store = self._visitSubscript(subscript, LoadTemp(index="expr"), LoadTemp(index="subs"), "OP_ASSIGN", LoadTemp()) |
paulb@10 | 489 | result.code = [store_expr, store_subs, get_incremented, store, ReleaseTemp(index="expr"), ReleaseTemp(index="subs"), ReleaseTemp()] |
paulb@10 | 490 | |
paul@2 | 491 | else: |
paul@2 | 492 | raise NotImplementedError, augassign.node.__class__ |
paul@2 | 493 | |
paul@2 | 494 | return result |
paul@2 | 495 | |
paul@0 | 496 | def visitAssign(self, assign): |
paul@0 | 497 | result = Assign(assign) |
paul@0 | 498 | store = StoreTemp(expr=self.dispatch(assign.expr)) |
paul@0 | 499 | release = ReleaseTemp() |
paul@0 | 500 | result.code = [store] + self.dispatches(assign.nodes, 0) + [release] |
paul@0 | 501 | return result |
paul@0 | 502 | |
paul@0 | 503 | def visitAssList(self, asslist, in_sequence=0): |
paul@0 | 504 | if not in_sequence: |
paulb@11 | 505 | expr = LoadTemp() |
paul@0 | 506 | else: |
paulb@11 | 507 | expr = Invoke(expr=LoadAttr(expr=LoadTemp(), name="next")) |
paul@0 | 508 | result = Assign(asslist) |
paul@0 | 509 | store = StoreTemp(expr=Invoke(expr=LoadAttr(name="__iter__", expr=expr))) |
paul@0 | 510 | release = ReleaseTemp() |
paul@0 | 511 | result.code = [store] + self.dispatches(asslist.nodes, 1) + [release] |
paul@0 | 512 | return result |
paul@0 | 513 | |
paul@0 | 514 | visitAssTuple = visitAssList |
paul@0 | 515 | |
paul@0 | 516 | def _visitAssNameOrAttr(self, node, in_sequence): |
paul@0 | 517 | if not in_sequence: |
paulb@11 | 518 | return LoadTemp() |
paul@0 | 519 | else: |
paulb@11 | 520 | return Invoke(expr=LoadAttr(expr=LoadTemp(), name="next")) |
paul@0 | 521 | |
paul@0 | 522 | def visitAssName(self, assname, in_sequence=0): |
paul@0 | 523 | expr = self._visitAssNameOrAttr(assname, in_sequence) |
paul@0 | 524 | result = StoreName(assname, name=assname.name, expr=expr) |
paul@0 | 525 | return result |
paul@0 | 526 | |
paul@0 | 527 | def visitAssAttr(self, assattr, in_sequence=0): |
paul@0 | 528 | expr = self._visitAssNameOrAttr(assattr, in_sequence) |
paul@0 | 529 | lvalue = self.dispatch(assattr.expr) |
paul@0 | 530 | result = StoreAttr(assattr, name=assattr.attrname, lvalue=lvalue, expr=expr) |
paul@0 | 531 | return result |
paul@0 | 532 | |
paulb@11 | 533 | def _visitSlice(self, slice, expr, lower, upper, flags, value=None): |
paulb@6 | 534 | if flags == "OP_ASSIGN": |
paulb@6 | 535 | args = [value] |
paulb@6 | 536 | result = Invoke(expr=LoadAttr(expr=expr, name="__setslice__")) |
paulb@6 | 537 | elif flags == "OP_APPLY": |
paulb@6 | 538 | args = [] |
paulb@6 | 539 | result = Invoke(expr=LoadAttr(expr=expr, name="__getslice__")) |
paulb@10 | 540 | elif flags == "OP_DELETE": |
paulb@10 | 541 | args = [] |
paulb@10 | 542 | result = Invoke(expr=LoadAttr(expr=expr, name="__delslice__")) |
paulb@6 | 543 | else: |
paulb@6 | 544 | raise NotImplementedError, flags |
paulb@6 | 545 | |
paulb@6 | 546 | # Add the dimensions. |
paulb@6 | 547 | |
paulb@6 | 548 | args.insert(0, lower) |
paulb@6 | 549 | args.insert(1, upper) |
paulb@6 | 550 | |
paulb@11 | 551 | result.original = slice |
paulb@6 | 552 | result.args = args |
paulb@6 | 553 | return result |
paulb@6 | 554 | |
paulb@6 | 555 | def visitSlice(self, slice, in_sequence=0): |
paulb@6 | 556 | value = self._visitAssNameOrAttr(slice, in_sequence) |
paulb@11 | 557 | return self._visitSlice(slice, self.dispatch(slice.expr), self.dispatch_or_none(slice.lower), |
paulb@11 | 558 | self.dispatch_or_none(slice.upper), slice.flags, value) |
paulb@6 | 559 | |
paulb@11 | 560 | def _visitSubscript(self, subscript, expr, subs, flags, value=None): |
paulb@10 | 561 | if flags == "OP_ASSIGN": |
paulb@10 | 562 | args = [value] |
paulb@10 | 563 | result = Invoke(expr=LoadAttr(expr=expr, name="__setitem__")) |
paulb@10 | 564 | elif flags == "OP_APPLY": |
paulb@10 | 565 | args = [] |
paulb@10 | 566 | result = Invoke(expr=LoadAttr(expr=expr, name="__getitem__")) |
paulb@10 | 567 | elif flags == "OP_DELETE": |
paulb@10 | 568 | args = [] |
paulb@10 | 569 | result = Invoke(expr=LoadAttr(expr=expr, name="__delitem__")) |
paulb@10 | 570 | else: |
paulb@10 | 571 | raise NotImplementedError, flags |
paulb@10 | 572 | |
paulb@10 | 573 | # Add the dimensions. |
paulb@10 | 574 | |
paulb@10 | 575 | args.insert(0, subs) |
paulb@10 | 576 | |
paulb@11 | 577 | result.original = subscript |
paulb@10 | 578 | result.args = args |
paulb@10 | 579 | return result |
paulb@10 | 580 | |
paulb@10 | 581 | def _visitSubscriptSubs(self, subs): |
paulb@10 | 582 | if len(subs) == 1: |
paulb@10 | 583 | return self.dispatch(subs[0]) |
paulb@10 | 584 | else: |
paulb@24 | 585 | return Invoke(expr=LoadName(name="tuple"), args=self.dispatches(subs)) |
paulb@10 | 586 | |
paulb@10 | 587 | def visitSubscript(self, subscript, in_sequence=0): |
paulb@10 | 588 | value = self._visitAssNameOrAttr(subscript, in_sequence) |
paulb@10 | 589 | subs = self._visitSubscriptSubs(subscript.subs) |
paulb@11 | 590 | return self._visitSubscript(subscript, self.dispatch(subscript.expr), subs, subscript.flags, value) |
paulb@10 | 591 | |
paul@0 | 592 | # Invocation and subprogram transformations. |
paul@0 | 593 | |
paulb@19 | 594 | def visitClass(self, class_): |
paulb@28 | 595 | structure = Class(name=class_.name, bases=self.dispatches(class_.bases)) |
paulb@19 | 596 | self.structures.append(structure) |
paulb@19 | 597 | |
paulb@24 | 598 | # Make a subprogram which initialises the class structure. |
paulb@24 | 599 | |
paulb@28 | 600 | subprogram = Subprogram(name=None, structure=structure, params=[], star=None, dstar=None) |
paulb@19 | 601 | self.current_subprograms.append(subprogram) |
paulb@19 | 602 | |
paulb@28 | 603 | # The class is initialised using the code found inside. |
paulb@28 | 604 | |
paulb@19 | 605 | subprogram.code = self.dispatch(class_.code) |
paulb@19 | 606 | |
paulb@19 | 607 | self.current_subprograms.pop() |
paulb@19 | 608 | self.subprograms.append(subprogram) |
paulb@19 | 609 | |
paulb@19 | 610 | # Make a definition of the class associating it with a name. |
paulb@19 | 611 | |
paulb@19 | 612 | result = Assign(class_) |
paulb@31 | 613 | store = StoreName(name=class_.name, expr=LoadRef(ref=structure)) |
paulb@19 | 614 | init = Invoke(expr=LoadRef(ref=subprogram), args=[], star=None, dstar=None) |
paulb@31 | 615 | result.code = [store, init] |
paulb@19 | 616 | return result |
paulb@19 | 617 | |
paul@0 | 618 | def _visitFunction(self, function, subprogram): |
paul@0 | 619 | if function.flags & 4 != 0: has_star = 1 |
paul@0 | 620 | else: has_star = 0 |
paul@0 | 621 | if function.flags & 8 != 0: has_dstar = 1 |
paul@0 | 622 | else: has_dstar = 0 |
paul@0 | 623 | ndefaults = len(function.defaults) |
paul@0 | 624 | npositional = len(function.argnames) - has_star - has_dstar |
paulb@24 | 625 | |
paulb@24 | 626 | # Produce star and dstar parameters with appropriate defaults. |
paulb@24 | 627 | |
paulb@24 | 628 | if has_star: |
paulb@24 | 629 | star = (function.argnames[npositional], Invoke(expr=LoadName(name="list"), args=[], star=None, dstar=None)) |
paulb@24 | 630 | else: |
paulb@24 | 631 | star = None |
paulb@24 | 632 | if has_dstar: |
paulb@24 | 633 | dstar = (function.argnames[npositional + has_star], Invoke(expr=LoadName(name="dict"), args=[], star=None, dstar=None)) |
paulb@24 | 634 | else: |
paulb@24 | 635 | dstar = None |
paul@0 | 636 | |
paul@0 | 637 | params = [] |
paul@0 | 638 | for i in range(0, npositional - ndefaults): |
paul@0 | 639 | params.append((function.argnames[i], None)) |
paul@0 | 640 | |
paul@0 | 641 | # NOTE: Fix/process defaults. |
paul@0 | 642 | |
paul@0 | 643 | for i in range(0, ndefaults): |
paul@0 | 644 | default = function.defaults[i] |
paul@0 | 645 | if default is not None: |
paul@0 | 646 | params.append((function.argnames[npositional - ndefaults + i], self.dispatch(default))) |
paul@0 | 647 | else: |
paul@0 | 648 | params.append((function.argnames[npositional - ndefaults + i], default)) |
paul@0 | 649 | |
paul@0 | 650 | subprogram.params = params |
paul@0 | 651 | subprogram.star = star |
paul@0 | 652 | subprogram.dstar = dstar |
paul@0 | 653 | self.subprograms.append(subprogram) |
paul@0 | 654 | |
paul@0 | 655 | def visitFunction(self, function): |
paul@0 | 656 | |
paul@0 | 657 | # Make a subprogram for the function and record it outside the main |
paul@0 | 658 | # tree. |
paul@0 | 659 | |
paulb@28 | 660 | subprogram = Subprogram(name=function.name, returns_value=1, star=None, dstar=None) |
paul@0 | 661 | self.current_subprograms.append(subprogram) |
paul@0 | 662 | subprogram.code = self.dispatch(function.code) |
paul@0 | 663 | self.current_subprograms.pop() |
paul@0 | 664 | self._visitFunction(function, subprogram) |
paul@0 | 665 | |
paul@0 | 666 | # Make a definition of the function associating it with a name. |
paul@0 | 667 | |
paulb@19 | 668 | result = StoreName(name=function.name, expr=LoadRef(ref=subprogram)) |
paul@0 | 669 | return result |
paul@0 | 670 | |
paul@0 | 671 | def visitLambda(self, lambda_): |
paul@0 | 672 | |
paul@0 | 673 | # Make a subprogram for the function and record it outside the main |
paul@0 | 674 | # tree. |
paul@0 | 675 | |
paulb@28 | 676 | subprogram = Subprogram(name=None, returns_value=1, star=None, dstar=None) |
paul@0 | 677 | self.current_subprograms.append(subprogram) |
paul@0 | 678 | subprogram.code = [Return(expr=self.dispatch(lambda_.code))] |
paul@0 | 679 | self.current_subprograms.pop() |
paul@0 | 680 | self._visitFunction(lambda_, subprogram) |
paul@0 | 681 | |
paul@0 | 682 | # Get the subprogram reference to the lambda. |
paul@0 | 683 | |
paulb@11 | 684 | return LoadRef(lambda_, ref=subprogram) |
paul@0 | 685 | |
paul@0 | 686 | def visitCallFunc(self, callfunc): |
paul@0 | 687 | result = Invoke(callfunc, same_frame=0, star=None, dstar=None) |
paul@0 | 688 | result.args = self.dispatches(callfunc.args) |
paul@0 | 689 | if callfunc.star_args is not None: |
paul@0 | 690 | result.star = self.dispatch(callfunc.star_args) |
paul@0 | 691 | if callfunc.dstar_args is not None: |
paul@0 | 692 | result.dstar = self.dispatch(callfunc.dstar_args) |
paul@0 | 693 | result.expr = self.dispatch(callfunc.node) |
paul@0 | 694 | return result |
paul@0 | 695 | |
paul@0 | 696 | def visitWhile(self, while_): |
paul@0 | 697 | |
paul@0 | 698 | # Make a subprogram for the block and record it outside the main tree. |
paul@0 | 699 | |
paulb@28 | 700 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paul@0 | 701 | self.current_subprograms.append(subprogram) |
paul@0 | 702 | |
paul@0 | 703 | # Include a conditional statement in the subprogram. |
paul@0 | 704 | |
paul@0 | 705 | test = Conditional(else_=[]) |
paul@0 | 706 | test.test = Invoke(expr=LoadAttr(expr=self.dispatch(while_.test), name="__true__"), |
paulb@17 | 707 | args=[], star=None, dstar=None) |
paul@0 | 708 | |
paul@0 | 709 | # Inside the conditional, add a recursive invocation to the subprogram |
paul@0 | 710 | # if the test condition was satisfied. |
paul@0 | 711 | |
paul@0 | 712 | continuation = Invoke(same_frame=1, star=None, dstar=None, args=[]) |
paul@0 | 713 | continuation.expr = LoadRef(ref=subprogram) |
paul@0 | 714 | test.body = self.dispatch(while_.body) + [continuation] |
paul@0 | 715 | if while_.else_ is not None: |
paul@0 | 716 | test.else_ = self.dispatch(while_.else_) |
paul@0 | 717 | subprogram.code = [test] |
paul@0 | 718 | |
paul@0 | 719 | self.current_subprograms.pop() |
paul@0 | 720 | self.subprograms.append(subprogram) |
paul@0 | 721 | |
paul@0 | 722 | # Make an invocation of the subprogram. |
paul@0 | 723 | |
paulb@7 | 724 | result = Invoke(while_, same_frame=1, produces_result=0, star=None, dstar=None, args=[]) |
paul@0 | 725 | result.expr = LoadRef(ref=subprogram) |
paul@0 | 726 | return result |
paul@0 | 727 | |
paul@0 | 728 | def visitFor(self, for_): |
paul@0 | 729 | |
paul@0 | 730 | # Make a subprogram for the block and record it outside the main tree. |
paul@0 | 731 | |
paulb@28 | 732 | subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) |
paul@0 | 733 | self.current_subprograms.append(subprogram) |
paul@0 | 734 | |
paulb@17 | 735 | if for_.else_ is not None: |
paulb@17 | 736 | else_stmt = self.dispatch(for_.else_) |
paulb@17 | 737 | else: |
paulb@17 | 738 | else_stmt = [] |
paulb@17 | 739 | |
paul@0 | 740 | # Wrap the assignment in a try...except statement. |
paul@0 | 741 | |
paulb@17 | 742 | try_except = Try(body=[], else_=[], finally_=[]) |
paulb@17 | 743 | try_except.handler = Conditional(test=Invoke(expr=LoadName(name="isinstance"), |
paulb@17 | 744 | args=[LoadExc(), LoadName(name="StopIteration")], star=None, dstar=None), |
paulb@17 | 745 | body=else_stmt, else_=[Raise(expr=LoadExc())]) |
paul@0 | 746 | |
paul@0 | 747 | assign = Assign() |
paul@0 | 748 | assign.code = [ |
paul@0 | 749 | StoreTemp(expr=Invoke(expr=LoadAttr(expr=LoadTemp(), name="next"))), |
paul@0 | 750 | self.dispatch(for_.assign), |
paul@0 | 751 | ReleaseTemp() |
paul@0 | 752 | ] |
paul@0 | 753 | |
paul@0 | 754 | # Inside the conditional, add a recursive invocation to the subprogram |
paul@0 | 755 | # if the test condition was satisfied. |
paul@0 | 756 | |
paulb@7 | 757 | continuation = Invoke(same_frame=1, produces_result=0, star=None, dstar=None, args=[]) |
paul@0 | 758 | continuation.expr = LoadRef(ref=subprogram) |
paul@0 | 759 | try_except.body = [assign] + self.dispatch(for_.body) + [continuation] |
paul@0 | 760 | subprogram.code = [try_except] |
paul@0 | 761 | |
paul@0 | 762 | self.subprograms.append(subprogram) |
paul@0 | 763 | self.current_subprograms.pop() |
paul@0 | 764 | |
paul@0 | 765 | # Obtain an iterator for the sequence involved. |
paul@0 | 766 | # Then, make an invocation of the subprogram. |
paul@0 | 767 | |
paul@0 | 768 | result = Assign(for_) |
paul@0 | 769 | result.code = [ |
paul@0 | 770 | StoreTemp(expr=Invoke(expr=LoadAttr(name="__iter__", expr=self.dispatch(for_.list)))), |
paulb@7 | 771 | Invoke(expr=LoadRef(ref=subprogram), same_frame=1, produces_result=0, star=None, dstar=None, args=[]), |
paul@0 | 772 | ReleaseTemp() |
paul@0 | 773 | ] |
paul@0 | 774 | return result |
paul@0 | 775 | |
paul@0 | 776 | # Exception node transformations. |
paul@0 | 777 | |
paul@0 | 778 | def visitTryFinally(self, tryfinally): |
paul@0 | 779 | result = Try(tryfinally, body=[], handlers=[], else_=[], finally_=[]) |
paul@0 | 780 | if tryfinally.body is not None: |
paul@0 | 781 | result.body = self.dispatch(tryfinally.body) |
paul@0 | 782 | if tryfinally.final is not None: |
paul@0 | 783 | result.finally_ = self.dispatch(tryfinally.final) |
paul@0 | 784 | return result |
paul@0 | 785 | |
paul@0 | 786 | # vim: tabstop=4 expandtab shiftwidth=4 |