Commit Graph

4 Commits

Author SHA1 Message Date
Serendipity c285a145c8 refactor: typeck.c 652→559 — 泛型单态化提取为 mono.c (97行) 2026-06-07 13:00:10 +08:00
Serendipity b34ad17aad refactor: AST Visitor dispatch — sema analyze_expr switch→vtable
新增 src/ast/visit.h/c: AstDispatch 函数指针表 + ast_visit() 统一入口
analyze_expr 的 switch 替换为 dispatch 表, 10 个 handler 通过 SEMA_HANDLER 宏注册
新增 AST 节点: 在 analyze_expr_init() 加一行即可, 编译器会检查函数签名

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 20:36:13 +08:00
Serendipity 3733b41453 refactor: TypeTable 数据驱动 — promote/convert/numeric/comparable 统一查表
新增 src/sema/type_table.h/c: TypeDesc{promote_rank, bit_width, is_signed, is_numeric}
promote/can_implicit_convert/is_numeric/is_comparable 从硬编码 switch 改为查表
新增类型只需在 TABLE[] 加一行, 从 7+ 文件改为 3-4 文件 (token + table + codegen)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 20:31:32 +08:00
Serendipity 6d1db585c4 refactor: sema.c + codegen.c 拆分,全部源文件 <800 行
sema.c 1129行 → sema.c 499行 + typeck.c 629行 + sema_internal.h 51行
  - typeck.c: 表达式类型检查 (10个analyze_*函数) + 泛型单态化 + 类型关系
  - sema.c: analyze_node + sema_analyze

codegen.c 947行 → codegen.c 453行 + cg_expr.c 440行 + codegen_internal.h 83行
  - cg_expr.c: LLVM表达式生成 + 类型映射 (to_llvm_type/coerce_int/type_info_to_llvm)
  - codegen.c: 语句生成 + 模块入口 + 符号表 + 内存清理

全部核心源文件 <800 行限制: parser(662+498), sema(499+629), codegen(453+440)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 19:26:54 +08:00