1.1 --- a/micropython/ast.py Sun Feb 10 22:05:23 2008 +0100
1.2 +++ b/micropython/ast.py Mon Feb 11 01:58:12 2008 +0100
1.3 @@ -66,6 +66,10 @@
1.4
1.5 self.labels = {}
1.6 self.label_number = 0
1.7 + self.loop_labels = []
1.8 +
1.9 + # The code itself.
1.10 +
1.11 self.code = None
1.12
1.13 def get_module_code(self):
1.14 @@ -197,7 +201,9 @@
1.15
1.16 def visitBitxor(self, node): pass
1.17
1.18 - def visitBreak(self, node): pass
1.19 + def visitBreak(self, node):
1.20 + next_label, exit_label = self.loop_labels[-1]
1.21 + self.new_op(Jump(exit_label))
1.22
1.23 def visitCallFunc(self, node):
1.24
1.25 @@ -291,6 +297,7 @@
1.26 def visitClass(self, node):
1.27 unit = self.unit
1.28 self.unit = node.unit
1.29 + self.unit.code_location = self.module.code_location + len(self.code)
1.30 self.dispatch(node.code)
1.31 self.unit = unit
1.32
1.33 @@ -311,7 +318,9 @@
1.34 const = self.module.constant_values[node.value]
1.35 self.new_op(LoadConst(const))
1.36
1.37 - def visitContinue(self, node): pass
1.38 + def visitContinue(self, node):
1.39 + next_label, exit_label = self.loop_labels[-1]
1.40 + self.new_op(Jump(next_label))
1.41
1.42 def visitDecorators(self, node): pass
1.43
1.44 @@ -372,7 +381,7 @@
1.45 if test is not None:
1.46 self.dispatch(test)
1.47 next_label = self.new_label()
1.48 - self.new_op(Jump(next_label))
1.49 + self.new_op(JumpIfFalse(next_label))
1.50 self.dispatch(body)
1.51 self.new_op(Jump(exit_label))
1.52 first = 0
1.53 @@ -448,7 +457,23 @@
1.54
1.55 def visitUnarySub(self, node): pass
1.56
1.57 - def visitWhile(self, node): pass
1.58 + def visitWhile(self, node):
1.59 + exit_label = self.new_label()
1.60 + self.dispatch(node.test)
1.61 + self.new_op(JumpIfFalse(exit_label))
1.62 +
1.63 + next_label = self.new_label()
1.64 + self.set_label(next_label)
1.65 + self.loop_labels.append((next_label, exit_label))
1.66 +
1.67 + self.dispatch(node.body)
1.68 + self.new_op(Jump(next_label))
1.69 +
1.70 + if node.else_ is not None:
1.71 + self.dispatch(node.else_)
1.72 +
1.73 + self.set_label(exit_label)
1.74 + self.loop_labels.pop()
1.75
1.76 def visitWith(self, node): pass
1.77