1.1 --- a/lib/builtins.py Sun Jun 07 20:04:16 2009 +0200
1.2 +++ b/lib/builtins.py Sun Jun 07 21:17:59 2009 +0200
1.3 @@ -207,9 +207,39 @@
1.4 pass
1.5
1.6 class xrange(object):
1.7 - def __init__(self, start_or_end, end=None, step=1): pass
1.8 - def __iter__(self): pass
1.9 - def next(self): pass
1.10 +
1.11 + "Implementation of xrange."
1.12 +
1.13 + def __init__(self, start_or_end, end=None, step=1):
1.14 +
1.15 + "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
1.16 +
1.17 + if end is None:
1.18 + self.start = 0
1.19 + self.end = start_or_end
1.20 + else:
1.21 + self.start = start_or_end
1.22 + self.end = end
1.23 +
1.24 + self.step = step
1.25 + self.current = self.start
1.26 +
1.27 + def __iter__(self):
1.28 +
1.29 + "Return an iterator, currently self."
1.30 +
1.31 + return self
1.32 +
1.33 + def next(self):
1.34 +
1.35 + "Return the next item or raise a StopIteration exception."
1.36 +
1.37 + if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
1.38 + raise StopIteration
1.39 +
1.40 + current = self.current
1.41 + self.current += self.step
1.42 + return current
1.43
1.44 # Exceptions and warnings.
1.45
2.1 --- a/micropython/__init__.py Sun Jun 07 20:04:16 2009 +0200
2.2 +++ b/micropython/__init__.py Sun Jun 07 21:17:59 2009 +0200
2.3 @@ -144,7 +144,7 @@
2.4
2.5 # Omit built-in function code where requested.
2.6
2.7 - if suppress_builtins:
2.8 + if suppress_builtins and not obj.astnode.doc is not None:
2.9 continue
2.10
2.11 # Generate the instantiator/initialiser.
2.12 @@ -175,7 +175,7 @@
2.13
2.14 # Omit built-in function code where requested.
2.15
2.16 - if suppress_builtins:
2.17 + if suppress_builtins and not obj.astnode.doc is not None:
2.18 pass
2.19
2.20 # Append the function code to the image.
2.21 @@ -256,7 +256,7 @@
2.22 # Set the code location only where the code has been
2.23 # generated.
2.24
2.25 - if not with_builtins and item.module.name == "__builtins__":
2.26 + if not with_builtins and item.module.name == "__builtins__" and item.astnode.doc is None:
2.27 item.code_location = item.full_name()
2.28
2.29 # Skip any defaults for named functions.
2.30 @@ -298,7 +298,8 @@
2.31
2.32 elif isinstance(item, micropython.data.Class):
2.33 assert item.instance_template_location == len(self.raw_code)
2.34 - self.raw_code += item.as_raw(objtable, paramtable, with_builtins or item.module.name != "__builtins__")
2.35 + self.raw_code += item.as_raw(objtable, paramtable,
2.36 + with_builtins or item.module.name != "__builtins__" or item.astnode.doc is not None)
2.37 assert item.location == len(self.raw_code) - 1
2.38
2.39 elif isinstance(item, micropython.data.Const):
2.40 @@ -311,7 +312,7 @@
2.41
2.42 # Check the code location only where the code has been generated.
2.43
2.44 - assert (not with_builtins and item.module.name == "__builtins__") or \
2.45 + assert (not with_builtins and item.module.name == "__builtins__" and item.astnode.doc is None) or \
2.46 item.name is not None and item.code_location == len(self.raw_code) + len(item.defaults) or \
2.47 item.name is None and item.code_location == len(self.raw_code)
2.48
3.1 --- a/micropython/ast.py Sun Jun 07 20:04:16 2009 +0200
3.2 +++ b/micropython/ast.py Sun Jun 07 21:17:59 2009 +0200
3.3 @@ -518,7 +518,7 @@
3.4 # Find the augmented assignment method and attempt to use it.
3.5
3.6 aug_method, (left_method, right_method) = augassign_methods[node.op]
3.7 - temp_out = self._generateOpMethod(node, temp1, temp2, aug_method, use_binary_block, end_block)
3.8 + temp_out = self._generateOpMethod(node, temp1, temp2, aug_method, use_binary_block, use_binary_block, end_block)
3.9 self.discard_temp(temp_out) # NOTE: Will re-use the same storage.
3.10
3.11 # Where no such method exists, use the binary operator methods.
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/cond_if_else.py Sun Jun 07 21:17:59 2009 +0200
4.3 @@ -0,0 +1,12 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +a = 0
4.7 +
4.8 +if a:
4.9 + b = 1
4.10 +else:
4.11 + b = 2
4.12 +
4.13 +result_2 = b
4.14 +
4.15 +# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/tests/for.py Sun Jun 07 20:04:16 2009 +0200
5.2 +++ b/tests/for.py Sun Jun 07 21:17:59 2009 +0200
5.3 @@ -1,7 +1,9 @@
5.4 #!/usr/bin/env python
5.5
5.6 -for i in range(0, 100, 10):
5.7 - for j in range(0, 10):
5.8 +for i in xrange(0, 100, 10):
5.9 + for j in xrange(0, 10):
5.10 k = i + j
5.11
5.12 +result_99 = k
5.13 +
5.14 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/xrange.py Sun Jun 07 21:17:59 2009 +0200
6.3 @@ -0,0 +1,8 @@
6.4 +#!/usr/bin/env python
6.5 +
6.6 +xr = xrange(0, 10, 1)
6.7 +result_0 = xr.start
6.8 +result_10 = xr.end
6.9 +result_1 = xr.step
6.10 +
6.11 +# vim: tabstop=4 expandtab shiftwidth=4