1.1 --- a/micropython/ast.py Sun Sep 07 18:43:40 2008 +0200
1.2 +++ b/micropython/ast.py Sun Sep 07 20:23:10 2008 +0200
1.3 @@ -93,7 +93,7 @@
1.4 a load operation from a CPU register or special memory location.
1.5 """
1.6
1.7 - return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadAddress))
1.8 + return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadException, LoadAddress))
1.9
1.10 def is_simple_input_user(self, instruction):
1.11
1.12 @@ -109,7 +109,7 @@
1.13 StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
1.14 LoadCallable,
1.15 TestIdentity, TestIdentityAddress, CheckSelf, # as one of the operands
1.16 - CheckFrame, MakeObject,
1.17 + CheckException, CheckFrame, MakeObject,
1.18 LoadContext # as the object providing the result
1.19 ))
1.20
1.21 @@ -187,7 +187,8 @@
1.22 # could be updated since first being referenced.
1.23
1.24 return isinstance(self.translation.active_value, (LoadName, LoadTemp, LoadAddress, LoadConst)) or \
1.25 - isinstance(self.translation.active_value, LoadResult) and self.translation.active_value is self.translation.active
1.26 + isinstance(self.translation.active_value, LoadResult) and self.translation.active_value is self.translation.active or \
1.27 + isinstance(self.translation.active_value, LoadException) and self.translation.active_value is self.translation.active
1.28
1.29 def have_correct_self_for_target(self, context):
1.30
1.31 @@ -2048,13 +2049,20 @@
1.32
1.33 if name is not None:
1.34 self.dispatch(name)
1.35 +
1.36 self.new_op(CheckException())
1.37 self.new_op(JumpIfFalse(next_label))
1.38
1.39 - # Handle assignment to exception variable.
1.40 -
1.41 - if assignment is not None:
1.42 - self.dispatch(assignment)
1.43 + # Handle assignment to exception variable.
1.44 +
1.45 + if assignment is not None:
1.46 + self.new_op(LoadException())
1.47 +
1.48 + # Record the value to be assigned.
1.49 +
1.50 + self.record_value()
1.51 + self.dispatch(assignment)
1.52 + self.discard_value()
1.53
1.54 # Produce the handler code, then jump to the exit.
1.55
1.56 @@ -2065,7 +2073,6 @@
1.57
1.58 # Unhandled exceptions.
1.59
1.60 - #self.new_op(LoadException())
1.61 self.new_op(RaiseException())
1.62
1.63 # Optional else clause.