# HG changeset patch # User Paul Boddie # Date 1283646005 -7200 # Node ID 454d8255a4b117e7fd05aab6ffb86625d5a305fa # Parent c799fef50ca277dfa095699445662614afe63af2 Fixed slice construction in the generated code. Fixed the xrange and slice builtins to use a special undefined value where the end of an xrange or slice is not defined. Added a test of class attribute usage with default function/method parameters. Moved the list slicing test into a new file, introducing a simpler testing of the slicing mechanism. diff -r c799fef50ca2 -r 454d8255a4b1 lib/builtins.py --- a/lib/builtins.py Sat Sep 04 00:55:37 2010 +0200 +++ b/lib/builtins.py Sun Sep 05 02:20:05 2010 +0200 @@ -292,11 +292,13 @@ "Implementation of xrange." - def __init__(self, start_or_end, end=None, step=1): + NO_END = object() + + def __init__(self, start_or_end, end=NO_END, step=1): "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." - if end is None: + if end is xrange.NO_END: self.start = 0 self.end = start_or_end else: @@ -305,7 +307,7 @@ self.step = step self.current = self.start - self.limited = self.end is not None + self.limited = self.end is not xrange.NO_END def __iter__(self): @@ -329,7 +331,7 @@ "Implementation of slice." - def __init__(self, start_or_end=None, end=None, step=1): + def __init__(self, start_or_end=None, end=xrange.NO_END, step=1): "Initialise the slice with the given 'start_or_end', 'end' and 'step'." diff -r c799fef50ca2 -r 454d8255a4b1 micropython/ast.py --- a/micropython/ast.py Sat Sep 04 00:55:37 2010 +0200 +++ b/micropython/ast.py Sun Sep 05 02:20:05 2010 +0200 @@ -422,6 +422,10 @@ args = [compiler.ast.Name("None"), node.upper] else: args = [node.lower] + if node.upper is None: + args.append(compiler.ast.Name("None")) + else: + args.append(node.upper) # NOTE: Need to guarantee reliable access to the slice built-in. diff -r c799fef50ca2 -r 454d8255a4b1 tests/call_func_default_class_attribute.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_func_default_class_attribute.py Sun Sep 05 02:20:05 2010 +0200 @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +class C: + + default = 101 + + def f(self, x=default): + return x + +c = C() +result_101 = c.f() +result_202 = c.f(202) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r c799fef50ca2 -r 454d8255a4b1 tests/slice.py --- a/tests/slice.py Sat Sep 04 00:55:37 2010 +0200 +++ b/tests/slice.py Sun Sep 05 02:20:05 2010 +0200 @@ -1,9 +1,16 @@ #!/usr/bin/env python -l = [1, 2, 3, 4, 5] +class C: + def __getitem__(self, slice): + return slice.start -result1_3 = len(l[2:]) -result_2 = len(l[:2]) -result2_3 = len(l[1:4]) +class D: + def __getitem__(self, slice): + return slice.end + +c = C() +d = D() +result_3 = c[3:] +result_4 = d[:4] # vim: tabstop=4 expandtab shiftwidth=4 diff -r c799fef50ca2 -r 454d8255a4b1 tests/slice_list.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/slice_list.py Sun Sep 05 02:20:05 2010 +0200 @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +l = [1, 2, 3, 4, 5] + +result1_3 = len(l[2:]) +result_2 = len(l[:2]) +result2_3 = len(l[1:4]) + +# vim: tabstop=4 expandtab shiftwidth=4