# HG changeset patch # User paulb@localhost.localdomain # Date 1165880822 -3600 # Node ID 869442abce841dddc88e2ab20220674a906c8d23 # Parent c1f7c777c71471ce7e093a4b4b72ef8d16e84392 Added incomplete support for dstar arguments (constant initialisation needs finishing). diff -r c1f7c777c714 -r 869442abce84 annotate.py --- a/annotate.py Mon Dec 11 23:51:42 2006 +0100 +++ b/annotate.py Tue Dec 12 00:47:02 2006 +0100 @@ -573,7 +573,7 @@ elif isinstance(expr, LoadExc): self.namespace.revoke_exception_type(attr) elif isinstance(expr, LoadTemp): - self.namespace.revoke_temp_type(expr.index, attr) + self.namespace.revoke_temp_type(getattr(expr, "index", None), attr) # LoadAttr cannot be pruned since this might unintentionally prune # legitimate types from other applications of the referenced type, it @@ -1066,7 +1066,7 @@ items.append((param, [])) # Annotation has not succeeded. params = params[1:] - dstar_args = kw_args.values() + dstar_args = kw_args.items() # Construct temporary objects. @@ -1078,7 +1078,7 @@ star_types = None if dstar_args: - dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args) # NOTE: To be written! + dstar_invocation = self.make_dstar_args(invocation, subprogram, dstar_args) self.dispatch(dstar_invocation) dstar_types = dstar_invocation.types else: @@ -1178,6 +1178,91 @@ return invocation.stars[subprogram.full_name()] + def make_dstar_args(self, invocation, subprogram, dstar_args): + + """ + Make a subprogram which initialises a dictionary built from the given + 'dstar_args'. + """ + + if not hasattr(invocation, "dstars"): + invocation.dstars = {} + + if not invocation.dstars.has_key(subprogram.full_name()): + code=[ + StoreTemp( + expr=InvokeFunction( + expr=LoadAttr( + expr=LoadRef( + ref=self.builtins + ), + name="dict", + nstype="module", + ) + ) + ) + ] + + for arg, value in dstar_args: + + # NOTE: Constant not added to table. + + constant = Constant(name=repr(arg), value=arg, namespace=Namespace()) + code += [ + StoreTemp( + expr=LoadRef( + ref=constant + ), + index="const" + ), + StoreAttr( + lvalue=LoadTemp( + index="const" + ), + name="__class__", + expr=LoadAttr( + expr=LoadRef( + ref=self.builtins + ), + name=constant.typename, + nstype="module", + ) + ), + InvokeFunction( + expr=LoadAttr( + expr=LoadTemp(), + name="__setitem__" + ), + args=[ + LoadTemp( + index="const", + release=1 + ), + value + ] + ) + ] + + code += [ + Return(expr=LoadTemp(release=1)) + ] + + invocation.dstars[subprogram.full_name()] = InvokeBlock( + produces_result=1, + expr=LoadRef( + ref=Subprogram( + name=None, + returns_value=1, + params=[], + star=None, + dstar=None, + code=code + ) + ) + ) + + return invocation.dstars[subprogram.full_name()] + # Namespace-related abstractions. class Namespace: