1.1 --- a/micropython/trans.py Sat May 23 02:46:04 2009 +0200
1.2 +++ b/micropython/trans.py Sun May 24 00:21:41 2009 +0200
1.3 @@ -151,7 +151,10 @@
1.4
1.5 def set_source(self):
1.6
1.7 - "Set the source of an assignment using the current assignment value."
1.8 + """
1.9 + Set the source of an assignment using the current assignment value. This
1.10 + sets the source input for the current instruction.
1.11 + """
1.12
1.13 self.optimiser.set_source(self.expr_temp[-1])
1.14
1.15 @@ -206,6 +209,7 @@
1.16 temp_position = 0
1.17 else:
1.18 temp_position = max(self.temp_positions) + 1
1.19 +
1.20 self.temp_positions.add(temp_position)
1.21 self.max_temp_position = max(self.max_temp_position, temp_position)
1.22 return self.unit.all_local_usage + temp_position # position in frame
1.23 @@ -852,6 +856,52 @@
1.24 else:
1.25 return None
1.26
1.27 + def _generateFunctionContextTest(self, node, check_block, body_block):
1.28 +
1.29 + """
1.30 + Generate code to test the context for 'node', jumping to 'check_block'
1.31 + and 'body_block' from this code.
1.32 + """
1.33 +
1.34 + adjust_block = self.new_block()
1.35 +
1.36 + # Check the context.
1.37 +
1.38 + temp = LoadName(Attr(0, None, None))
1.39 +
1.40 + # No usable context => remove the context and continue.
1.41 +
1.42 + self.new_op(temp)
1.43 + self.new_op(CheckContext())
1.44 + self.new_op(JumpIfFalse(adjust_block))
1.45 +
1.46 + # Check for a class as the context.
1.47 + # Not a class as context => preserve the context and continue.
1.48 +
1.49 + self.new_op(temp)
1.50 + self.new_op(CheckClassContext())
1.51 + self.new_op(JumpIfFalse(check_block))
1.52 +
1.53 + # Check the context's compatibility with the first parameter.
1.54 + # Compatible class => remove the context and continue.
1.55 + # NOTE: Handle insufficient arguments.
1.56 +
1.57 + self.new_op(LoadName(Attr(1, None, None)))
1.58 + self.new_op(CheckSelf())
1.59 + self.optimiser.set_source(temp)
1.60 + self.new_op(JumpIfTrue(adjust_block))
1.61 +
1.62 + # Incompatible class => type error.
1.63 +
1.64 + self.make_exception("TypeError", node)
1.65 + self.new_op(StoreException())
1.66 + self.new_op(RaiseException())
1.67 +
1.68 + # Remove the context from the parameters.
1.69 +
1.70 + self.set_block(adjust_block)
1.71 + self.new_op(AdjustFrame(1))
1.72 +
1.73 def _visitName(self, node, classes):
1.74
1.75 """