1.1 --- a/lib/builtins.py Sun Sep 07 20:23:10 2008 +0200
1.2 +++ b/lib/builtins.py Mon Sep 15 01:34:37 2008 +0200
1.3 @@ -262,7 +262,8 @@
1.4
1.5 # Various types.
1.6
1.7 -class EllipsisType(object): pass
1.8 +class EllipsisType: pass
1.9 +class NoneType: pass
1.10 class NotImplementedType: pass
1.11
1.12 # Special values.
2.1 --- a/micropython/ast.py Sun Sep 07 20:23:10 2008 +0200
2.2 +++ b/micropython/ast.py Mon Sep 15 01:34:37 2008 +0200
2.3 @@ -1512,7 +1512,19 @@
2.4
2.5 def visitAssign(self, node):
2.6 self.dispatch(node.expr)
2.7 - self.record_value(0)
2.8 +
2.9 + # Check nodes for immediate usage.
2.10 +
2.11 + immediate = 1
2.12 +
2.13 + for n in node.nodes:
2.14 + if not isinstance(n, compiler.ast.AssName):
2.15 + immediate = 0
2.16 + break
2.17 +
2.18 + # Record the value and then dispatch to the assignment targets.
2.19 +
2.20 + self.record_value(immediate)
2.21
2.22 for n in node.nodes:
2.23 self.dispatch(n)
2.24 @@ -1713,6 +1725,8 @@
2.25 self._visitBinary(node, "__floordiv__", "__rfloordiv__")
2.26
2.27 def visitFor(self, node):
2.28 + next_handler_label = self.new_label()
2.29 + end_handler_label = self.new_label()
2.30 exit_label = self.new_label()
2.31 next_label = self.new_label()
2.32 else_label = self.new_label()
2.33 @@ -1732,6 +1746,10 @@
2.34
2.35 self.set_label(next_label)
2.36
2.37 + # Handle exceptions when calling "next"...
2.38 +
2.39 + self.new_op(PushHandler(next_handler_label))
2.40 +
2.41 # Use the iterator to get the next value.
2.42
2.43 self._startCallFunc()
2.44 @@ -1745,6 +1763,15 @@
2.45
2.46 self.record_value()
2.47
2.48 + # Skip the handler where the call was successful.
2.49 +
2.50 + self.new_op(Jump(end_handler_label))
2.51 +
2.52 + # Enter the exception handler.
2.53 +
2.54 + self.set_label(next_handler_label)
2.55 + self.new_op(PopHandler())
2.56 +
2.57 # Test for StopIteration.
2.58
2.59 self.load_builtin("StopIteration", node)
2.60 @@ -1754,6 +1781,14 @@
2.61 else:
2.62 self.new_op(JumpIfTrue(exit_label))
2.63
2.64 + # Re-raise the exception otherwise.
2.65 +
2.66 + self.new_op(RaiseException())
2.67 +
2.68 + # After the handler.
2.69 +
2.70 + self.set_label(end_handler_label)
2.71 +
2.72 # Assign to the target.
2.73
2.74 self.dispatch(node.assign)
3.1 --- a/micropython/rsvp.py Sun Sep 07 20:23:10 2008 +0200
3.2 +++ b/micropython/rsvp.py Mon Sep 15 01:34:37 2008 +0200
3.3 @@ -23,6 +23,12 @@
3.4 from micropython.data import Attr, Class, Const, Function
3.5
3.6 def raw(code, objtable, paramtable):
3.7 +
3.8 + """
3.9 + Return the raw image representation of the given 'code', using the given
3.10 + 'objtable' and 'paramtable' to populate structures.
3.11 + """
3.12 +
3.13 new_code = []
3.14 for item in code:
3.15
3.16 @@ -50,8 +56,8 @@
3.17 elif isinstance(item, Const):
3.18 # NOTE: Need class details!
3.19 new_code.append((
3.20 - None, #objtable.as_list().get_code(item.full_name()),
3.21 - None, #objtable.get_index(item.full_name()),
3.22 + objtable.as_list().get_code(item.value_type_name()),
3.23 + objtable.get_index(item.value_type_name()),
3.24 None,
3.25 None,
3.26 1
4.1 --- a/rsvp.py Sun Sep 07 20:23:10 2008 +0200
4.2 +++ b/rsvp.py Mon Sep 15 01:34:37 2008 +0200
4.3 @@ -68,7 +68,7 @@
4.4
4.5 "A really simple virtual processor."
4.6
4.7 - def __init__(self, memory, objlist, paramlist, pc=None, debug=0):
4.8 + def __init__(self, memory, objlist, paramlist, attr_error, type_error, pc=None, debug=0):
4.9
4.10 """
4.11 Initialise the processor with a 'memory' (a list of values containing
4.12 @@ -102,6 +102,11 @@
4.13 self.result = None
4.14 self.exception = None
4.15
4.16 + # Constants.
4.17 +
4.18 + self.attr_error = attr_error
4.19 + self.type_error = type_error
4.20 +
4.21 def dump(self):
4.22 print "PC", self.pc, "->", self.load(self.pc)
4.23 print "PC stack", self.pc_stack
4.24 @@ -311,8 +316,7 @@
4.25 else:
4.26 self.value = self.load(ref + offset)
4.27 else:
4.28 - # NOTE: This should cause an attribute error.
4.29 - raise Exception, "LoadAttrIndex % r" % element
4.30 + self.exception = self.attr_error
4.31
4.32 def StoreAttrIndex(self):
4.33 context, ref = self.value
4.34 @@ -321,14 +325,11 @@
4.35 attr_index, class_attr, replace_context, offset = element
4.36 if attr_index == self.operand:
4.37 if class_attr:
4.38 - # NOTE: This should cause an attribute or type error.
4.39 - # Class attributes cannot be changed at run-time.
4.40 - raise Exception, "StoreAttrIndex % r" % element
4.41 + self.exception = self.type_error
4.42 else:
4.43 self.save(ref + offset, self.source)
4.44 else:
4.45 - # NOTE: This should cause an attribute error.
4.46 - raise Exception, "StoreAttrIndex % r" % element
4.47 + self.exception = self.attr_error
4.48
4.49 # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden.
4.50
4.51 @@ -356,8 +357,7 @@
4.52 if attr_index == self.operand:
4.53 self.frame_stack[frame + offset] = self.value
4.54 else:
4.55 - # NOTE: This should cause an argument error.
4.56 - raise Exception, "StoreFrameIndex % r" % element
4.57 + self.exception = self.type_error
4.58
4.59 def LoadCallable(self):
4.60 context, ref = self.value
5.1 --- a/test.py Sun Sep 07 20:23:10 2008 +0200
5.2 +++ b/test.py Mon Sep 15 01:34:37 2008 +0200
5.3 @@ -33,11 +33,14 @@
5.4 print "Getting raw structures..."
5.5 ot = importer.get_object_table()
5.6 pt = importer.get_parameter_table()
5.7 - objlist = ot.as_raw()
5.8 - paramlist = pt.as_raw()
5.9 + objlist = ot.as_list()
5.10 + paramlist = pt.as_list()
5.11 + attr_error = objlist.access("__builtins__", "AttributeError").value.location
5.12 + type_error = objlist.access("__builtins__", "TypeError").value.location
5.13 + print "Getting raw image..."
5.14 rc = raw(importer.get_image(), ot, pt)
5.15 print "Initialising the machine..."
5.16 - rm = rsvp.RSVPMachine(rc, objlist, paramlist, debug=debug)
5.17 + rm = rsvp.RSVPMachine(rc, objlist.as_raw(), paramlist.as_raw(), attr_error, type_error, debug=debug)
5.18 rm.pc = importer.code_location
5.19 return rm
5.20