1.1 --- a/micropython/data.py Sun Aug 07 19:23:49 2011 +0200
1.2 +++ b/micropython/data.py Sun Aug 07 20:38:24 2011 +0200
1.3 @@ -238,7 +238,7 @@
1.4
1.5 if value is None:
1.6 print "Warning: name %r in namespace %r has an unknown value (evaluated to None)." % (name, self.full_name())
1.7 - value = Instance()
1.8 + value = make_instance()
1.9
1.10 if name in self.globals:
1.11 self.module.set(name, value, 0)
1.12 @@ -933,7 +933,7 @@
1.13 """
1.14
1.15 if self.context_values.issuperset(context_values) and \
1.16 - not (Instance(), Instance()) in context_values:
1.17 + not (make_instance(), make_instance()) in context_values:
1.18 return
1.19
1.20 if self.assignments is None:
1.21 @@ -1098,6 +1098,11 @@
1.22
1.23 __shortrepr__ = __repr__
1.24
1.25 +common_instance = Instance()
1.26 +
1.27 +def make_instance():
1.28 + return common_instance
1.29 +
1.30 class Constant:
1.31
1.32 "A superclass for all constant or context-free structures."
1.33 @@ -1462,7 +1467,7 @@
1.34
1.35 d = {}
1.36 for i, name in enumerate(self._get_position_list(instattr)):
1.37 - d[name] = Attr(i, Instance(), name)
1.38 + d[name] = Attr(i, make_instance(), name)
1.39 return d
1.40
1.41 def _get_position_list(self, positions):
1.42 @@ -1645,11 +1650,11 @@
1.43 "Add 'argnames' to the namespace."
1.44
1.45 for name in argnames:
1.46 - self.set(name, Instance())
1.47 + self.set(name, make_instance())
1.48
1.49 for name, top_level in self._flattened_parameters(argnames):
1.50 if not top_level:
1.51 - self.set(name, Instance())
1.52 + self.set(name, make_instance())
1.53
1.54 def _flattened_parameters(self, argnames, top_level=1):
1.55 l = []
1.56 @@ -1718,7 +1723,7 @@
1.57 name = "<context>"
1.58 self.argnames.insert(0, name)
1.59 self.positional_names.insert(0, name)
1.60 - self.set(name, Instance())
1.61 + self.set(name, make_instance())
1.62
1.63 # Namespace-related methods.
1.64
2.1 --- a/micropython/inspect.py Sun Aug 07 19:23:49 2011 +0200
2.2 +++ b/micropython/inspect.py Sun Aug 07 20:38:24 2011 +0200
2.3 @@ -171,7 +171,7 @@
2.4 if isinstance(n, compiler.ast.Global):
2.5 for name in n.names:
2.6 if not self.has_key(name):
2.7 - self[name] = Instance()
2.8 + self[name] = make_instance()
2.9 else:
2.10 self.process_globals(n)
2.11
2.12 @@ -427,7 +427,7 @@
2.13 def OP(self, node):
2.14 for n in node.getChildNodes():
2.15 self.dispatch(n)
2.16 - return Instance()
2.17 + return make_instance()
2.18
2.19 # Generic support for classes of operations.
2.20
2.21 @@ -468,21 +468,21 @@
2.22 if attrname == "__class__" and isinstance(value, Class):
2.23 attr = type_class
2.24 else:
2.25 - attr = value.get(attrname) or Instance()
2.26 + attr = value.get(attrname) or make_instance()
2.27 self.use_specific_attribute(value.full_name(), attrname)
2.28
2.29 elif isinstance(value, UnresolvedName):
2.30 attr = UnresolvedName(attrname, value.full_name(), self)
2.31
2.32 else:
2.33 - attr = Instance()
2.34 + attr = make_instance()
2.35
2.36 # Note usage of the attribute where a local is involved.
2.37
2.38 self._visitAttrUser(expr, attrname, node)
2.39
2.40 else:
2.41 - attr = Instance()
2.42 + attr = make_instance()
2.43 self.use_name(attrname, node)
2.44
2.45 return attr
2.46 @@ -851,7 +851,7 @@
2.47 # NOTE: Could generate AST nodes for the actual operations instead of
2.48 # NOTE: manually generating code in micropython.ast.
2.49
2.50 - self.expr = Instance() # each element is a result of a function call
2.51 + self.expr = make_instance() # each element is a result of a function call
2.52 self.dispatch(node.assign)
2.53
2.54 # Enter the loop.
2.55 @@ -972,7 +972,7 @@
2.56 self.shelve_branch()
2.57
2.58 self.merge_branches()
2.59 - return Instance() # either outcome is possible
2.60 + return make_instance() # either outcome is possible
2.61
2.62 def visitImport(self, node):
2.63 for name, alias in node.names:
2.64 @@ -1005,7 +1005,7 @@
2.65 for qual in node.quals:
2.66 self.dispatch(qual)
2.67 self.dispatch(node.expr)
2.68 - return Instance()
2.69 + return make_instance()
2.70
2.71 def visitListCompFor(self, node):
2.72 self.new_branchpoint()
2.73 @@ -1022,7 +1022,7 @@
2.74 # NOTE: Could generate AST nodes for the actual operations instead of
2.75 # NOTE: manually generating code in micropython.ast.
2.76
2.77 - self.expr = Instance() # each element is a result of a function call
2.78 + self.expr = make_instance() # each element is a result of a function call
2.79 self.dispatch(node.assign)
2.80
2.81 # Enter the loop.
2.82 @@ -1052,7 +1052,7 @@
2.83 visitMul = _visitBinary
2.84
2.85 def visitName(self, node):
2.86 - return self.get_namespace().get_using_node(node.name, node) or Instance()
2.87 + return self.get_namespace().get_using_node(node.name, node) or make_instance()
2.88
2.89 visitNot = OP
2.90