1.1 --- a/annotate.py Sun Oct 15 01:03:44 2006 +0200
1.2 +++ b/annotate.py Sun Oct 15 02:44:46 2006 +0200
1.3 @@ -132,6 +132,7 @@
1.4
1.5 # Process the module, supplying builtins if possible.
1.6
1.7 + self.builtins = builtins
1.8 self.global_namespace = Namespace()
1.9
1.10 if builtins is not None:
1.11 @@ -249,7 +250,10 @@
1.12 def visitLoadTemp(self, loadtemp):
1.13 index = getattr(loadtemp, "index", None)
1.14 try:
1.15 - self.namespace.set_types(self.namespace.temp[index][-1])
1.16 + if getattr(loadtemp, "release", 0):
1.17 + self.namespace.set_types(self.namespace.temp[index].pop())
1.18 + else:
1.19 + self.namespace.set_types(self.namespace.temp[index][-1])
1.20 except KeyError:
1.21 raise AnnotationMessage, "Temporary store index '%s' not defined." % index
1.22 self.annotate(loadtemp)
1.23 @@ -421,7 +425,7 @@
1.24 self.annotate(invoke)
1.25
1.26 invoke.invocations = invocations
1.27 -
1.28 + self.namespace.set_types(getattr(invoke, "types", []))
1.29 return invoke
1.30
1.31 visitInvokeFunction = visitInvoke
1.32 @@ -581,16 +585,17 @@
1.33 # Construct temporary objects.
1.34
1.35 if star_args:
1.36 - list_type = self.builtins_namespace.load("list")[0] # NOTE: Hack to get list type.
1.37 - star = self.new_instance(invocation, "star", subprogram.full_name(), list_type.type)
1.38 - star_types = [Attribute(None, star)]
1.39 + star_invocation = self.make_star_args(invocation, subprogram, star_args)
1.40 + self.dispatch(star_invocation)
1.41 + star_invocation.pprint()
1.42 + star_types = star_invocation.types
1.43 else:
1.44 star_types = None
1.45
1.46 if dstar_args:
1.47 - dict_type = self.builtins_namespace.load("dict")[0] # NOTE: Hack to get dict type.
1.48 - dstar = self.new_instance(invocation, "dstar", subprogram.full_name(), dict_type.type)
1.49 - dstar_types = [Attribute(None, dstar)]
1.50 + dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args)
1.51 + self.dispatch(dstar_invocation)
1.52 + dstar_types = dstar_invocation.types
1.53 else:
1.54 dstar_types = None
1.55
1.56 @@ -625,6 +630,64 @@
1.57
1.58 return items
1.59
1.60 + def make_star_args(self, invocation, subprogram, star_args):
1.61 +
1.62 + "Make a subprogram which initialises a list containing 'star_args'."
1.63 +
1.64 + if not hasattr(invocation, "stars"):
1.65 + invocation.stars = {}
1.66 +
1.67 + if not invocation.stars.has_key(subprogram.full_name()):
1.68 + code=[
1.69 + StoreTemp(
1.70 + expr=InvokeFunction(
1.71 + expr=LoadAttr(
1.72 + expr=LoadRef(
1.73 + ref=self.builtins
1.74 + ),
1.75 + name="list",
1.76 + nstype="module",
1.77 + ),
1.78 + args=[],
1.79 + star=None,
1.80 + dstar=None
1.81 + )
1.82 + )
1.83 + ]
1.84 +
1.85 + for arg in star_args:
1.86 + code.append(
1.87 + InvokeFunction(
1.88 + expr=LoadAttr(
1.89 + expr=LoadTemp(),
1.90 + name="append"
1.91 + ),
1.92 + args=[arg],
1.93 + star=None,
1.94 + dstar=None
1.95 + )
1.96 + )
1.97 +
1.98 + code += [
1.99 + Return(expr=LoadTemp(release=1))
1.100 + ]
1.101 +
1.102 + invocation.stars[subprogram.full_name()] = InvokeBlock(
1.103 + produces_result=1,
1.104 + expr=LoadRef(
1.105 + ref=Subprogram(
1.106 + name=None,
1.107 + returns_value=1,
1.108 + params=[],
1.109 + star=None,
1.110 + dstar=None,
1.111 + code=code
1.112 + )
1.113 + )
1.114 + )
1.115 +
1.116 + return invocation.stars[subprogram.full_name()]
1.117 +
1.118 def make_namespace(self, items):
1.119 namespace = Namespace()
1.120 namespace.merge_items(items)