1.1 --- a/common.py Fri Sep 01 22:22:37 2023 +0200
1.2 +++ b/common.py Fri Sep 01 22:29:19 2023 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Common functions.
1.6
1.7 -Copyright (C) 2007-2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007-2019, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -623,7 +623,7 @@
1.13 # raise LoopExit
1.14
1.15 [(compiler.ast.Name("StopIteration"), None,
1.16 - compiler.ast.Raise(compiler.ast.Name("LoopExit")))],
1.17 + compiler.ast.Raise(compiler.ast.Name("$loop_exit")))],
1.18 None),
1.19
1.20 # <var>... = <t3>
2.1 --- a/inspector.py Fri Sep 01 22:22:37 2023 +0200
2.2 +++ b/inspector.py Fri Sep 01 22:29:19 2023 +0200
2.3 @@ -907,6 +907,20 @@
2.4 self.set_special(n.name, value)
2.5 return value
2.6
2.7 + # Special case for loops.
2.8 +
2.9 + elif n.name == "$loop_exit":
2.10 +
2.11 + # Attempt to get a reference.
2.12 +
2.13 + ref = self.get_builtin("__loop_exit")
2.14 +
2.15 + # Record the imported name and provide the resolved name reference.
2.16 +
2.17 + value = ResolvedNameRef(n.name, ref)
2.18 + self.set_special(n.name, value)
2.19 + return value
2.20 +
2.21 # Test for self usage, which is only allowed in methods.
2.22
2.23 if n.name == "self" and not (self.in_function and self.in_class):
3.1 --- a/lib/__builtins__/__init__.py Fri Sep 01 22:22:37 2023 +0200
3.2 +++ b/lib/__builtins__/__init__.py Fri Sep 01 22:29:19 2023 +0200
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Simple built-in classes and functions.
3.6
3.7 -Copyright (C) 2015, 2016, 2017, 2019, 2021 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2015-2017, 2019, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -50,7 +50,8 @@
3.13 UnicodeEncodeError,
3.14 UnicodeError,
3.15 UnicodeTranslateError,
3.16 - ValueError
3.17 + ValueError,
3.18 + __loop_exit
3.19 )
3.20
3.21 # Classes.
4.1 --- a/lib/__builtins__/exception/__init__.py Fri Sep 01 22:22:37 2023 +0200
4.2 +++ b/lib/__builtins__/exception/__init__.py Fri Sep 01 22:29:19 2023 +0200
4.3 @@ -3,7 +3,7 @@
4.4 """
4.5 Exception objects.
4.6
4.7 -Copyright (C) 2015, 2016, 2017, 2019 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2015, 2016, 2017, 2019, 2023 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -30,7 +30,8 @@
4.13 NotImplementedError,
4.14 RuntimeError,
4.15 StopIteration,
4.16 - ValueError
4.17 + ValueError,
4.18 + __loop_exit
4.19 )
4.20
4.21 from __builtins__.exception.io import (
5.1 --- a/lib/__builtins__/exception/base.py Fri Sep 01 22:22:37 2023 +0200
5.2 +++ b/lib/__builtins__/exception/base.py Fri Sep 01 22:29:19 2023 +0200
5.3 @@ -3,7 +3,7 @@
5.4 """
5.5 Base exception objects. See __builtins__.core for the core exceptions.
5.6
5.7 -Copyright (C) 2015, 2016, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
5.8 +Copyright (C) 2015, 2016, 2018, 2019, 2023 Paul Boddie <paul@boddie.org.uk>
5.9
5.10 This program is free software; you can redistribute it and/or modify it under
5.11 the terms of the GNU General Public License as published by the Free Software
5.12 @@ -87,4 +87,8 @@
5.13
5.14 pass
5.15
5.16 +# Common loop exit instance.
5.17 +
5.18 +__loop_exit = LoopExit()
5.19 +
5.20 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/referencing.py Fri Sep 01 22:22:37 2023 +0200
6.2 +++ b/referencing.py Fri Sep 01 22:29:19 2023 +0200
6.3 @@ -3,7 +3,7 @@
6.4 """
6.5 Reference abstractions.
6.6
6.7 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
6.8 +Copyright (C) 2016, 2017, 2023 Paul Boddie <paul@boddie.org.uk>
6.9
6.10 This program is free software; you can redistribute it and/or modify it under
6.11 the terms of the GNU General Public License as published by the Free Software
6.12 @@ -222,6 +222,12 @@
6.13 name = self.get_name()
6.14 return name and name.rsplit(".")[-1].startswith("$c")
6.15
6.16 + def is_well_defined_instance(self):
6.17 +
6.18 + "Return whether this reference involves a well-defined instance."
6.19 +
6.20 + return self.get_kind() == "<instance>"
6.21 +
6.22 def is_predefined_value(self):
6.23
6.24 "Return whether this reference identifies a predefined value."
7.1 --- a/resolving.py Fri Sep 01 22:22:37 2023 +0200
7.2 +++ b/resolving.py Fri Sep 01 22:29:19 2023 +0200
7.3 @@ -3,7 +3,7 @@
7.4 """
7.5 Name resolution.
7.6
7.7 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
7.8 +Copyright (C) 2016, 2017, 2023 Paul Boddie <paul@boddie.org.uk>
7.9
7.10 This program is free software; you can redistribute it and/or modify it under
7.11 the terms of the GNU General Public License as published by the Free Software
7.12 @@ -73,7 +73,11 @@
7.13
7.14 for name, value in self.special.items():
7.15 ref, paths = value
7.16 - self.special[name] = self.importer.identify(ref.get_origin()), paths
7.17 +
7.18 + # Handle special instances.
7.19 +
7.20 + origin = ref.is_well_defined_instance() and ref.get_name() or ref.get_origin()
7.21 + self.special[name] = self.importer.identify(origin), paths
7.22
7.23 def check_names_used(self):
7.24
8.1 --- a/results.py Fri Sep 01 22:22:37 2023 +0200
8.2 +++ b/results.py Fri Sep 01 22:29:19 2023 +0200
8.3 @@ -3,7 +3,7 @@
8.4 """
8.5 Result abstractions.
8.6
8.7 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
8.8 +Copyright (C) 2016, 2017, 2023 Paul Boddie <paul@boddie.org.uk>
8.9
8.10 This program is free software; you can redistribute it and/or modify it under
8.11 the terms of the GNU General Public License as published by the Free Software
8.12 @@ -164,6 +164,9 @@
8.13 def is_constant_alias(self):
8.14 return self.ref and self.ref.is_constant_alias()
8.15
8.16 + def is_well_defined_instance(self):
8.17 + return self.ref and self.ref.is_well_defined_instance()
8.18 +
8.19 class ResolvedNameRef(ResolvedRef, NameRef):
8.20
8.21 "A resolved name-based reference."
9.1 --- a/translator.py Fri Sep 01 22:22:37 2023 +0200
9.2 +++ b/translator.py Fri Sep 01 22:29:19 2023 +0200
9.3 @@ -1619,7 +1619,8 @@
9.4 # function names to references.
9.5
9.6 elif n.name.startswith("$L") or n.name.startswith("$op") or \
9.7 - n.name.startswith("$seq") or n.name.startswith("$print"):
9.8 + n.name.startswith("$seq") or n.name.startswith("$print") or \
9.9 + n.name == "$loop_exit":
9.10
9.11 ref, paths = self.importer.get_module(self.name).special[n.name]
9.12 return TrResolvedNameRef(n.name, ref)
9.13 @@ -1736,7 +1737,7 @@
9.14 else:
9.15 exc = self.process_structure_node(n.expr1)
9.16
9.17 - if isinstance(exc, TrInstanceRef):
9.18 + if isinstance(exc, TrInstanceRef) or exc.is_well_defined_instance():
9.19 self.writestmt("__Raise(%s);" % exc)
9.20 else:
9.21 self.writestmt("__Raise(__ensure_instance(%s));" % exc)