1.1 --- a/rsvp.py Sun Sep 07 20:23:10 2008 +0200
1.2 +++ b/rsvp.py Mon Sep 15 01:34:37 2008 +0200
1.3 @@ -68,7 +68,7 @@
1.4
1.5 "A really simple virtual processor."
1.6
1.7 - def __init__(self, memory, objlist, paramlist, pc=None, debug=0):
1.8 + def __init__(self, memory, objlist, paramlist, attr_error, type_error, pc=None, debug=0):
1.9
1.10 """
1.11 Initialise the processor with a 'memory' (a list of values containing
1.12 @@ -102,6 +102,11 @@
1.13 self.result = None
1.14 self.exception = None
1.15
1.16 + # Constants.
1.17 +
1.18 + self.attr_error = attr_error
1.19 + self.type_error = type_error
1.20 +
1.21 def dump(self):
1.22 print "PC", self.pc, "->", self.load(self.pc)
1.23 print "PC stack", self.pc_stack
1.24 @@ -311,8 +316,7 @@
1.25 else:
1.26 self.value = self.load(ref + offset)
1.27 else:
1.28 - # NOTE: This should cause an attribute error.
1.29 - raise Exception, "LoadAttrIndex % r" % element
1.30 + self.exception = self.attr_error
1.31
1.32 def StoreAttrIndex(self):
1.33 context, ref = self.value
1.34 @@ -321,14 +325,11 @@
1.35 attr_index, class_attr, replace_context, offset = element
1.36 if attr_index == self.operand:
1.37 if class_attr:
1.38 - # NOTE: This should cause an attribute or type error.
1.39 - # Class attributes cannot be changed at run-time.
1.40 - raise Exception, "StoreAttrIndex % r" % element
1.41 + self.exception = self.type_error
1.42 else:
1.43 self.save(ref + offset, self.source)
1.44 else:
1.45 - # NOTE: This should cause an attribute error.
1.46 - raise Exception, "StoreAttrIndex % r" % element
1.47 + self.exception = self.attr_error
1.48
1.49 # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden.
1.50
1.51 @@ -356,8 +357,7 @@
1.52 if attr_index == self.operand:
1.53 self.frame_stack[frame + offset] = self.value
1.54 else:
1.55 - # NOTE: This should cause an argument error.
1.56 - raise Exception, "StoreFrameIndex % r" % element
1.57 + self.exception = self.type_error
1.58
1.59 def LoadCallable(self):
1.60 context, ref = self.value