1.1 --- a/annotate.py Thu Jan 25 01:03:33 2007 +0100
1.2 +++ b/annotate.py Fri Jan 26 00:05:20 2007 +0100
1.3 @@ -451,7 +451,7 @@
1.4
1.5 # Instantiate the class.
1.6
1.7 - instance = self.new_instance(invoke, "new", attr.type.full_name(), attr.type)
1.8 + instance = self.new_instance(invoke, attr.type)
1.9
1.10 # For instantiations, switch the context.
1.11
1.12 @@ -869,22 +869,9 @@
1.13 # Utility methods.
1.14
1.15 def get_builtin_instances(self, node, name):
1.16 - return [Attribute(None, self._new_instance(node, attr.type)) for attr in self.builtins.namespace[name]]
1.17 -
1.18 - def new_instance(self, node, reason, target, type):
1.19 -
1.20 - "Create, on the given 'node', a new instance with the given 'type'."
1.21 + return [Attribute(None, self.new_instance(node, attr.type)) for attr in self.builtins.namespace[name]]
1.22
1.23 - if not hasattr(node, "instances"):
1.24 - node.instances = {}
1.25 -
1.26 - if not node.instances.has_key((reason, target, type)):
1.27 - instance = self._new_instance(node, type)
1.28 - node.instances[(reason, target, type)] = instance
1.29 -
1.30 - return node.instances[(reason, target, type)]
1.31 -
1.32 - def _new_instance(self, node, type):
1.33 + def new_instance(self, node, type):
1.34
1.35 "For the given 'node', obtain an instance from the given 'type'."
1.36
1.37 @@ -1153,6 +1140,7 @@
1.38 code=[
1.39 StoreTemp(
1.40 expr=InvokeFunction(
1.41 + invocation.original,
1.42 expr=LoadAttr(
1.43 expr=LoadRef(
1.44 ref=self.builtins
1.45 @@ -1170,6 +1158,7 @@
1.46 for arg in star_args:
1.47 code.append(
1.48 InvokeFunction(
1.49 + invocation.original,
1.50 expr=LoadAttr(
1.51 expr=LoadTemp(),
1.52 name="append"
1.53 @@ -1185,6 +1174,7 @@
1.54 ]
1.55
1.56 invocation.stars[subprogram.full_name()] = InvokeBlock(
1.57 + invocation.original,
1.58 produces_result=1,
1.59 expr=LoadRef(
1.60 ref=Subprogram(
1.61 @@ -1214,6 +1204,7 @@
1.62 code=[
1.63 StoreTemp(
1.64 expr=InvokeFunction(
1.65 + invocation.original,
1.66 expr=LoadAttr(
1.67 expr=LoadRef(
1.68 ref=self.builtins
1.69 @@ -1252,6 +1243,7 @@
1.70 )
1.71 ),
1.72 InvokeFunction(
1.73 + invocation.original,
1.74 expr=LoadAttr(
1.75 expr=LoadTemp(),
1.76 name="__setitem__"
1.77 @@ -1271,6 +1263,7 @@
1.78 ]
1.79
1.80 invocation.dstars[subprogram.full_name()] = InvokeBlock(
1.81 + invocation.original,
1.82 produces_result=1,
1.83 expr=LoadRef(
1.84 ref=Subprogram(
2.1 --- a/simplified.py Thu Jan 25 01:03:33 2007 +0100
2.2 +++ b/simplified.py Fri Jan 26 00:05:20 2007 +0100
2.3 @@ -151,7 +151,7 @@
2.4 choices Any choices which may be included in the final program.
2.5 """
2.6
2.7 - common_attributes = "name", "index", "value", "nstype", "internal", "returns_value", "is_method", "ref", "module", "structures", "original_def"
2.8 + common_attributes = "name", "index", "value", "nstype", "internal", "returns_value", "is_method", "ref", "module", "structures", "original"
2.9 expression_attributes = "expr", "lvalue", "test", "star", "dstar"
2.10 invocation_attributes = "params", # not "args" - see "pos_args", "kw_args"
2.11 grouping_attributes = "code", "body", "else_", "handler", "finally_", "choices"
2.12 @@ -285,20 +285,13 @@
2.13
2.14 # Node manipulation functions.
2.15
2.16 - def copy(self, new_name=None, original_def=None):
2.17 + def copy(self, new_name=None):
2.18
2.19 """
2.20 Perform a deep copy of the node, optionally specifying a 'new_name',
2.21 returning a new unannotated copy.
2.22 -
2.23 - The 'original_def' parameter is used to assign a particular AST node to
2.24 - copied regions of the simplified node tree.
2.25 """
2.26
2.27 - # Obtain an AST node to be assigned to the copied nodes.
2.28 -
2.29 - original_def = getattr(self, "original", None) or original_def or getattr(self, "original_def", None)
2.30 -
2.31 # Copy the common attributes of this node.
2.32
2.33 common = {}
2.34 @@ -309,13 +302,9 @@
2.35 if new_name is not None:
2.36 common["name"] = new_name
2.37
2.38 - if original_def is not None:
2.39 - common["original_def"] = original_def
2.40 -
2.41 # Instantiate the copy, avoiding side-effects with original and defining.
2.42
2.43 node = self.__class__(**common)
2.44 - node.original = self.original
2.45 node.defining = self.defining
2.46
2.47 # Add links to copied nodes from original AST nodes.
2.48 @@ -333,7 +322,7 @@
2.49 if n is None:
2.50 n2 = n
2.51 else:
2.52 - n2 = n.copy(original_def=original_def)
2.53 + n2 = n.copy()
2.54 setattr(node, attr, n2)
2.55
2.56 for attr in self.invocation_attributes:
2.57 @@ -344,23 +333,23 @@
2.58 if n is None:
2.59 l2.append((name, n))
2.60 else:
2.61 - l2.append((name, n.copy(original_def=original_def)))
2.62 + l2.append((name, n.copy()))
2.63 setattr(node, attr, l2)
2.64
2.65 for attr in self.grouping_attributes:
2.66 if hasattr(self, attr):
2.67 l = getattr(self, attr)
2.68 - setattr(node, attr, [n.copy(original_def=original_def) for n in l])
2.69 + setattr(node, attr, [n.copy() for n in l])
2.70
2.71 # Arguments are usually processed further - "args" is useless.
2.72
2.73 if hasattr(self, "pos_args"):
2.74 - node.pos_args = [n.copy(original_def=original_def) for n in self.pos_args]
2.75 + node.pos_args = [n.copy() for n in self.pos_args]
2.76
2.77 if hasattr(self, "kw_args"):
2.78 node.kw_args = {}
2.79 for name, n in self.kw_args.items():
2.80 - node.kw_args[name] = n.copy(original_def=original_def)
2.81 + node.kw_args[name] = n.copy()
2.82
2.83 return node
2.84
2.85 @@ -549,7 +538,7 @@
2.86 self.attributes_for_instances = {}
2.87
2.88 def _get_key(self, node):
2.89 - return getattr(node, "original_def", None) or getattr(node, "original", None) # self.module.original
2.90 + return id(getattr(node, "original", None)) # self.module.original
2.91
2.92 def has_instance(self, node):
2.93 return self.instances.has_key(self._get_key(node))
3.1 --- a/simplify.py Thu Jan 25 01:03:33 2007 +0100
3.2 +++ b/simplify.py Fri Jan 26 00:05:20 2007 +0100
3.3 @@ -224,9 +224,9 @@
3.4 if not in_sequence:
3.5 expr = LoadTemp()
3.6 else:
3.7 - expr = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"))
3.8 + expr = InvokeFunction(asslist, expr=LoadAttr(expr=LoadTemp(), name="next"))
3.9 result = Assign(asslist, 1)
3.10 - store = StoreTemp(expr=InvokeFunction(expr=LoadAttr(name="__iter__", expr=expr)))
3.11 + store = StoreTemp(expr=InvokeFunction(asslist, expr=LoadAttr(name="__iter__", expr=expr)))
3.12 release = ReleaseTemp()
3.13 result.code = [store] + self.dispatches(asslist.nodes, 1) + [release]
3.14 return result
3.15 @@ -237,7 +237,7 @@
3.16 if not in_sequence:
3.17 return LoadTemp()
3.18 else:
3.19 - return InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"))
3.20 + return InvokeFunction(node, expr=LoadAttr(expr=LoadTemp(), name="next"))
3.21
3.22 def visitAssName(self, assname, in_sequence=0):
3.23 expr = self._visitAssNameOrAttr(assname, in_sequence)
3.24 @@ -277,6 +277,7 @@
3.25 result.code = [
3.26 StoreTemp(
3.27 expr=InvokeFunction( # referenced below
3.28 + augassign,
3.29 args=[expr],
3.30 star=None,
3.31 dstar=None,
3.32 @@ -309,6 +310,7 @@
3.33 ),
3.34 StoreTemp(
3.35 expr=InvokeFunction( # referenced below
3.36 + augassign,
3.37 args=[expr], star=None, dstar=None,
3.38 expr=LoadAttr(
3.39 expr=LoadAttr(augassign.node, 1,
3.40 @@ -353,6 +355,7 @@
3.41 ),
3.42 StoreTemp(
3.43 expr=InvokeFunction( # referenced below
3.44 + augassign,
3.45 args=[expr], star=None, dstar=None,
3.46 expr=LoadAttr(
3.47 expr=self._visitSlice(
3.48 @@ -394,6 +397,7 @@
3.49 StoreTemp(index="subs", expr=self._visitSubscriptSubs(augassign.node, augassign.node.subs)),
3.50 StoreTemp(
3.51 expr=InvokeFunction( # referenced below
3.52 + augassign,
3.53 args=[expr], star=None, dstar=None,
3.54 expr=LoadAttr(
3.55 expr=self._visitSubscript(
3.56 @@ -478,6 +482,7 @@
3.57 expr=LoadRef(ref=structure)
3.58 ),
3.59 InvokeBlock(
3.60 + class_,
3.61 share_locals=0, # override the local sharing usually in InvokeBlock
3.62 expr=LoadRef(ref=subprogram)
3.63 )
3.64 @@ -531,6 +536,7 @@
3.65 method_name = self.comparison_methods[op_name]
3.66 if method_name:
3.67 invocation = InvokeFunction(
3.68 + compare,
3.69 expr=LoadAttr(
3.70 expr=previous,
3.71 name=method_name),
3.72 @@ -540,6 +546,7 @@
3.73
3.74 elif op_name == "is":
3.75 invocation = InvokeFunction(
3.76 + compare,
3.77 expr=LoadName(name="__is__"),
3.78 args=[previous, expr],
3.79 star=None,
3.80 @@ -548,6 +555,7 @@
3.81 elif op_name == "is not":
3.82 invocation = Not(
3.83 expr=InvokeFunction(
3.84 + compare,
3.85 expr=LoadName(name="__is__"),
3.86 args=[previous, expr],
3.87 star=None,
3.88 @@ -618,7 +626,7 @@
3.89 result = InvokeFunction(dict, 1, expr=LoadName(name="dict"), star=None, dstar=None)
3.90 args = []
3.91 for key, value in dict.items:
3.92 - tuple = InvokeFunction(expr=LoadName(name="tuple"), star=None, dstar=None)
3.93 + tuple = InvokeFunction(dict, expr=LoadName(name="tuple"), star=None, dstar=None)
3.94 tuple.set_args([self.dispatch(key), self.dispatch(value)])
3.95 args.append(tuple)
3.96 result.set_args(args)
3.97 @@ -671,18 +679,20 @@
3.98 body=[
3.99 Assign(
3.100 code=[
3.101 - StoreTemp(expr=InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"))),
3.102 + StoreTemp(expr=InvokeFunction(for_, expr=LoadAttr(expr=LoadTemp(), name="next"))),
3.103 self.dispatch(for_.assign),
3.104 ReleaseTemp()
3.105 ])
3.106 ] + self.dispatch(for_.body) + [
3.107 InvokeBlock(
3.108 + for_,
3.109 expr=LoadRef(ref=subprogram)
3.110 )
3.111 ],
3.112 handler=[
3.113 Conditional(
3.114 test=InvokeFunction(
3.115 + for_,
3.116 expr=LoadName(name="isinstance"),
3.117 args=[LoadExc(), LoadName(name="StopIteration")],
3.118 star=None,
3.119 @@ -709,13 +719,14 @@
3.120 code=[
3.121 StoreTemp(
3.122 expr=InvokeFunction(
3.123 + for_,
3.124 expr=LoadAttr(
3.125 name="__iter__",
3.126 expr=self.dispatch(for_.list)
3.127 )
3.128 )
3.129 ),
3.130 - InvokeBlock(expr=LoadRef(ref=subprogram)),
3.131 + InvokeBlock(for_, expr=LoadRef(ref=subprogram)),
3.132 ReleaseTemp()
3.133 ]
3.134 )
3.135 @@ -780,14 +791,14 @@
3.136 if has_star:
3.137 star = (
3.138 function.argnames[npositional],
3.139 - InvokeFunction(expr=LoadName(name="list"))
3.140 + self.dispatch(compiler.ast.List([]))
3.141 )
3.142 else:
3.143 star = None
3.144 if has_dstar:
3.145 dstar = (
3.146 function.argnames[npositional + has_star],
3.147 - InvokeFunction(expr=LoadName(name="dict"))
3.148 + self.dispatch(compiler.ast.Dict([]))
3.149 )
3.150 else:
3.151 dstar = None
3.152 @@ -887,6 +898,7 @@
3.153
3.154 test = Conditional(if_, first,
3.155 test=InvokeFunction(
3.156 + if_,
3.157 expr=LoadAttr(
3.158 expr=self.dispatch(compare),
3.159 name="__bool__"
3.160 @@ -959,6 +971,7 @@
3.161
3.162 def _visitNot(self, expr, not_=None):
3.163 invocation = InvokeFunction(
3.164 + not_, # NOTE: May need a real original node.
3.165 expr=LoadAttr(
3.166 expr=expr,
3.167 name="__bool__"
3.168 @@ -1007,7 +1020,7 @@
3.169
3.170 if node is not last:
3.171 nodes.append(StoreTemp(expr=expr))
3.172 - invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__bool__"))
3.173 + invocation = InvokeFunction(or_, expr=LoadAttr(expr=LoadTemp(), name="__bool__"))
3.174 test = Conditional(test=invocation, body=[ReturnFromBlock(expr=LoadTemp())])
3.175 nodes.append(test)
3.176
3.177 @@ -1079,6 +1092,7 @@
3.178 for node in print_.nodes:
3.179 result.code.append(
3.180 InvokeFunction(
3.181 + print_,
3.182 expr=LoadTemp(index="print"),
3.183 args=[self.dispatch(node)],
3.184 star=None,
3.185 @@ -1097,6 +1111,7 @@
3.186 result.code.insert(
3.187 len(result.code) - 1,
3.188 InvokeFunction(
3.189 + printnl,
3.190 expr=LoadTemp(index="print"),
3.191 args=[self.dispatch(compiler.ast.Const("\n"))],
3.192 star=None,
3.193 @@ -1111,6 +1126,7 @@
3.194 result.expr = self.dispatch(raise_.expr1)
3.195 else:
3.196 result.expr = InvokeFunction(
3.197 + raise_,
3.198 expr=self.dispatch(raise_.expr1),
3.199 args=[self.dispatch(raise_.expr2)],
3.200 star=None,
3.201 @@ -1362,12 +1378,14 @@
3.202
3.203 test = Conditional(
3.204 test=InvokeFunction(
3.205 + while_,
3.206 expr=LoadAttr(
3.207 expr=self.dispatch(while_.test),
3.208 name="__bool__"),
3.209 ),
3.210 body=self.dispatch(while_.body) + [
3.211 InvokeBlock(
3.212 + while_,
3.213 expr=LoadRef(ref=subprogram)
3.214 ),
3.215 ReturnFromBlock()
3.216 @@ -1422,6 +1440,7 @@
3.217 body=[
3.218 ReturnFromBlock(
3.219 expr=InvokeFunction(
3.220 + binary,
3.221 expr=LoadAttr(expr=self.dispatch(binary.left), name=left_name),
3.222 args=[self.dispatch(binary.right)],
3.223 star=None,
3.224 @@ -1436,6 +1455,7 @@
3.225 body=[
3.226 ReturnFromBlock(
3.227 expr=InvokeFunction(
3.228 + binary,
3.229 expr=LoadAttr(expr=self.dispatch(binary.right), name=right_name),
3.230 args=[self.dispatch(binary.left)],
3.231 star=None,
3.232 @@ -1452,6 +1472,7 @@
3.233 self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
3.234
3.235 result = InvokeBlock(
3.236 + binary,
3.237 produces_result=1,
3.238 expr=LoadRef(ref=subprogram)
3.239 )