4.1 --- a/simplify.py Sat Oct 14 02:17:40 2006 +0200
4.2 +++ b/simplify.py Sun Oct 15 01:03:44 2006 +0200
4.3 @@ -91,7 +91,7 @@
4.4 if node is not None:
4.5 return self.dispatch(node, *args)
4.6 else:
4.7 - return LoadName(name="None")
4.8 + return LoadName(node, name="None")
4.9
4.10 # Placeholder or deletion transformations.
4.11
4.12 @@ -99,7 +99,7 @@
4.13 return self.dispatches(stmt.nodes)
4.14
4.15 def visitPass(self, pass_):
4.16 - return Pass(pass_)
4.17 + return Pass(pass_, 1)
4.18
4.19 def visitDiscard(self, discard):
4.20 return self.dispatch(discard.expr)
4.21 @@ -113,7 +113,7 @@
4.22 resulting program nodes.
4.23 """
4.24
4.25 - result = Module(module, name="module")
4.26 + result = Module(module, 1, name="module")
4.27 module_code = self.dispatch(module.node)
4.28
4.29 # NOTE: Constant initialisation necessary for annotation but perhaps
4.30 @@ -138,27 +138,27 @@
4.31 return result
4.32
4.33 def visitGetattr(self, getattr):
4.34 - result = LoadAttr(getattr,
4.35 + result = LoadAttr(getattr, 1,
4.36 name=getattr.attrname,
4.37 expr=self.dispatch(getattr.expr)
4.38 )
4.39 return result
4.40
4.41 def visitKeyword(self, keyword):
4.42 - result = Keyword(keyword,
4.43 + result = Keyword(keyword, 1,
4.44 name=keyword.name,
4.45 expr=self.dispatch(keyword.expr)
4.46 )
4.47 return result
4.48
4.49 def visitGlobal(self, global_):
4.50 - result = Global(global_,
4.51 + result = Global(global_, 1,
4.52 names=global_.names
4.53 )
4.54 return result
4.55
4.56 def visitImport(self, import_):
4.57 - result = Assign(import_)
4.58 + result = Assign(import_, 1)
4.59 code = []
4.60 for path, alias in import_.names:
4.61 importer = Import(import_, name=path)
4.62 @@ -168,7 +168,7 @@
4.63 return result
4.64
4.65 def visitFrom(self, from_):
4.66 - result = Assign(from_)
4.67 + result = Assign(from_, 1)
4.68 code = []
4.69 code.append(StoreTemp(from_, expr=Import(from_, name=from_.modname)))
4.70 for name, alias in from_.names:
4.71 @@ -184,33 +184,33 @@
4.72 return result
4.73
4.74 def visitName(self, name):
4.75 - result = LoadName(name, name=name.name)
4.76 + result = LoadName(name, 1, name=name.name)
4.77 return result
4.78
4.79 def visitConst(self, const):
4.80 if not self.constants.has_key(const.value):
4.81 self.constants[const.value] = Constant(const, name=repr(const.value), value=const.value)
4.82 - result = LoadRef(const, ref=self.constants[const.value])
4.83 + result = LoadRef(const, 1, ref=self.constants[const.value])
4.84 return result
4.85
4.86 def visitReturn(self, return_):
4.87 - result = Return(return_,
4.88 + result = Return(return_, 1,
4.89 expr=self.dispatch(return_.value)
4.90 )
4.91 return result
4.92
4.93 def visitBreak(self, break_):
4.94 - result = Return(break_)
4.95 + result = Return(break_, 1)
4.96 return result
4.97
4.98 def visitContinue(self, continue_):
4.99 - result = InvokeBlock(continue_,
4.100 + result = InvokeBlock(continue_, 1,
4.101 expr=LoadRef(continue_, ref=self.current_subprograms[-1])
4.102 )
4.103 return result
4.104
4.105 def visitRaise(self, raise_):
4.106 - result = Raise(raise_, expr=self.dispatch(raise_.expr1), traceback=None)
4.107 + result = Raise(raise_, 1, expr=self.dispatch(raise_.expr1), traceback=None)
4.108 if raise_.expr2 is not None:
4.109 result.args = [self.dispatch(raise_.expr2)]
4.110 if raise_.expr3 is not None:
4.111 @@ -218,7 +218,7 @@
4.112 return result
4.113
4.114 def _visitBuiltin(self, builtin, name):
4.115 - result = InvokeFunction(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
4.116 + result = InvokeFunction(builtin, 1, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
4.117 return result
4.118
4.119 def visitTuple(self, tuple):
4.120 @@ -228,7 +228,7 @@
4.121 return self._visitBuiltin(list, "list")
4.122
4.123 def visitDict(self, dict):
4.124 - result = InvokeFunction(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
4.125 + result = InvokeFunction(dict, 1, expr=LoadName(dict, name="dict"), star=None, dstar=None)
4.126 args = []
4.127 for key, value in dict.items:
4.128 tuple = InvokeFunction(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
4.129 @@ -266,8 +266,12 @@
4.130 # Produce something like...
4.131 # expr.__true__() ? body
4.132
4.133 + first = 1
4.134 for compare, stmt in if_.tests:
4.135 - test = Conditional(if_,
4.136 +
4.137 + # Set the first as the defining node.
4.138 +
4.139 + test = Conditional(if_, first,
4.140 test=InvokeFunction(if_,
4.141 expr=LoadAttr(if_,
4.142 expr=self.dispatch(compare),
4.143 @@ -280,6 +284,7 @@
4.144 test.body = self.dispatch(stmt)
4.145 nodes.append(test)
4.146 nodes = test.else_ = []
4.147 + first = 0
4.148
4.149 # Add the compound statement from any else clause to the end.
4.150
4.151 @@ -312,7 +317,7 @@
4.152 (else) -> ...
4.153 """
4.154
4.155 - result = Try(tryexcept, body=[], else_=[], finally_=[])
4.156 + result = Try(tryexcept, 1, body=[], else_=[], finally_=[])
4.157
4.158 if tryexcept.body is not None:
4.159 result.body = self.dispatch(tryexcept.body)
4.160 @@ -459,11 +464,11 @@
4.161 subprogram.code = results
4.162
4.163 self.current_subprograms.pop()
4.164 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.165 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.166
4.167 # Make an invocation of the subprogram.
4.168
4.169 - result = InvokeBlock(compare, produces_result=1)
4.170 + result = InvokeBlock(compare, 1, produces_result=1)
4.171 result.expr = LoadRef(compare, ref=subprogram)
4.172 return result
4.173
4.174 @@ -519,11 +524,11 @@
4.175 subprogram.code = results
4.176
4.177 self.current_subprograms.pop()
4.178 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.179 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.180
4.181 # Make an invocation of the subprogram.
4.182
4.183 - result = InvokeBlock(and_, produces_result=1)
4.184 + result = InvokeBlock(and_, 1, produces_result=1)
4.185 result.expr = LoadRef(and_, ref=subprogram)
4.186 return result
4.187
4.188 @@ -581,28 +586,28 @@
4.189 subprogram.code = results
4.190
4.191 self.current_subprograms.pop()
4.192 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.193 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.194
4.195 # Make an invocation of the subprogram.
4.196
4.197 - result = InvokeBlock(or_, produces_result=1)
4.198 + result = InvokeBlock(or_, 1, produces_result=1)
4.199 result.expr = LoadRef(or_, ref=subprogram)
4.200 return result
4.201
4.202 def visitNot(self, not_):
4.203 - result = Not(not_, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
4.204 + result = Not(not_, 1, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
4.205 return result
4.206
4.207 # Operators.
4.208
4.209 def visitUnaryAdd(self, unaryadd):
4.210 - return InvokeFunction(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
4.211 + return InvokeFunction(unaryadd, 1, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
4.212
4.213 def visitUnarySub(self, unarysub):
4.214 - return InvokeFunction(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
4.215 + return InvokeFunction(unarysub, 1, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
4.216
4.217 def visitInvert(self, invert):
4.218 - return InvokeFunction(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
4.219 + return InvokeFunction(invert, 1, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
4.220
4.221 def visitAdd(self, add):
4.222
4.223 @@ -616,7 +621,7 @@
4.224 (else)
4.225 """
4.226
4.227 - result = Try(add,
4.228 + result = Try(add, 1,
4.229 body=[
4.230 InvokeFunction(add,
4.231 expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"),
4.232 @@ -656,7 +661,7 @@
4.233 }
4.234
4.235 def visitAugAssign(self, augassign):
4.236 - result = Assign(augassign)
4.237 + result = Assign(augassign, 1)
4.238 expr = self.dispatch(augassign.expr)
4.239
4.240 # Simple augmented assignment: name += expr
4.241 @@ -800,7 +805,7 @@
4.242 return result
4.243
4.244 def visitAssign(self, assign):
4.245 - result = Assign(assign)
4.246 + result = Assign(assign, 1)
4.247 store = StoreTemp(assign, expr=self.dispatch(assign.expr))
4.248 release = ReleaseTemp(assign)
4.249 result.code = [store] + self.dispatches(assign.nodes, 0) + [release]
4.250 @@ -811,7 +816,7 @@
4.251 expr = LoadTemp(asslist)
4.252 else:
4.253 expr = InvokeFunction(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
4.254 - result = Assign(asslist)
4.255 + result = Assign(asslist, 1)
4.256 store = StoreTemp(asslist, expr=InvokeFunction(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
4.257 release = ReleaseTemp(asslist)
4.258 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
4.259 @@ -827,25 +832,25 @@
4.260
4.261 def visitAssName(self, assname, in_sequence=0):
4.262 expr = self._visitAssNameOrAttr(assname, in_sequence)
4.263 - result = StoreName(assname, name=assname.name, expr=expr)
4.264 + result = StoreName(assname, 1, name=assname.name, expr=expr)
4.265 return result
4.266
4.267 def visitAssAttr(self, assattr, in_sequence=0):
4.268 expr = self._visitAssNameOrAttr(assattr, in_sequence)
4.269 lvalue = self.dispatch(assattr.expr)
4.270 - result = StoreAttr(assattr, name=assattr.attrname, lvalue=lvalue, expr=expr)
4.271 + result = StoreAttr(assattr, 1, name=assattr.attrname, lvalue=lvalue, expr=expr)
4.272 return result
4.273
4.274 def _visitSlice(self, slice, expr, lower, upper, flags, value=None):
4.275 if flags == "OP_ASSIGN":
4.276 args = [value]
4.277 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
4.278 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
4.279 elif flags == "OP_APPLY":
4.280 args = []
4.281 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
4.282 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
4.283 elif flags == "OP_DELETE":
4.284 args = []
4.285 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
4.286 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
4.287 else:
4.288 raise NotImplementedError, flags
4.289
4.290 @@ -865,13 +870,13 @@
4.291 def _visitSubscript(self, subscript, expr, subs, flags, value=None):
4.292 if flags == "OP_ASSIGN":
4.293 args = [value]
4.294 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
4.295 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
4.296 elif flags == "OP_APPLY":
4.297 args = []
4.298 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
4.299 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
4.300 elif flags == "OP_DELETE":
4.301 args = []
4.302 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
4.303 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
4.304 else:
4.305 raise NotImplementedError, flags
4.306
4.307 @@ -887,7 +892,7 @@
4.308 if len(subs) == 1:
4.309 return self.dispatch(subs[0])
4.310 else:
4.311 - return InvokeFunction(node,
4.312 + return InvokeFunction(node, 1,
4.313 expr=LoadName(node, name="tuple"),
4.314 args=self.dispatches(subs),
4.315 star=None,
4.316 @@ -915,13 +920,13 @@
4.317 subprogram.code = self.dispatch(class_.code) + [Return(class_)]
4.318
4.319 self.current_subprograms.pop()
4.320 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.321 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.322
4.323 # Make a definition of the class associating it with a name.
4.324
4.325 result = Assign(class_,
4.326 code=[
4.327 - StoreName(class_,
4.328 + StoreName(class_, 1, # defines the class
4.329 name=class_.name,
4.330 expr=LoadRef(class_, ref=structure)
4.331 ),
4.332 @@ -958,11 +963,17 @@
4.333 # Produce star and dstar parameters with appropriate defaults.
4.334
4.335 if has_star:
4.336 - star = (function.argnames[npositional], InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
4.337 + star = (
4.338 + function.argnames[npositional],
4.339 + InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None)
4.340 + )
4.341 else:
4.342 star = None
4.343 if has_dstar:
4.344 - dstar = (function.argnames[npositional + has_star], InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
4.345 + dstar = (
4.346 + function.argnames[npositional + has_star],
4.347 + InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None)
4.348 + )
4.349 else:
4.350 dstar = None
4.351
4.352 @@ -982,7 +993,7 @@
4.353 subprogram.params = params
4.354 subprogram.star = star
4.355 subprogram.dstar = dstar
4.356 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.357 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.358
4.359 def visitFunction(self, function):
4.360
4.361 @@ -997,7 +1008,7 @@
4.362
4.363 # Make a definition of the function associating it with a name.
4.364
4.365 - result = StoreName(function, name=function.name, expr=LoadRef(function, ref=subprogram))
4.366 + result = StoreName(function, 1, name=function.name, expr=LoadRef(function, ref=subprogram))
4.367 return result
4.368
4.369 def visitLambda(self, lambda_):
4.370 @@ -1013,10 +1024,10 @@
4.371
4.372 # Get the subprogram reference to the lambda.
4.373
4.374 - return LoadRef(lambda_, ref=subprogram)
4.375 + return LoadRef(lambda_, 1, ref=subprogram)
4.376
4.377 def visitCallFunc(self, callfunc):
4.378 - result = InvokeFunction(callfunc, star=None, dstar=None, args=self.dispatches(callfunc.args))
4.379 + result = InvokeFunction(callfunc, 1, star=None, dstar=None, args=self.dispatches(callfunc.args))
4.380 if callfunc.star_args is not None:
4.381 result.star = self.dispatch(callfunc.star_args)
4.382 if callfunc.dstar_args is not None:
4.383 @@ -1068,11 +1079,11 @@
4.384 subprogram.code = [test]
4.385
4.386 self.current_subprograms.pop()
4.387 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.388 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.389
4.390 # Make an invocation of the subprogram.
4.391
4.392 - result = InvokeBlock(while_)
4.393 + result = InvokeBlock(while_, 1)
4.394 result.expr = LoadRef(while_, ref=subprogram)
4.395 return result
4.396
4.397 @@ -1137,14 +1148,24 @@
4.398 # Finish the subprogram definition.
4.399
4.400 self.current_subprograms.pop()
4.401 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
4.402 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
4.403
4.404 # Obtain an iterator for the sequence involved.
4.405 # Then, make an invocation of the subprogram.
4.406
4.407 - result = Assign(for_)
4.408 + result = Assign(for_, 1)
4.409 result.code = [
4.410 - StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
4.411 + StoreTemp(for_,
4.412 + expr=InvokeFunction(for_,
4.413 + expr=LoadAttr(for_,
4.414 + name="__iter__",
4.415 + expr=self.dispatch(for_.list)
4.416 + ),
4.417 + args=[],
4.418 + star=None,
4.419 + dstar=None
4.420 + )
4.421 + ),
4.422 InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)),
4.423 ReleaseTemp(for_)
4.424 ]
4.425 @@ -1153,7 +1174,7 @@
4.426 # Exception node transformations.
4.427
4.428 def visitTryFinally(self, tryfinally):
4.429 - result = Try(tryfinally, body=[], else_=[], finally_=[])
4.430 + result = Try(tryfinally, 1, body=[], else_=[], finally_=[])
4.431 if tryfinally.body is not None:
4.432 result.body = self.dispatch(tryfinally.body)
4.433 if tryfinally.final is not None: