Commit Graph

59 Commits

Author SHA1 Message Date
Serendipity 66b170a27f docs: CLAUDE.md 反映 desugar pass + 文件行数更新
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 20:20:50 +08:00
Serendipity eaae0b1c62 refactor: 独立 desugar pass — match/guard/for/if-let/复合赋值去糖提取
5 种去糖逻辑从 parser.c/expr.c 内联代码提取到 desugar.c:
  desugar_match() — match → let + if-else 链
  desugar_guard() — guard → if !(cond)
  desugar_for()  — for-in-to → var + while
  desugar_if_let() — if let → let + if
  desugar_compound_assign() — +=/-= → assign + binary

parser.c 662→564 行, 新增 desugar.c 109 行, 管道+插值保留在 expr.c

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 20:20:33 +08:00
Serendipity f3cca30cca docs: CLAUDE.md 数据同步 — 197单元+36集成,架构图反映文件拆分
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 20:16:51 +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
Serendipity 90d081c3fd fix: P0审查修复 P2补强 — parser.c 拆分 + 测试扩充
P0-③: parser.c 1211行 → parser.c 662行 + expr.c 498行 + parse_internal.h 71行
  - expr.c: 表达式解析 (Pratt主循环/字面量/标识符/类型/运算符)
  - parser.c: 语句/声明/程序入口 (block/match/let/if/while/for/guard/fn/parse)
  - parse_internal.h: 共享 Parser struct + 内联辅助 + 向前声明

P2-①: parser 测试 5函数→20函数, 15断言→54断言
  - 新增: struct声明、字面量类型、优先级链、guard去糖、命名参数
  - 新增: 字段访问、方法调用、match、enum声明、for去糖、管道
  - 新增: 类型别名、trait声明、数组类型、if表达式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 18:57:07 +08:00
Serendipity 466be76fd8 fix: P1审查修复 — error.c arena化 + Self类型解析 + trait查找加固 + 缓冲区安全
P1-①: error_init/add 从 malloc/realloc/strdup 改为 arena_alloc/arena_strdup
P1-②: impl 方法中 Self 类型在 sema 解析为实际结构体名
P1-③: trait 方法 fallback 增加前缀校验(strncmp),method_name 统一更新
P1-④: codegen args[16] 增加溢出检查,移除 parser 未使用的 mods/uses 数组
新增: 36_self_type.l 集成测试(Self 类型 + trait 方法)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 17:09:28 +08:00
Serendipity 17c19fd9b9 fix: P0审查修复 — CLAUDE.md数据更新 + load_module malloc→arena 2026-06-06 16:54:23 +08:00
Serendipity b3b3d285f9 feat: trait 接口系统 — trait Show { fn method } + extend Trait Struct { } 2026-06-06 16:41:21 +08:00
Serendipity 9169796b77 feat: 泛型单态化完成 — fn id<T>(x: T) -> T 全流水线通过 2026-06-06 16:25:18 +08:00
Serendipity 350eeef3c5 feat: 泛型基础设施 — <T>解析 + 类型推断 (单态化 codegen 待补) 2026-06-06 16:17:15 +08:00
Serendipity fa734b8a23 feat: 模块系统 mod + pub — 多文件编译支持 2026-06-06 16:09:30 +08:00
Serendipity e02cc7b1d6 feat: if let 语句 — if let Option::Some = expr { ... } 2026-06-06 15:20:34 +08:00
Serendipity 0e1f8c5795 feat: 枚举关联数据 ADT — enum Option { Some(i64), None } 2026-06-06 14:21:43 +08:00
Serendipity 0ec3c3d65f feat: 表达式作为值 — if/else 和 block 可产生值 2026-06-06 13:52:36 +08:00
Serendipity 380b52930a docs: Token 计数修正 50→67 (AGENTS.md + CLAUDE.md) 2026-06-06 13:33:39 +08:00
Serendipity 031dedfb8e refactor: 拆分 sema analyze_expr 为 9 个辅助函数 + 调度器 2026-06-06 01:36:37 +08:00
Serendipity de91886712 fix: CreateProcess 替代 system() 调 ld.lld,消除 shell 转义问题 v0.6.0 2026-06-05 22:07:53 +08:00
Serendipity 39d8bad022 feat: 自包含安装包 — ld.lld + MinGW 库 (39MB, 零依赖) 2026-06-05 22:01:01 +08:00
Serendipity 1e161ecfff feat: NSIS 安装包脚本 (62MB, 含 LLVM+clang+lld) 2026-06-05 21:51:22 +08:00
Serendipity 143174ee4f refactor: 链接器从 gcc 改为 clang + lld(优先 clang→fallback gcc) 2026-06-05 21:43:48 +08:00
Serendipity 2baf762d82 docs: README/CHANGELOG/语言参考更新至 v0.6 2026-06-05 21:02:05 +08:00
Serendipity 459d1e1e10 feat: 管道 |> + 字符串插值 \(expr) — P0 四特性收官 2026-06-05 20:59:00 +08:00
Serendipity 6b6925b2b8 feat: 命名参数 draw_rect(width: 10, height: 20) 2026-06-05 20:54:58 +08:00
Serendipity c6e492662e feat: guard 语句 guard x >= 0 else { return -1; } 2026-06-05 20:49:03 +08:00
Serendipity 18172ca724 feat: 新增 i32 / u64 / char 类型 + 字符字面量 "'a'" 2026-06-05 20:47:44 +08:00
Serendipity 6fc599e6c2 feat: impl 关键字改为 extend 2026-06-05 19:50:40 +08:00
Serendipity 175f8a6658 feat: 数组类型语法 [T; N] 改为 T[N] 后置语法 2026-06-05 19:48:56 +08:00
Serendipity ab4cc9a28b feat: let mut 改为 var 关键字声明可变变量 2026-06-05 19:47:00 +08:00
Serendipity a28d33854c feat: for..in 范围语法 .. 改为 to 关键字 2026-06-05 19:44:26 +08:00
Serendipity 9a256d9be1 docs: 测试计数更新 145→158 单元 + 23→24 集成 2026-06-05 19:39:12 +08:00
Serendipity a45f7d8e2f feat: 数组支持 struct 元素类型 [Point; N] 2026-06-05 19:38:48 +08:00
Serendipity beac40fd74 test: match sema + codegen 单元测试,总断言 145→158 2026-06-05 19:36:26 +08:00
Serendipity a0a78de26e docs: 补充数组初始化 = arr 语法说明 2026-06-05 19:31:46 +08:00
Serendipity 095604dc9f docs: CLAUDE.md 语言设计哲学增加L化适配原则 2026-06-05 19:07:54 +08:00
Serendipity 6bd6eaae47 docs: CLAUDE.md 语言设计哲学 + 多语言特性分析
- 去糖优先: 复杂语法在parser层降级
- 博采众长: Elixir/Swift/Python/Go/Kotlin/Zig 候选特性
- P0-P3 优先级矩阵: 管道/guard/插值/命名参数优先
2026-06-05 18:59:02 +08:00
Serendipity 29648ef110 docs: L Language 语言参考手册 (language-reference.md)
- 14 章完整教程: 类型/变量/运算符/控制流/函数/struct/enum/数组/impl/match
- 3 个完整示例: 斐波那契/学生成绩/数组操作
- 快速参考卡片
- README 添加手册链接
2026-06-05 18:45:58 +08:00
Serendipity 5a0bf60698 docs: CHANGELOG v0.4/v0.5 + README/CLAUDE 版本刷新
- CHANGELOG: 新增 v0.4.0 (struct+RAII) 和 v0.5.0 (alias+enum+array+impl+match)
- README: 版本0.5.0, 测试145, 完整功能列表+运算符表
- CLAUDE: v0.5 已知限制更新
2026-06-05 18:42:24 +08:00
Serendipity a15cd9d56e feat: match 表达式 (P1 #8 收官)
- lexer: TOK_MATCH, TOK_MATCH_ARROW, TOK_UNDERSCORE
- parser: parse_match_stmt() desugar → let+if-else链
- 零 sema/codegen 改动
- 4个集成测试: enum/int literal/wildcard match

P1 全部完成: type alias + enum + array + impl + match
2026-06-05 14:41:52 +08:00
Serendipity 9f6e695ba8 feat: struct方法 impl (P1 #9)
- lexer: TOK_IMPL 关键字
- ast: AST_IMPL_BLOCK, AST_METHOD_CALL + AST_PROGRAM impls数组
- parser: impl StructName { fn ... } + p.method() 方法调用
- sema: 方法名mangle(StructName$method), self参数, 类型检查
- codegen: METHOD_CALL→mangled函数调用(recv为第一参数)
- 新增集成测试: 19_struct_method.l

P1 4项全部完成: type alias + enum + array + impl
测试: 145 通过 (41+15+65+24)
2026-06-05 14:30:24 +08:00
Serendipity 2923e7574d feat: 数组+索引 [T;N], arr[i] (P1 #6)
- lexer: TOK_LBRACKET, TOK_RBRACKET
- type: TYPE_ARRAY + TypeInfo扩展(element_type/array_size)
- ast: AST_INDEX_EXPR, AST_ARRAY_ASSIGN_STMT
- parser: parse_type_expr()支持[T;N], Pratt加[索引], 数组元素赋值
- sema: 数组类型检查, 索引必须i64, 元素赋值类型匹配
- codegen: type_info_to_llvm(TYPE_ARRAY), GEP+load/store
- 新增集成测试: 18_array.l

测试: 136 通过 (41+15+59+21)
2026-06-05 14:19:01 +08:00
Serendipity 5237398245 feat: 枚举 enum (P1 #7)
- lexer: TOK_ENUM, TOK_COLON_COLON
- ast: AST_ENUM_DECL, AST_ENUM_VARIANT + AST_PROGRAM enums数组
- parser: enum Name { A, B } + Enum::Variant语法
- sema: SYM_ENUM, 变体验证, enum→i64类型兼容
- codegen: TYPE_ENUM→i64, 变体→ConstInt(索引值)
- 新增集成测试: 17_enum.l

测试: 121 通过 (41+15+47+18)
2026-06-05 14:01:47 +08:00
Serendipity ab88ea2753 feat: 类型别名 type alias (P1 #10)
- lexer: TOK_TYPE 关键字
- ast: AST_TYPE_ALIAS + AST_PROGRAM aliases数组
- parser: parse_type_expr() 抽取, type Name = Type; 解析
- sema: 别名注册+解析, 类型标注/struct字段/函数参数均支持
- 新增测试: 15_type_alias.l, 16_type_alias_struct.l

测试: 112 通过 (41+15+41+15)
2026-06-05 13:54:58 +08:00
Serendipity da9a7065dd feat: struct参数/返回值 + SourceLoc + 测试补全
- struct 可作函数参数和返回值 (fn make_point -> Point)
- SourceLoc 抽象: 所有 ast_make_* 参数 + AstNode 迁移完毕
- sema: +4 struct 类型检查测试 (字段类型/未定义/数量/嵌套)
- codegen: +2 struct IR 生成测试 (decl + field_access)
- 新增集成测试 14_struct_fn.l

测试: 104 单元 + 14 集成 = 全部通过
2026-06-05 13:29:31 +08:00
Serendipity 4046ab1875 refactor: tok_is_type 统一 + 架构改进文档
- parser.c: 删除重复的is_type_token, 统一使用token.c的tok_is_type
- docs/architecture-improvements.md: TypeKind解耦/Visitor/SourceLoc/去糖方案
2026-06-05 13:13:51 +08:00
Serendipity a7fca5964e fix: 5项立即修复 + 2项尽快修复
立即:
- lexer: token数组容量改为src_len+16 + idx越界防御
- symbol: 4个函数arena_alloc加NULL检查
- codegen: verify_err fallback用arena_strdup替代静态字符串
- codegen: cleanup_list从固定64改为arena动态扩容
- lexer: 标识符/字符串字面量65535字符上限

尽快:
- to_llvm_type: TYPE_STRUCT/TYPE_UNKNOWN/TYPE_ERROR显式case
- LLVMGetValueType2不存在(LLVM 22仍用旧名), 保留GlobalGetValueType
2026-06-05 13:12:00 +08:00
Serendipity af0725caca fix: 全面代码审查 — 修复 3 CRITICAL + 4 HIGH 问题
CRITICAL:
- parser: 6处栈数组加边界检查 (struct_init/decl/block/params/functions/structs)
- codegen: return前跳过返回值alloca防止use-after-free
- ast: NEW宏加NULL检查防止arena耗尽崩溃

HIGH:
- main: shell元字符过滤防命令注入
- codegen: LLVMContext泄漏修复 (out_context参数)
- codegen: f64隐式return用LLVMConstReal替代LLVMConstInt
- sema: 返回类型与函数声明校验

其他:
- parser/codegen: 递归深度限制1000层
- codegen: struct值类型不追踪cleanup (栈上数据不能free)

基于三份审查报告 (架构/code quality/安全) 修复。
2026-06-05 13:05:27 +08:00
Serendipity 1d4fb27170 feat: 自动内存管理 — 作用域级 RAII for str
- codegen: 声明 CRT free(), cleanup_add/cleanup_emit 辅助函数
- LET_STMT: str 拼接/struct 初始化 → 追踪到 cleanup_list
- BLOCK: 作用域退出时自动 emit free() 释放 str 堆分配
- RETURN: return 前先释放当前作用域所有 str 分配
- 函数隐式 return: 退出前 cleanup_emit
- str 字面量不追踪(全局常量,free 会崩溃)

内存模型(类 Rust):
  let s = "a" + "b"  → malloc 分配 → 作用域退出 → free
  let s = "literal"  → 全局常量 → 不追踪 → 不 free
  let mut s = ...    → 重新赋值时旧值需手动管理(v0.5 扩展)

消除报告 §5-1 str concat malloc 内存泄漏。
2026-06-05 12:43:00 +08:00
Serendipity b390d390f3 feat: 结构体 struct — 最后一项 P0 功能
- lexer: TOK_STRUCT, TOK_DOT 关键字和运算符
- ast: AST_STRUCT_DECL/STRUCT_INIT/FIELD_ACCESS 3 种新节点
- parser: struct 声明 + .field 访问 + Name{field:val} 初始化
- sema: struct 类型符号表,字段类型解析,初始化字段检查
- codegen: LLVMStructType + extractvalue/insertvalue 字段操作
- 新增集成测试: 12_struct.l, 13_struct_nested.l
- 基于 Codex 分析报告 P0 #4

所有 P0 功能已全部完成。
2026-06-05 12:21:22 +08:00
Serendipity 620cec4d57 docs: CHANGELOG 更新 v0.3 — for循环 + 测试补全 2026-06-05 08:33:40 +08:00
Serendipity 382cd089d0 test: sema + codegen 测试补全 — 86 单元测试
- test_sema: +4 测试 (let_mut_assign_ok, assign_immutable_error, str_type_ok, str_concat_ok) → 21 tests
- test_codegen: +1 测试 (while_loop LLVMVerifyModule) → 9 tests
- 总单元测试: 86 (词法41+语法15+语义21+代码生成9)
- 基于 Codex 分析报告 §5-3 §5-4 技术债务补偿
2026-06-05 06:34:45 +08:00