@@ -952,7 +952,7 @@ def declarations(scope):
952
952
if sym .stmt :
953
953
continue
954
954
decl = sym_declaration (sym )
955
- if decl :
955
+ if not decl . is_empty :
956
956
decls .append (decl )
957
957
958
958
return decls
@@ -2036,19 +2036,20 @@ def mk_sym(name, typ, mkunique=not dml.globals.debuggable):
2036
2036
tgts , location , scope )
2037
2037
if method_invocation is not None and stmt .site .dml_version != (1 , 2 ):
2038
2038
for sym in syms_to_add :
2039
- scope .add (sym )
2039
+ if sym .name != '_' :
2040
+ scope .add (sym )
2040
2041
stmts .extend (sym_declaration (sym ) for sym in tgt_syms )
2041
2042
stmts .append (method_invocation )
2042
- stmts .extend (sym_declaration (sym )
2043
- for sym in late_declared_syms )
2043
+ stmts .extend (sym_declaration (sym ) for sym in late_declared_syms )
2044
2044
else :
2045
2045
if len (tgts ) != 1 :
2046
2046
report (ERETLVALS (stmt .site , 1 , len (tgts )))
2047
2047
else :
2048
2048
sym = syms_to_add [0 ]
2049
2049
sym .init = ExpressionInitializer (
2050
2050
codegen_expression (inits [0 ].args [0 ], location , scope ))
2051
- scope .add (sym )
2051
+ if not (sym .name == '_' and stmt .site .dml_version () != (1 , 2 )):
2052
+ scope .add (sym )
2052
2053
stmts .append (sym_declaration (sym ))
2053
2054
else :
2054
2055
# Initializer evaluation and variable declarations are done in separate
@@ -2057,9 +2058,13 @@ def mk_sym(name, typ, mkunique=not dml.globals.debuggable):
2057
2058
inits = [get_initializer (stmt .site , typ , init , location , scope )
2058
2059
for ((_ , typ ), init ) in zip (decls , inits )]
2059
2060
for ((name , typ ), init ) in zip (decls , inits ):
2060
- sym = scope .add_variable (
2061
- name , type = typ , site = stmt .site , init = init , stmt = True ,
2062
- make_unique = not dml .globals .debuggable )
2061
+ if not (name == '_' and stmt .site .dml_version () != (1 , 2 )):
2062
+ sym = scope .add_variable (
2063
+ name , type = typ , site = stmt .site , init = init ,
2064
+ stmt = True , make_unique = not dml .globals .debuggable )
2065
+ else :
2066
+ sym = mk_sym (name , typ )
2067
+
2063
2068
stmts .append (sym_declaration (sym ))
2064
2069
2065
2070
return stmts
@@ -2401,7 +2406,7 @@ def stmt_assign(stmt, location, scope):
2401
2406
2402
2407
lscope = Symtab (scope )
2403
2408
sym = lscope .add_variable (
2404
- 'tmp ' , type = init_typ , site = init .site , init = init ,
2409
+ '_tmp ' , type = init_typ , site = init .site , init = init ,
2405
2410
stmt = True )
2406
2411
init_expr = mkLocalVariable (init .site , sym )
2407
2412
stmts = [sym_declaration (sym )]
@@ -2437,7 +2442,7 @@ def stmt_assign(stmt, location, scope):
2437
2442
else :
2438
2443
init = eval_initializer (site , tgt .ctype (), src_ast , location ,
2439
2444
scope , False )
2440
- name = 'tmp %d' % (i ,)
2445
+ name = '_tmp %d' % (i ,)
2441
2446
sym = lscope .add_variable (
2442
2447
name , type = tgt .ctype (), site = tgt .site , init = init ,
2443
2448
stmt = True )
@@ -2930,6 +2935,9 @@ def stmt_afteronhook(stmt, location, scope):
2930
2935
2931
2936
msg_comp_params = {}
2932
2937
for (idx , (mcp_site , mcp_name )) in enumerate (msg_comp_param_asts ):
2938
+ if mcp_name == '_' :
2939
+ continue
2940
+
2933
2941
if mcp_name in msg_comp_params :
2934
2942
raise EDVAR (mcp_site , msg_comp_params [mcp_name ][1 ],
2935
2943
mcp_name )
@@ -3079,7 +3087,8 @@ def stmt_select(stmt, location, scope):
3079
3087
clauses = []
3080
3088
for it in l :
3081
3089
condscope = Symtab (scope )
3082
- condscope .add (ExpressionSymbol (itername , it , stmt .site ))
3090
+ if not (itername == '_' and stmt .site .dml_version () != (1 , 2 )):
3091
+ condscope .add (ExpressionSymbol (itername , it , stmt .site ))
3083
3092
cond = as_bool (codegen_expression (
3084
3093
cond_ast , location , condscope ))
3085
3094
if cond .constant and not cond .value :
@@ -3115,9 +3124,10 @@ def foreach_each_in(site, itername, trait, each_in,
3115
3124
body_ast , location , scope ):
3116
3125
inner_scope = Symtab (scope )
3117
3126
trait_type = TTrait (trait )
3118
- inner_scope .add_variable (
3119
- itername , type = trait_type , site = site ,
3120
- init = ForeachSequence .itervar_initializer (site , trait ))
3127
+ if itername != '_' :
3128
+ inner_scope .add_variable (
3129
+ itername , type = trait_type , site = site ,
3130
+ init = ForeachSequence .itervar_initializer (site , trait ))
3121
3131
context = GotoLoopContext ()
3122
3132
with context :
3123
3133
inner_body = mkCompound (site , declarations (inner_scope )
@@ -3198,8 +3208,9 @@ def foreach_constant_list(site, itername, lst, statement, location, scope):
3198
3208
TInt (32 , True ))
3199
3209
for dim in range (len (items .dimsizes )))
3200
3210
loopscope = Symtab (scope )
3201
- loopscope .add (ExpressionSymbol (
3202
- itername , items .expr (loopvars ), site ))
3211
+ if not (itername == '_' and site .dml_version () != (1 , 2 )):
3212
+ loopscope .add (ExpressionSymbol (
3213
+ itername , items .expr (loopvars ), site ))
3203
3214
stmt = codegen_statement (statement , location , loopscope )
3204
3215
3205
3216
if stmt .is_empty :
@@ -3584,6 +3595,7 @@ def codegen_inline(site, meth_node, indices, inargs, outargs,
3584
3595
# call is safe.
3585
3596
return codegen_call (site , meth_node , indices ,
3586
3597
inargs , outargs )
3598
+ pre = []
3587
3599
for (arg , (parmname , parmtype ), argno ) in zip (inargs , meth_node .inp ,
3588
3600
list (range (len (inargs )))):
3589
3601
# Create an alias
@@ -3604,7 +3616,12 @@ def codegen_inline(site, meth_node, indices, inargs, outargs,
3604
3616
raise ECONSTP (site , parmname , "method call" )
3605
3617
arg = coerce_if_eint (arg )
3606
3618
3607
- if inhibit_copyin or undefined (arg ):
3619
+ if (parmname == '_'
3620
+ and meth_node .astcode .site .dml_version () != (1 , 2 )):
3621
+ if not arg .constant :
3622
+ pre .append (mkExpressionStatement (arg .site , arg ,
3623
+ explicit_discard = True ))
3624
+ elif inhibit_copyin or undefined (arg ):
3608
3625
param_scope .add (ExpressionSymbol (parmname , arg , arg .site ))
3609
3626
elif arg .constant and (
3610
3627
parmtype is None
@@ -3661,13 +3678,13 @@ def codegen_inline(site, meth_node, indices, inargs, outargs,
3661
3678
exit_handler = GotoExit_dml14 (outargs )
3662
3679
with exit_handler :
3663
3680
code = codegen_statements (subs , location , param_scope )
3664
- decls = declarations (param_scope )
3681
+ pre . extend ( declarations (param_scope ) )
3665
3682
post = ([mkLabel (site , exit_handler .label )]
3666
3683
if exit_handler .used else [])
3667
- body = mkCompound (site , decls + code , rbrace_site )
3684
+ body = mkCompound (site , pre + code , rbrace_site )
3668
3685
if meth_node .outp and body .control_flow ().fallthrough :
3669
3686
report (ENORET (meth_node .astcode .site ))
3670
- return mkInlinedMethod (site , meth_node , decls , code , post )
3687
+ return mkInlinedMethod (site , meth_node , pre , code , post )
3671
3688
3672
3689
def c_rettype (outp , throws ):
3673
3690
if throws :
@@ -3725,14 +3742,24 @@ def __init__(self, method, inp, outp, throws, independent, startup,
3725
3742
3726
3743
# rettype is the return type of the C function
3727
3744
self .rettype = c_rettype (outp , throws )
3745
+ cparams = list (cparams )
3746
+
3747
+ if method .astcode .site .dml_version () != (1 , 2 ):
3748
+ discarded = 0
3749
+ for (i , (n , t )) in enumerate (cparams ):
3750
+ if n == '_' :
3751
+ cparams [i ] = (f'_unused_{ discarded } ' , t )
3752
+ discarded += 1
3753
+
3728
3754
self .cparams = c_inargs (
3729
- implicit_params (method ) + list ( cparams ) , outp , throws )
3755
+ implicit_params (method ) + cparams , outp , throws )
3730
3756
3731
3757
@property
3732
3758
def prototype (self ):
3733
3759
return self .rettype .declaration (
3734
3760
"%s(%s)" % (self .get_cname (),
3735
3761
", " .join ([t .declaration (n )
3762
+ + ' UNUSED' * n .startswith ('_unused_' )
3736
3763
for (n , t ) in self .cparams ])))
3737
3764
3738
3765
def cfunc_expr (self , site ):
@@ -3826,7 +3853,9 @@ def codegen_method_func(func):
3826
3853
if dml .globals .dml_version == (1 , 2 ) and (
3827
3854
compat .dml12_misc not in dml .globals .enabled_compat ):
3828
3855
check_varname (method .site , name )
3829
- if isinstance (e , Expression ):
3856
+ if (isinstance (e , Expression )
3857
+ and not (name == '_'
3858
+ and method .astcode .site .dml_version () != (1 , 2 ))):
3830
3859
inlined_arg = (
3831
3860
mkInlinedParam (method .site , e , name , e .ctype ())
3832
3861
if defined (e ) else e )
@@ -3881,7 +3910,9 @@ def codegen_method(site, inp, outp, throws, independent, memoization, ast,
3881
3910
with (crep .DeviceInstanceContext () if not independent
3882
3911
else contextlib .nullcontext ()):
3883
3912
for (arg , etype ) in inp :
3884
- fnscope .add_variable (arg , type = etype , site = site , make_unique = False )
3913
+ if not (arg == '_' and ast .site .dml_version () != (1 , 2 )):
3914
+ fnscope .add_variable (arg , type = etype , site = site ,
3915
+ make_unique = False )
3885
3916
initializers = [get_initializer (site , parmtype , None , None , None )
3886
3917
for (_ , parmtype ) in outp ]
3887
3918
0 commit comments