1.1 --- a/simplify.py Wed Oct 04 01:05:41 2006 +0200
1.2 +++ b/simplify.py Sat Oct 07 00:21:19 2006 +0200
1.3 @@ -117,7 +117,13 @@
1.4
1.5 init_code = []
1.6 for value, constant in self.constants.items():
1.7 - init_code.append(StoreAttr(lvalue=LoadRef(ref=constant), name="__class__", expr=LoadName(name=constant.typename)))
1.8 + init_code.append(
1.9 + StoreAttr(module,
1.10 + lvalue=LoadRef(module, ref=constant),
1.11 + name="__class__",
1.12 + expr=LoadName(module, name=constant.typename)
1.13 + )
1.14 + )
1.15
1.16 # NOTE: Hack to ensure correct initialisation of constants.
1.17
1.18 @@ -151,18 +157,25 @@
1.19 result = Assign(import_)
1.20 code = []
1.21 for path, alias in import_.names:
1.22 - importer = Import(name=path)
1.23 + importer = Import(import_, name=path)
1.24 top = alias or path.split(".")[0]
1.25 - code.append(StoreName(expr=importer, name=top))
1.26 + code.append(StoreName(import_, expr=importer, name=top))
1.27 result.code = code
1.28 return result
1.29
1.30 def visitFrom(self, from_):
1.31 result = Assign(from_)
1.32 code = []
1.33 - code.append(StoreTemp(expr=Import(name=from_.modname)))
1.34 + code.append(StoreTemp(from_, expr=Import(from_, name=from_.modname)))
1.35 for name, alias in from_.names:
1.36 - code.append(StoreName(expr=LoadAttr(expr=LoadTemp(), name=name), name=(alias or name)))
1.37 + code.append(
1.38 + StoreName(from_,
1.39 + expr=LoadAttr(from_,
1.40 + expr=LoadTemp(from_),
1.41 + name=name),
1.42 + name=(alias or name)
1.43 + )
1.44 + )
1.45 result.code = code
1.46 return result
1.47
1.48 @@ -172,8 +185,8 @@
1.49
1.50 def visitConst(self, const):
1.51 if not self.constants.has_key(const.value):
1.52 - self.constants[const.value] = Constant(name=repr(const.value), value=const.value)
1.53 - result = LoadRef(ref=self.constants[const.value])
1.54 + self.constants[const.value] = Constant(const, name=repr(const.value), value=const.value)
1.55 + result = LoadRef(const, ref=self.constants[const.value])
1.56 return result
1.57
1.58 def visitReturn(self, return_):
1.59 @@ -188,7 +201,7 @@
1.60
1.61 def visitContinue(self, continue_):
1.62 result = InvokeBlock(continue_,
1.63 - expr=LoadRef(ref=self.current_subprograms[-1])
1.64 + expr=LoadRef(continue_, ref=self.current_subprograms[-1])
1.65 )
1.66 return result
1.67
1.68 @@ -201,7 +214,7 @@
1.69 return result
1.70
1.71 def _visitBuiltin(self, builtin, name):
1.72 - result = Invoke(builtin, expr=LoadName(name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.73 + result = Invoke(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.74 return result
1.75
1.76 def visitTuple(self, tuple):
1.77 @@ -211,10 +224,10 @@
1.78 return self._visitBuiltin(list, "list")
1.79
1.80 def visitDict(self, dict):
1.81 - result = Invoke(dict, expr=LoadName(name="dict"), star=None, dstar=None)
1.82 + result = Invoke(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
1.83 args = []
1.84 for key, value in dict.items:
1.85 - tuple = Invoke(expr=LoadName(name="tuple"), star=None, dstar=None)
1.86 + tuple = Invoke(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
1.87 tuple.args = [self.dispatch(key), self.dispatch(value)]
1.88 args.append(tuple)
1.89 result.args = args
1.90 @@ -246,10 +259,20 @@
1.91
1.92 results = nodes = []
1.93
1.94 + # Produce something like...
1.95 + # expr.__true__() ? body
1.96 +
1.97 for compare, stmt in if_.tests:
1.98 - # Produce something like...
1.99 - # expr.__true__() ? body
1.100 - test = Conditional(test=Invoke(expr=LoadAttr(expr=self.dispatch(compare), name="__true__"), args=[], star=None, dstar=None))
1.101 + test = Conditional(if_,
1.102 + test=Invoke(if_,
1.103 + expr=LoadAttr(if_,
1.104 + expr=self.dispatch(compare),
1.105 + name="__true__"
1.106 + ),
1.107 + args=[],
1.108 + star=None,
1.109 + dstar=None)
1.110 + )
1.111 test.body = self.dispatch(stmt)
1.112 nodes.append(test)
1.113 nodes = test.else_ = []
1.114 @@ -305,21 +328,33 @@
1.115
1.116 else:
1.117 new_spec = self.dispatch(spec)
1.118 - test = Conditional(test=Invoke(expr=LoadName(name="isinstance"), args=[LoadExc(), new_spec], star=None, dstar=None))
1.119 + test = Conditional(tryexcept,
1.120 + test=Invoke(tryexcept,
1.121 + expr=LoadName(tryexcept, name="isinstance"),
1.122 + args=[LoadExc(tryexcept), new_spec],
1.123 + star=None,
1.124 + dstar=None)
1.125 + )
1.126 test.body = []
1.127
1.128 if assign is not None:
1.129 - test.body.append(Assign(code=[StoreTemp(expr=LoadExc()), self.dispatch(assign), ReleaseTemp()]))
1.130 + test.body.append(
1.131 + Assign(tryexcept,
1.132 + code=[StoreTemp(expr=LoadExc(tryexcept)), self.dispatch(assign), ReleaseTemp(tryexcept)])
1.133 + )
1.134
1.135 # Always return from conditional sections.
1.136
1.137 - test.body += self.dispatch(stmt) + [Return()]
1.138 + test.body += self.dispatch(stmt) + [Return(tryexcept)]
1.139 nodes.append(test)
1.140 nodes = test.else_ = []
1.141
1.142 # Add a raise operation to deal with unhandled exceptions.
1.143
1.144 - nodes.append(Raise(expr=LoadExc()))
1.145 + nodes.append(
1.146 + Raise(tryexcept,
1.147 + expr=LoadExc(tryexcept))
1.148 + )
1.149
1.150 result.handler = results
1.151 return result
1.152 @@ -346,7 +381,7 @@
1.153 (else) -> ...
1.154 """
1.155
1.156 - subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.157 + subprogram = Subprogram(compare, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.158 self.current_subprograms.append(subprogram)
1.159
1.160 # In the subprogram, make instructions which invoke a method on the
1.161 @@ -365,29 +400,29 @@
1.162
1.163 method_name = self.comparison_methods[op_name]
1.164 if method_name:
1.165 - invocation = Invoke(expr=LoadAttr(expr=previous, name=method_name), args=[expr], star=None, dstar=None)
1.166 + invocation = Invoke(compare, expr=LoadAttr(compare, expr=previous, name=method_name), args=[expr], star=None, dstar=None)
1.167 elif op_name == "is":
1.168 - invocation = Invoke(expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None)
1.169 + invocation = Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None)
1.170 elif op_name == "is not":
1.171 - invocation = Not(expr=Invoke(expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None))
1.172 + invocation = Not(compare, expr=Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None))
1.173 else:
1.174 raise NotImplementedError, op_name
1.175 - nodes.append(StoreTemp(expr=invocation))
1.176 + nodes.append(StoreTemp(compare, expr=invocation))
1.177
1.178 # Return from the subprogram where the test is not satisfied.
1.179
1.180 if op is not last:
1.181 - test = Conditional(test=Not(expr=LoadTemp()), body=[Return(expr=LoadTemp())])
1.182 + test = Conditional(compare, test=Not(compare, expr=LoadTemp(compare)), body=[Return(compare, expr=LoadTemp(compare))])
1.183 nodes.append(test)
1.184
1.185 # Put subsequent operations in the else section of this conditional.
1.186
1.187 - nodes = test.else_ = [ReleaseTemp()]
1.188 + nodes = test.else_ = [ReleaseTemp(compare)]
1.189
1.190 # For the last operation, return the result.
1.191
1.192 else:
1.193 - nodes.append(Return(expr=LoadTemp()))
1.194 + nodes.append(Return(compare, expr=LoadTemp(compare)))
1.195
1.196 previous = expr
1.197
1.198 @@ -401,7 +436,7 @@
1.199 # Make an invocation of the subprogram.
1.200
1.201 result = InvokeBlock(compare, produces_result=1)
1.202 - result.expr = LoadRef(ref=subprogram)
1.203 + result.expr = LoadRef(compare, ref=subprogram)
1.204 return result
1.205
1.206 def visitAnd(self, and_):
1.207 @@ -421,7 +456,7 @@
1.208 (else) -> ...
1.209 """
1.210
1.211 - subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.212 + subprogram = Subprogram(and_, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.213 self.current_subprograms.append(subprogram)
1.214
1.215 # In the subprogram, make instructions which store each operand, test
1.216 @@ -437,19 +472,19 @@
1.217 # Return from the subprogram where the test is not satisfied.
1.218
1.219 if node is not last:
1.220 - nodes.append(StoreTemp(expr=expr))
1.221 - invocation = Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
1.222 - test = Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())])
1.223 + nodes.append(StoreTemp(and_, expr=expr))
1.224 + invocation = Invoke(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None)
1.225 + test = Conditional(and_, test=Not(and_, expr=invocation), body=[Return(and_, expr=LoadTemp(and_))])
1.226 nodes.append(test)
1.227
1.228 # Put subsequent operations in the else section of this conditional.
1.229
1.230 - nodes = test.else_ = [ReleaseTemp()]
1.231 + nodes = test.else_ = [ReleaseTemp(and_)]
1.232
1.233 # For the last operation, return the result.
1.234
1.235 else:
1.236 - nodes.append(Return(expr=expr))
1.237 + nodes.append(Return(and_, expr=expr))
1.238
1.239 # Finish the subprogram definition.
1.240
1.241 @@ -461,7 +496,7 @@
1.242 # Make an invocation of the subprogram.
1.243
1.244 result = InvokeBlock(and_, produces_result=1)
1.245 - result.expr = LoadRef(ref=subprogram)
1.246 + result.expr = LoadRef(and_, ref=subprogram)
1.247 return result
1.248
1.249 def visitOr(self, or_):
1.250 @@ -481,7 +516,7 @@
1.251 (else) -> ...
1.252 """
1.253
1.254 - subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.255 + subprogram = Subprogram(or_, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None)
1.256 self.current_subprograms.append(subprogram)
1.257
1.258 # In the subprogram, make instructions which store each operand, test
1.259 @@ -497,19 +532,21 @@
1.260 # Return from the subprogram where the test is satisfied.
1.261
1.262 if node is not last:
1.263 - nodes.append(StoreTemp(expr=expr))
1.264 - invocation = Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
1.265 - test = Conditional(test=invocation, body=[Return(expr=LoadTemp())])
1.266 + nodes.append(StoreTemp(or_, expr=expr))
1.267 + invocation = Invoke(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None)
1.268 + test = Conditional(or_, test=invocation, body=[Return(or_, expr=LoadTemp(or_))])
1.269 nodes.append(test)
1.270
1.271 # Put subsequent operations in the else section of this conditional.
1.272
1.273 - nodes = test.else_ = [ReleaseTemp()]
1.274 + nodes = test.else_ = [ReleaseTemp(or_)]
1.275
1.276 # For the last operation, return the result.
1.277
1.278 else:
1.279 - nodes.append(Return(expr=expr))
1.280 + nodes.append(
1.281 + Return(or_, expr=expr)
1.282 + )
1.283
1.284 # Finish the subprogram definition.
1.285
1.286 @@ -521,23 +558,23 @@
1.287 # Make an invocation of the subprogram.
1.288
1.289 result = InvokeBlock(or_, produces_result=1)
1.290 - result.expr = LoadRef(ref=subprogram)
1.291 + result.expr = LoadRef(or_, ref=subprogram)
1.292 return result
1.293
1.294 def visitNot(self, not_):
1.295 - result = Not(not_, expr=Invoke(expr=LoadAttr(expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.296 + result = Not(not_, expr=Invoke(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.297 return result
1.298
1.299 # Operators.
1.300
1.301 def visitUnaryAdd(self, unaryadd):
1.302 - return Invoke(unaryadd, expr=LoadAttr(expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.303 + return Invoke(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.304
1.305 def visitUnarySub(self, unarysub):
1.306 - return Invoke(unarysub, expr=LoadAttr(expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.307 + return Invoke(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.308
1.309 def visitInvert(self, invert):
1.310 - return Invoke(invert, expr=LoadAttr(expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.311 + return Invoke(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.312
1.313 def visitAdd(self, add):
1.314
1.315 @@ -553,15 +590,27 @@
1.316
1.317 result = Try(add,
1.318 body=[
1.319 - Invoke(expr=LoadAttr(expr=self.dispatch(add.left), name="__add__"), args=[self.dispatch(add.right)], star=None, dstar=None)
1.320 + Invoke(add,
1.321 + expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"),
1.322 + args=[self.dispatch(add.right)],
1.323 + star=None,
1.324 + dstar=None)
1.325 ],
1.326 else_=[],
1.327 finally_=[],
1.328 handler=[
1.329 - Conditional(
1.330 - test=Invoke(expr=LoadName(name="isinstance"), args=[LoadExc(), LoadName(name="TypeError")], star=None, dstar=None),
1.331 + Conditional(add,
1.332 + test=Invoke(add,
1.333 + expr=LoadName(add, name="isinstance"),
1.334 + args=[LoadExc(add), LoadName(add, name="TypeError")],
1.335 + star=None,
1.336 + dstar=None),
1.337 body=[
1.338 - Invoke(expr=LoadAttr(expr=self.dispatch(add.right), name="__radd__"), args=[self.dispatch(add.left)], star=None, dstar=None)
1.339 + Invoke(add,
1.340 + expr=LoadAttr(add, expr=self.dispatch(add.right), name="__radd__"),
1.341 + args=[self.dispatch(add.left)],
1.342 + star=None,
1.343 + dstar=None)
1.344 ],
1.345 else_=[]
1.346 )
1.347 @@ -586,19 +635,21 @@
1.348
1.349 if isinstance(augassign.node, compiler.ast.Name):
1.350 result.code = [
1.351 - StoreTemp(
1.352 - expr=Invoke(
1.353 - args=[expr], star=None, dstar=None,
1.354 - expr=LoadAttr(
1.355 + StoreTemp(augassign,
1.356 + expr=Invoke(augassign,
1.357 + args=[expr],
1.358 + star=None,
1.359 + dstar=None,
1.360 + expr=LoadAttr(augassign,
1.361 expr=self.dispatch(augassign.node),
1.362 name=self.augassign_methods[augassign.op]
1.363 )
1.364 )
1.365 ),
1.366 - StoreName(
1.367 - expr=LoadTemp(),
1.368 + StoreName(augassign,
1.369 + expr=LoadTemp(augassign),
1.370 name=augassign.node.name),
1.371 - ReleaseTemp()
1.372 + ReleaseTemp(augassign)
1.373 ]
1.374
1.375 # Complicated augmented assignment: lvalue.attr += expr
1.376 @@ -608,29 +659,29 @@
1.377 # <lvalue> -> setattr(<lvalue>, getattr(<lvalue>, "attr").__xxx__(expr))
1.378
1.379 result.code = [
1.380 - StoreTemp(
1.381 + StoreTemp(augassign,
1.382 index="expr",
1.383 expr=self.dispatch(augassign.node.expr)
1.384 ),
1.385 - StoreTemp(
1.386 - expr=Invoke(
1.387 + StoreTemp(augassign,
1.388 + expr=Invoke(augassign,
1.389 args=[expr], star=None, dstar=None,
1.390 - expr=LoadAttr(
1.391 - expr=LoadAttr(
1.392 - expr=LoadTemp(index="expr"),
1.393 + expr=LoadAttr(augassign,
1.394 + expr=LoadAttr(augassign,
1.395 + expr=LoadTemp(augassign, index="expr"),
1.396 name=augassign.node.attrname
1.397 ),
1.398 name=self.augassign_methods[augassign.op]
1.399 )
1.400 )
1.401 ),
1.402 - StoreAttr(
1.403 - expr=LoadTemp(),
1.404 - lvalue=LoadTemp(index="expr"),
1.405 + StoreAttr(augassign,
1.406 + expr=LoadTemp(augassign),
1.407 + lvalue=LoadTemp(augassign, index="expr"),
1.408 name=augassign.node.attrname
1.409 ),
1.410 - ReleaseTemp(index="expr"),
1.411 - ReleaseTemp()
1.412 + ReleaseTemp(augassign, index="expr"),
1.413 + ReleaseTemp(augassign)
1.414 ]
1.415
1.416 # Complicated augassign using slices: lvalue[lower:upper] += expr
1.417 @@ -640,32 +691,44 @@
1.418 # <lvalue>, <lower>, <upper> -> <lvalue>.__setslice__(<lower>, <upper>, <lvalue>.__getslice__(<lower>, <upper>).__xxx__(expr))
1.419
1.420 result.code = [
1.421 - StoreTemp(
1.422 + StoreTemp(augassign,
1.423 index="expr",
1.424 expr=self.dispatch(augassign.node.expr)
1.425 ),
1.426 - StoreTemp(
1.427 + StoreTemp(augassign,
1.428 index="lower",
1.429 expr=self.dispatch_or_none(augassign.node.lower)
1.430 ),
1.431 - StoreTemp(
1.432 + StoreTemp(augassign,
1.433 index="upper",
1.434 expr=self.dispatch_or_none(augassign.node.upper)
1.435 ),
1.436 - StoreTemp(
1.437 - expr=Invoke(
1.438 + StoreTemp(augassign,
1.439 + expr=Invoke(augassign,
1.440 args=[expr], star=None, dstar=None,
1.441 - expr=LoadAttr(
1.442 - expr=self._visitSlice(augassign.node, LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_APPLY"),
1.443 + expr=LoadAttr(augassign,
1.444 + expr=self._visitSlice(
1.445 + augassign.node,
1.446 + LoadTemp(augassign, index="expr"),
1.447 + LoadTemp(augassign, index="lower"),
1.448 + LoadTemp(augassign, index="upper"),
1.449 + "OP_APPLY"),
1.450 name=self.augassign_methods[augassign.op]
1.451 )
1.452 )
1.453 ),
1.454 - self._visitSlice(augassign.node, LoadTemp(index="expr"), LoadTemp(index="lower"), LoadTemp(index="upper"), "OP_ASSIGN", LoadTemp()),
1.455 - ReleaseTemp(index="expr"),
1.456 - ReleaseTemp(index="lower"),
1.457 - ReleaseTemp(index="upper"),
1.458 - ReleaseTemp()
1.459 + self._visitSlice(
1.460 + augassign.node,
1.461 + LoadTemp(augassign, index="expr"),
1.462 + LoadTemp(augassign, index="lower"),
1.463 + LoadTemp(augassign, index="upper"),
1.464 + "OP_ASSIGN",
1.465 + LoadTemp(augassign)
1.466 + ),
1.467 + ReleaseTemp(augassign, index="expr"),
1.468 + ReleaseTemp(augassign, index="lower"),
1.469 + ReleaseTemp(augassign, index="upper"),
1.470 + ReleaseTemp(augassign)
1.471 ]
1.472
1.473 # Complicated augassign using subscripts: lvalue[subs] += expr
1.474 @@ -675,21 +738,32 @@
1.475 # <lvalue>, <subs> -> <lvalue>.__setitem__(<subs>, <lvalue>.__getitem__(<subs>).__xxx__(expr))
1.476
1.477 result.code = [
1.478 - StoreTemp(index="expr", expr=self.dispatch(augassign.node.expr)),
1.479 - StoreTemp(index="subs", expr=self._visitSubscriptSubs(augassign.node.subs)),
1.480 - StoreTemp(
1.481 - expr=Invoke(
1.482 + StoreTemp(augassign, index="expr", expr=self.dispatch(augassign.node.expr)),
1.483 + StoreTemp(augassign, index="subs", expr=self._visitSubscriptSubs(augassign.node.subs)),
1.484 + StoreTemp(augassign,
1.485 + expr=Invoke(augassign,
1.486 args=[expr], star=None, dstar=None,
1.487 - expr=LoadAttr(
1.488 - expr=self._visitSubscript(augassign.node, LoadTemp(index="expr"), LoadTemp(index="subs"), "OP_APPLY"),
1.489 + expr=LoadAttr(augassign,
1.490 + expr=self._visitSubscript(
1.491 + augassign.node,
1.492 + LoadTemp(augassign, index="expr"),
1.493 + LoadTemp(augassign, index="subs"),
1.494 + "OP_APPLY"
1.495 + ),
1.496 name=self.augassign_methods[augassign.op]
1.497 )
1.498 )
1.499 ),
1.500 - self._visitSubscript(augassign.node, LoadTemp(index="expr"), LoadTemp(index="subs"), "OP_ASSIGN", LoadTemp()),
1.501 - ReleaseTemp(index="expr"),
1.502 - ReleaseTemp(index="subs"),
1.503 - ReleaseTemp()
1.504 + self._visitSubscript(
1.505 + augassign.node,
1.506 + LoadTemp(augassign, index="expr"),
1.507 + LoadTemp(augassign, index="subs"),
1.508 + "OP_ASSIGN",
1.509 + LoadTemp(augassign)
1.510 + ),
1.511 + ReleaseTemp(augassign, index="expr"),
1.512 + ReleaseTemp(augassign, index="subs"),
1.513 + ReleaseTemp(augassign)
1.514 ]
1.515
1.516 else:
1.517 @@ -699,19 +773,19 @@
1.518
1.519 def visitAssign(self, assign):
1.520 result = Assign(assign)
1.521 - store = StoreTemp(expr=self.dispatch(assign.expr))
1.522 - release = ReleaseTemp()
1.523 + store = StoreTemp(assign, expr=self.dispatch(assign.expr))
1.524 + release = ReleaseTemp(assign)
1.525 result.code = [store] + self.dispatches(assign.nodes, 0) + [release]
1.526 return result
1.527
1.528 def visitAssList(self, asslist, in_sequence=0):
1.529 if not in_sequence:
1.530 - expr = LoadTemp()
1.531 + expr = LoadTemp(asslist)
1.532 else:
1.533 - expr = Invoke(expr=LoadAttr(expr=LoadTemp(), name="next"), star=None, dstar=None, args=[])
1.534 + expr = Invoke(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
1.535 result = Assign(asslist)
1.536 - store = StoreTemp(expr=Invoke(expr=LoadAttr(name="__iter__", expr=expr), star=None, dstar=None, args=[]))
1.537 - release = ReleaseTemp()
1.538 + store = StoreTemp(asslist, expr=Invoke(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
1.539 + release = ReleaseTemp(asslist)
1.540 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
1.541 return result
1.542
1.543 @@ -719,9 +793,9 @@
1.544
1.545 def _visitAssNameOrAttr(self, node, in_sequence):
1.546 if not in_sequence:
1.547 - return LoadTemp()
1.548 + return LoadTemp(node)
1.549 else:
1.550 - return Invoke(expr=LoadAttr(expr=LoadTemp(), name="next"), star=None, dstar=None, args=[])
1.551 + return Invoke(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[])
1.552
1.553 def visitAssName(self, assname, in_sequence=0):
1.554 expr = self._visitAssNameOrAttr(assname, in_sequence)
1.555 @@ -737,13 +811,13 @@
1.556 def _visitSlice(self, slice, expr, lower, upper, flags, value=None):
1.557 if flags == "OP_ASSIGN":
1.558 args = [value]
1.559 - result = Invoke(expr=LoadAttr(expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.560 + result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.561 elif flags == "OP_APPLY":
1.562 args = []
1.563 - result = Invoke(expr=LoadAttr(expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.564 + result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.565 elif flags == "OP_DELETE":
1.566 args = []
1.567 - result = Invoke(expr=LoadAttr(expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.568 + result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.569 else:
1.570 raise NotImplementedError, flags
1.571
1.572 @@ -763,13 +837,13 @@
1.573 def _visitSubscript(self, subscript, expr, subs, flags, value=None):
1.574 if flags == "OP_ASSIGN":
1.575 args = [value]
1.576 - result = Invoke(expr=LoadAttr(expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.577 + result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.578 elif flags == "OP_APPLY":
1.579 args = []
1.580 - result = Invoke(expr=LoadAttr(expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.581 + result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.582 elif flags == "OP_DELETE":
1.583 args = []
1.584 - result = Invoke(expr=LoadAttr(expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.585 + result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.586 else:
1.587 raise NotImplementedError, flags
1.588
1.589 @@ -785,7 +859,7 @@
1.590 if len(subs) == 1:
1.591 return self.dispatch(subs[0])
1.592 else:
1.593 - return Invoke(expr=LoadName(name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
1.594 + return Invoke(subs, expr=LoadName(subs, name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
1.595
1.596 def visitSubscript(self, subscript, in_sequence=0):
1.597 return self._visitSubscript(
1.598 @@ -796,17 +870,17 @@
1.599 # Invocation and subprogram transformations.
1.600
1.601 def visitClass(self, class_):
1.602 - structure = Class(name=class_.name, bases=self.dispatches(class_.bases))
1.603 + structure = Class(class_, name=class_.name, bases=self.dispatches(class_.bases))
1.604 self.structures.append(structure)
1.605
1.606 # Make a subprogram which initialises the class structure.
1.607
1.608 - subprogram = Subprogram(name=None, structure=structure, params=[], star=None, dstar=None)
1.609 + subprogram = Subprogram(class_, name=None, structure=structure, params=[], star=None, dstar=None)
1.610 self.current_subprograms.append(subprogram)
1.611
1.612 # The class is initialised using the code found inside.
1.613
1.614 - subprogram.code = self.dispatch(class_.code) + [Return()]
1.615 + subprogram.code = self.dispatch(class_.code) + [Return(class_)]
1.616
1.617 self.current_subprograms.pop()
1.618 self.subprograms.append(subprogram)
1.619 @@ -815,13 +889,13 @@
1.620
1.621 result = Assign(class_,
1.622 code=[
1.623 - StoreName(
1.624 + StoreName(class_,
1.625 name=class_.name,
1.626 - expr=LoadRef(ref=structure)
1.627 + expr=LoadRef(class_, ref=structure)
1.628 ),
1.629 - Invoke(
1.630 + Invoke(class_,
1.631 args=[], star=None, dstar=None,
1.632 - expr=LoadRef(ref=subprogram)
1.633 + expr=LoadRef(class_, ref=subprogram)
1.634 )
1.635 ]
1.636 )
1.637 @@ -853,11 +927,11 @@
1.638 # Produce star and dstar parameters with appropriate defaults.
1.639
1.640 if has_star:
1.641 - star = (function.argnames[npositional], Invoke(expr=LoadName(name="list"), args=[], star=None, dstar=None))
1.642 + star = (function.argnames[npositional], Invoke(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
1.643 else:
1.644 star = None
1.645 if has_dstar:
1.646 - dstar = (function.argnames[npositional + has_star], Invoke(expr=LoadName(name="dict"), args=[], star=None, dstar=None))
1.647 + dstar = (function.argnames[npositional + has_star], Invoke(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
1.648 else:
1.649 dstar = None
1.650
1.651 @@ -886,13 +960,13 @@
1.652
1.653 subprogram = Subprogram(function, name=function.name, acquire_locals=0, returns_value=1, star=None, dstar=None)
1.654 self.current_subprograms.append(subprogram)
1.655 - subprogram.code = self.dispatch(function.code) + [Return()]
1.656 + subprogram.code = self.dispatch(function.code) + [Return(function)]
1.657 self.current_subprograms.pop()
1.658 self._visitFunction(function, subprogram)
1.659
1.660 # Make a definition of the function associating it with a name.
1.661
1.662 - result = StoreName(name=function.name, expr=LoadRef(ref=subprogram))
1.663 + result = StoreName(function, name=function.name, expr=LoadRef(function, ref=subprogram))
1.664 return result
1.665
1.666 def visitLambda(self, lambda_):
1.667 @@ -900,9 +974,9 @@
1.668 # Make a subprogram for the function and record it outside the main
1.669 # tree.
1.670
1.671 - subprogram = Subprogram(name=None, acquire_locals=0, returns_value=1, star=None, dstar=None)
1.672 + subprogram = Subprogram(lambda_, name=None, acquire_locals=0, returns_value=1, star=None, dstar=None)
1.673 self.current_subprograms.append(subprogram)
1.674 - subprogram.code = [Return(expr=self.dispatch(lambda_.code))]
1.675 + subprogram.code = [Return(lambda_, expr=self.dispatch(lambda_.code))]
1.676 self.current_subprograms.pop()
1.677 self._visitFunction(lambda_, subprogram)
1.678
1.679 @@ -936,28 +1010,28 @@
1.680 (else) -> ...
1.681 """
1.682
1.683 - subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None)
1.684 + subprogram = Subprogram(while_, name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None)
1.685 self.current_subprograms.append(subprogram)
1.686
1.687 # Include a conditional statement in the subprogram.
1.688
1.689 - test = Conditional(else_=[])
1.690 - test.test = Invoke(expr=LoadAttr(expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
1.691 + test = Conditional(while_, else_=[])
1.692 + test.test = Invoke(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
1.693
1.694 # Inside the conditional, add a recursive invocation to the subprogram
1.695 # if the test condition was satisfied.
1.696
1.697 - continuation = InvokeBlock()
1.698 - continuation.expr = LoadRef(ref=subprogram)
1.699 + continuation = InvokeBlock(while_)
1.700 + continuation.expr = LoadRef(while_, ref=subprogram)
1.701
1.702 # Return within the main section of the loop.
1.703
1.704 - test.body = self.dispatch(while_.body) + [continuation, Return()]
1.705 + test.body = self.dispatch(while_.body) + [continuation, Return(while_)]
1.706
1.707 # Provide the else section, if present, along with an explicit return.
1.708
1.709 if while_.else_ is not None:
1.710 - test.else_ = self.dispatch(while_.else_) + [Return()]
1.711 + test.else_ = self.dispatch(while_.else_) + [Return(while_)]
1.712
1.713 # Finish the subprogram definition.
1.714
1.715 @@ -969,7 +1043,7 @@
1.716 # Make an invocation of the subprogram.
1.717
1.718 result = InvokeBlock(while_)
1.719 - result.expr = LoadRef(ref=subprogram)
1.720 + result.expr = LoadRef(while_, ref=subprogram)
1.721 return result
1.722
1.723 def visitFor(self, for_):
1.724 @@ -992,39 +1066,39 @@
1.725 (else) -> ...
1.726 """
1.727
1.728 - subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None)
1.729 + subprogram = Subprogram(for_, name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None)
1.730 self.current_subprograms.append(subprogram)
1.731
1.732 # Always return from conditional sections/subprograms.
1.733
1.734 if for_.else_ is not None:
1.735 - else_stmt = self.dispatch(for_.else_) + [Return()]
1.736 + else_stmt = self.dispatch(for_.else_) + [Return(for_)]
1.737 else:
1.738 - else_stmt = [Return()]
1.739 + else_stmt = [Return(for_)]
1.740
1.741 # Wrap the assignment in a try...except statement.
1.742
1.743 - try_except = Try(body=[], else_=[], finally_=[])
1.744 - test = Conditional(
1.745 - test=Invoke(expr=LoadName(name="isinstance"), args=[LoadExc(), LoadName(name="StopIteration")], star=None, dstar=None),
1.746 + try_except = Try(for_, body=[], else_=[], finally_=[])
1.747 + test = Conditional(for_,
1.748 + test=Invoke(for_, expr=LoadName(for_, name="isinstance"), args=[LoadExc(for_), LoadName(for_, name="StopIteration")], star=None, dstar=None),
1.749 body=else_stmt,
1.750 - else_=[Raise(expr=LoadExc())])
1.751 + else_=[Raise(for_, expr=LoadExc(for_))])
1.752 try_except.handler = [test]
1.753
1.754 - assign = Assign()
1.755 - assign.code = [
1.756 - StoreTemp(expr=Invoke(expr=LoadAttr(expr=LoadTemp(), name="next"), args=[], star=None, dstar=None)),
1.757 - self.dispatch(for_.assign),
1.758 - ReleaseTemp()
1.759 - ]
1.760 + assign = Assign(for_,
1.761 + code=[
1.762 + StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)),
1.763 + self.dispatch(for_.assign),
1.764 + ReleaseTemp(for_)
1.765 + ])
1.766
1.767 # Inside the conditional, add a recursive invocation to the subprogram
1.768 # if the test condition was satisfied.
1.769
1.770 - continuation = InvokeBlock()
1.771 - continuation.expr = LoadRef(ref=subprogram)
1.772 + continuation = InvokeBlock(for_)
1.773 + continuation.expr = LoadRef(for_, ref=subprogram)
1.774 try_except.body = [assign] + self.dispatch(for_.body) + [continuation]
1.775 - subprogram.code = [try_except, Return()]
1.776 + subprogram.code = [try_except, Return(for_)]
1.777
1.778 # Finish the subprogram definition.
1.779
1.780 @@ -1036,9 +1110,9 @@
1.781
1.782 result = Assign(for_)
1.783 result.code = [
1.784 - StoreTemp(expr=Invoke(expr=LoadAttr(name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
1.785 - InvokeBlock(expr=LoadRef(ref=subprogram)),
1.786 - ReleaseTemp()
1.787 + StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
1.788 + InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)),
1.789 + ReleaseTemp(for_)
1.790 ]
1.791 return result
1.792