1.1 --- a/docs/structures.txt Tue Aug 19 00:41:30 2008 +0200
1.2 +++ b/docs/structures.txt Thu Aug 21 00:49:15 2008 +0200
1.3 @@ -74,12 +74,13 @@
1.4 attribute; other attributes have
1.5 their context preserved
1.6
1.7 - LoadAttrIndex Load attribute from Classes, functions and modules as
1.8 - unknown object the unknown object accessor cause
1.9 + LoadAttrIndex Load attribute from Functions and modules as unknown
1.10 + object the unknown object accessor cause
1.11 the loaded attribute to be
1.12 - retrieved unchanged; whereas
1.13 + retrieved unchanged; classes and
1.14 instances cause the LoadAttr rules
1.15 - to apply
1.16 + to apply (class compatibility
1.17 + applies)
1.18
1.19 A certain amount of run-time testing might be required for both LoadAttr and
1.20 LoadAttrIndex instructions. However, with certain restrictions in place around
2.1 --- a/micropython/data.py Tue Aug 19 00:41:30 2008 +0200
2.2 +++ b/micropython/data.py Thu Aug 21 00:49:15 2008 +0200
2.3 @@ -271,6 +271,9 @@
2.4 else:
2.5 return self
2.6
2.7 + def is_class_attribute(self):
2.8 + return isinstance(self.parent, Class)
2.9 +
2.10 def defined_within_hierarchy(self):
2.11
2.12 """
3.1 --- a/micropython/table.py Tue Aug 19 00:41:30 2008 +0200
3.2 +++ b/micropython/table.py Thu Aug 21 00:49:15 2008 +0200
3.3 @@ -153,9 +153,9 @@
3.4 else:
3.5 position = None # NOTE: Should fix unpositioned attributes.
3.6
3.7 - # Class offset/code, context instance override flag, location/position.
3.8 + # Class offset/code, attribute type, context instance override flag, location/position.
3.9
3.10 - result.append((offset, attr.defined_within_hierarchy(), position))
3.11 + result.append((offset, attr.is_class_attribute(), attr.defined_within_hierarchy(), position))
3.12
3.13 return result
3.14
4.1 --- a/rsvp.py Tue Aug 19 00:41:30 2008 +0200
4.2 +++ b/rsvp.py Thu Aug 21 00:49:15 2008 +0200
4.3 @@ -241,12 +241,8 @@
4.4
4.5 def LoadAttr(self):
4.6 context, ref = self.value
4.7 - loaded_context, loaded_ref = self.load(ref + self.operand)
4.8 - if loaded_context is None:
4.9 - # Override null context with owning instance.
4.10 - self.value = ref, loaded_ref
4.11 - else:
4.12 - self.value = loaded_context, loaded_ref
4.13 + # Retrieved context should already be appropriate for the instance.
4.14 + self.value = self.load(ref + self.operand)
4.15
4.16 def StoreAttr(self):
4.17 context, ref = self.value
4.18 @@ -256,18 +252,24 @@
4.19 context, ref = self.value
4.20 code = self.load(ref) # + 0 (the classcode)
4.21 element = self.objtable[code + self.operand]
4.22 - found_code, found_attr = element
4.23 + found_code, class_attr, replace_context, offset = element
4.24 if found_code == code:
4.25 - # NOTE: The found context should be tested against the object's context.
4.26 - # NOTE: Compatibility between contexts should be stored in the table, or
4.27 - # NOTE: an incompatible context should be preserved.
4.28 - self.value = ref, found_ref
4.29 + if class_attr:
4.30 + loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute
4.31 + if replace_context:
4.32 + self.value = ref, loaded_ref # classes can also replace the context if compatible
4.33 + return
4.34 + self.value = loaded_context, loaded_ref
4.35 + else:
4.36 + self.value = self.load(ref + offset)
4.37 else:
4.38 # NOTE: This should cause an attribute error.
4.39 self.value = None
4.40
4.41 def StoreAttrIndex(self): pass
4.42
4.43 + # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden.
4.44 +
4.45 def MakeFrame(self):
4.46 self.invocation_sp_stack.append(len(self.frame_stack))
4.47 self.frame_stack.extend([None] * self.operand)