# HG changeset patch # User Paul Boddie # Date 1312742304 -7200 # Node ID 95e3c8b48a1d499d0a03941c2cd2aa460863a4ac # Parent 1c036da5aff9b4ecb2ce8371e00239754f1bbb9c Replaced Instance instantiation with usage of a function that obtains a common instance of the class. diff -r 1c036da5aff9 -r 95e3c8b48a1d micropython/data.py --- a/micropython/data.py Sun Aug 07 19:23:49 2011 +0200 +++ b/micropython/data.py Sun Aug 07 20:38:24 2011 +0200 @@ -238,7 +238,7 @@ if value is None: print "Warning: name %r in namespace %r has an unknown value (evaluated to None)." % (name, self.full_name()) - value = Instance() + value = make_instance() if name in self.globals: self.module.set(name, value, 0) @@ -933,7 +933,7 @@ """ if self.context_values.issuperset(context_values) and \ - not (Instance(), Instance()) in context_values: + not (make_instance(), make_instance()) in context_values: return if self.assignments is None: @@ -1098,6 +1098,11 @@ __shortrepr__ = __repr__ +common_instance = Instance() + +def make_instance(): + return common_instance + class Constant: "A superclass for all constant or context-free structures." @@ -1462,7 +1467,7 @@ d = {} for i, name in enumerate(self._get_position_list(instattr)): - d[name] = Attr(i, Instance(), name) + d[name] = Attr(i, make_instance(), name) return d def _get_position_list(self, positions): @@ -1645,11 +1650,11 @@ "Add 'argnames' to the namespace." for name in argnames: - self.set(name, Instance()) + self.set(name, make_instance()) for name, top_level in self._flattened_parameters(argnames): if not top_level: - self.set(name, Instance()) + self.set(name, make_instance()) def _flattened_parameters(self, argnames, top_level=1): l = [] @@ -1718,7 +1723,7 @@ name = "" self.argnames.insert(0, name) self.positional_names.insert(0, name) - self.set(name, Instance()) + self.set(name, make_instance()) # Namespace-related methods. diff -r 1c036da5aff9 -r 95e3c8b48a1d micropython/inspect.py --- a/micropython/inspect.py Sun Aug 07 19:23:49 2011 +0200 +++ b/micropython/inspect.py Sun Aug 07 20:38:24 2011 +0200 @@ -171,7 +171,7 @@ if isinstance(n, compiler.ast.Global): for name in n.names: if not self.has_key(name): - self[name] = Instance() + self[name] = make_instance() else: self.process_globals(n) @@ -427,7 +427,7 @@ def OP(self, node): for n in node.getChildNodes(): self.dispatch(n) - return Instance() + return make_instance() # Generic support for classes of operations. @@ -468,21 +468,21 @@ if attrname == "__class__" and isinstance(value, Class): attr = type_class else: - attr = value.get(attrname) or Instance() + attr = value.get(attrname) or make_instance() self.use_specific_attribute(value.full_name(), attrname) elif isinstance(value, UnresolvedName): attr = UnresolvedName(attrname, value.full_name(), self) else: - attr = Instance() + attr = make_instance() # Note usage of the attribute where a local is involved. self._visitAttrUser(expr, attrname, node) else: - attr = Instance() + attr = make_instance() self.use_name(attrname, node) return attr @@ -851,7 +851,7 @@ # NOTE: Could generate AST nodes for the actual operations instead of # NOTE: manually generating code in micropython.ast. - self.expr = Instance() # each element is a result of a function call + self.expr = make_instance() # each element is a result of a function call self.dispatch(node.assign) # Enter the loop. @@ -972,7 +972,7 @@ self.shelve_branch() self.merge_branches() - return Instance() # either outcome is possible + return make_instance() # either outcome is possible def visitImport(self, node): for name, alias in node.names: @@ -1005,7 +1005,7 @@ for qual in node.quals: self.dispatch(qual) self.dispatch(node.expr) - return Instance() + return make_instance() def visitListCompFor(self, node): self.new_branchpoint() @@ -1022,7 +1022,7 @@ # NOTE: Could generate AST nodes for the actual operations instead of # NOTE: manually generating code in micropython.ast. - self.expr = Instance() # each element is a result of a function call + self.expr = make_instance() # each element is a result of a function call self.dispatch(node.assign) # Enter the loop. @@ -1052,7 +1052,7 @@ visitMul = _visitBinary def visitName(self, node): - return self.get_namespace().get_using_node(node.name, node) or Instance() + return self.get_namespace().get_using_node(node.name, node) or make_instance() visitNot = OP