Skip to content

Commit

Permalink
Extract goto to a separate compat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mandolaerik committed Oct 10, 2023
1 parent bc55035 commit 18febee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/1.2/dml-builtins.dml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions lib/1.4/dml-builtins.dml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion py/dml/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
14 changes: 12 additions & 2 deletions py/dml/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions py/dml/dmlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 18febee

Please sign in to comment.