1.1 --- a/micropython/__init__.py Sun Feb 10 22:05:23 2008 +0100
1.2 +++ b/micropython/__init__.py Mon Feb 11 01:58:12 2008 +0100
1.3 @@ -137,6 +137,8 @@
1.4 pos += len(attributes.keys())
1.5
1.6 # Class-level code is generated separately.
1.7 + # The code location is set within the code generation
1.8 + # process for the module.
1.9
1.10 # NOTE: Generate module and function code here.
1.11
2.1 --- a/micropython/ast.py Sun Feb 10 22:05:23 2008 +0100
2.2 +++ b/micropython/ast.py Mon Feb 11 01:58:12 2008 +0100
2.3 @@ -66,6 +66,10 @@
2.4
2.5 self.labels = {}
2.6 self.label_number = 0
2.7 + self.loop_labels = []
2.8 +
2.9 + # The code itself.
2.10 +
2.11 self.code = None
2.12
2.13 def get_module_code(self):
2.14 @@ -197,7 +201,9 @@
2.15
2.16 def visitBitxor(self, node): pass
2.17
2.18 - def visitBreak(self, node): pass
2.19 + def visitBreak(self, node):
2.20 + next_label, exit_label = self.loop_labels[-1]
2.21 + self.new_op(Jump(exit_label))
2.22
2.23 def visitCallFunc(self, node):
2.24
2.25 @@ -291,6 +297,7 @@
2.26 def visitClass(self, node):
2.27 unit = self.unit
2.28 self.unit = node.unit
2.29 + self.unit.code_location = self.module.code_location + len(self.code)
2.30 self.dispatch(node.code)
2.31 self.unit = unit
2.32
2.33 @@ -311,7 +318,9 @@
2.34 const = self.module.constant_values[node.value]
2.35 self.new_op(LoadConst(const))
2.36
2.37 - def visitContinue(self, node): pass
2.38 + def visitContinue(self, node):
2.39 + next_label, exit_label = self.loop_labels[-1]
2.40 + self.new_op(Jump(next_label))
2.41
2.42 def visitDecorators(self, node): pass
2.43
2.44 @@ -372,7 +381,7 @@
2.45 if test is not None:
2.46 self.dispatch(test)
2.47 next_label = self.new_label()
2.48 - self.new_op(Jump(next_label))
2.49 + self.new_op(JumpIfFalse(next_label))
2.50 self.dispatch(body)
2.51 self.new_op(Jump(exit_label))
2.52 first = 0
2.53 @@ -448,7 +457,23 @@
2.54
2.55 def visitUnarySub(self, node): pass
2.56
2.57 - def visitWhile(self, node): pass
2.58 + def visitWhile(self, node):
2.59 + exit_label = self.new_label()
2.60 + self.dispatch(node.test)
2.61 + self.new_op(JumpIfFalse(exit_label))
2.62 +
2.63 + next_label = self.new_label()
2.64 + self.set_label(next_label)
2.65 + self.loop_labels.append((next_label, exit_label))
2.66 +
2.67 + self.dispatch(node.body)
2.68 + self.new_op(Jump(next_label))
2.69 +
2.70 + if node.else_ is not None:
2.71 + self.dispatch(node.else_)
2.72 +
2.73 + self.set_label(exit_label)
2.74 + self.loop_labels.pop()
2.75
2.76 def visitWith(self, node): pass
2.77
3.1 --- a/micropython/inspect.py Sun Feb 10 22:05:23 2008 +0100
3.2 +++ b/micropython/inspect.py Mon Feb 11 01:58:12 2008 +0100
3.3 @@ -677,7 +677,7 @@
3.4
3.5 def visitClass(self, node):
3.6 if self.namespaces:
3.7 - print "Class %r in %r is not global: ignored." % (node.name, self)
3.8 + print "Class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name())
3.9 else:
3.10 cls = Class(node.name, self.get_parent().full_name(), self, node)
3.11
4.1 --- a/micropython/rsvp.py Sun Feb 10 22:05:23 2008 +0100
4.2 +++ b/micropython/rsvp.py Mon Feb 11 01:58:12 2008 +0100
4.3 @@ -61,6 +61,7 @@
4.4 # Invocation-related instructions.
4.5
4.6 class Jump(Instruction): pass
4.7 +class JumpIfFalse(Instruction): pass
4.8 class LoadCallable(Instruction): pass
4.9 class Return(Instruction): pass
4.10
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/loop_while.py Mon Feb 11 01:58:12 2008 +0100
5.3 @@ -0,0 +1,9 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +class C:
5.7 + value = "hello"
5.8 + while x > 0:
5.9 + subvalue = "world"
5.10 + x -= 1
5.11 +
5.12 +# vim: tabstop=4 expandtab shiftwidth=4