# HG changeset patch # User Paul Boddie # Date 1229039984 -3600 # Node ID e38b8757fabcb5712829f8dc4854a347f8d44ed6 # Parent e9402bb3f2de875774614b7fd6f7466476c6dbcc Added some support for constant data. Fixed LoadAttr and StoreAttr to actually access attribute locations. Fixed RSVP execution of source and input instructions. diff -r e9402bb3f2de -r e38b8757fabc micropython/__init__.py --- a/micropython/__init__.py Tue Dec 02 01:13:19 2008 +0100 +++ b/micropython/__init__.py Fri Dec 12 00:59:44 2008 +0100 @@ -315,6 +315,8 @@ pos += 1 if isinstance(item, micropython.data.Function): item.code_location = pos + elif isinstance(item, micropython.data.Const): + pos += len(self.raw_data(item)) else: pos += 1 @@ -331,7 +333,7 @@ )) elif isinstance(item, Block): - self.raw_code += self.raw_block(item, len(self.raw_code)) + self.raw_code += self.raw_block(item) # Using classcode, attrcode, codeaddr, codedetails, instance. @@ -366,6 +368,8 @@ 1 )) + self.raw_code += self.raw_data(item) + elif isinstance(item, micropython.data.Function): assert item.location == len(self.raw_code) @@ -409,19 +413,29 @@ self.code_location = self.modules["__main__"].code_location return self.raw_code - def raw_block(self, block, location): + def raw_block(self, block): - """ - Return the code for the given 'block', appearing at the given - 'location'. - """ + "Return the code for the given 'block'." - assert block.location == location + assert block.location == len(self.raw_code) for i, item in enumerate(block.code): if hasattr(item, "location"): item.location = location + i return block.code + def raw_data(self, item): + + "Return the data for the given 'item'." + + datatype = item.value_type_name() + + # NOTE: Start simple and use single entries for most types. + + if datatype in ("__builtins__.tuple", "__builtins__.list"): + return [len(item.value)] + list(item.value) + else: + return [item.value] + def get_object_table(self): "Return a table with details of attributes for classes and modules." diff -r e9402bb3f2de -r e38b8757fabc rsvp.py --- a/rsvp.py Tue Dec 02 01:13:19 2008 +0100 +++ b/rsvp.py Fri Dec 12 00:59:44 2008 +0100 @@ -257,9 +257,11 @@ instructions would otherwise have. """ - for input in (self.instruction.input, self.instruction.source): - if input is not None: - self.perform(input) + if self.instruction.source is not None: + self.perform(self.instruction.source) + self.source = self.value + if self.instruction.input is not None: + self.perform(self.instruction.input) def jump(self, addr, next): @@ -318,12 +320,12 @@ def LoadAttr(self): context, ref = self.value # Retrieved context should already be appropriate for the instance. - self.value = self.load(ref + self.operand) + self.value = self.load(ref + self.operand + 1) def StoreAttr(self): context, ref = self.value # Target should already be an instance. - self.save(ref + self.operand, self.source) + self.save(ref + self.operand + 1, self.source) def LoadAttrIndex(self): context, ref = self.value