2923e7574d
- 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)
58 lines
1.4 KiB
C
58 lines
1.4 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_ENUM, // 枚举类型
|
||
TYPE_ARRAY, // 固定大小数组类型
|
||
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";
|
||
case TYPE_ENUM: return "enum";
|
||
case TYPE_ARRAY: return "array";
|
||
default: return "<unknown>";
|
||
}
|
||
}
|
||
|
||
// === 源码位置(替代分散的 line/col 参数)===
|
||
typedef struct {
|
||
int line;
|
||
int col;
|
||
} SourceLoc;
|
||
|
||
// 手动创建 SourceLoc
|
||
static inline SourceLoc loc_at(int line, int col) {
|
||
return (SourceLoc){ .line = line, .col = col };
|
||
}
|
||
|
||
// === 向前声明 ===
|
||
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
|