1.1 --- a/simplify.py Sat Oct 14 02:17:40 2006 +0200
1.2 +++ b/simplify.py Sun Oct 15 01:03:44 2006 +0200
1.3 @@ -91,7 +91,7 @@
1.4 if node is not None:
1.5 return self.dispatch(node, *args)
1.6 else:
1.7 - return LoadName(name="None")
1.8 + return LoadName(node, name="None")
1.9
1.10 # Placeholder or deletion transformations.
1.11
1.12 @@ -99,7 +99,7 @@
1.13 return self.dispatches(stmt.nodes)
1.14
1.15 def visitPass(self, pass_):
1.16 - return Pass(pass_)
1.17 + return Pass(pass_, 1)
1.18
1.19 def visitDiscard(self, discard):
1.20 return self.dispatch(discard.expr)
1.21 @@ -113,7 +113,7 @@
1.22 resulting program nodes.
1.23 """
1.24
1.25 - result = Module(module, name="module")
1.26 + result = Module(module, 1, name="module")
1.27 module_code = self.dispatch(module.node)
1.28
1.29 # NOTE: Constant initialisation necessary for annotation but perhaps
1.30 @@ -138,27 +138,27 @@
1.31 return result
1.32
1.33 def visitGetattr(self, getattr):
1.34 - result = LoadAttr(getattr,
1.35 + result = LoadAttr(getattr, 1,
1.36 name=getattr.attrname,
1.37 expr=self.dispatch(getattr.expr)
1.38 )
1.39 return result
1.40
1.41 def visitKeyword(self, keyword):
1.42 - result = Keyword(keyword,
1.43 + result = Keyword(keyword, 1,
1.44 name=keyword.name,
1.45 expr=self.dispatch(keyword.expr)
1.46 )
1.47 return result
1.48
1.49 def visitGlobal(self, global_):
1.50 - result = Global(global_,
1.51 + result = Global(global_, 1,
1.52 names=global_.names
1.53 )
1.54 return result
1.55
1.56 def visitImport(self, import_):
1.57 - result = Assign(import_)
1.58 + result = Assign(import_, 1)
1.59 code = []
1.60 for path, alias in import_.names:
1.61 importer = Import(import_, name=path)
1.62 @@ -168,7 +168,7 @@
1.63 return result
1.64
1.65 def visitFrom(self, from_):
1.66 - result = Assign(from_)
1.67 + result = Assign(from_, 1)
1.68 code = []
1.69 code.append(StoreTemp(from_, expr=Import(from_, name=from_.modname)))
1.70 for name, alias in from_.names:
1.71 @@ -184,33 +184,33 @@
1.72 return result
1.73
1.74 def visitName(self, name):
1.75 - result = LoadName(name, name=name.name)
1.76 + result = LoadName(name, 1, name=name.name)
1.77 return result
1.78
1.79 def visitConst(self, const):
1.80 if not self.constants.has_key(const.value):
1.81 self.constants[const.value] = Constant(const, name=repr(const.value), value=const.value)
1.82 - result = LoadRef(const, ref=self.constants[const.value])
1.83 + result = LoadRef(const, 1, ref=self.constants[const.value])
1.84 return result
1.85
1.86 def visitReturn(self, return_):
1.87 - result = Return(return_,
1.88 + result = Return(return_, 1,
1.89 expr=self.dispatch(return_.value)
1.90 )
1.91 return result
1.92
1.93 def visitBreak(self, break_):
1.94 - result = Return(break_)
1.95 + result = Return(break_, 1)
1.96 return result
1.97
1.98 def visitContinue(self, continue_):
1.99 - result = InvokeBlock(continue_,
1.100 + result = InvokeBlock(continue_, 1,
1.101 expr=LoadRef(continue_, ref=self.current_subprograms[-1])
1.102 )
1.103 return result
1.104
1.105 def visitRaise(self, raise_):
1.106 - result = Raise(raise_, expr=self.dispatch(raise_.expr1), traceback=None)
1.107 + result = Raise(raise_, 1, expr=self.dispatch(raise_.expr1), traceback=None)
1.108 if raise_.expr2 is not None:
1.109 result.args = [self.dispatch(raise_.expr2)]
1.110 if raise_.expr3 is not None:
1.111 @@ -218,7 +218,7 @@
1.112 return result
1.113
1.114 def _visitBuiltin(self, builtin, name):
1.115 - result = InvokeFunction(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.116 + result = InvokeFunction(builtin, 1, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.117 return result
1.118
1.119 def visitTuple(self, tuple):
1.120 @@ -228,7 +228,7 @@
1.121 return self._visitBuiltin(list, "list")
1.122
1.123 def visitDict(self, dict):
1.124 - result = InvokeFunction(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
1.125 + result = InvokeFunction(dict, 1, expr=LoadName(dict, name="dict"), star=None, dstar=None)
1.126 args = []
1.127 for key, value in dict.items:
1.128 tuple = InvokeFunction(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
1.129 @@ -266,8 +266,12 @@
1.130 # Produce something like...
1.131 # expr.__true__() ? body
1.132
1.133 + first = 1
1.134 for compare, stmt in if_.tests:
1.135 - test = Conditional(if_,
1.136 +
1.137 + # Set the first as the defining node.
1.138 +
1.139 + test = Conditional(if_, first,
1.140 test=InvokeFunction(if_,
1.141 expr=LoadAttr(if_,
1.142 expr=self.dispatch(compare),
1.143 @@ -280,6 +284,7 @@
1.144 test.body = self.dispatch(stmt)
1.145 nodes.append(test)
1.146 nodes = test.else_ = []
1.147 + first = 0
1.148
1.149 # Add the compound statement from any else clause to the end.
1.150
1.151 @@ -312,7 +317,7 @@
1.152 (else) -> ...
1.153 """
1.154
1.155 - result = Try(tryexcept, body=[], else_=[], finally_=[])
1.156 + result = Try(tryexcept, 1, body=[], else_=[], finally_=[])
1.157
1.158 if tryexcept.body is not None:
1.159 result.body = self.dispatch(tryexcept.body)
1.160 @@ -459,11 +464,11 @@
1.161 subprogram.code = results
1.162
1.163 self.current_subprograms.pop()
1.164 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.165 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.166
1.167 # Make an invocation of the subprogram.
1.168
1.169 - result = InvokeBlock(compare, produces_result=1)
1.170 + result = InvokeBlock(compare, 1, produces_result=1)
1.171 result.expr = LoadRef(compare, ref=subprogram)
1.172 return result
1.173
1.174 @@ -519,11 +524,11 @@
1.175 subprogram.code = results
1.176
1.177 self.current_subprograms.pop()
1.178 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.179 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.180
1.181 # Make an invocation of the subprogram.
1.182
1.183 - result = InvokeBlock(and_, produces_result=1)
1.184 + result = InvokeBlock(and_, 1, produces_result=1)
1.185 result.expr = LoadRef(and_, ref=subprogram)
1.186 return result
1.187
1.188 @@ -581,28 +586,28 @@
1.189 subprogram.code = results
1.190
1.191 self.current_subprograms.pop()
1.192 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.193 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.194
1.195 # Make an invocation of the subprogram.
1.196
1.197 - result = InvokeBlock(or_, produces_result=1)
1.198 + result = InvokeBlock(or_, 1, produces_result=1)
1.199 result.expr = LoadRef(or_, ref=subprogram)
1.200 return result
1.201
1.202 def visitNot(self, not_):
1.203 - result = Not(not_, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.204 + result = Not(not_, 1, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.205 return result
1.206
1.207 # Operators.
1.208
1.209 def visitUnaryAdd(self, unaryadd):
1.210 - return InvokeFunction(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.211 + return InvokeFunction(unaryadd, 1, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.212
1.213 def visitUnarySub(self, unarysub):
1.214 - return InvokeFunction(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.215 + return InvokeFunction(unarysub, 1, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.216
1.217 def visitInvert(self, invert):
1.218 - return InvokeFunction(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.219 + return InvokeFunction(invert, 1, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.220
1.221 def visitAdd(self, add):
1.222
1.223 @@ -616,7 +621,7 @@
1.224 (else)
1.225 """
1.226
1.227 - result = Try(add,
1.228 + result = Try(add, 1,
1.229 body=[
1.230 InvokeFunction(add,
1.231 expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"),
1.232 @@ -656,7 +661,7 @@
1.233 }
1.234
1.235 def visitAugAssign(self, augassign):
1.236 - result = Assign(augassign)
1.237 + result = Assign(augassign, 1)
1.238 expr = self.dispatch(augassign.expr)
1.239
1.240 # Simple augmented assignment: name += expr
1.241 @@ -800,7 +805,7 @@
1.242 return result
1.243
1.244 def visitAssign(self, assign):
1.245 - result = Assign(assign)
1.246 + result = Assign(assign, 1)
1.247 store = StoreTemp(assign, expr=self.dispatch(assign.expr))
1.248 release = ReleaseTemp(assign)
1.249 result.code = [store] + self.dispatches(assign.nodes, 0) + [release]
1.250 @@ -811,7 +816,7 @@
1.251 expr = LoadTemp(asslist)
1.252 else:
1.253 expr = InvokeFunction(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
1.254 - result = Assign(asslist)
1.255 + result = Assign(asslist, 1)
1.256 store = StoreTemp(asslist, expr=InvokeFunction(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
1.257 release = ReleaseTemp(asslist)
1.258 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
1.259 @@ -827,25 +832,25 @@
1.260
1.261 def visitAssName(self, assname, in_sequence=0):
1.262 expr = self._visitAssNameOrAttr(assname, in_sequence)
1.263 - result = StoreName(assname, name=assname.name, expr=expr)
1.264 + result = StoreName(assname, 1, name=assname.name, expr=expr)
1.265 return result
1.266
1.267 def visitAssAttr(self, assattr, in_sequence=0):
1.268 expr = self._visitAssNameOrAttr(assattr, in_sequence)
1.269 lvalue = self.dispatch(assattr.expr)
1.270 - result = StoreAttr(assattr, name=assattr.attrname, lvalue=lvalue, expr=expr)
1.271 + result = StoreAttr(assattr, 1, name=assattr.attrname, lvalue=lvalue, expr=expr)
1.272 return result
1.273
1.274 def _visitSlice(self, slice, expr, lower, upper, flags, value=None):
1.275 if flags == "OP_ASSIGN":
1.276 args = [value]
1.277 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.278 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.279 elif flags == "OP_APPLY":
1.280 args = []
1.281 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.282 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.283 elif flags == "OP_DELETE":
1.284 args = []
1.285 - result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.286 + result = InvokeFunction(slice, 1, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.287 else:
1.288 raise NotImplementedError, flags
1.289
1.290 @@ -865,13 +870,13 @@
1.291 def _visitSubscript(self, subscript, expr, subs, flags, value=None):
1.292 if flags == "OP_ASSIGN":
1.293 args = [value]
1.294 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.295 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.296 elif flags == "OP_APPLY":
1.297 args = []
1.298 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.299 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.300 elif flags == "OP_DELETE":
1.301 args = []
1.302 - result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.303 + result = InvokeFunction(subscript, 1, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.304 else:
1.305 raise NotImplementedError, flags
1.306
1.307 @@ -887,7 +892,7 @@
1.308 if len(subs) == 1:
1.309 return self.dispatch(subs[0])
1.310 else:
1.311 - return InvokeFunction(node,
1.312 + return InvokeFunction(node, 1,
1.313 expr=LoadName(node, name="tuple"),
1.314 args=self.dispatches(subs),
1.315 star=None,
1.316 @@ -915,13 +920,13 @@
1.317 subprogram.code = self.dispatch(class_.code) + [Return(class_)]
1.318
1.319 self.current_subprograms.pop()
1.320 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.321 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.322
1.323 # Make a definition of the class associating it with a name.
1.324
1.325 result = Assign(class_,
1.326 code=[
1.327 - StoreName(class_,
1.328 + StoreName(class_, 1, # defines the class
1.329 name=class_.name,
1.330 expr=LoadRef(class_, ref=structure)
1.331 ),
1.332 @@ -958,11 +963,17 @@
1.333 # Produce star and dstar parameters with appropriate defaults.
1.334
1.335 if has_star:
1.336 - star = (function.argnames[npositional], InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
1.337 + star = (
1.338 + function.argnames[npositional],
1.339 + InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None)
1.340 + )
1.341 else:
1.342 star = None
1.343 if has_dstar:
1.344 - dstar = (function.argnames[npositional + has_star], InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
1.345 + dstar = (
1.346 + function.argnames[npositional + has_star],
1.347 + InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None)
1.348 + )
1.349 else:
1.350 dstar = None
1.351
1.352 @@ -982,7 +993,7 @@
1.353 subprogram.params = params
1.354 subprogram.star = star
1.355 subprogram.dstar = dstar
1.356 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.357 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.358
1.359 def visitFunction(self, function):
1.360
1.361 @@ -997,7 +1008,7 @@
1.362
1.363 # Make a definition of the function associating it with a name.
1.364
1.365 - result = StoreName(function, name=function.name, expr=LoadRef(function, ref=subprogram))
1.366 + result = StoreName(function, 1, name=function.name, expr=LoadRef(function, ref=subprogram))
1.367 return result
1.368
1.369 def visitLambda(self, lambda_):
1.370 @@ -1013,10 +1024,10 @@
1.371
1.372 # Get the subprogram reference to the lambda.
1.373
1.374 - return LoadRef(lambda_, ref=subprogram)
1.375 + return LoadRef(lambda_, 1, ref=subprogram)
1.376
1.377 def visitCallFunc(self, callfunc):
1.378 - result = InvokeFunction(callfunc, star=None, dstar=None, args=self.dispatches(callfunc.args))
1.379 + result = InvokeFunction(callfunc, 1, star=None, dstar=None, args=self.dispatches(callfunc.args))
1.380 if callfunc.star_args is not None:
1.381 result.star = self.dispatch(callfunc.star_args)
1.382 if callfunc.dstar_args is not None:
1.383 @@ -1068,11 +1079,11 @@
1.384 subprogram.code = [test]
1.385
1.386 self.current_subprograms.pop()
1.387 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.388 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.389
1.390 # Make an invocation of the subprogram.
1.391
1.392 - result = InvokeBlock(while_)
1.393 + result = InvokeBlock(while_, 1)
1.394 result.expr = LoadRef(while_, ref=subprogram)
1.395 return result
1.396
1.397 @@ -1137,14 +1148,24 @@
1.398 # Finish the subprogram definition.
1.399
1.400 self.current_subprograms.pop()
1.401 - self.subprograms.append(subprogram); self.subnames[subprogram.full_name] = subprogram
1.402 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.403
1.404 # Obtain an iterator for the sequence involved.
1.405 # Then, make an invocation of the subprogram.
1.406
1.407 - result = Assign(for_)
1.408 + result = Assign(for_, 1)
1.409 result.code = [
1.410 - StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
1.411 + StoreTemp(for_,
1.412 + expr=InvokeFunction(for_,
1.413 + expr=LoadAttr(for_,
1.414 + name="__iter__",
1.415 + expr=self.dispatch(for_.list)
1.416 + ),
1.417 + args=[],
1.418 + star=None,
1.419 + dstar=None
1.420 + )
1.421 + ),
1.422 InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)),
1.423 ReleaseTemp(for_)
1.424 ]
1.425 @@ -1153,7 +1174,7 @@
1.426 # Exception node transformations.
1.427
1.428 def visitTryFinally(self, tryfinally):
1.429 - result = Try(tryfinally, body=[], else_=[], finally_=[])
1.430 + result = Try(tryfinally, 1, body=[], else_=[], finally_=[])
1.431 if tryfinally.body is not None:
1.432 result.body = self.dispatch(tryfinally.body)
1.433 if tryfinally.final is not None: