Commit 210ca83c
210ca83c0a4fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
refactor: arr[arr.length-1] → arr.last (28 occurrences)
Replace verbose array last-element access with .last method. Bootstrap loop verified: gen2==gen3 (0 diff). 58/59 tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 210ca83c0a4f
- Parent
- 498becd773a9
spinel_codegen.rbmodifiedView file
@@ -606,7 +606,7 @@
606606
607607
def pop_scope608608
while @scope_names.length > 0609-
top_name = @scope_names[@scope_names.length - 1]609+
top_name = @scope_names.last610610
if top_name == "---"611611
@scope_names.pop612612
@scope_types.pop@@ -880,7 +880,7 @@
880880
if body >= 0881881
stmts = get_stmts(body)882882
if stmts.length > 0883-
return infer_type(stmts[stmts.length - 1])883+
return infer_type(stmts.last)884884
end885885
end886886
return "void"@@ -895,7 +895,7 @@
895895
if ibody >= 0896896
is = get_stmts(ibody)897897
if is.length > 0898-
return infer_type(is[is.length - 1])898+
return infer_type(is.last)899899
end900900
end901901
end@@ -912,7 +912,7 @@
912912
if wbody >= 0913913
ws = get_stmts(wbody)914914
if ws.length > 0915-
return infer_type(ws[ws.length - 1])915+
return infer_type(ws.last)916916
end917917
end918918
end@@ -930,7 +930,7 @@
930930
if body >= 0931931
stmts = get_stmts(body)932932
if stmts.length > 0933-
return infer_type(stmts[stmts.length - 1])933+
return infer_type(stmts.last)934934
end935935
end936936
return "void"@@ -1481,7 +1481,7 @@
14811481
if bbody >= 014821482
bbs = get_stmts(bbody)14831483
if bbs.length > 01484-
bret = infer_type(bbs[bbs.length - 1])1484+
bret = infer_type(bbs.last)14851485
if bret == "string"14861486
return "str_array"14871487
end@@ -4629,7 +4629,7 @@
46294629
return rt46304630
end46314631
# Last expression4632-
infer_type(stmts[stmts.length - 1])4632+
infer_type(stmts.last)46334633
end46344634
46354635
def scan_return_type_nid(nid)@@ -7786,7 +7786,7 @@
77867786
if body >= 077877787
stmts = get_stmts(body)77887788
if stmts.length > 07789-
return compile_expr(stmts[stmts.length - 1])7789+
return compile_expr(stmts.last)77907790
end77917791
end77927792
return "0"@@ -7854,7 +7854,7 @@
78547854
if t == "StatementsNode"78557855
stmts = parse_id_list(@nd_stmts[nid])78567856
if stmts.length > 07857-
return compile_expr(stmts[stmts.length - 1])7857+
return compile_expr(stmts.last)78587858
end78597859
return "0"78607860
end@@ -7903,7 +7903,7 @@
79037903
compile_stmt(ws[i])79047904
i = i + 179057905
end7906-
emit(" " + tmp + " = " + compile_expr(ws[ws.length - 1]) + ";")7906+
emit(" " + tmp + " = " + compile_expr(ws.last) + ";")79077907
end79087908
end79097909
end@@ -7935,7 +7935,7 @@
79357935
compile_stmt(ws[i])79367936
i = i + 179377937
end7938-
emit(" " + tmp + " = " + compile_expr(ws[ws.length - 1]) + ";")7938+
emit(" " + tmp + " = " + compile_expr(ws.last) + ";")79397939
end79407940
end79417941
end@@ -7954,7 +7954,7 @@
79547954
compile_stmt(es[i])79557955
i = i + 179567956
end7957-
emit(" " + tmp + " = " + compile_expr(es[es.length - 1]) + ";")7957+
emit(" " + tmp + " = " + compile_expr(es.last) + ";")79587958
end79597959
end79607960
end@@ -9188,7 +9188,7 @@
91889188
if bbody >= 091899189
bs = get_stmts(bbody)91909190
if bs.length > 09191-
bexpr = compile_expr(bs[bs.length - 1])9191+
bexpr = compile_expr(bs.last)91929192
end91939193
end91949194
emit(" if (" + bexpr + ") " + tmp + "++;")@@ -9212,7 +9212,7 @@
92129212
if bbody >= 092139213
bs = get_stmts(bbody)92149214
if bs.length > 09215-
bexpr = compile_expr(bs[bs.length - 1])9215+
bexpr = compile_expr(bs.last)92169216
end92179217
end92189218
emit(" mrb_int _v = " + bexpr + ";")@@ -9236,7 +9236,7 @@
92369236
if bbody >= 092379237
bs = get_stmts(bbody)92389238
if bs.length > 09239-
bexpr = compile_expr(bs[bs.length - 1])9239+
bexpr = compile_expr(bs.last)92409240
end92419241
end92429242
emit(" mrb_int _v = " + bexpr + ";")@@ -9261,7 +9261,7 @@
92619261
if bbody >= 092629262
bs = get_stmts(bbody)92639263
if bs.length > 09264-
bexpr = compile_expr(bs[bs.length - 1])9264+
bexpr = compile_expr(bs.last)92659265
end92669266
end92679267
emit(" mrb_int _ka = " + bexpr + ";")@@ -9343,7 +9343,7 @@
93439343
if bbody >= 093449344
bs = get_stmts(bbody)93459345
if bs.length > 09346-
bexpr = compile_expr(bs[bs.length - 1])9346+
bexpr = compile_expr(bs.last)93479347
end93489348
end93499349
emit(" if (" + bexpr + ") " + tmp + "++;")@@ -9398,7 +9398,7 @@
93989398
if bbody >= 093999399
bs = get_stmts(bbody)94009400
if bs.length > 09401-
bexpr = compile_expr(bs[bs.length - 1])9401+
bexpr = compile_expr(bs.last)94029402
end94039403
end94049404
emit(" sp_StrIntHash_set(" + tmp + ", " + rc + "->keys[_i], " + bexpr + ");")@@ -10227,7 +10227,7 @@
1022710227
if body >= 01022810228
stmts = get_stmts(body)1022910229
if stmts.length > 010230-
then_val = compile_expr(stmts[stmts.length - 1])10230+
then_val = compile_expr(stmts.last)1023110231
end1023210232
end1023310233
else_val = "0"@@ -10238,7 +10238,7 @@
1023810238
if eb >= 01023910239
es = get_stmts(eb)1024010240
if es.length > 010241-
else_val = compile_expr(es[es.length - 1])10241+
else_val = compile_expr(es.last)1024210242
end1024310243
end1024410244
else@@ -10255,7 +10255,7 @@
1025510255
if body >= 01025610256
stmts = get_stmts(body)1025710257
if stmts.length > 010258-
then_val = compile_expr(stmts[stmts.length - 1])10258+
then_val = compile_expr(stmts.last)1025910259
end1026010260
end1026110261
"(!" + cond + " ? " + then_val + " : 0)"@@ -11800,7 +11800,7 @@
1180011800
if body >= 01180111801
bs = get_stmts(body)1180211802
if bs.length > 011803-
bexpr = compile_lambda_body_expr(bs[bs.length - 1], params, captures)11803+
bexpr = compile_lambda_body_expr(bs.last, params, captures)1180411804
end1180511805
end1180611806
ec = @nd_else_clause[nid]@@ -11875,7 +11875,7 @@
1187511875
@out = ""1187611876
@lambda_params = param_arr1187711877
@lambda_captures = free_vars11878-
bexpr = compile_lambda_body_expr(bs[bs.length - 1], param_arr, free_vars)11878+
bexpr = compile_lambda_body_expr(bs.last, param_arr, free_vars)1187911879
body_stmts = @out1188011880
@out = save_out1188111881
@lambda_params = save_params@@ -12340,7 +12340,7 @@
1234012340
if body >= 01234112341
stmts = get_stmts(body)1234212342
if stmts.length > 012343-
block_ret = infer_type(stmts[stmts.length - 1])12343+
block_ret = infer_type(stmts.last)1234412344
end1234512345
end1234612346
end@@ -12452,7 +12452,7 @@
1245212452
if body >= 01245312453
stmts = get_stmts(body)1245412454
if stmts.length > 012455-
last = stmts[stmts.length - 1]12455+
last = stmts.last1245612456
cond = compile_expr(last)1245712457
emit(" if (" + cond + ") sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")1245812458
end@@ -12499,7 +12499,7 @@
1249912499
if body >= 01250012500
stmts = get_stmts(body)1250112501
if stmts.length > 012502-
last = stmts[stmts.length - 1]12502+
last = stmts.last1250312503
val = compile_expr(last)1250412504
emit(" lv_" + bp1 + " = " + val + ";")1250512505
end@@ -12531,7 +12531,7 @@
1253112531
if body >= 01253212532
stmts = get_stmts(body)1253312533
if stmts.length > 012534-
last = stmts[stmts.length - 1]12534+
last = stmts.last1253512535
cond = compile_expr(last)1253612536
emit(" if (!(" + cond + ")) sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")1253712537
end@@ -12565,7 +12565,7 @@
1256512565
if body >= 01256612566
stmts = get_stmts(body)1256712567
if stmts.length > 012568-
last = stmts[stmts.length - 1]12568+
last = stmts.last1256912569
cond = compile_expr(last)1257012570
emit(" if (!(" + cond + ")) sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")1257112571
end@@ -12624,7 +12624,7 @@
1262412624
k = k + 11262512625
end1262612626
if stmts.length > 012627-
last = stmts[stmts.length - 1]12627+
last = stmts.last1262812628
emit(" " + tmp + " = " + compile_expr(last) + ";")1262912629
end1263012630
end@@ -13451,7 +13451,7 @@
1345113451
if body >= 01345213452
stmts = get_stmts(body)1345313453
if stmts.length > 013454-
last = stmts[stmts.length - 1]13454+
last = stmts.last1345513455
val = compile_expr(last)1345613456
emit(" sp_IntArray_push(" + tmp_arr + ", " + val + ");")1345713457
end@@ -13472,7 +13472,7 @@
1347213472
if body >= 01347313473
stmts = get_stmts(body)1347413474
if stmts.length > 013475-
last = stmts[stmts.length - 1]13475+
last = stmts.last1347613476
val = compile_expr(last)1347713477
emit(" sp_StrArray_push(" + tmp_arr + ", " + val + ");")1347813478
end@@ -13508,7 +13508,7 @@
1350813508
if body >= 01350913509
stmts = get_stmts(body)1351013510
if stmts.length > 013511-
last = stmts[stmts.length - 1]13511+
last = stmts.last1351213512
cond = compile_expr(last)1351313513
emit(" if (" + cond + ") sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")1351413514
end@@ -13552,7 +13552,7 @@
1355213552
compile_stmt(stmts[i])1355313553
i = i + 11355413554
end13555-
last = stmts[stmts.length - 1]13555+
last = stmts.last1355613556
if @nd_type[last] == "ReturnNode"1355713557
compile_return_stmt(last)1355813558
return