1.1 --- a/simplify.py Sat Oct 07 01:50:03 2006 +0200
1.2 +++ b/simplify.py Sat Oct 07 19:46:21 2006 +0200
1.3 @@ -218,7 +218,7 @@
1.4 return result
1.5
1.6 def _visitBuiltin(self, builtin, name):
1.7 - result = Invoke(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.8 + result = InvokeFunction(builtin, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
1.9 return result
1.10
1.11 def visitTuple(self, tuple):
1.12 @@ -228,13 +228,13 @@
1.13 return self._visitBuiltin(list, "list")
1.14
1.15 def visitDict(self, dict):
1.16 - result = Invoke(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
1.17 + result = InvokeFunction(dict, expr=LoadName(dict, name="dict"), star=None, dstar=None)
1.18 args = []
1.19 for key, value in dict.items:
1.20 - tuple = Invoke(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
1.21 - tuple.args = [self.dispatch(key), self.dispatch(value)]
1.22 + tuple = InvokeFunction(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None)
1.23 + tuple.set_args([self.dispatch(key), self.dispatch(value)])
1.24 args.append(tuple)
1.25 - result.args = args
1.26 + result.set_args(args)
1.27 return result
1.28
1.29 # Logical and comparison operations plus chained statements.
1.30 @@ -268,7 +268,7 @@
1.31
1.32 for compare, stmt in if_.tests:
1.33 test = Conditional(if_,
1.34 - test=Invoke(if_,
1.35 + test=InvokeFunction(if_,
1.36 expr=LoadAttr(if_,
1.37 expr=self.dispatch(compare),
1.38 name="__true__"
1.39 @@ -333,7 +333,7 @@
1.40 else:
1.41 new_spec = self.dispatch(spec)
1.42 test = Conditional(tryexcept,
1.43 - test=Invoke(tryexcept,
1.44 + test=InvokeFunction(tryexcept,
1.45 expr=LoadName(tryexcept, name="isinstance"),
1.46 args=[LoadExc(tryexcept), new_spec],
1.47 star=None,
1.48 @@ -404,11 +404,11 @@
1.49
1.50 method_name = self.comparison_methods[op_name]
1.51 if method_name:
1.52 - invocation = Invoke(compare, expr=LoadAttr(compare, expr=previous, name=method_name), args=[expr], star=None, dstar=None)
1.53 + invocation = InvokeFunction(compare, expr=LoadAttr(compare, expr=previous, name=method_name), args=[expr], star=None, dstar=None)
1.54 elif op_name == "is":
1.55 - invocation = Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None)
1.56 + invocation = InvokeFunction(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None)
1.57 elif op_name == "is not":
1.58 - invocation = Not(compare, expr=Invoke(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None))
1.59 + invocation = Not(compare, expr=InvokeFunction(compare, expr=LoadName(compare, name="__is__"), args=[previous, expr], star=None, dstar=None))
1.60 else:
1.61 raise NotImplementedError, op_name
1.62 nodes.append(StoreTemp(compare, expr=invocation))
1.63 @@ -477,7 +477,7 @@
1.64
1.65 if node is not last:
1.66 nodes.append(StoreTemp(and_, expr=expr))
1.67 - invocation = Invoke(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None)
1.68 + invocation = InvokeFunction(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None)
1.69 test = Conditional(and_, test=Not(and_, expr=invocation), body=[Return(and_, expr=LoadTemp(and_))])
1.70 nodes.append(test)
1.71
1.72 @@ -537,7 +537,7 @@
1.73
1.74 if node is not last:
1.75 nodes.append(StoreTemp(or_, expr=expr))
1.76 - invocation = Invoke(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None)
1.77 + invocation = InvokeFunction(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None)
1.78 test = Conditional(or_, test=invocation, body=[Return(or_, expr=LoadTemp(or_))])
1.79 nodes.append(test)
1.80
1.81 @@ -566,19 +566,19 @@
1.82 return result
1.83
1.84 def visitNot(self, not_):
1.85 - result = Not(not_, expr=Invoke(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.86 + result = Not(not_, expr=InvokeFunction(not_, expr=LoadAttr(not_, expr=self.dispatch(not_.expr), name="__true__"), args=[], star=None, dstar=None))
1.87 return result
1.88
1.89 # Operators.
1.90
1.91 def visitUnaryAdd(self, unaryadd):
1.92 - return Invoke(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.93 + return InvokeFunction(unaryadd, expr=LoadAttr(unaryadd, expr=self.dispatch(unaryadd.expr), name="__pos__"), args=[], star=None, dstar=None)
1.94
1.95 def visitUnarySub(self, unarysub):
1.96 - return Invoke(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.97 + return InvokeFunction(unarysub, expr=LoadAttr(unarysub, expr=self.dispatch(unarysub.expr), name="__neg__"), args=[], star=None, dstar=None)
1.98
1.99 def visitInvert(self, invert):
1.100 - return Invoke(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.101 + return InvokeFunction(invert, expr=LoadAttr(invert, expr=self.dispatch(invert.expr), name="__invert__"), args=[], star=None, dstar=None)
1.102
1.103 def visitAdd(self, add):
1.104
1.105 @@ -594,7 +594,7 @@
1.106
1.107 result = Try(add,
1.108 body=[
1.109 - Invoke(add,
1.110 + InvokeFunction(add,
1.111 expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"),
1.112 args=[self.dispatch(add.right)],
1.113 star=None,
1.114 @@ -604,13 +604,13 @@
1.115 finally_=[],
1.116 handler=[
1.117 Conditional(add,
1.118 - test=Invoke(add,
1.119 + test=InvokeFunction(add,
1.120 expr=LoadName(add, name="isinstance"),
1.121 args=[LoadExc(add), LoadName(add, name="TypeError")],
1.122 star=None,
1.123 dstar=None),
1.124 body=[
1.125 - Invoke(add,
1.126 + InvokeFunction(add,
1.127 expr=LoadAttr(add, expr=self.dispatch(add.right), name="__radd__"),
1.128 args=[self.dispatch(add.left)],
1.129 star=None,
1.130 @@ -640,7 +640,7 @@
1.131 if isinstance(augassign.node, compiler.ast.Name):
1.132 result.code = [
1.133 StoreTemp(augassign,
1.134 - expr=Invoke(augassign,
1.135 + expr=InvokeFunction(augassign,
1.136 args=[expr],
1.137 star=None,
1.138 dstar=None,
1.139 @@ -668,7 +668,7 @@
1.140 expr=self.dispatch(augassign.node.expr)
1.141 ),
1.142 StoreTemp(augassign,
1.143 - expr=Invoke(augassign,
1.144 + expr=InvokeFunction(augassign,
1.145 args=[expr], star=None, dstar=None,
1.146 expr=LoadAttr(augassign,
1.147 expr=LoadAttr(augassign,
1.148 @@ -708,7 +708,7 @@
1.149 expr=self.dispatch_or_none(augassign.node.upper)
1.150 ),
1.151 StoreTemp(augassign,
1.152 - expr=Invoke(augassign,
1.153 + expr=InvokeFunction(augassign,
1.154 args=[expr], star=None, dstar=None,
1.155 expr=LoadAttr(augassign,
1.156 expr=self._visitSlice(
1.157 @@ -745,7 +745,7 @@
1.158 StoreTemp(augassign, index="expr", expr=self.dispatch(augassign.node.expr)),
1.159 StoreTemp(augassign, index="subs", expr=self._visitSubscriptSubs(augassign.node.subs)),
1.160 StoreTemp(augassign,
1.161 - expr=Invoke(augassign,
1.162 + expr=InvokeFunction(augassign,
1.163 args=[expr], star=None, dstar=None,
1.164 expr=LoadAttr(augassign,
1.165 expr=self._visitSubscript(
1.166 @@ -786,9 +786,9 @@
1.167 if not in_sequence:
1.168 expr = LoadTemp(asslist)
1.169 else:
1.170 - expr = Invoke(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
1.171 + expr = InvokeFunction(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[])
1.172 result = Assign(asslist)
1.173 - store = StoreTemp(asslist, expr=Invoke(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
1.174 + store = StoreTemp(asslist, expr=InvokeFunction(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[]))
1.175 release = ReleaseTemp(asslist)
1.176 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
1.177 return result
1.178 @@ -799,7 +799,7 @@
1.179 if not in_sequence:
1.180 return LoadTemp(node)
1.181 else:
1.182 - return Invoke(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[])
1.183 + return InvokeFunction(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[])
1.184
1.185 def visitAssName(self, assname, in_sequence=0):
1.186 expr = self._visitAssNameOrAttr(assname, in_sequence)
1.187 @@ -815,13 +815,13 @@
1.188 def _visitSlice(self, slice, expr, lower, upper, flags, value=None):
1.189 if flags == "OP_ASSIGN":
1.190 args = [value]
1.191 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.192 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__setslice__"), star=None, dstar=None, args=[])
1.193 elif flags == "OP_APPLY":
1.194 args = []
1.195 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.196 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__getslice__"), star=None, dstar=None, args=[])
1.197 elif flags == "OP_DELETE":
1.198 args = []
1.199 - result = Invoke(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.200 + result = InvokeFunction(slice, expr=LoadAttr(slice, expr=expr, name="__delslice__"), star=None, dstar=None, args=[])
1.201 else:
1.202 raise NotImplementedError, flags
1.203
1.204 @@ -831,7 +831,7 @@
1.205 args.insert(1, upper)
1.206
1.207 result.original = slice
1.208 - result.args = args
1.209 + result.set_args(args)
1.210 return result
1.211
1.212 def visitSlice(self, slice, in_sequence=0):
1.213 @@ -841,13 +841,13 @@
1.214 def _visitSubscript(self, subscript, expr, subs, flags, value=None):
1.215 if flags == "OP_ASSIGN":
1.216 args = [value]
1.217 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.218 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__setitem__"), star=None, dstar=None, args=[])
1.219 elif flags == "OP_APPLY":
1.220 args = []
1.221 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.222 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__getitem__"), star=None, dstar=None, args=[])
1.223 elif flags == "OP_DELETE":
1.224 args = []
1.225 - result = Invoke(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.226 + result = InvokeFunction(subscript, expr=LoadAttr(subscript, expr=expr, name="__delitem__"), star=None, dstar=None, args=[])
1.227 else:
1.228 raise NotImplementedError, flags
1.229
1.230 @@ -856,14 +856,14 @@
1.231 args.insert(0, subs)
1.232
1.233 result.original = subscript
1.234 - result.args = args
1.235 + result.set_args(args)
1.236 return result
1.237
1.238 def _visitSubscriptSubs(self, subs):
1.239 if len(subs) == 1:
1.240 return self.dispatch(subs[0])
1.241 else:
1.242 - return Invoke(subs, expr=LoadName(subs, name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
1.243 + return InvokeFunction(subs, expr=LoadName(subs, name="tuple"), args=self.dispatches(subs), star=None, dstar=None)
1.244
1.245 def visitSubscript(self, subscript, in_sequence=0):
1.246 return self._visitSubscript(
1.247 @@ -897,8 +897,7 @@
1.248 name=class_.name,
1.249 expr=LoadRef(class_, ref=structure)
1.250 ),
1.251 - Invoke(class_,
1.252 - args=[], star=None, dstar=None,
1.253 + InvokeBlock(class_,
1.254 expr=LoadRef(class_, ref=subprogram)
1.255 )
1.256 ]
1.257 @@ -931,11 +930,11 @@
1.258 # Produce star and dstar parameters with appropriate defaults.
1.259
1.260 if has_star:
1.261 - star = (function.argnames[npositional], Invoke(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
1.262 + star = (function.argnames[npositional], InvokeFunction(function, expr=LoadName(function, name="list"), args=[], star=None, dstar=None))
1.263 else:
1.264 star = None
1.265 if has_dstar:
1.266 - dstar = (function.argnames[npositional + has_star], Invoke(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
1.267 + dstar = (function.argnames[npositional + has_star], InvokeFunction(function, expr=LoadName(function, name="dict"), args=[], star=None, dstar=None))
1.268 else:
1.269 dstar = None
1.270
1.271 @@ -989,8 +988,7 @@
1.272 return LoadRef(lambda_, ref=subprogram)
1.273
1.274 def visitCallFunc(self, callfunc):
1.275 - result = InvokeFunction(callfunc, star=None, dstar=None)
1.276 - result.args = self.dispatches(callfunc.args)
1.277 + result = InvokeFunction(callfunc, star=None, dstar=None, args=self.dispatches(callfunc.args))
1.278 if callfunc.star_args is not None:
1.279 result.star = self.dispatch(callfunc.star_args)
1.280 if callfunc.dstar_args is not None:
1.281 @@ -1020,7 +1018,7 @@
1.282 # Include a conditional statement in the subprogram.
1.283
1.284 test = Conditional(while_, else_=[])
1.285 - test.test = Invoke(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
1.286 + test.test = InvokeFunction(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
1.287
1.288 # Inside the conditional, add a recursive invocation to the subprogram
1.289 # if the test condition was satisfied.
1.290 @@ -1084,14 +1082,18 @@
1.291
1.292 try_except = Try(for_, body=[], else_=[], finally_=[])
1.293 test = Conditional(for_,
1.294 - test=Invoke(for_, expr=LoadName(for_, name="isinstance"), args=[LoadExc(for_), LoadName(for_, name="StopIteration")], star=None, dstar=None),
1.295 + test=InvokeFunction(for_,
1.296 + expr=LoadName(for_, name="isinstance"),
1.297 + args=[LoadExc(for_), LoadName(for_, name="StopIteration")],
1.298 + star=None,
1.299 + dstar=None),
1.300 body=else_stmt,
1.301 else_=[Raise(for_, expr=LoadExc(for_))])
1.302 try_except.handler = [test]
1.303
1.304 assign = Assign(for_,
1.305 code=[
1.306 - StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)),
1.307 + StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)),
1.308 self.dispatch(for_.assign),
1.309 ReleaseTemp(for_)
1.310 ])
1.311 @@ -1114,7 +1116,7 @@
1.312
1.313 result = Assign(for_)
1.314 result.code = [
1.315 - StoreTemp(for_, expr=Invoke(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
1.316 + StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, name="__iter__", expr=self.dispatch(for_.list)), args=[], star=None, dstar=None)),
1.317 InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)),
1.318 ReleaseTemp(for_)
1.319 ]