Commit 991d5fe0
991d5fe0dc3eMerged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): scan const-init expressions for block-param locals
emit_main scans top-level statements for locals so they get declared at main()'s frame before any code runs. Constant initializer expressions are then compiled into main() right before the user statements, but they were not part of the local scan. Block params introduced inside a const RHS — e.g. `FRAME_CLOCKS = [29830, ...].map { |n| RP2A03_CC * n }`'s `n` — never got a corresponding `mrb_int lv_n;` declaration, and the emitted assignment `lv_n = sp_IntArray_get(...);` fell through with "undeclared identifier".
Walk @const_expr_ids alongside the existing top-level statement scan so any local introduced inside a const's RHS gets the same treatment.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 991d5fe0dc3e
- Parent
- bee7e89d5b64
spinel_codegen.rbmodifiedView file
end end } # Constant initializer expressions get compiled into main() right # before the user statements run, but the block params they # introduce (e.g. \`FRAME = [...].map { |n| ... }\`) need # declarations in the same scope. Scan each const's RHS so the # block param names land in lnames alongside the user-stmt locals. ci_lc = 0 while ci_lc < @const_expr_ids.length if @const_expr_ids[ci_lc] >= 0 scan_locals(@const_expr_ids[ci_lc], lnames, ltypes, empty_params) end ci_lc = ci_lc + 1 end # Declare vars for second pass to resolve dependent types j = 0test/const_init_block_param_scan.rbaddedView file
Loading diff…