Commit a4063082
a406308232e9Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
refactor(codegen): more single-method ptypes/pnames sites (4/N)
Migrate three additional clean single-method sites to the get/put helpers:
- resolve_ivar_init_from_initialize_param: replace the manual
"iterate mnames looking for
initialize" loop with a direct cls_find_method_direct + helper get. - compile_call_args_with_defaults' target ptypes lookup: cls_meth_ptypes_get(target_ci, target_midx).
- compile_yield_call_stmt's param remapping setup: cls_meth_pnames_get / cls_meth_ptypes_get.
Also one per-class loop site (infer_class_body_call_types) where the writeback was a single per-call put — net-zero perf since the loop already split the table N times.
Tests: 301 pass. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- a406308232e9
- Parent
- 5e6f0b15e3c1
spinel_codegen.rbmodifiedView file
@@ -12015,21 +12015,13 @@
1201512015
@current_class_idx = ci1201612016
bodies = @cls_meth_bodies[ci].split(";")1201712017
mnames = @cls_meth_names[ci].split(";")12018-
all_params = @cls_meth_params[ci].split("|")12019-
all_ptypes = @cls_meth_ptypes[ci].split("|")1202012018
bj = 01202112019
while bj < bodies.length1202212020
bid = bodies[bj].to_i1202312021
if bid >= 01202412022
push_scope12025-
pnames2 = "".split(",")12026-
ptypes2 = "".split(",")12027-
if bj < all_params.length12028-
pnames2 = all_params[bj].split(",")12029-
end12030-
if bj < all_ptypes.length12031-
ptypes2 = all_ptypes[bj].split(",")12032-
end12023+
pnames2 = cls_meth_pnames_get(ci, bj)12024+
ptypes2 = cls_meth_ptypes_get(ci, bj)1203312025
pk = 01203412026
while pk < pnames2.length1203512027
pt = "int"@@ -14279,32 +14271,19 @@
1427914271
return ivt1428014272
end1428114273
# Scan initialize body for @ivar = param assignments14282-
all_bodies = @cls_meth_bodies[ci].split(";")14283-
all_mnames = @cls_meth_names[ci].split(";")14284-
all_params = @cls_meth_params[ci].split("|")14285-
all_ptypes = @cls_meth_ptypes[ci].split("|")14286-
bj = 014287-
while bj < all_mnames.length14288-
if all_mnames[bj] == "initialize"14289-
bid = all_bodies[bj].to_i14290-
if bid >= 014291-
pnames = "".split(",")14292-
ptypes = "".split(",")14293-
if bj < all_params.length14294-
pnames = all_params[bj].split(",")14295-
end14296-
if bj < all_ptypes.length14297-
ptypes = all_ptypes[bj].split(",")14298-
end14299-
# Find @ivar = param_name in initialize body14300-
resolve_ivar_from_body(ci, bid, iname, pnames, ptypes)14301-
ivt2 = cls_ivar_type(ci, iname)14302-
if ivt2 != "int"14303-
return ivt214304-
end14274+
bj = cls_find_method_direct(ci, "initialize")14275+
if bj >= 014276+
bodies = @cls_meth_bodies[ci].split(";")14277+
bid = bj < bodies.length ? bodies[bj].to_i : -114278+
if bid >= 014279+
pnames = cls_meth_pnames_get(ci, bj)14280+
ptypes = cls_meth_ptypes_get(ci, bj)14281+
resolve_ivar_from_body(ci, bid, iname, pnames, ptypes)14282+
ivt2 = cls_ivar_type(ci, iname)14283+
if ivt2 != "int"14284+
return ivt21430514285
end1430614286
end14307-
bj = bj + 11430814287
end1430914288
""1431014289
end@@ -29295,13 +29274,9 @@
2929529274
if args_id >= 02929629275
arg_ids = get_args(args_id)2929729276
end29298-
all_ptypes = @cls_meth_ptypes[target_ci].split("|")2929929277
all_defaults = @cls_meth_defaults[target_ci].split("|")29300-
ptypes = "".split(",")29278+
ptypes = cls_meth_ptypes_get(target_ci, target_midx)2930129279
defaults = "".split(",")29302-
if target_midx < all_ptypes.length29303-
ptypes = all_ptypes[target_midx].split(",")29304-
end2930529280
if target_midx < all_defaults.length2930629281
defaults = all_defaults[target_midx].split(",")2930729282
end@@ -38243,16 +38218,8 @@
3824338218
suffix = "_y" + @block_counter.to_s3824438219
3824538220
# For the method params and locals, create remapped names38246-
all_params = @cls_meth_params[cci].split("|")38247-
all_ptypes = @cls_meth_ptypes[cci].split("|")38248-
pnames = "".split(",")38249-
ptypes = "".split(",")38250-
if midx < all_params.length38251-
pnames = all_params[midx].split(",")38252-
end38253-
if midx < all_ptypes.length38254-
ptypes = all_ptypes[midx].split(",")38255-
end38221+
pnames = cls_meth_pnames_get(cci, midx)38222+
ptypes = cls_meth_ptypes_get(cci, midx)3825638223
3825738224
map_from = "".split(",")3825838225
map_to = "".split(",")