Commit 71fd1105
71fd1105f109Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · ~5 modified
Description
Support compiler_state_* class macros natively (legacy dogfooding)
The legacy Ruby compiler declares its analyzer/codegen state via a compiler_state_int/str/sa/ia DSL and auto-synthesizes init_compiler_state / dump_compiler_state_ir / compiler_state_set_* via define_method (under a RUBY_ENGINE==ruby bootstrap shim). spinelc rejected the resulting init_compiler_state call.
Recognize the macros natively: register the declared ivars with their kind's type, record a per-class compiler_state registry, and synthesize the six methods as bodyless Scopes marked cs_synth. Codegen emits their bodies (field inits / ir_emit_* dump / sp_str_eq setters); inference pins their return types and reachability marks ir_emit_* live. First step toward compiling the legacy compiler with spinelc.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 71fd1105f109
- Parent
- 2efc0f4970dc
src/analyze.cmodifiedView file
for (int ni = 0; ni < sc_n[s]; ni++) MARK_NAME(scope_calls[s][ni]); } /* The synthesized compiler_state dump method calls ir_emit_int/str/sa/ia, but it has no AST so the BFS above can't see those calls. Mark them reachable when any class declares compiler_state fields. */ { int any_cs = 0; for (int ci = 0; ci < c->nclasses; ci++) if (c->classes[ci].ncs > 0) { any_cs = 1; break; } if (any_cs) { MARK_NAME("ir_emit_int"); MARK_NAME("ir_emit_str"); MARK_NAME("ir_emit_sa"); MARK_NAME("ir_emit_ia"); while (qhead < qtail) { int s = queue[qhead++]; for (int ni = 0; ni < sc_n[s]; ni++) MARK_NAME(scope_calls[s][ni]); } } } /* Alias/prep_to propagation: when alias_new (or alias_old) is in called_names, make the counterpart reachable too (aliases have no scope of their own). */ int changed = 1;src/analyze_pass.cmodifiedView file
Loading diff…
src/analyze_scope.cmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…
src/compiler.hmodifiedView file
Loading diff…