# HG changeset patch # User Paul Boddie # Date 1298594702 -3600 # Node ID 83dc777c7083c766b565a97310b7daf21ef6d590 # Parent 62d65b1b793669ef9d0431975db65250f69e2847 Fixed constant raw image generation to actually refer to the class of each constant. Referenced NoneType and NotImplementedType so that the standard constants can be generated. Added a __class__ attribute to function instances. Fixed exception raising so that __class__ is included in allocated exception instances. Fixed item retrieval from list fragments which had erroneously been changed to resemble tuple item retrieval. Fixed list fragment reference initialisation for list literals. Added start and end parameters to the RSVPMachine.show method. Added an up method to RSVPMachine as a complement to the step and run methods. diff -r 62d65b1b7936 -r 83dc777c7083 lib/builtins.py --- a/lib/builtins.py Sun Feb 20 19:31:50 2011 +0100 +++ b/lib/builtins.py Fri Feb 25 01:45:02 2011 +0100 @@ -618,14 +618,16 @@ function AttributeError +#IndexError +NoneType +NotImplementedType #StopIteration TypeError -#IndexError +#bool +#ellipsis #list tuple #xrange -#ellipsis -#bool # vim: tabstop=4 expandtab shiftwidth=4 diff -r 62d65b1b7936 -r 83dc777c7083 micropython/data.py --- a/micropython/data.py Sun Feb 20 19:31:50 2011 +0100 +++ b/micropython/data.py Fri Feb 25 01:45:02 2011 +0100 @@ -1108,7 +1108,10 @@ return hash(self.value) def value_type_name(self): - return "__builtins__." + self.value.__class__.__name__ + return ".".join(self.value_type_name_parts()) + + def value_type_name_parts(self): + return "__builtins__", self.value.__class__.__name__ class Class(NamespaceDict, Naming, Constant): diff -r 62d65b1b7936 -r 83dc777c7083 micropython/rsvp.py --- a/micropython/rsvp.py Sun Feb 20 19:31:50 2011 +0100 +++ b/micropython/rsvp.py Fri Feb 25 01:45:02 2011 +0100 @@ -158,6 +158,10 @@ item = self.item classcode = objtable.as_list().get_code(item.value_type_name()) attrcode = objtable.get_index(item.value_type_name()) + name_parts = item.value_type_name_parts() + attr = objtable.access(*name_parts) + cls = attr.get_value() + return [ DataObject( classcode, @@ -171,7 +175,7 @@ DataValue( PlaceholderContext, - item.location + cls.location ) # NOTE: The RSVP library needs changing if more attributes are added @@ -202,23 +206,27 @@ if not self.is_generated(with_builtins): item.code_location = item.full_name() - # Skip any defaults for static functions. + # Skip __class__ plus any defaults for static functions. elif not item.is_dynamic(): - item.code_location = location + len(item.defaults) + item.code_location = location + 1 + len(item.defaults) - # Skip any defaults for dynamic functions. + # Skip __class__ plus any defaults for dynamic functions. else: - item.code_location = location + item.code_location = location + 1 - return location + # Include the __class__ attribute. + + return location + 1 def finalise_location(self, with_builtins): self._finalise_location(with_builtins) def as_raw(self, objtable, paramtable, with_builtins): item = self.item + attr = objtable.access("__builtins__", "function") + cls = attr.get_value() # NOTE: Need class and parameter details! Should arguably be an instance of types.FunctionType. return [ DataObject( @@ -228,6 +236,13 @@ "__builtins__.function", len(item.defaults) + 1, # size (not accurate for lambda functions before instantiation) paramtable.as_list().get_code(item.full_name()) # funccode + ), + + # The __class__ attribute for functions. + + DataValue( + PlaceholderContext, + cls.location ) ] diff -r 62d65b1b7936 -r 83dc777c7083 micropython/trans.py --- a/micropython/trans.py Sun Feb 20 19:31:50 2011 +0100 +++ b/micropython/trans.py Fri Feb 25 01:45:02 2011 +0100 @@ -49,7 +49,7 @@ "Make an exception of the given 'name' using 'node'." - # NOTE: Reserving only one attribute. + # NOTE: Reserving an attribute plus __class__. self.make_instance(self.get_builtin_class(name, node), 1) @@ -1414,7 +1414,7 @@ self.make_instance(self.get_builtin_class("list", node), 2) list_temp = self.get_temp() self.new_op(list_temp) - self.new_op(StoreAttr(Attr(0, None, None))) + self.new_op(StoreAttr(Attr(1, None, None))) self.set_source() self.discard_value() diff -r 62d65b1b7936 -r 83dc777c7083 rsvp.py --- a/rsvp.py Sun Feb 20 19:31:50 2011 +0100 +++ b/rsvp.py Fri Feb 25 01:45:02 2011 +0100 @@ -174,8 +174,8 @@ print "Result", self.result print "Exception", self.exception - def show(self): - self.show_memory(self.memory, self.coverage, 0) + def show(self, start=None, end=None): + self.show_memory(self.memory[start:end], self.coverage[start:end], start or 0) def show_pc(self, run_in=10): start = max(0, self.pc - run_in) @@ -204,6 +204,15 @@ def set_break(self, location): self.breakpoints.add(location) + def up(self): + retaddr = self.pc_stack[-1] + new_breakpoint = retaddr not in self.breakpoints + if new_breakpoint: + self.set_break(retaddr) + self.run() + if new_breakpoint: + self.breakpoints.remove(retaddr) + # Internal operations. def load(self, address): @@ -271,7 +280,7 @@ print "Execution terminated", if self.exception is not None: ref = self.exception - addr = self.load(ref + 1) + addr = self.load(ref + Library.instance_data_offset) print "with exception:", self.load(ref) print "At address %d: %r" % (addr, self.load(addr)) elif breakpoint: @@ -497,7 +506,7 @@ self.value = self.load(value.ref + offset) return - self.exception = self._MakeObject(2, self.attr_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.attr_error_instance) return self.RaiseException() # LoadAttrIndexContext not defined. @@ -520,7 +529,7 @@ self.value = self.load(inst_value.ref + offset) return - self.exception = self._MakeObject(2, self.attr_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.attr_error_instance) return self.RaiseException() def StoreAttrIndex(self): @@ -532,13 +541,13 @@ attr_index, static_attr, offset = element if attr_index == self.operand: if static_attr: - self.exception = self._MakeObject(2, self.type_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.type_error_instance) return self.RaiseException() else: self.save(value.ref + offset, self.source) return - self.exception = self._MakeObject(2, self.attr_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.attr_error_instance) return self.RaiseException() # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden. @@ -569,7 +578,7 @@ self.frame_stack[frame + offset] = self.source return - self.exception = self._MakeObject(2, self.type_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.type_error_instance) return self.RaiseException() def LoadCallable(self): @@ -618,7 +627,7 @@ if not ((nargs - ndefaults) <= nlocals): raise Exception, "CheckFrame %r (%r <= %r <= %r)" % (self.operand, nargs - ndefaults, nlocals, nargs) - self.exception = self._MakeObject(2, self.type_error_instance) + self.exception = self._MakeObject(Library.instance_size, self.type_error_instance) return self.RaiseException() def CheckExtra(self): @@ -742,8 +751,8 @@ self.exception = None def RaiseException(self): - # NOTE: Adding the program counter as the first attribute. - self.save(self.exception + 1, self.pc) + # NOTE: Adding the program counter as the first attribute after __class__. + self.save(self.exception + 2, self.pc) # Jumping to the current handler. if self.abort_upon_exception: raise Exception diff -r 62d65b1b7936 -r 83dc777c7083 rsvplib.py --- a/rsvplib.py Sun Feb 20 19:31:50 2011 +0100 +++ b/rsvplib.py Fri Feb 25 01:45:02 2011 +0100 @@ -300,7 +300,7 @@ # Get the item itself. - self.machine.result = self.machine.load(fragment.ref + self.instance_data_offset + item_pos) + self.machine.result = self.machine.load(fragment.ref + 1 + item_pos) def builtins_list_len(self): frame = self.local_sp_stack[-1]