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
func_info_t *find_func(codegen_ctx_t *ctx, const char *name);/* --- Built-in method table (methods.c) --- */#define MAX_METHOD_ARGS 4typedef struct { const char *name; spinel_type_t return_type; int min_argc; /* minimum required args (-1 = don't care) */ int max_argc; /* maximum args (-1 = variadic) */ bool needs_block; /* true if method requires a block */ spinel_type_t arg_types[MAX_METHOD_ARGS]; /* expected arg types (0=any) */} builtin_method_def_t;const builtin_method_def_t *builtin_find_method(spinel_type_t kind, const char *name);bool builtin_has_method(spinel_type_t kind, const char *name);spinel_type_t builtin_return_type(spinel_type_t recv_kind, const char *name);spinel_type_t builtin_arg_type(spinel_type_t recv_kind, const char *name, int arg_idx);/* --- Extension method lookup (codegen.c) --- */method_info_t *find_ext_method(codegen_ctx_t *ctx, spinel_type_t recv_type, const char *name);src/methods.cmodifiedView file
Loading diff…