mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-12 14:21:25 -07:00
Change push allocator system; update core libraries
This commit is contained in:
+16
-8
@@ -5179,7 +5179,6 @@ bool ternary_compare_types(Type *x, Type *y) {
|
||||
return are_types_identical(x, y);
|
||||
}
|
||||
|
||||
|
||||
ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
|
||||
ExprKind kind = Expr_Stmt;
|
||||
|
||||
@@ -5550,16 +5549,17 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
}
|
||||
}
|
||||
|
||||
isize field_index = 0;
|
||||
bool seen_field_value = false;
|
||||
|
||||
for_array(index, cl->elems) {
|
||||
Entity *field = t->Struct.fields_in_src_order[field_index++];
|
||||
if (!all_fields_are_blank && is_blank_ident(field->token)) {
|
||||
// NOTE(bill): Ignore blank identifiers
|
||||
continue;
|
||||
}
|
||||
Entity *field = nullptr;
|
||||
AstNode *elem = cl->elems[index];
|
||||
if (elem->kind == AstNode_FieldValue) {
|
||||
error(elem, "Mixture of `field = value` and value elements in a literal is not allowed");
|
||||
seen_field_value = true;
|
||||
// error(elem, "Mixture of `field = value` and value elements in a literal is not allowed");
|
||||
// continue;
|
||||
} else if (seen_field_value) {
|
||||
error(elem, "Value elements cannot be used after a `field = value`");
|
||||
continue;
|
||||
}
|
||||
if (index >= field_count) {
|
||||
@@ -5567,6 +5567,14 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
break;
|
||||
}
|
||||
|
||||
if (field == nullptr) {
|
||||
field = t->Struct.fields_in_src_order[index];
|
||||
}
|
||||
if (!all_fields_are_blank && is_blank_ident(field->token)) {
|
||||
// NOTE(bill): Ignore blank identifiers
|
||||
continue;
|
||||
}
|
||||
|
||||
check_expr_with_type_hint(c, o, elem, field->type);
|
||||
|
||||
if (!check_is_field_exported(c, field)) {
|
||||
|
||||
+8
-12
@@ -170,9 +170,6 @@ bool check_is_terminating(AstNode *node) {
|
||||
return has_default;
|
||||
case_end;
|
||||
|
||||
case_ast_node(pa, PushAllocator, node);
|
||||
return check_is_terminating(pa->body);
|
||||
case_end;
|
||||
case_ast_node(pc, PushContext, node);
|
||||
return check_is_terminating(pc->body);
|
||||
case_end;
|
||||
@@ -697,7 +694,13 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
array_init(&rhs_operands, c->tmp_allocator, 2 * lhs_count);
|
||||
|
||||
for_array(i, as->lhs) {
|
||||
check_expr(c, &lhs_operands[i], as->lhs[i]);
|
||||
if (is_blank_ident(as->lhs[i])) {
|
||||
Operand *o = &lhs_operands[i];
|
||||
o->expr = as->lhs[i];
|
||||
o->mode = Addressing_Value;
|
||||
} else {
|
||||
check_expr(c, &lhs_operands[i], as->lhs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
check_unpack_arguments(c, nullptr, lhs_operands.count, &rhs_operands, as->rhs, true);
|
||||
@@ -1648,18 +1651,11 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
case_end;
|
||||
|
||||
|
||||
case_ast_node(pa, PushAllocator, node);
|
||||
Operand op = {};
|
||||
check_expr(c, &op, pa->expr);
|
||||
check_assignment(c, &op, t_allocator, str_lit("argument to push_allocator"));
|
||||
check_stmt(c, pa->body, mod_flags);
|
||||
case_end;
|
||||
|
||||
|
||||
case_ast_node(pa, PushContext, node);
|
||||
Operand op = {};
|
||||
check_expr(c, &op, pa->expr);
|
||||
check_assignment(c, &op, t_context, str_lit("argument to push_context"));
|
||||
check_assignment(c, &op, t_context, str_lit("argument to context <-"));
|
||||
check_stmt(c, pa->body, mod_flags);
|
||||
case_end;
|
||||
|
||||
|
||||
-26
@@ -7251,32 +7251,6 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
case_end;
|
||||
|
||||
|
||||
|
||||
case_ast_node(pa, PushAllocator, node);
|
||||
ir_emit_comment(proc, str_lit("push_allocator"));
|
||||
irValue *new_allocator = ir_build_expr(proc, pa->expr);
|
||||
|
||||
ir_open_scope(proc);
|
||||
|
||||
irValue *prev = ir_find_or_generate_context_ptr(proc);
|
||||
irValue *next = ir_add_local_generated(proc, t_context);
|
||||
ir_emit_store(proc, next, ir_emit_load(proc, prev));
|
||||
|
||||
Selection sel = lookup_field(proc->module->allocator, t_context, str_lit("allocator"), false);
|
||||
irValue *gep = ir_emit_deep_field_gep(proc, next, sel);
|
||||
ir_emit_store(proc, gep, new_allocator);
|
||||
|
||||
array_add(&proc->context_stack, next);
|
||||
defer (array_pop(&proc->context_stack));
|
||||
|
||||
// TODO(bill): is this too leaky?
|
||||
|
||||
ir_build_stmt(proc, pa->body);
|
||||
|
||||
ir_close_scope(proc, irDeferExit_Default, nullptr);
|
||||
case_end;
|
||||
|
||||
|
||||
case_ast_node(pc, PushContext, node);
|
||||
ir_emit_comment(proc, str_lit("push_context"));
|
||||
irValue *new_context = ir_build_expr(proc, pc->expr);
|
||||
|
||||
+20
-56
@@ -313,12 +313,7 @@ AST_NODE_KIND(_ComplexStmtBegin, "", i32) \
|
||||
AstNode *clobber_list; \
|
||||
isize output_count, input_count, clobber_count; \
|
||||
}) \
|
||||
AST_NODE_KIND(PushAllocator, "push_allocator statement", struct { \
|
||||
Token token; \
|
||||
AstNode *expr; \
|
||||
AstNode *body; \
|
||||
}) \
|
||||
AST_NODE_KIND(PushContext, "push_context statement", struct { \
|
||||
AST_NODE_KIND(PushContext, "context <- statement", struct { \
|
||||
Token token; \
|
||||
AstNode *expr; \
|
||||
AstNode *body; \
|
||||
@@ -596,7 +591,6 @@ Token ast_node_token(AstNode *node) {
|
||||
case AstNode_BranchStmt: return node->BranchStmt.token;
|
||||
case AstNode_UsingStmt: return node->UsingStmt.token;
|
||||
case AstNode_AsmStmt: return node->AsmStmt.token;
|
||||
case AstNode_PushAllocator: return node->PushAllocator.token;
|
||||
case AstNode_PushContext: return node->PushContext.token;
|
||||
|
||||
case AstNode_BadDecl: return node->BadDecl.begin;
|
||||
@@ -829,10 +823,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
|
||||
n->AsmStmt.input_list = clone_ast_node(a, n->AsmStmt.input_list);
|
||||
n->AsmStmt.clobber_list = clone_ast_node(a, n->AsmStmt.clobber_list);
|
||||
break;
|
||||
case AstNode_PushAllocator:
|
||||
n->PushAllocator.expr = clone_ast_node(a, n->PushAllocator.expr);
|
||||
n->PushAllocator.body = clone_ast_node(a, n->PushAllocator.body);
|
||||
break;
|
||||
case AstNode_PushContext:
|
||||
n->PushContext.expr = clone_ast_node(a, n->PushContext.expr);
|
||||
n->PushContext.body = clone_ast_node(a, n->PushContext.body);
|
||||
@@ -1365,14 +1355,6 @@ AstNode *ast_asm_stmt(AstFile *f, Token token, bool is_volatile, Token open, Tok
|
||||
return result;
|
||||
}
|
||||
|
||||
AstNode *ast_push_allocator(AstFile *f, Token token, AstNode *expr, AstNode *body) {
|
||||
AstNode *result = make_ast_node(f, AstNode_PushAllocator);
|
||||
result->PushAllocator.token = token;
|
||||
result->PushAllocator.expr = expr;
|
||||
result->PushAllocator.body = body;
|
||||
return result;
|
||||
}
|
||||
|
||||
AstNode *ast_push_context(AstFile *f, Token token, AstNode *expr, AstNode *body) {
|
||||
AstNode *result = make_ast_node(f, AstNode_PushContext);
|
||||
result->PushContext.token = token;
|
||||
@@ -1832,9 +1814,6 @@ void fix_advance_to_next_stmt(AstFile *f) {
|
||||
case Token_continue:
|
||||
case Token_fallthrough:
|
||||
|
||||
case Token_push_allocator:
|
||||
case Token_push_context:
|
||||
|
||||
case Token_Hash:
|
||||
{
|
||||
if (t.pos == f->fix_prev_pos &&
|
||||
@@ -4454,6 +4433,25 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
switch (token.kind) {
|
||||
// Operands
|
||||
case Token_context:
|
||||
if (look_ahead_token_kind(f, 1) == Token_ArrowLeft) {
|
||||
advance_token(f);
|
||||
Token arrow = expect_token(f, Token_ArrowLeft);
|
||||
AstNode *body = nullptr;
|
||||
isize prev_level = f->expr_level;
|
||||
f->expr_level = -1;
|
||||
AstNode *expr = parse_expr(f, false);
|
||||
f->expr_level = prev_level;
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
|
||||
return ast_push_context(f, token, expr, body);
|
||||
}
|
||||
/*fallthrough*/
|
||||
|
||||
case Token_Ident:
|
||||
case Token_Integer:
|
||||
case Token_Float:
|
||||
@@ -4539,40 +4537,6 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
return ast_bad_stmt(f, token, f->curr_token);
|
||||
} break;
|
||||
|
||||
case Token_push_allocator: {
|
||||
advance_token(f);
|
||||
AstNode *body = nullptr;
|
||||
isize prev_level = f->expr_level;
|
||||
f->expr_level = -1;
|
||||
AstNode *expr = parse_expr(f, false);
|
||||
f->expr_level = prev_level;
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
|
||||
return ast_push_allocator(f, token, expr, body);
|
||||
} break;
|
||||
|
||||
case Token_push_context: {
|
||||
advance_token(f);
|
||||
AstNode *body = nullptr;
|
||||
isize prev_level = f->expr_level;
|
||||
f->expr_level = -1;
|
||||
AstNode *expr = parse_expr(f, false);
|
||||
f->expr_level = prev_level;
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
|
||||
return ast_push_context(f, token, expr, body);
|
||||
} break;
|
||||
|
||||
case Token_At: {
|
||||
advance_token(f);
|
||||
|
||||
|
||||
@@ -2176,9 +2176,6 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
|
||||
ssa_emit_jump(p, b);
|
||||
case_end;
|
||||
|
||||
case_ast_node(pa, PushAllocator, node);
|
||||
GB_PANIC("TODO: PushAllocator");
|
||||
case_end;
|
||||
case_ast_node(pc, PushContext, node);
|
||||
GB_PANIC("TODO: PushContext");
|
||||
case_end;
|
||||
|
||||
@@ -117,8 +117,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||
TOKEN_KIND(Token_inline, "inline"), \
|
||||
TOKEN_KIND(Token_no_inline, "no_inline"), \
|
||||
TOKEN_KIND(Token_context, "context"), \
|
||||
TOKEN_KIND(Token_push_context, "push_context"), \
|
||||
TOKEN_KIND(Token_push_allocator, "push_allocator"), \
|
||||
TOKEN_KIND(Token_size_of, "size_of"), \
|
||||
TOKEN_KIND(Token_align_of, "align_of"), \
|
||||
TOKEN_KIND(Token_offset_of, "offset_of"), \
|
||||
|
||||
Reference in New Issue
Block a user