Commit 97b6b8ac
97b6b8acb437Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 5 files · +1 added · ~4 modified
Description
refactor: introduce methods.c as single source of truth for built-in methods
Move built-in method definitions to a table-driven system in methods.c. Each type (Integer, Float, String, Array, Hash, etc.) has a static table of {name, return_type, min_argc, max_argc, needs_block} entries.
Three lookup functions serve all consumers:
- builtin_find_method() → full method descriptor
- builtin_has_method() → respond_to? resolution
- builtin_return_type() → type inference
This replaces:
- 273 lines of if-else chains in type.c (deleted)
- 76 lines of method lists in codegen.c (deleted)
Adding a new method now requires:
- One table entry in methods.c (type inference + respond_to? automatic)
- Code generation handler in expr.c (unchanged) Previously required editing 3 files with manual synchronization.
60/60 tests, 39/39 benchmarks pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 97b6b8acb437
- Parent
- 4290be439110
MakefilemodifiedView file
@@ -18,7 +18,7 @@
1818
PRISM_CFLAGS = -I$(PRISM_DIR)/include1919
2020
# Sources21-
SRCS = src/main.c src/codegen.c src/type.c src/expr.c src/stmt.c src/emit.c21+
SRCS = src/main.c src/codegen.c src/type.c src/expr.c src/stmt.c src/emit.c src/methods.c2222
OBJS = $(SRCS:.c=.o)2323
2424
# Default targetsrc/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…
src/methods.caddedView file
Loading diff…
src/type.cmodifiedView file
Loading diff…