Files
l-language/include/l_lang.h
T
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

54 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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>";
}
}
// === 源码位置(替代分散的 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