Commit 224db21e
224db21e47fbMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 3 files · +1 added · ~2 modified
Description
refactor: extract runtime into lib/sp_runtime.h
Move all runtime code (GC, arrays, hash, strings, regexp helpers, fiber, lambda, proc, mutable string, StringIO, setjmp, file I/O) from emit_raw() calls in spinel_codegen.rb to lib/sp_runtime.h.
Generated C now starts with #include "sp_runtime.h" instead of embedding ~400 lines of runtime inline. Only program-specific regexp patterns remain in codegen output.
Removes ~120 lines of conditional emit logic from generate_code. All 65 tests and 52 benchmarks pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 224db21e47fb
- Parent
- bdcfb33d1abd
MakefilemodifiedView file
@@ -73,10 +73,10 @@
7373
./spinel_parse spinel_codegen.rb build/codegen.ast7474
@echo "=== Bootstrap Step 2: gen1 (CRuby) ==="7575
ruby spinel_codegen.rb build/codegen.ast build/gen1.c76-
$(CC) $(CFLAGS) build/gen1.c -lm -o build/bin176+
$(CC) $(CFLAGS) -Ilib build/gen1.c -lm -o build/bin17777
@echo "=== Bootstrap Step 3: gen2 (bin1) ==="7878
./build/bin1 build/codegen.ast build/gen2.c79-
$(CC) $(CFLAGS) build/gen2.c -lm -o build/bin279+
$(CC) $(CFLAGS) -Ilib build/gen2.c -lm -o build/bin28080
@echo "=== Bootstrap Step 4: gen3 (bin2) - verify ==="8181
./build/bin2 build/codegen.ast build/gen3.c8282
@diff build/gen2.c build/gen3.c > /dev/null && echo "gen2.c == gen3.c (bootstrap OK)" || (echo "BOOTSTRAP FAILED: gen2.c != gen3.c" && exit 1)@@ -91,7 +91,7 @@
9191
bn=$$(basename "$$f" .rb); \9292
./spinel_parse "$$f" /tmp/_sp_t.ast 2>/dev/null && \9393
./spinel_codegen /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \94-
$(CC) $(CFLAGS) /tmp/_sp_t.c $(SP_RT_LIB) -lm -o /tmp/_sp_t_bin 2>/dev/null; \94+
$(CC) $(CFLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) -lm -o /tmp/_sp_t_bin 2>/dev/null; \9595
if [ $$? -eq 0 ]; then \9696
expected=$$(timeout 10 ruby "$$f" 2>/dev/null); \9797
actual=$$(timeout 10 /tmp/_sp_t_bin 2>/dev/null); \@@ -114,7 +114,7 @@
114114
bn=$$(basename "$$f" .rb); \115115
timeout 10 ./spinel_parse "$$f" /tmp/_sp_b.ast 2>/dev/null && \116116
timeout 10 ./spinel_codegen /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \117-
$(CC) $(CFLAGS) /tmp/_sp_b.c $(SP_RT_LIB) -lm -o /tmp/_sp_b_bin 2>/dev/null; \117+
$(CC) $(CFLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) -lm -o /tmp/_sp_b_bin 2>/dev/null; \118118
if [ $$? -eq 0 ]; then \119119
expected=$$(timeout 60 ruby "$$f" 2>/dev/null); \120120
ruby_rc=$$?; \lib/sp_runtime.haddedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…