Skip to content

Commit d940bfa

Browse files
committed
Codegen the discard reference via dedicated AST dispatch
1 parent dce32e4 commit d940bfa

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

py/dml/ast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __setstate__(self, data):
5454
'default',
5555
'default_dml12',
5656
'delete',
57+
'discardref',
5758
'dml',
5859
'dml_typedef',
5960
'dowhile',

py/dml/codegen.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,16 +1207,13 @@ def expr_variable(tree, location, scope):
12071207
if in_dev_tree:
12081208
e = in_dev_tree
12091209
if e is None:
1210-
# TODO/HACK: The discard ref is exposed like this to allow it to be as
1211-
# keyword-like as possible while still allowing it to be shadowed.
1212-
# Once we remove support for discard_ref_shadowing the discard ref
1213-
# should become a proper keyword and its codegen be done via dedicated
1214-
# dispatch
1215-
if name == '_' and tree.site.dml_version() != (1, 2):
1216-
return mkDiscardRef(tree.site)
12171210
raise EIDENT(tree.site, name)
12181211
return e
12191212

1213+
@expression_dispatcher
1214+
def expr_discardref(tree, location, scope):
1215+
return mkDiscardRef(tree.site)
1216+
12201217
@expression_dispatcher
12211218
def expr_objectref(tree, location, scope):
12221219
[name] = tree.args

py/dml/dmllex14.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
keywords_dml14 = dict(keywords_common)
2222
for kw in ['param', 'saved', 'async', 'await', 'with', 'shared', 'stringify',
23-
'export', 'as', 'independent', 'startup', 'memoized', 'hook']:
23+
'export', 'as', 'independent', 'startup', 'memoized', 'hook', '_']:
2424
keywords_dml14[kw] = kw.upper()
2525
tokens += (kw.upper(),)
2626

py/dml/dmlparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,11 @@ def expression_ident(t):
17581758
| DEFAULT'''
17591759
t[0] = ast.variable(site(t), t[1])
17601760

1761+
@prod_dml14
1762+
def expression_discardref(t):
1763+
'''expression : _'''
1764+
t[0] = ast.discardref(site(t))
1765+
17611766
@prod_dml14
17621767
def expression_this(t):
17631768
'''expression : THIS'''

0 commit comments

Comments
 (0)