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

@@ -54,6 +54,19 @@
5454 for (int ni = 0; ni < sc_n[s]; ni++) MARK_NAME(scope_calls[s][ni]);
5555 }
5656
57+ /* The synthesized compiler_state dump method calls ir_emit_int/str/sa/ia,
58+ but it has no AST so the BFS above can't see those calls. Mark them
59+ reachable when any class declares compiler_state fields. */
60+ {
61+ int any_cs = 0;
62+ for (int ci = 0; ci < c->nclasses; ci++) if (c->classes[ci].ncs > 0) { any_cs = 1; break; }
63+ if (any_cs) {
64+ MARK_NAME("ir_emit_int"); MARK_NAME("ir_emit_str");
65+ MARK_NAME("ir_emit_sa"); MARK_NAME("ir_emit_ia");
66+ while (qhead < qtail) { int s = queue[qhead++]; for (int ni = 0; ni < sc_n[s]; ni++) MARK_NAME(scope_calls[s][ni]); }
67+ }
68+ }
69+
5770 /* Alias/prep_to propagation: when alias_new (or alias_old) is in called_names,
5871 make the counterpart reachable too (aliases have no scope of their own). */
5972 int changed = 1;