Commit e4d1b4a2

e4d1b4a27f92Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

First-class Proc: Proc#parameters

Emit each proc's parameter metadata -- kind (:req for lambdas, :opt for procs) and name, as interned symbol ids -- as static sp_sym arrays passed to sp_proc_new_meta, and dispatch #parameters on a TY_PROC receiver to sp_proc_parameters (-> [[:kind, :name], ...]).

The kind/name symbols are pre-interned during analyze (alongside the existing SymbolNode-literal interning) so they are present in the symbol table before the codegen prologue emits sp_sym_names.

make test: 167 pass / 5 fail / 672 error (was 166 / 5 / 673); proc_introspection green, no regressions.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
e4d1b4a27f92
Parent
f09c6f97a644

src/analyze.cmodifiedView file

@@ -176,6 +176,7 @@
176176 if (recv >= 0 && rt == TY_PROC && argc == 0) {
177177 if (!strcmp(name, "arity")) return TY_INT;
178178 if (!strcmp(name, "lambda?")) return TY_BOOL;
179+ if (!strcmp(name, "parameters")) return TY_POLY_ARRAY;
179180 }
180181
181182 /* identity methods: return the receiver unchanged */
@@ -1937,6 +1938,17 @@
19371938 if (v) comp_sym_intern(c, v);
19381939 }
19391940 }
1941+ /* Proc#parameters reports param kinds (:req/:opt) and names as symbols;
1942+ intern them now so they land in the table before the codegen prologue. */
1943+ for (int id = 0; id < c->nt->count; id++) {
1944+ if (!is_proc_create(c, id)) continue;
1945+ comp_sym_intern(c, "req");
1946+ comp_sym_intern(c, "opt");
1947+ int pn = a_proc_params_node(c, id);
1948+ if (pn < 0) continue;
1949+ int rn = 0; const int *reqs = nt_arr(c->nt, pn, "requireds", &rn);
1950+ for (int k = 0; k < rn; k++) { const char *nm = nt_str(c->nt, reqs[k], "name"); if (nm) comp_sym_intern(c, nm); }
1951+ }
19401952
19411953 for (int iter = 0; iter < 128; iter++) {
19421954 int ch = 0;