Commit b764f192

b764f192c6f8Merged

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

Description

Split the 19k-line code generator into six stage files

codegen.c had grown to 19.4k lines / 240 functions. It is now split by emission stage, sharing the former file-statics through codegen_internal.h:

  • codegen_util.c buffers, escaping, C type names, regex registry, globals
  • codegen_fold.c enumerable fusion (emit_*_expr), arg filling, dispatch
  • codegen_call.c emit_call, array mutation, index writes, inlining, loops
  • codegen_expr.c interpolation + expression emission
  • codegen_stmt.c output calls, assignment, control flow, pattern match, rescue, the statement switches
  • codegen.c boxing, scope/method/class/proc/fiber emission, driver

Cross-file functions and globals lost their static linkage and are declared in the internal header; single-file helpers stay static. Two split hazards fixed in the process: static Buf *g_pre landing in the header gave every unit its own prelude buffer (state forked silently), and the one-line multi-declaration static ... g_re_src; static ... g_re_flg; ... left the regex-literal registry half per-unit, so the driver emitted no sp_re_pat_N definitions.

No behavior change: 845 pass / 0 fail / 0 error before and after.

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

Details

Commit
b764f192c6f8
Parent
22d92395b987

MakefilemodifiedView file

@@ -127,9 +127,11 @@
127127 # The binary emits C; the test harness invokes cc to link libspinel_rt.a.
128128
129129 SPINELC = build/spinelc$(EXE)
130-SPINELC_HDRS = src/node_table.h src/codegen.h src/types.h src/compiler.h src/analyze.h
130+SPINELC_HDRS = src/node_table.h src/codegen.h src/codegen_internal.h src/types.h src/compiler.h src/analyze.h
131131 SPINELC_OBJ = build/csrc/node_table.o build/csrc/types.o build/csrc/compiler.o \
132- build/csrc/analyze.o build/csrc/codegen.o build/csrc/main.o
132+ build/csrc/analyze.o build/csrc/codegen.o build/csrc/codegen_util.o \
133+ build/csrc/codegen_fold.o build/csrc/codegen_call.o \
134+ build/csrc/codegen_expr.o build/csrc/codegen_stmt.o build/csrc/main.o
133135
134136 build/csrc:
135137 @mkdir -p build/csrc