1.1 --- a/micropython/data.py Sat Jun 12 03:04:08 2010 +0200
1.2 +++ b/micropython/data.py Sat Jun 12 21:33:36 2010 +0200
1.3 @@ -124,6 +124,7 @@
1.4 def __init__(self, module=None):
1.5 self.namespace = {}
1.6 self.globals = set()
1.7 + self.scope_usage = {}
1.8 self.module = module
1.9 self.finalised = 0
1.10
1.11 @@ -271,6 +272,27 @@
1.12 else:
1.13 return 0
1.14
1.15 + def note_scope(self, name, scope):
1.16 +
1.17 + "Note usage of 'name' from the given 'scope' in the current namespace."
1.18 +
1.19 + if not self.scope_usage.has_key(name):
1.20 + self.scope_usage[name] = scope
1.21 + return 1
1.22 + elif self.scope_usage[name] == scope:
1.23 + return 1
1.24 + else:
1.25 + return 0
1.26 +
1.27 + def used_in_scope(self, name, scope):
1.28 +
1.29 + """
1.30 + Return whether 'name' is used from the given 'scope' in the current
1.31 + namespace.
1.32 + """
1.33 +
1.34 + return self.scope_usage.get(name) == scope
1.35 +
1.36 # Attribute positioning.
1.37
1.38 def attributes_as_list(self):
1.39 @@ -1244,6 +1266,9 @@
1.40 # Namespace-related methods.
1.41
1.42 def make_global(self, name):
1.43 +
1.44 + "Declare 'name' as a global in the current namespace."
1.45 +
1.46 if name not in self.argnames and not self.has_key(name):
1.47 self.globals.add(name)
1.48 return 1