1.1 --- a/micropython/data.py Sat Jun 07 21:55:24 2008 +0200
1.2 +++ b/micropython/data.py Mon Jun 09 21:09:37 2008 +0200
1.3 @@ -40,8 +40,8 @@
1.4
1.5 These specific methods are useful in certain situations.
1.6
1.7 -The above classes also provide a 'node' attribute, indicating the AST node where
1.8 -each such object is defined.
1.9 +The above classes also provide an 'astnode' attribute, indicating the AST node
1.10 +where each such object is defined.
1.11 """
1.12
1.13 from micropython.common import *
1.14 @@ -62,6 +62,7 @@
1.15 self.namespace = {}
1.16 self.globals = set()
1.17 self.global_namespace = global_namespace
1.18 + self.finalised = 0
1.19
1.20 def __getitem__(self, name):
1.21 return self.namespace[name]
1.22 @@ -155,6 +156,9 @@
1.23 return None
1.24
1.25 def attributes_as_list(self):
1.26 +
1.27 + "Return the attributes in a list."
1.28 +
1.29 self.finalise_attributes()
1.30 l = [None] * len(self.keys())
1.31 for attr in self.values():
1.32 @@ -165,11 +169,16 @@
1.33
1.34 "Make sure all attributes are fully defined."
1.35
1.36 + if self.finalised:
1.37 + return
1.38 +
1.39 # The default action is to assign attribute positions sequentially.
1.40
1.41 for i, attr in enumerate(self.values()):
1.42 attr.position = i
1.43
1.44 + self.finalised = 1
1.45 +
1.46 # Program data structures. There are two separate kinds of structures: those
1.47 # with context, which are the values manipulated by programs, and those without
1.48 # context, which are typically constant things which are stored alongside the
1.49 @@ -381,8 +390,12 @@
1.50
1.51 "Make sure that all attributes are fully defined."
1.52
1.53 + if self.finalised:
1.54 + return
1.55 +
1.56 self.finalise_class_attributes()
1.57 self.finalise_instance_attributes()
1.58 + self.finalised = 1
1.59
1.60 def get_instantiator(self):
1.61
1.62 @@ -783,6 +796,7 @@
1.63 attr.position = i + j
1.64
1.65 self.stack_local_usage = i
1.66 + self.finalised = 1
1.67
1.68 def function_from_method(self):
1.69