Serendipity
|
6ebe551ee3
|
fix: AST_PARAMETER 增加数组元素类型字段 + 五子棋集成测试
问题: 函数参数声明 i64[N] 只在 TypeInfo 存储数组信息, AST_PARAMETER
仅存 TypeKind(TYPE_ARRAY), 丢失元素类型和大小, 导致 sema 将参数
数组误判为 i32[N], codegen 生成 void GEP 而崩溃。
修复:
- AST_PARAMETER 新增 arr_elem_type/arr_elem_struct/arr_size 字段
- parser 传入 parse_type_expr 的完整数组信息
- sema 将数组信息从 AST 节点复制到 Symbol
- codegen 为数组参数生成正确的 LLVMArrayType
附加: 45_gomoku.l — 5x5 五子棋双AI对弈, 测试数组/函数/循环/字符串
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-07 18:48:04 +08:00 |
|
Serendipity
|
c8da286d31
|
feat: in/out 参数 — out 关键字引用传递
fn swap(out x: i64, out y: i64) 声明 out 参数,codegen 层面
函数签名变为 T* 指针,调用点自动传 &variable 地址。
in 是默认行为(值传递),无需显式标注。
Token → Parser → Sema → Codegen 全流水线:
- TOK_OUT + "out" 关键字注册
- AST parameter.is_out 字段
- parse_function 解析 out 前缀
- Sema: out 参数注册为 SYM_VARIABLE+is_mut(可赋值)
- Codegen: LLVM 函数签名使用 T*,调用点传 alloca
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-07 14:45:38 +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
|
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
|
0e1f8c5795
|
feat: 枚举关联数据 ADT — enum Option { Some(i64), None }
|
2026-06-06 14:21:43 +08:00 |
|
Serendipity
|
6b6925b2b8
|
feat: 命名参数 draw_rect(width: 10, height: 20)
|
2026-06-05 20:54:58 +08:00 |
|
Serendipity
|
175f8a6658
|
feat: 数组类型语法 [T; N] 改为 T[N] 后置语法
|
2026-06-05 19:48:56 +08:00 |
|
Serendipity
|
beac40fd74
|
test: match sema + codegen 单元测试,总断言 145→158
|
2026-06-05 19:36:26 +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
|
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
|
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
|
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 |
|
Serendipity
|
72a971e5bf
|
test: 新增 codegen 层单元测试 (7 tests)
- test_codegen.c: 构造 AST → codegen_module → LLVMVerifyModule
- 覆盖: 函数+返回字面量, if/else 分支, 二元运算(1+2*3)
- 总单元测试: 41+15+9+7 = 72
- 基于 Codex 分析报告 §5-4 技术债务补偿
|
2026-06-05 02:40:58 +08:00 |
|