Commit f09c6f97

f09c6f97a644Merged

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

Description

First-class Proc: #arity and #lambda? introspection

Dispatch arity/lambda? on a TY_PROC receiver to the sp_Proc metadata helpers (sp_proc_arity / sp_proc_lambda_p), which already carry the values set at sp_proc_new_meta time. arity -> int, lambda? -> bool; proc{}/Proc.new are non-lambdas, lambda{}/->() are lambdas.

(#parameters defers: it needs :req/:opt and the param-name symbols pre-interned in analyze so they land in the symbol table before the codegen prologue is emitted -- a separate change.)

make test: 166 pass / 5 fail / 673 error (unchanged; additive), no regressions.

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

Details

Commit
f09c6f97a644
Parent
2317220e354e

src/analyze.cmodifiedView file

@@ -172,6 +172,12 @@
172172 (!strcmp(name, "call") || !strcmp(name, "()") || !strcmp(name, "[]")))
173173 return proc_call_ret(c, recv);
174174
175+ /* Proc introspection */
176+ if (recv >= 0 && rt == TY_PROC && argc == 0) {
177+ if (!strcmp(name, "arity")) return TY_INT;
178+ if (!strcmp(name, "lambda?")) return TY_BOOL;
179+ }
180+
175181 /* identity methods: return the receiver unchanged */
176182 if (recv >= 0 && argc == 0 &&
177183 (!strcmp(name, "freeze") || !strcmp(name, "itself") ||