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)
This commit is contained in:
+22
-1
@@ -6,6 +6,8 @@
|
||||
AstNode* n = (AstNode*)arena_alloc_impl(alloc, sizeof(AstNode)); \
|
||||
if (!n) return NULL; \
|
||||
n->kind = (k); n->type.kind = TYPE_UNKNOWN; n->type.struct_name = NULL; \
|
||||
n->type.element_type = 0; n->type.element_struct_name = NULL; \
|
||||
n->type.array_size = 0; \
|
||||
n->loc = loc
|
||||
|
||||
AstNode* ast_make_program(void* alloc, AstNode** fns, size_t fn_count,
|
||||
@@ -49,12 +51,16 @@ AstNode* ast_make_block(void* alloc, AstNode** stmts, size_t count, SourceLoc lo
|
||||
}
|
||||
|
||||
AstNode* ast_make_let(void* alloc, const char* name, TypeKind annot_type, bool has_type_annot,
|
||||
bool is_mut, AstNode* init, const char* struct_type_name, SourceLoc loc) {
|
||||
bool is_mut, AstNode* init, const char* struct_type_name,
|
||||
TypeKind annot_elem_type, const char* annot_elem_struct, int64_t annot_array_size, SourceLoc loc) {
|
||||
NEW(alloc, AST_LET_STMT);
|
||||
n->as.let_stmt.name = name; n->as.let_stmt.annot_type = annot_type;
|
||||
n->as.let_stmt.has_type_annot = has_type_annot; n->as.let_stmt.is_mut = is_mut;
|
||||
n->as.let_stmt.init = init;
|
||||
n->as.let_stmt.struct_type_name = struct_type_name;
|
||||
n->as.let_stmt.annot_element_type = annot_elem_type;
|
||||
n->as.let_stmt.annot_element_struct_name = annot_elem_struct;
|
||||
n->as.let_stmt.annot_array_size = annot_array_size;
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -200,3 +206,18 @@ AstNode* ast_make_enum_variant(void* alloc, const char* enum_name,
|
||||
n->as.enum_variant.variant_index = -1;
|
||||
return n;
|
||||
}
|
||||
|
||||
AstNode* ast_make_index_expr(void* alloc, AstNode* array, AstNode* index, SourceLoc loc) {
|
||||
NEW(alloc, AST_INDEX_EXPR);
|
||||
n->as.index_expr.array = array;
|
||||
n->as.index_expr.index = index;
|
||||
return n;
|
||||
}
|
||||
|
||||
AstNode* ast_make_array_assign(void* alloc, const char* name, AstNode* index, AstNode* value, SourceLoc loc) {
|
||||
NEW(alloc, AST_ARRAY_ASSIGN_STMT);
|
||||
n->as.array_assign.name = name;
|
||||
n->as.array_assign.index = index;
|
||||
n->as.array_assign.value = value;
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user