Serendipity
|
0a0667776a
|
feat: const 编译期常量 — const N = 42;
Token(77): +TOK_CONST, AST_LET_STMT 新增 is_const, Symbol 新增 const_value
sema: 字面量初始化自动折叠为编译期常量值
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-07 14:26:59 +08:00 |
|
Serendipity
|
443b22bdf1
|
feat: 列表推导式 [for x in arr: expr] — parser+sema+codegen
AST(29): +AST_LIST_COMP, parser 解析 [for var in expr: body]
sema: 创建子作用域注册循环变量, codegen: for 循环绑定+填充结果数组
已知限制: 仅支持 2 元素及以下数组 (大数组 alloca 对齐问题待修)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-07 13:58:54 +08:00 |
|
Serendipity
|
0088347576
|
feat: defer 延迟执行 — defer { stmts; } 在 return 前按 LIFO 执行
Token(73): +TOK_DEFER, AST(28): +AST_DEFER_STMT, 新增 38_defer.l
parser: defer { ... } 块 + defer expr; 表达式两种形式
codegen: defer 栈压入 block, emit_deferred() 在 return 前 LIFO 发射
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-07 13:51:10 +08:00 |
|
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 |
|
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
|
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
|
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
|
031dedfb8e
|
refactor: 拆分 sema analyze_expr 为 9 个辅助函数 + 调度器
|
2026-06-06 01:36:37 +08:00 |
|
Serendipity
|
6b6925b2b8
|
feat: 命名参数 draw_rect(width: 10, height: 20)
|
2026-06-05 20:54:58 +08:00 |
|
Serendipity
|
18172ca724
|
feat: 新增 i32 / u64 / char 类型 + 字符字面量 "'a'"
|
2026-06-05 20:47:44 +08:00 |
|
Serendipity
|
ab4cc9a28b
|
feat: let mut 改为 var 关键字声明可变变量
|
2026-06-05 19:47:00 +08:00 |
|
Serendipity
|
a45f7d8e2f
|
feat: 数组支持 struct 元素类型 [Point; N]
|
2026-06-05 19:38:48 +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
|
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
|
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
|
9a53d97274
|
feat: 字符串类型 + 字面量 + print_str
- 新增 TYPE_STR 类型 (i8* 指针)
- lexer: 双引号字符串字面量 + str 关键字
- parser: TOK_STR_LIT → AST_LITERAL_EXPR(str_val)
- sema: print_str 内置函数注册 + 字符串拼接类型检查
- codegen: GlobalStringPtr 生成字符串常量,print_str → printf("%s")
- 新增集成测试 07_hello_str.l
基于 Codex 分析报告 P0 建议。
|
2026-06-05 00:47:53 +08:00 |
|
Serendipity
|
bd02a4989e
|
feat: let mut + 赋值语句 — while 循环可修改变量
- lexer: 新增 TOK_MUT 关键字
- ast: AST_ASSIGN_STMT 节点 + let_stmt.is_mut 标志
- parser: ‘let mut’ 前缀识别 + ‘ident = expr;’ 赋值语句
- sema: Symbol.is_mut 可变性检查(不可变变量赋值报错)
- codegen: AST_ASSIGN_STMT → store 指令
- 新增集成测试 06_mut_while.l(while 循环 + 计数器)
基于 Codex 分析报告 P0 建议。
|
2026-06-05 00:42:50 +08:00 |
|
Serendipity
|
3b7bab1e1b
|
feat: L Language v0.1 编译器完整实现
5 阶段编译流水线: 词法分析 → 语法分析(Pratt) → 语义分析(类型推断) → LLVM IR → .exe
模块:
- lexer: 手写状态机, 40 种 Token, // 和 /* */ 注释
- parser: Pratt 表达式解析(9 级优先级) + 递归下降语句/函数
- ast: 14 种节点类型 + 工厂函数
- sema: 作用域链符号表 + 类型推断 + 类型检查
- codegen: AST → LLVM-C API, print_i64/f64/bool 内建
- driver: 命令行 + 流水线串联 + 错误报告
- util: Arena bump allocator (8MB)
测试: 65 单元测试(词法41+语法15+语义9) + 5 集成测试 全部通过
语言特性: i64/f64/bool/void, let不可变变量, if/else, while, 递归函数
|
2026-06-05 00:26:59 +08:00 |
|