Files
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

28 lines
660 B
C

#ifndef TEST_UTILS_H
#define TEST_UTILS_H
#include <stdio.h>
#include <stdlib.h>
static int _tests_run = 0;
static int _tests_failed = 0;
#define ASSERT(expr) do { \
_tests_run++; \
if (!(expr)) { \
fprintf(stderr, "\033[1;31mFAIL\033[0m %s:%d: %s\n", __FILE__, __LINE__, #expr); \
_tests_failed++; \
} \
} while(0)
#define TEST_RUN(func) do { \
fprintf(stderr, " RUN %s\n", #func); \
func(); \
} while(0)
static inline int test_summary(void) {
fprintf(stderr, "\n%d tests, %d passed, %d failed\n",
_tests_run, _tests_run - _tests_failed, _tests_failed);
return _tests_failed > 0 ? 1 : 0;
}
#endif