# HG changeset patch # User paulb@localhost.localdomain # Date 1165362509 -3600 # Node ID 053d9f313f654a4d01a90a5045da4e1a4e42f6f9 # Parent 10e0442613e0c544daceaa4755c95f6ec05a7f38 Moved system count testing back to before namespace construction in the invocation and annotation of subprograms (reverting changes in changeset #146); this may have been changed earlier because default value types were not being remembered. Fixed constant storage by differentiating between values more thoroughly. Fixed/improved keyword argument handling, removing the Keyword node from the annotation phase. Changed the CSS class for keyword arguments. diff -r 10e0442613e0 -r 053d9f313f65 annotate.py --- a/annotate.py Sun Dec 03 23:47:41 2006 +0100 +++ b/annotate.py Wed Dec 06 00:48:29 2006 +0100 @@ -122,7 +122,7 @@ Raise, ReleaseTemp, ReturnFromBlock, ReturnFromFunction, StoreAttr, StoreName, StoreTemp, Subprogram, Try. - Missing: Keyword, Global, Import. + Missing: Global, Import. """ def __init__(self): @@ -698,6 +698,7 @@ writes = {} non_writes = [] for attr in self.namespace.types: + # NOTE: Impose "atomic" constraints on certain types. if attr is None: if not attr in non_writes: non_writes.append(attr) @@ -851,6 +852,16 @@ context = None target = attribute.type + # Test to see if anything has changed. + + if hasattr(invoke, "syscount") and invoke.syscount == self.system.count: + return + + # Remember the state of the system. + + else: + invoke.syscount = self.system.count + # Provide the correct namespace for the invocation. if getattr(invoke, "share_locals", 0): @@ -866,16 +877,6 @@ namespace.merge_items(items) using_module_namespace = 0 - # Test to see if anything has changed. - - if hasattr(invoke, "syscount") and invoke.syscount == self.system.count: - return - - # Remember the state of the system. - - else: - invoke.syscount = self.system.count - # Process the subprogram. # In order to keep global accesses working, the module namespace must be # adjusted. @@ -965,7 +966,11 @@ pos_args = [Self(context)] + invocation.pos_args else: pos_args = invocation.pos_args - kw_args = invocation.kw_args + + # Duplicate the keyword arguments - we remove them in processing below. + + kw_args = {} + kw_args.update(invocation.kw_args) # Sort the arguments into positional and keyword arguments. @@ -1038,9 +1043,9 @@ raise AnnotationMessage, "Invocation provides unwanted *args." elif subprogram.star is not None: param, default = subprogram.star - if not hasattr(arg, "types"): - arg = self.dispatch(default) # NOTE: Review reprocessing. - items.append((param, arg.types)) + if not hasattr(default, "types"): + subprogram.star = param, self.dispatch(default) # NOTE: Review reprocessing. + items.append((param, default.types)) if dstar_types is not None: if subprogram.dstar is not None: @@ -1050,9 +1055,9 @@ raise AnnotationMessage, "Invocation provides unwanted **args." elif subprogram.dstar is not None: param, default = subprogram.dstar - if not hasattr(arg, "types"): - arg = self.dispatch(default) # NOTE: Review reprocessing. - items.append((param, arg.types)) + if not hasattr(default, "types"): + subprogram.dstar = param, self.dispatch(default) # NOTE: Review reprocessing. + items.append((param, default.types)) # Record the parameter types. diff -r 10e0442613e0 -r 053d9f313f65 simplified.py --- a/simplified.py Sun Dec 03 23:47:41 2006 +0100 +++ b/simplified.py Wed Dec 06 00:48:29 2006 +0100 @@ -360,7 +360,7 @@ add_kw = 1 if add_kw: if isinstance(arg, Keyword): - self.kw_args[arg.name] = arg + self.kw_args[arg.name] = arg.expr else: raise TypeError, "Positional argument appears after keyword arguments in '%s'." % self diff -r 10e0442613e0 -r 053d9f313f65 simplify.py --- a/simplify.py Sun Dec 03 23:47:41 2006 +0100 +++ b/simplify.py Wed Dec 06 00:48:29 2006 +0100 @@ -582,9 +582,10 @@ return result def visitConst(self, const): - if not self.constants.has_key(const.value): - self.constants[const.value] = Constant(name=repr(const.value), value=const.value) - result = LoadRef(const, 1, ref=self.constants[const.value]) + key = "%s-%s" % (const.value.__class__.__name__, const.value) + if not self.constants.has_key(key): + self.constants[key] = Constant(name=repr(const.value), value=const.value) + result = LoadRef(const, 1, ref=self.constants[key]) return result def visitContinue(self, continue_): diff -r 10e0442613e0 -r 053d9f313f65 viewer.py --- a/viewer.py Sun Dec 03 23:47:41 2006 +0100 +++ b/viewer.py Wed Dec 06 00:48:29 2006 +0100 @@ -589,7 +589,7 @@ self.stream.write("\n") def visitKeyword(self, node): - self.stream.write("\n") + self.stream.write("\n") self.stream.write(node.name) self.stream.write("=") self.dispatch(node.expr)