3.1 --- a/simplify.py Sat Oct 07 01:50:03 2006 +0200
3.2 +++ b/simplify.py Sat Oct 07 19:46:21 2006 +0200
3.3 @@ -218,7 +218,7 @@
3.4 return result
3.5
3.6 def _visitBuiltin(self, builtin, name):
3.7 - result = Invoke(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
3.8 + result = InvokeFunction(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
3.9 return result
3.10
3.11 def visitTuple(self, tuple):
3.12 @@ -228,13 +228,13 @@
3.13 return self._visitBuiltin(list, "list")
3.14
3.15 def visitDict(self, dict):
3.16 - result = Invoke(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
3.17 + result = InvokeFunction(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
3.18 args = []
3.19 for key, value in dict.items:
3.20 - tuple = Invoke(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
3.21 - tuple.args = [self.dispatch(key), self.dispatch(value)]
3.22 + tuple = InvokeFunction(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
3.23 + tuple.set_args([self.dispatch(key), self.dispatch(value)])
3.24 args.append(tuple)
3.25 - result.args = args
3.26 + result.set_args(args)
3.27 return result
3.28
3.29 # Logical and comparison operations plus chained statements.
3.30 @@ -268,7 +268,7 @@
3.31
3.32 for compare, stmt in if_.tests:
3.33 test = Conditional(if_,
3.34 - test=Invoke(if_,
3.35 + test=InvokeFunction(if_,
3.36 expr=LoadAttr(if_,
3.37 expr=self.dispatch(compare),
3.38 name="__true__"
3.39 @@ -333,7 +333,7 @@
3.40 else:
3.41 new_spec = self.dispatch(spec)
3.42 test = Conditional(tryexcept,
3.43 - test=Invoke(tryexcept,
3.44 + test=InvokeFunction(tryexcept,
3.45 expr=LoadName(tryexcept, name="isinstance"),
3.46 args=[LoadExc(tryexcept), new_spec],
3.47 star=None,
3.48 @@ -404,11 +404,11 @@
3.49
3.50 method_name = self.comparison_methods[op_name]
3.51 if method_name:
3.52 - invocation = Invoke(compare, expr=LoadAttr(compare, expr=previous, name=method_name), args=[expr], star=None, dstar=None)
3.53 + invocation = InvokeFunction(compare, expr=LoadAttr(compare, expr=previous, name=method_name), args=[expr], star=None, dstar=None)
3.54 elif op_name == "is":
3.55 - invocation = Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None)
3.56 + invocation = InvokeFunction(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None)
3.57 elif op_name == "is not":
3.58 - invocation = Not(compare, expr=Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None))
3.59 + invocation = Not(compare, expr=InvokeFunction(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None))
3.60 else:
3.61 raise NotImplementedError, op_name
3.62 nodes.append(StoreTemp(compare, expr=invocation))
3.63 @@ -477,7 +477,7 @@
3.64
3.65 if node is not last:
3.66 nodes.append(StoreTemp(and_, expr=expr))
3.67 - invocation = Invoke(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None)
3.68 + invocation = InvokeFunction(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None)
3.69 test = Conditional(and_, test=Not(and_, expr=invocation), body=[Return(and_, expr=LoadTemp(and_))])
3.70 nodes.append(test)
3.71
3.72 @@ -537,7 +537,7 @@
3.73
3.74 if node is not last:
3.75 nodes.append(StoreTemp(or_, expr=expr))
3.76 - invocation = Invoke(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None)
3.77 + invocation = InvokeFunction(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None)
3.78 test = Conditional(or_, test=invocation, body=[Return(or_, expr=LoadTemp(or_))])
3.79 nodes.append(test)
3.80
3.81 @@ -566,19 +566,19 @@
3.82 return result
3.83
3.84 def visitNot(self, not_):
3.85 - result = Not(not_, expr=Invoke(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
3.86 + result = Not(not_, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
3.87 return result
3.88
3.89 # Operators.
3.90
3.91 def visitUnaryAdd(self, unaryadd):
3.92 - return Invoke(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
3.93 + return InvokeFunction(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
3.94
3.95 def visitUnarySub(self, unarysub):
3.96 - return Invoke(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
3.97 + return InvokeFunction(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
3.98
3.99 def visitInvert(self, invert):
3.100 - return Invoke(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
3.101 + return InvokeFunction(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
3.102
3.103 def visitAdd(self, add):
3.104
3.105 @@ -594,7 +594,7 @@
3.106
3.107 result = Try(add,
3.108 body=[
3.109 - Invoke(add,
3.110 + InvokeFunction(add,
3.111 expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"),
3.112 args=[self.dispatch(add.right)],
3.113 star=None,
3.114 @@ -604,13 +604,13 @@
3.115 finally_=[],
3.116 handler=[
3.117 Conditional(add,
3.118 - test=Invoke(add,
3.119 + test=InvokeFunction(add,
3.120 expr=LoadName(add, name="isinstance"),
3.121 args=[LoadExc(add), LoadName(add, name="TypeError")],
3.122 star=None,
3.123 dstar=None),
3.124 body=[
3.125 - Invoke(add,
3.126 + InvokeFunction(add,
3.127 expr=LoadAttr(add, expr=self.dispatch(add.right), name="__radd__"),
3.128 args=[self.dispatch(add.left)],
3.129 star=None,
3.130 @@ -640,7 +640,7 @@
3.131 if isinstance(augassign.node, compiler.ast.Name):
3.132 result.code = [
3.133 StoreTemp(augassign,
3.134 - expr=Invoke(augassign,
3.135 + expr=InvokeFunction(augassign,
3.136 args=[expr],
3.137 star=None,
3.138 dstar=None,
3.139 @@ -668,7 +668,7 @@
3.140 expr=self.dispatch(augassign.node.expr)
3.141 ),
3.142 StoreTemp(augassign,
3.143 - expr=Invoke(augassign,
3.144 + expr=InvokeFunction(augassign,
3.145 args=[expr], star=None, dstar=None,
3.146 expr=LoadAttr(augassign,
3.147 expr=LoadAttr(augassign,
3.148 @@ -708,7 +708,7 @@
3.149 expr=self.dispatch_or_none(augassign.node.upper)
3.150 ),
3.151 StoreTemp(augassign,
3.152 - expr=Invoke(augassign,
3.153 + expr=InvokeFunction(augassign,
3.154 args=[expr], star=None, dstar=None,
3.155 expr=LoadAttr(augassign,
3.156 expr=self._visitSlice(
3.157 @@ -745,7 +745,7 @@
3.158 StoreTemp(augassign, index="expr", expr=self.dispatch(augassign.node.expr)),
3.159 StoreTemp(augassign, index="subs", expr=self._visitSubscriptSubs(augassign.node.subs)),
3.160 StoreTemp(augassign,
3.161 - expr=Invoke(augassign,
3.162 + expr=InvokeFunction(augassign,
3.163 args=[expr], star=None, dstar=None,
3.164 expr=LoadAttr(augassign,
3.165 expr=self._visitSubscript(
3.166 @@ -786,9 +786,9 @@
3.167 if not in_sequence:
3.168 expr = LoadTemp(asslist)
3.169 else:
3.170 - expr = Invoke(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
3.171 + expr = InvokeFunction(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
3.172 result = Assign(asslist)
3.173 - store = StoreTemp(asslist, expr=Invoke(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
3.174 + store = StoreTemp(asslist, expr=InvokeFunction(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
3.175 release = ReleaseTemp(asslist)
3.176 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
3.177 return result
3.178 @@ -799,7 +799,7 @@
3.179 if not in_sequence:
3.180 return LoadTemp(node)
3.181 else:
3.182 - return Invoke(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[])
3.183 + return InvokeFunction(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[])
3.184
3.185 def visitAssName(self, assname, in_sequence=0):
3.186 expr = self._visitAssNameOrAttr(assname, in_sequence)
3.187 @@ -815,13 +815,13 @@
3.188 def _visitSlice(self, slice, expr, lower, upper, flags, value=None):
3.189 if flags == "OP_ASSIGN":
3.190 args = [value]
3.191 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
3.192 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
3.193 elif flags == "OP_APPLY":
3.194 args = []
3.195 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
3.196 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
3.197 elif flags == "OP_DELETE":
3.198 args = []
3.199 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
3.200 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
3.201 else:
3.202 raise NotImplementedError, flags
3.203
3.204 @@ -831,7 +831,7 @@
3.205 args.insert(1, upper)
3.206
3.207 result.original = slice
3.208 - result.args = args
3.209 + result.set_args(args)
3.210 return result
3.211
3.212 def visitSlice(self, slice, in_sequence=0):
3.213 @@ -841,13 +841,13 @@
3.214 def _visitSubscript(self, subscript, expr, subs, flags, value=None):
3.215 if flags == "OP_ASSIGN":
3.216 args = [value]
3.217 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
3.218 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
3.219 elif flags == "OP_APPLY":
3.220 args = []
3.221 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
3.222 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
3.223 elif flags == "OP_DELETE":
3.224 args = []
3.225 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
3.226 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
3.227 else:
3.228 raise NotImplementedError, flags
3.229
3.230 @@ -856,14 +856,14 @@
3.231 args.insert(0, subs)
3.232
3.233 result.original = subscript
3.234 - result.args = args
3.235 + result.set_args(args)
3.236 return result
3.237
3.238 def _visitSubscriptSubs(self, subs):
3.239 if len(subs) == 1:
3.240 return self.dispatch(subs[0])
3.241 else:
3.242 - return Invoke(subs, expr=LoadName(subs, name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
3.243 + return InvokeFunction(subs, expr=LoadName(subs, name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
3.244
3.245 def visitSubscript(self, subscript, in_sequence=0):
3.246 return self._visitSubscript(
3.247 @@ -897,8 +897,7 @@
3.248 name=class_.name,
3.249 expr=LoadRef(class_, ref=structure)
3.250 ),
3.251 - Invoke(class_,
3.252 - args=[], star=None, dstar=None,
3.253 + InvokeBlock(class_,
3.254 expr=LoadRef(class_, ref=subprogram)
3.255 )
3.256 ]
3.257 @@ -931,11 +930,11 @@
3.258 # Produce star and dstar parameters with appropriate defaults.
3.259
3.260 if has_star:
3.261 - star = (function.argnames[npositional], Invoke(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
3.262 + star = (function.argnames[npositional], InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
3.263 else:
3.264 star = None
3.265 if has_dstar:
3.266 - dstar = (function.argnames[npositional + has_star], Invoke(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
3.267 + dstar = (function.argnames[npositional + has_star], InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
3.268 else:
3.269 dstar = None
3.270
3.271 @@ -989,8 +988,7 @@
3.272 return LoadRef(lambda_, ref=subprogram)
3.273
3.274 def visitCallFunc(self, callfunc):
3.275 - result = InvokeFunction(callfunc, star=None, dstar=None)
3.276 - result.args = self.dispatches(callfunc.args)
3.277 + result = InvokeFunction(callfunc, star=None, dstar=None, args=self.dispatches(callfunc.args))
3.278 if callfunc.star_args is not None:
3.279 result.star = self.dispatch(callfunc.star_args)
3.280 if callfunc.dstar_args is not None:
3.281 @@ -1020,7 +1018,7 @@
3.282 # Include a conditional statement in the subprogram.
3.283
3.284 test = Conditional(while_, else_=[])
3.285 - test.test = Invoke(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
3.286 + test.test = InvokeFunction(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
3.287
3.288 # Inside the conditional, add a recursive invocation to the subprogram
3.289 # if the test condition was satisfied.
3.290 @@ -1084,14 +1082,18 @@
3.291
3.292 try_except = Try(for_, body=[], else_=[], finally_=[])
3.293 test = Conditional(for_,
3.294 - test=Invoke(for_, expr=LoadName(for_, name="isinstance"), args=[LoadExc(for_), LoadName(for_, name="StopIteration")], star=None, dstar=None),
3.295 + test=InvokeFunction(for_,
3.296 + expr=LoadName(for_, name="isinstance"),
3.297 + args=[LoadExc(for_), LoadName(for_, name="StopIteration")],
3.298 + star=None,
3.299 + dstar=None),
3.300 body=else_stmt,
3.301 else_=[Raise(for_, expr=LoadExc(for_))])
3.302 try_except.handler = [test]
3.303
3.304 assign = Assign(for_,
3.305 code=[
3.306 - StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)),
3.307 + StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)),
3.308 self.dispatch(for_.assign),
3.309 ReleaseTemp(for_)
3.310 ])
3.311 @@ -1114,7 +1116,7 @@
3.312
3.313 result = Assign(for_)
3.314 result.code = [
3.315 - StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
3.316 + StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
3.317 InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)),
3.318 ReleaseTemp(for_)
3.319 ]