b390d390f3
- 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 功能已全部完成。
43 lines
1.0 KiB
C
43 lines
1.0 KiB
C
#ifndef L_LANG_H
|
||
#define L_LANG_H
|
||
|
||
#include <stddef.h>
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
|
||
// === 类型系统 ===
|
||
typedef enum {
|
||
TYPE_I64,
|
||
TYPE_F64,
|
||
TYPE_BOOL,
|
||
TYPE_STR,
|
||
TYPE_VOID,
|
||
TYPE_STRUCT, // 结构体类型
|
||
TYPE_UNKNOWN, // 尚未推断
|
||
TYPE_ERROR, // 类型错误
|
||
} TypeKind;
|
||
|
||
static inline const char* type_name(TypeKind kind) {
|
||
switch (kind) {
|
||
case TYPE_I64: return "i64";
|
||
case TYPE_F64: return "f64";
|
||
case TYPE_BOOL: return "bool";
|
||
case TYPE_STR: return "str";
|
||
case TYPE_VOID: return "void";
|
||
case TYPE_STRUCT: return "struct";
|
||
default: return "<unknown>";
|
||
}
|
||
}
|
||
|
||
// === 向前声明 ===
|
||
typedef struct Token Token;
|
||
typedef struct AstNode AstNode;
|
||
typedef struct Scope Scope;
|
||
typedef struct Arena Arena;
|
||
|
||
// === 跨模块分配器接口(避免循环依赖,各模块通过 void* 使用 arena)===
|
||
void* arena_alloc_impl(void* alloc, size_t size);
|
||
char* arena_strdup_impl(void* alloc, const char* src, size_t len);
|
||
|
||
#endif
|