1.1 --- a/lib/builtins.py Sun Jun 07 21:17:59 2009 +0200
1.2 +++ b/lib/builtins.py Sun Jun 07 22:55:59 2009 +0200
1.3 @@ -1,9 +1,10 @@
1.4 #!/usr/bin/env python
1.5
1.6 """
1.7 -Simple built-in classes and functions.
1.8 +Simple built-in classes and functions. Objects which provide code which shall
1.9 +always be compiled should provide docstrings.
1.10
1.11 -Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.12 +Copyright (C) 2005, 2006, 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk>
1.13
1.14 This program is free software; you can redistribute it and/or modify it under
1.15 the terms of the GNU General Public License as published by the Free Software
1.16 @@ -235,7 +236,7 @@
1.17 "Return the next item or raise a StopIteration exception."
1.18
1.19 if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
1.20 - raise StopIteration
1.21 + raise StopIteration()
1.22
1.23 current = self.current
1.24 self.current += self.step
1.25 @@ -244,6 +245,9 @@
1.26 # Exceptions and warnings.
1.27
1.28 class BaseException(object):
1.29 +
1.30 + "Implementation of BaseException."
1.31 +
1.32 def __init__(self, *args):
1.33 self.args = args
1.34
1.35 @@ -277,7 +281,7 @@
1.36 class RuntimeError(Exception): pass
1.37 class RuntimeWarning(Warning): pass
1.38 class StandardError(Exception): pass
1.39 -class StopIteration(Exception): pass
1.40 +class StopIteration(Exception): "Implementation of StopIteration."
1.41 class SyntaxError(Exception): pass
1.42 class SyntaxWarning(Warning): pass
1.43 class SystemError(Exception): pass
2.1 --- a/micropython/__init__.py Sun Jun 07 21:17:59 2009 +0200
2.2 +++ b/micropython/__init__.py Sun Jun 07 22:55:59 2009 +0200
2.3 @@ -211,7 +211,6 @@
2.4 # Position the objects.
2.5
2.6 pos = 0
2.7 - current_function = None
2.8
2.9 for item in self.code:
2.10
2.11 @@ -221,14 +220,6 @@
2.12 item.location = pos
2.13 pos += len(item.code)
2.14
2.15 - # Set code body information on functions, assuming that the
2.16 - # first block is for argument checks.
2.17 -
2.18 - if current_function is not None:
2.19 - current_function.code_body_location = pos
2.20 -
2.21 - current_function = None
2.22 -
2.23 # Other multi-location objects.
2.24
2.25 elif isinstance(item, (
2.26 @@ -269,14 +260,8 @@
2.27 else:
2.28 item.code_location = pos
2.29
2.30 - current_function = item
2.31 -
2.32 elif isinstance(item, micropython.data.Const):
2.33 pos += len(item.raw_data())
2.34 - current_function = None
2.35 -
2.36 - else:
2.37 - current_function = None
2.38
2.39 else:
2.40 pos += 1
2.41 @@ -323,6 +308,15 @@
2.42 else:
2.43 self.raw_code.append(item)
2.44
2.45 + # Set the code body location for items now that the code blocks have
2.46 + # been positioned.
2.47 +
2.48 + if isinstance(item, (micropython.data.Class, micropython.data.Function)):
2.49 + if not with_builtins and item.module.name == "__builtins__" and item.astnode.doc is None:
2.50 + item.code_body_location = item.full_name()
2.51 + else:
2.52 + item.code_body_location = item.get_body_block().location
2.53 +
2.54 # Fix the module locations.
2.55
2.56 for module in self.importer.modules_ordered:
3.1 --- a/micropython/ast.py Sun Jun 07 21:17:59 2009 +0200
3.2 +++ b/micropython/ast.py Sun Jun 07 22:55:59 2009 +0200
3.3 @@ -757,7 +757,10 @@
3.4 self._doCallFunc(temp_target, target)
3.5 self._endCallFunc(temp_target, target, temp_context)
3.6
3.7 - temp_iterator = self.optimiser.optimise_temp_storage()
3.8 + # Use a long-lasting temporary storage slot, since any result from the
3.9 + # __iter__ method will not remain around for long.
3.10 +
3.11 + temp_iterator = self.get_temp()
3.12
3.13 # In the loop...
3.14
3.15 @@ -806,7 +809,6 @@
3.16 # After the handler, clear the exception.
3.17
3.18 self.set_block(end_handler_block)
3.19 - self.new_op(ClearException())
3.20
3.21 # Assign to the target.
3.22
3.23 @@ -826,13 +828,19 @@
3.24 # Produce the "else" section.
3.25
3.26 if node.else_ is not None:
3.27 - self.set_block(exit_block)
3.28 -
3.29 + self.set_block(else_block)
3.30 + self.new_op(ClearException())
3.31 self.dispatch(node.else_)
3.32
3.33 - # After the loop...
3.34 + # After the loop...
3.35 +
3.36 + self.set_block(exit_block)
3.37
3.38 - self.set_block(exit_block)
3.39 + else:
3.40 + # After the loop...
3.41 +
3.42 + self.set_block(exit_block)
3.43 + self.new_op(ClearException())
3.44
3.45 # Compilation duties...
3.46
4.1 --- a/micropython/data.py Sun Jun 07 21:17:59 2009 +0200
4.2 +++ b/micropython/data.py Sun Jun 07 22:55:59 2009 +0200
4.3 @@ -556,6 +556,8 @@
4.4
4.5 self.location = None
4.6 self.code_location = None
4.7 + self.code_body_location = None # corresponds to the instantiator
4.8 +
4.9 self.instantiator = None
4.10 self.instance_template_location = None # for creating instances at run-time
4.11
4.12 @@ -967,6 +969,7 @@
4.13
4.14 self.location = None
4.15 self.code_location = None
4.16 + self.code_body_location = None
4.17
4.18 # Program-related details.
4.19
5.1 --- a/micropython/rsvp.py Sun Jun 07 21:17:59 2009 +0200
5.2 +++ b/micropython/rsvp.py Sun Jun 07 22:55:59 2009 +0200
5.3 @@ -136,7 +136,7 @@
5.4 return "%s(%r) # %r" % (self.__class__.__name__, self.get_operand(), name(self.attr))
5.5
5.6 def get_operand(self):
5.7 - return self.attr.get_body_block().location
5.8 + return self.attr.code_body_location
5.9
5.10 Target = TargetInstruction
5.11
6.1 --- a/rsvp.py Sun Jun 07 21:17:59 2009 +0200
6.2 +++ b/rsvp.py Sun Jun 07 22:55:59 2009 +0200
6.3 @@ -875,9 +875,15 @@
6.4 def builtins_int_lt(self):
6.5 return self.builtins_int_op(operator.lt, 0)
6.6
6.7 + def builtins_int_le(self):
6.8 + return self.builtins_int_op(operator.le, 0)
6.9 +
6.10 def builtins_int_gt(self):
6.11 return self.builtins_int_op(operator.gt, 0)
6.12
6.13 + def builtins_int_ge(self):
6.14 + return self.builtins_int_op(operator.ge, 0)
6.15 +
6.16 def builtins_int_eq(self):
6.17 return self.builtins_int_op(operator.eq, 0)
6.18
6.19 @@ -936,10 +942,13 @@
6.20 native_functions = {
6.21 "__builtins__.int.__add__" : builtins_int_add,
6.22 "__builtins__.int.__radd__" : builtins_int_add, # NOTE: To be made distinct.
6.23 + "__builtins__.int.__iadd__" : builtins_int_add,
6.24 "__builtins__.int.__bool__" : builtins_int_bool,
6.25 "__builtins__.int.__neg__" : builtins_int_neg,
6.26 "__builtins__.int.__lt__" : builtins_int_lt,
6.27 + "__builtins__.int.__le__" : builtins_int_le,
6.28 "__builtins__.int.__gt__" : builtins_int_gt,
6.29 + "__builtins__.int.__ge__" : builtins_int_ge,
6.30 "__builtins__.int.__eq__" : builtins_int_eq,
6.31 "__builtins__.int.__ne__" : builtins_int_ne,
6.32 "__builtins__.bool.__bool__" : builtins_bool_bool,