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 = ci
1201612016 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 = 0
1202112019 while bj < bodies.length
1202212020 bid = bodies[bj].to_i
1202312021 if bid >= 0
1202412022 push_scope
12025- pnames2 = "".split(",")
12026- ptypes2 = "".split(",")
12027- if bj < all_params.length
12028- pnames2 = all_params[bj].split(",")
12029- end
12030- if bj < all_ptypes.length
12031- ptypes2 = all_ptypes[bj].split(",")
12032- end
12023+ pnames2 = cls_meth_pnames_get(ci, bj)
12024+ ptypes2 = cls_meth_ptypes_get(ci, bj)
1203312025 pk = 0
1203412026 while pk < pnames2.length
1203512027 pt = "int"
@@ -14279,32 +14271,19 @@
1427914271 return ivt
1428014272 end
1428114273 # Scan initialize body for @ivar = param assignments
14282- 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 = 0
14287- while bj < all_mnames.length
14288- if all_mnames[bj] == "initialize"
14289- bid = all_bodies[bj].to_i
14290- if bid >= 0
14291- pnames = "".split(",")
14292- ptypes = "".split(",")
14293- if bj < all_params.length
14294- pnames = all_params[bj].split(",")
14295- end
14296- if bj < all_ptypes.length
14297- ptypes = all_ptypes[bj].split(",")
14298- end
14299- # Find @ivar = param_name in initialize body
14300- resolve_ivar_from_body(ci, bid, iname, pnames, ptypes)
14301- ivt2 = cls_ivar_type(ci, iname)
14302- if ivt2 != "int"
14303- return ivt2
14304- end
14274+ bj = cls_find_method_direct(ci, "initialize")
14275+ if bj >= 0
14276+ bodies = @cls_meth_bodies[ci].split(";")
14277+ bid = bj < bodies.length ? bodies[bj].to_i : -1
14278+ if bid >= 0
14279+ 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 ivt2
1430514285 end
1430614286 end
14307- bj = bj + 1
1430814287 end
1430914288 ""
1431014289 end
@@ -29295,13 +29274,9 @@
2929529274 if args_id >= 0
2929629275 arg_ids = get_args(args_id)
2929729276 end
29298- 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.length
29303- ptypes = all_ptypes[target_midx].split(",")
29304- end
2930529280 if target_midx < all_defaults.length
2930629281 defaults = all_defaults[target_midx].split(",")
2930729282 end
@@ -38243,16 +38218,8 @@
3824338218 suffix = "_y" + @block_counter.to_s
3824438219
3824538220 # For the method params and locals, create remapped names
38246- 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.length
38251- pnames = all_params[midx].split(",")
38252- end
38253- if midx < all_ptypes.length
38254- ptypes = all_ptypes[midx].split(",")
38255- end
38221+ pnames = cls_meth_pnames_get(cci, midx)
38222+ ptypes = cls_meth_ptypes_get(cci, midx)
3825638223
3825738224 map_from = "".split(",")
3825838225 map_to = "".split(",")