Commit fad1746d

fad1746d64caMerged

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

Description

feat: add argument type information to built-in method tables

Extend builtin_method_def_t with arg_types[MAX_METHOD_ARGS] field. Add MA1/MA2 macros for specifying 1-2 argument types in tables.

Argument types now defined for key methods: Integer: arithmetic (+,-,*,/,%,**), gcd, lcm, pow, clamp String: include?, start_with?, end_with?, count, index, rindex, +, *, <<, concat, gsub, sub, tr Array: push, <<, unshift, insert, delete, delete_at Hash: [], []=, store, fetch, delete

Add builtin_arg_type() lookup function for use by future type checking and reverse type inference.

60/60 tests, 39/39 benchmarks pass.

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

Details

Commit
fad1746d64ca
Parent
97b6b8acb437

src/codegen.hmodifiedView file

@@ -385,17 +385,20 @@
385385 func_info_t *find_func(codegen_ctx_t *ctx, const char *name);
386386
387387 /* --- Built-in method table (methods.c) --- */
388+#define MAX_METHOD_ARGS 4
388389 typedef struct {
389390 const char *name;
390391 spinel_type_t return_type;
391392 int min_argc; /* minimum required args (-1 = don't care) */
392393 int max_argc; /* maximum args (-1 = variadic) */
393394 bool needs_block; /* true if method requires a block */
395+ spinel_type_t arg_types[MAX_METHOD_ARGS]; /* expected arg types (0=any) */
394396 } builtin_method_def_t;
395397
396398 const builtin_method_def_t *builtin_find_method(spinel_type_t kind, const char *name);
397399 bool builtin_has_method(spinel_type_t kind, const char *name);
398400 spinel_type_t builtin_return_type(spinel_type_t recv_kind, const char *name);
401+spinel_type_t builtin_arg_type(spinel_type_t recv_kind, const char *name, int arg_idx);
399402
400403 /* --- Extension method lookup (codegen.c) --- */
401404 method_info_t *find_ext_method(codegen_ctx_t *ctx, spinel_type_t recv_type, const char *name);