From 18febee9902dbd535ef16a125e86b920a5ca3585 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Thu, 5 Oct 2023 08:27:43 +0200 Subject: [PATCH] Extract goto to a separate compat feature --- lib/1.2/dml-builtins.dml | 1 + lib/1.4/dml-builtins.dml | 1 + py/dml/codegen.py | 2 +- py/dml/compat.py | 14 ++++++++++++-- py/dml/dmlc.py | 5 +++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/1.2/dml-builtins.dml b/lib/1.2/dml-builtins.dml index 22d1252cf..b269bf15c 100644 --- a/lib/1.2/dml-builtins.dml +++ b/lib/1.2/dml-builtins.dml @@ -212,6 +212,7 @@ template device { parameter _compat_io_memory auto; parameter _compat_dml12_inline auto; parameter _compat_dml12_not auto; + parameter _compat_dml12_goto auto; parameter _compat_dml12_misc auto; parameter _compat_dml12_int auto; diff --git a/lib/1.4/dml-builtins.dml b/lib/1.4/dml-builtins.dml index 4f5086c21..e921a3594 100644 --- a/lib/1.4/dml-builtins.dml +++ b/lib/1.4/dml-builtins.dml @@ -546,6 +546,7 @@ template device { param _compat_io_memory auto; param _compat_dml12_inline auto; param _compat_dml12_not auto; + param _compat_dml12_goto auto; param _compat_dml12_misc auto; param _compat_dml12_int auto; diff --git a/py/dml/codegen.py b/py/dml/codegen.py index 2a3adf1df..a952b3b07 100644 --- a/py/dml/codegen.py +++ b/py/dml/codegen.py @@ -2545,7 +2545,7 @@ def stmt_assert(stmt, location, scope): @statement_dispatcher def stmt_goto(stmt, location, scope): [label] = stmt.args - if compat.dml12_misc not in dml.globals.enabled_compat: + if compat.dml12_goto not in dml.globals.enabled_compat: report(ESYNTAX(stmt.site, 'goto', 'goto statement not allowed')) return [mkGoto(stmt.site, label)] diff --git a/py/dml/compat.py b/py/dml/compat.py index f6bb02a7c..956ef8a22 100644 --- a/py/dml/compat.py +++ b/py/dml/compat.py @@ -137,8 +137,6 @@ class dml12_misc(CompatFeature): * the `typeof` operator on an expression that isn't an lvalue - * the `goto` statement - * `select` statements over `vect` types * Passing a string literal in a (non-`const`) `char *` method argument @@ -169,6 +167,18 @@ class dml12_misc(CompatFeature): last_api_version = api_6 +@feature +class dml12_goto(CompatFeature): + '''The `goto` statement is deprecated; this compatibility feature + preserves it. Most `goto` based control structures can be reworked by + changing the `goto` into a `throw`, and its label into a `catch` + block; since this is sometimes nontrivial, it can be useful to disable + the `goto` statement separately. + ''' + short = "Disable the goto statement in DML 1.2" + last_api_version = api_6 + + @feature class dml12_int(CompatFeature): '''This compatibility feature affects many semantic details of diff --git a/py/dml/dmlc.py b/py/dml/dmlc.py index 0483b996f..5821ff55a 100644 --- a/py/dml/dmlc.py +++ b/py/dml/dmlc.py @@ -410,7 +410,7 @@ def main(argv): parser.add_argument('--strict-dml12', action='store_true', help='Alias for --no-compat=dml12_inline' - ',dml12_not,dml12_misc,dml12_int') + ',dml12_not,dml12_goto,dml12_misc,dml12_int') parser.add_argument('--strict-int', action='store_true', help='Alias for --no-compat=dml12_int') @@ -608,7 +608,8 @@ def main(argv): if options.strict_dml12: for feature in [compat.dml12_inline, compat.dml12_not, - compat.dml12_misc, compat.dml12_int]: + compat.dml12_goto, compat.dml12_misc, + compat.dml12_int]: tag = feature.tag() if tag in features: del features[tag]