# HG changeset patch # User Paul Boddie # Date 1596406006 -7200 # Node ID d63c2cf15fb0d326db2384d4e2c1efe29a8a335d # Parent 5c96e5ca1036b5c2b7f3c0a349ae30a9623f27c2# Parent a5450be2b2f2d1844854e5f6ad82696dcf8af571 Merged concurrent changes. diff -r 5c96e5ca1036 -r d63c2cf15fb0 common.py --- a/common.py Mon Aug 03 00:06:08 2020 +0200 +++ b/common.py Mon Aug 03 00:06:46 2020 +0200 @@ -563,6 +563,8 @@ self.next_temporary() t2 = self.get_temporary_name() self.next_temporary() + t3 = self.get_temporary_name() + self.next_temporary() node = compiler.ast.Stmt([ @@ -583,9 +585,10 @@ # try: # while True: # try: - # ... = () + # = () # except StopIteration: # raise LoopExit + # ... = # {n.body} # except LoopExit: # {n.else_} @@ -595,21 +598,47 @@ [compiler.ast.AssName(t2, "OP_ASSIGN")], compiler.ast.Getattr(compiler.ast.Name(t1), "next")), + # try: + compiler.ast.TryExcept( + + # while True: + compiler.ast.While( compiler.ast.Name("True"), compiler.ast.Stmt([ + + # try: + compiler.ast.TryExcept( + + # = () + compiler.ast.Assign( - [n.assign], + [compiler.ast.AssName(t3, "OP_ASSIGN")], compiler.ast.CallFunc( compiler.ast.Name(t2), [])), + + # except StopIteration: + # raise LoopExit + [(compiler.ast.Name("StopIteration"), None, compiler.ast.Raise(compiler.ast.Name("LoopExit")))], None), + + # ... = + + compiler.ast.Assign( + [n.assign], + compiler.ast.Name(t3)), n.body]), None), + + # except LoopExit: + # {n.else_} + # pass + [(compiler.ast.Name("LoopExit"), None, n.else_ or compiler.ast.Pass())], None) ]) diff -r 5c96e5ca1036 -r d63c2cf15fb0 docs/COPYING.txt --- a/docs/COPYING.txt Mon Aug 03 00:06:08 2020 +0200 +++ b/docs/COPYING.txt Mon Aug 03 00:06:46 2020 +0200 @@ -1,8 +1,8 @@ Licence Agreement ----------------- -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, - 2014, 2015, 2016, 2017 Paul Boddie +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, + 2016, 2017, 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff -r 5c96e5ca1036 -r d63c2cf15fb0 inspector.py --- a/inspector.py Mon Aug 03 00:06:08 2020 +0200 +++ b/inspector.py Mon Aug 03 00:06:46 2020 +0200 @@ -3,8 +3,8 @@ """ Inspect and obtain module structure. -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, - 2014, 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -659,6 +659,9 @@ self.function_defaults[function_name] = [] for argname, default in compiler.ast.get_defaults(n): + if argname[0] == ".": + argname = argname[1:] + if default: # Obtain any reference for the default. diff -r 5c96e5ca1036 -r d63c2cf15fb0 internal_tests/branches.py --- a/internal_tests/branches.py Mon Aug 03 00:06:08 2020 +0200 +++ b/internal_tests/branches.py Mon Aug 03 00:06:46 2020 +0200 @@ -687,4 +687,77 @@ bt.get_assignment_positions_for_branches("a", ar) names.append(bt.assignments["a"]) +# This demonstrates why the assignment in a "for" loop construct must appear +# outside the inner "try" body: null usage escapes the loop via the exception +# handler and the raise statement, even though the assignment would only be +# valid otherwise. + +# Equivalent to... +# +# try: +# while ...: +# try: +# a = ... +# except: +# raise ... +# a.p +# except: +# pass + +bt = branching.BranchTracker() +bt.new_branchpoint() # begin (try) +bt.new_branchpoint(True) # begin (while) +bt.new_branch(True) # while ... +bt.new_branchpoint() # begin (try) +a = bt.assign_names(["a"]) +bt.resume_abandoned_branches() # except +bt.abandon_branch() # raise +bt.shelve_branch() +bt.new_branch() # (null) +bt.shelve_branch() +bt.merge_branches() # end (try) +ap = bt.use_attribute("a", "p") +bt.resume_continuing_branches() +bt.shelve_branch(True) +bt.new_branch() # (null) +bt.shelve_branch() +bt.merge_branches() # end (while) +bt.resume_broken_branches() +bt.resume_abandoned_branches() # except +bt.shelve_branch() +bt.new_branch() # (null) +bt.shelve_branch() +bt.merge_branches() # end (try) + +print simple_usage(a) == \ + {'a' : set([('p',), ()])}, simple_usage(a) +print bt.get_assignment_positions_for_branches("a", ap) == [0], \ + bt.get_assignment_positions_for_branches("a", ap) +names.append(bt.assignments["a"]) + +# Equivalent to... +# +# b = ... +# while ...: +# a = ... +# a.p + +bt = branching.BranchTracker() +bt.new_branchpoint(True) # begin +b = bt.assign_names(["b"]) +bt.new_branch(True) # while ... +a = bt.assign_names(["a"]) +ap = bt.use_attribute("a", "p") +bt.resume_continuing_branches() +bt.shelve_branch(True) +bt.new_branch() # (null) +bt.shelve_branch() +bt.merge_branches() # end + +print simple_usage(a) == \ + {'a' : set([('p',)])}, simple_usage(a) +print bt.get_assignment_positions_for_branches("a", ap) == [0], \ + bt.get_assignment_positions_for_branches("a", ap) +names.append(bt.assignments["a"]) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 5c96e5ca1036 -r d63c2cf15fb0 lib/__builtins__/exception/base.py --- a/lib/__builtins__/exception/base.py Mon Aug 03 00:06:08 2020 +0200 +++ b/lib/__builtins__/exception/base.py Mon Aug 03 00:06:46 2020 +0200 @@ -71,7 +71,11 @@ "An exception signalling the end of iteration." - pass + def __init__(self, .iterator=None): + + "Initialise the exception with the given 'iterator'." + + pass class ValueError(Exception): diff -r 5c96e5ca1036 -r d63c2cf15fb0 lib/__builtins__/iteration/iterator.py --- a/lib/__builtins__/iteration/iterator.py Mon Aug 03 00:06:08 2020 +0200 +++ b/lib/__builtins__/iteration/iterator.py Mon Aug 03 00:06:46 2020 +0200 @@ -3,7 +3,7 @@ """ Iterator objects. -Copyright (C) 2015, 2016 Paul Boddie +Copyright (C) 2015, 2016, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,6 +39,6 @@ self.i += 1 return value except IndexError: - raise StopIteration() + raise StopIteration, self # vim: tabstop=4 expandtab shiftwidth=4 diff -r 5c96e5ca1036 -r d63c2cf15fb0 lib/__builtins__/set.py --- a/lib/__builtins__/set.py Mon Aug 03 00:06:08 2020 +0200 +++ b/lib/__builtins__/set.py Mon Aug 03 00:06:46 2020 +0200 @@ -3,7 +3,7 @@ """ Set objects. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -323,7 +323,7 @@ try: bucket = self.mapping.buckets[self.index] except IndexError: - raise StopIteration + raise StopIteration, self # Access the current item. If no such item exists, get another # bucket. diff -r 5c96e5ca1036 -r d63c2cf15fb0 lib/__builtins__/span.py --- a/lib/__builtins__/span.py Mon Aug 03 00:06:08 2020 +0200 +++ b/lib/__builtins__/span.py Mon Aug 03 00:06:46 2020 +0200 @@ -3,7 +3,7 @@ """ Span-related objects. -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -101,7 +101,7 @@ "Return the next item or raise a StopIteration exception." if not self.count: - raise StopIteration + raise StopIteration, self current = self.current self.current = self.current.__add__(self.step) diff -r 5c96e5ca1036 -r d63c2cf15fb0 templates/types.h --- a/templates/types.h Mon Aug 03 00:06:08 2020 +0200 +++ b/templates/types.h Mon Aug 03 00:06:46 2020 +0200 @@ -127,8 +127,8 @@ #define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT}) #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS) -#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS)) - 1) -#define __MININT (-(1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS))) +#define __MAXINT ((1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)) - 1) +#define __MININT (-(1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS))) /* Argument lists. */