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_scope
608608 while @scope_names.length > 0
609- top_name = @scope_names[@scope_names.length - 1]
609+ top_name = @scope_names.last
610610 if top_name == "---"
611611 @scope_names.pop
612612 @scope_types.pop
@@ -880,7 +880,7 @@
880880 if body >= 0
881881 stmts = get_stmts(body)
882882 if stmts.length > 0
883- return infer_type(stmts[stmts.length - 1])
883+ return infer_type(stmts.last)
884884 end
885885 end
886886 return "void"
@@ -895,7 +895,7 @@
895895 if ibody >= 0
896896 is = get_stmts(ibody)
897897 if is.length > 0
898- return infer_type(is[is.length - 1])
898+ return infer_type(is.last)
899899 end
900900 end
901901 end
@@ -912,7 +912,7 @@
912912 if wbody >= 0
913913 ws = get_stmts(wbody)
914914 if ws.length > 0
915- return infer_type(ws[ws.length - 1])
915+ return infer_type(ws.last)
916916 end
917917 end
918918 end
@@ -930,7 +930,7 @@
930930 if body >= 0
931931 stmts = get_stmts(body)
932932 if stmts.length > 0
933- return infer_type(stmts[stmts.length - 1])
933+ return infer_type(stmts.last)
934934 end
935935 end
936936 return "void"
@@ -1481,7 +1481,7 @@
14811481 if bbody >= 0
14821482 bbs = get_stmts(bbody)
14831483 if bbs.length > 0
1484- 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 rt
46304630 end
46314631 # Last expression
4632- infer_type(stmts[stmts.length - 1])
4632+ infer_type(stmts.last)
46334633 end
46344634
46354635 def scan_return_type_nid(nid)
@@ -7786,7 +7786,7 @@
77867786 if body >= 0
77877787 stmts = get_stmts(body)
77887788 if stmts.length > 0
7789- return compile_expr(stmts[stmts.length - 1])
7789+ return compile_expr(stmts.last)
77907790 end
77917791 end
77927792 return "0"
@@ -7854,7 +7854,7 @@
78547854 if t == "StatementsNode"
78557855 stmts = parse_id_list(@nd_stmts[nid])
78567856 if stmts.length > 0
7857- return compile_expr(stmts[stmts.length - 1])
7857+ return compile_expr(stmts.last)
78587858 end
78597859 return "0"
78607860 end
@@ -7903,7 +7903,7 @@
79037903 compile_stmt(ws[i])
79047904 i = i + 1
79057905 end
7906- emit(" " + tmp + " = " + compile_expr(ws[ws.length - 1]) + ";")
7906+ emit(" " + tmp + " = " + compile_expr(ws.last) + ";")
79077907 end
79087908 end
79097909 end
@@ -7935,7 +7935,7 @@
79357935 compile_stmt(ws[i])
79367936 i = i + 1
79377937 end
7938- emit(" " + tmp + " = " + compile_expr(ws[ws.length - 1]) + ";")
7938+ emit(" " + tmp + " = " + compile_expr(ws.last) + ";")
79397939 end
79407940 end
79417941 end
@@ -7954,7 +7954,7 @@
79547954 compile_stmt(es[i])
79557955 i = i + 1
79567956 end
7957- emit(" " + tmp + " = " + compile_expr(es[es.length - 1]) + ";")
7957+ emit(" " + tmp + " = " + compile_expr(es.last) + ";")
79587958 end
79597959 end
79607960 end
@@ -9188,7 +9188,7 @@
91889188 if bbody >= 0
91899189 bs = get_stmts(bbody)
91909190 if bs.length > 0
9191- bexpr = compile_expr(bs[bs.length - 1])
9191+ bexpr = compile_expr(bs.last)
91929192 end
91939193 end
91949194 emit(" if (" + bexpr + ") " + tmp + "++;")
@@ -9212,7 +9212,7 @@
92129212 if bbody >= 0
92139213 bs = get_stmts(bbody)
92149214 if bs.length > 0
9215- bexpr = compile_expr(bs[bs.length - 1])
9215+ bexpr = compile_expr(bs.last)
92169216 end
92179217 end
92189218 emit(" mrb_int _v = " + bexpr + ";")
@@ -9236,7 +9236,7 @@
92369236 if bbody >= 0
92379237 bs = get_stmts(bbody)
92389238 if bs.length > 0
9239- bexpr = compile_expr(bs[bs.length - 1])
9239+ bexpr = compile_expr(bs.last)
92409240 end
92419241 end
92429242 emit(" mrb_int _v = " + bexpr + ";")
@@ -9261,7 +9261,7 @@
92619261 if bbody >= 0
92629262 bs = get_stmts(bbody)
92639263 if bs.length > 0
9264- bexpr = compile_expr(bs[bs.length - 1])
9264+ bexpr = compile_expr(bs.last)
92659265 end
92669266 end
92679267 emit(" mrb_int _ka = " + bexpr + ";")
@@ -9343,7 +9343,7 @@
93439343 if bbody >= 0
93449344 bs = get_stmts(bbody)
93459345 if bs.length > 0
9346- bexpr = compile_expr(bs[bs.length - 1])
9346+ bexpr = compile_expr(bs.last)
93479347 end
93489348 end
93499349 emit(" if (" + bexpr + ") " + tmp + "++;")
@@ -9398,7 +9398,7 @@
93989398 if bbody >= 0
93999399 bs = get_stmts(bbody)
94009400 if bs.length > 0
9401- bexpr = compile_expr(bs[bs.length - 1])
9401+ bexpr = compile_expr(bs.last)
94029402 end
94039403 end
94049404 emit(" sp_StrIntHash_set(" + tmp + ", " + rc + "->keys[_i], " + bexpr + ");")
@@ -10227,7 +10227,7 @@
1022710227 if body >= 0
1022810228 stmts = get_stmts(body)
1022910229 if stmts.length > 0
10230- then_val = compile_expr(stmts[stmts.length - 1])
10230+ then_val = compile_expr(stmts.last)
1023110231 end
1023210232 end
1023310233 else_val = "0"
@@ -10238,7 +10238,7 @@
1023810238 if eb >= 0
1023910239 es = get_stmts(eb)
1024010240 if es.length > 0
10241- else_val = compile_expr(es[es.length - 1])
10241+ else_val = compile_expr(es.last)
1024210242 end
1024310243 end
1024410244 else
@@ -10255,7 +10255,7 @@
1025510255 if body >= 0
1025610256 stmts = get_stmts(body)
1025710257 if stmts.length > 0
10258- then_val = compile_expr(stmts[stmts.length - 1])
10258+ then_val = compile_expr(stmts.last)
1025910259 end
1026010260 end
1026110261 "(!" + cond + " ? " + then_val + " : 0)"
@@ -11800,7 +11800,7 @@
1180011800 if body >= 0
1180111801 bs = get_stmts(body)
1180211802 if bs.length > 0
11803- bexpr = compile_lambda_body_expr(bs[bs.length - 1], params, captures)
11803+ bexpr = compile_lambda_body_expr(bs.last, params, captures)
1180411804 end
1180511805 end
1180611806 ec = @nd_else_clause[nid]
@@ -11875,7 +11875,7 @@
1187511875 @out = ""
1187611876 @lambda_params = param_arr
1187711877 @lambda_captures = free_vars
11878- 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 = @out
1188011880 @out = save_out
1188111881 @lambda_params = save_params
@@ -12340,7 +12340,7 @@
1234012340 if body >= 0
1234112341 stmts = get_stmts(body)
1234212342 if stmts.length > 0
12343- block_ret = infer_type(stmts[stmts.length - 1])
12343+ block_ret = infer_type(stmts.last)
1234412344 end
1234512345 end
1234612346 end
@@ -12452,7 +12452,7 @@
1245212452 if body >= 0
1245312453 stmts = get_stmts(body)
1245412454 if stmts.length > 0
12455- last = stmts[stmts.length - 1]
12455+ last = stmts.last
1245612456 cond = compile_expr(last)
1245712457 emit(" if (" + cond + ") sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")
1245812458 end
@@ -12499,7 +12499,7 @@
1249912499 if body >= 0
1250012500 stmts = get_stmts(body)
1250112501 if stmts.length > 0
12502- last = stmts[stmts.length - 1]
12502+ last = stmts.last
1250312503 val = compile_expr(last)
1250412504 emit(" lv_" + bp1 + " = " + val + ";")
1250512505 end
@@ -12531,7 +12531,7 @@
1253112531 if body >= 0
1253212532 stmts = get_stmts(body)
1253312533 if stmts.length > 0
12534- last = stmts[stmts.length - 1]
12534+ last = stmts.last
1253512535 cond = compile_expr(last)
1253612536 emit(" if (!(" + cond + ")) sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")
1253712537 end
@@ -12565,7 +12565,7 @@
1256512565 if body >= 0
1256612566 stmts = get_stmts(body)
1256712567 if stmts.length > 0
12568- last = stmts[stmts.length - 1]
12568+ last = stmts.last
1256912569 cond = compile_expr(last)
1257012570 emit(" if (!(" + cond + ")) sp_IntArray_push(" + tmp_arr + ", lv_" + bp1 + ");")
1257112571 end
@@ -12624,7 +12624,7 @@
1262412624 k = k + 1
1262512625 end
1262612626 if stmts.length > 0
12627- last = stmts[stmts.length - 1]
12627+ last = stmts.last
1262812628 emit(" " + tmp + " = " + compile_expr(last) + ";")
1262912629 end
1263012630 end
@@ -13451,7 +13451,7 @@
1345113451 if body >= 0
1345213452 stmts = get_stmts(body)
1345313453 if stmts.length > 0
13454- last = stmts[stmts.length - 1]
13454+ last = stmts.last
1345513455 val = compile_expr(last)
1345613456 emit(" sp_IntArray_push(" + tmp_arr + ", " + val + ");")
1345713457 end
@@ -13472,7 +13472,7 @@
1347213472 if body >= 0
1347313473 stmts = get_stmts(body)
1347413474 if stmts.length > 0
13475- last = stmts[stmts.length - 1]
13475+ last = stmts.last
1347613476 val = compile_expr(last)
1347713477 emit(" sp_StrArray_push(" + tmp_arr + ", " + val + ");")
1347813478 end
@@ -13508,7 +13508,7 @@
1350813508 if body >= 0
1350913509 stmts = get_stmts(body)
1351013510 if stmts.length > 0
13511- last = stmts[stmts.length - 1]
13511+ last = stmts.last
1351213512 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 + 1
1355413554 end
13555- last = stmts[stmts.length - 1]
13555+ last = stmts.last
1355613556 if @nd_type[last] == "ReturnNode"
1355713557 compile_return_stmt(last)
1355813558 return