# HG changeset patch # User Paul Boddie # Date 1219272555 -7200 # Node ID 5054b2ba3f9c465250d411dc0ee9b567d89f2caa # Parent dd607ca6396812e8ea2eb7d7db3c4eb7f3d10378 Added more support for LoadAttr and LoadAttrIndex in the RSVP implementation. diff -r dd607ca63968 -r 5054b2ba3f9c docs/structures.txt --- a/docs/structures.txt Tue Aug 19 00:41:30 2008 +0200 +++ b/docs/structures.txt Thu Aug 21 00:49:15 2008 +0200 @@ -74,12 +74,13 @@ attribute; other attributes have their context preserved - LoadAttrIndex Load attribute from Classes, functions and modules as - unknown object the unknown object accessor cause + LoadAttrIndex Load attribute from Functions and modules as unknown + object the unknown object accessor cause the loaded attribute to be - retrieved unchanged; whereas + retrieved unchanged; classes and instances cause the LoadAttr rules - to apply + to apply (class compatibility + applies) A certain amount of run-time testing might be required for both LoadAttr and LoadAttrIndex instructions. However, with certain restrictions in place around diff -r dd607ca63968 -r 5054b2ba3f9c micropython/data.py --- a/micropython/data.py Tue Aug 19 00:41:30 2008 +0200 +++ b/micropython/data.py Thu Aug 21 00:49:15 2008 +0200 @@ -271,6 +271,9 @@ else: return self + def is_class_attribute(self): + return isinstance(self.parent, Class) + def defined_within_hierarchy(self): """ diff -r dd607ca63968 -r 5054b2ba3f9c micropython/table.py --- a/micropython/table.py Tue Aug 19 00:41:30 2008 +0200 +++ b/micropython/table.py Thu Aug 21 00:49:15 2008 +0200 @@ -153,9 +153,9 @@ else: position = None # NOTE: Should fix unpositioned attributes. - # Class offset/code, context instance override flag, location/position. + # Class offset/code, attribute type, context instance override flag, location/position. - result.append((offset, attr.defined_within_hierarchy(), position)) + result.append((offset, attr.is_class_attribute(), attr.defined_within_hierarchy(), position)) return result diff -r dd607ca63968 -r 5054b2ba3f9c rsvp.py --- a/rsvp.py Tue Aug 19 00:41:30 2008 +0200 +++ b/rsvp.py Thu Aug 21 00:49:15 2008 +0200 @@ -241,12 +241,8 @@ def LoadAttr(self): context, ref = self.value - loaded_context, loaded_ref = self.load(ref + self.operand) - if loaded_context is None: - # Override null context with owning instance. - self.value = ref, loaded_ref - else: - self.value = loaded_context, loaded_ref + # Retrieved context should already be appropriate for the instance. + self.value = self.load(ref + self.operand) def StoreAttr(self): context, ref = self.value @@ -256,18 +252,24 @@ context, ref = self.value code = self.load(ref) # + 0 (the classcode) element = self.objtable[code + self.operand] - found_code, found_attr = element + found_code, class_attr, replace_context, offset = element if found_code == code: - # NOTE: The found context should be tested against the object's context. - # NOTE: Compatibility between contexts should be stored in the table, or - # NOTE: an incompatible context should be preserved. - self.value = ref, found_ref + if class_attr: + loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute + if replace_context: + self.value = ref, loaded_ref # classes can also replace the context if compatible + return + self.value = loaded_context, loaded_ref + else: + self.value = self.load(ref + offset) else: # NOTE: This should cause an attribute error. self.value = None def StoreAttrIndex(self): pass + # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden. + def MakeFrame(self): self.invocation_sp_stack.append(len(self.frame_stack)) self.frame_stack.extend([None] * self.operand)