mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix defer ir bug
This commit is contained in:
+4
-4
@@ -2040,7 +2040,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as
|
|||||||
add_package_dependency(c, "runtime", "__dynamic_map_get");
|
add_package_dependency(c, "runtime", "__dynamic_map_get");
|
||||||
} else if (is_type_bit_set(y->type)) {
|
} else if (is_type_bit_set(y->type)) {
|
||||||
Type *yt = base_type(y->type);
|
Type *yt = base_type(y->type);
|
||||||
check_assignment(c, x, yt->BitSet.base_type, str_lit("bit_set 'in'"));
|
check_assignment(c, x, yt->BitSet.base, str_lit("bit_set 'in'"));
|
||||||
} else {
|
} else {
|
||||||
gbString t = type_to_string(y->type);
|
gbString t = type_to_string(y->type);
|
||||||
error(x->expr, "expected either a map or bitset for 'in', got %s", t);
|
error(x->expr, "expected either a map or bitset for 'in', got %s", t);
|
||||||
@@ -5527,7 +5527,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
if (cl->elems.count == 0) {
|
if (cl->elems.count == 0) {
|
||||||
break; // NOTE(bill): No need to init
|
break; // NOTE(bill): No need to init
|
||||||
}
|
}
|
||||||
Type *et = base_type(t->BitSet.base_type);
|
Type *et = base_type(t->BitSet.base);
|
||||||
isize field_count = 0;
|
isize field_count = 0;
|
||||||
if (et->kind == Type_Enum) {
|
if (et->kind == Type_Enum) {
|
||||||
field_count = et->Enum.fields.count;
|
field_count = et->Enum.fields.count;
|
||||||
@@ -5551,7 +5551,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
is_constant = o->mode == Addressing_Constant;
|
is_constant = o->mode == Addressing_Constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_assignment(c, o, t->BitSet.base_type, str_lit("bit_set literal"));
|
check_assignment(c, o, t->BitSet.base, str_lit("bit_set literal"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -6293,7 +6293,7 @@ gbString write_expr_to_string(gbString str, Ast *node) {
|
|||||||
|
|
||||||
case_ast_node(bs, BitSetType, node);
|
case_ast_node(bs, BitSetType, node);
|
||||||
str = gb_string_appendc(str, "bit_set[");
|
str = gb_string_appendc(str, "bit_set[");
|
||||||
str = write_expr_to_string(str, bs->base_type);
|
str = write_expr_to_string(str, bs->base);
|
||||||
str = gb_string_appendc(str, "]");
|
str = gb_string_appendc(str, "]");
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -502,8 +502,8 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
|
|||||||
base_type = check_type(ctx, et->base_type);
|
base_type = check_type(ctx, et->base_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base_type == nullptr || !(is_type_integer(base_type) || is_type_float(base_type))) {
|
if (base_type == nullptr || !is_type_integer(base_type)) {
|
||||||
error(node, "Base type for enumeration must be numeric");
|
error(node, "Base type for enumeration must be an integer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (is_type_enum(base_type)) {
|
if (is_type_enum(base_type)) {
|
||||||
@@ -685,16 +685,16 @@ void check_bit_set_type(CheckerContext *ctx, Type *type, Ast *node) {
|
|||||||
ast_node(bs, BitSetType, node);
|
ast_node(bs, BitSetType, node);
|
||||||
GB_ASSERT(type->kind == Type_BitSet);
|
GB_ASSERT(type->kind == Type_BitSet);
|
||||||
|
|
||||||
Type *bt = check_type_expr(ctx, bs->base_type, nullptr);
|
Type *bt = check_type_expr(ctx, bs->base, nullptr);
|
||||||
|
|
||||||
type->BitSet.base_type = bt;
|
type->BitSet.base = bt;
|
||||||
if (!is_type_enum(bt)) {
|
if (!is_type_enum(bt)) {
|
||||||
error(bs->base_type, "Expected an enum type for a bit_set");
|
error(bs->base, "Expected an enum type for a bit_set");
|
||||||
} else {
|
} else {
|
||||||
Type *et = base_type(bt);
|
Type *et = base_type(bt);
|
||||||
GB_ASSERT(et->kind == Type_Enum);
|
GB_ASSERT(et->kind == Type_Enum);
|
||||||
if (!is_type_integer(et->Enum.base_type)) {
|
if (!is_type_integer(et->Enum.base_type)) {
|
||||||
error(bs->base_type, "Enum type for bit_set must be an integer");
|
error(bs->base, "Enum type for bit_set must be an integer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i64 min_value = 0;
|
i64 min_value = 0;
|
||||||
@@ -713,8 +713,10 @@ void check_bit_set_type(CheckerContext *ctx, Type *type, Ast *node) {
|
|||||||
max_value = gb_max(max_value, x);
|
max_value = gb_max(max_value, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GB_ASSERT(min_value <= max_value);
|
||||||
|
|
||||||
if (max_value - min_value > 64) {
|
if (max_value - min_value > 64) {
|
||||||
error(bs->base_type, "bit_set range is greater than 64 bits");
|
error(bs->base, "bit_set range is greater than 64 bits");
|
||||||
}
|
}
|
||||||
|
|
||||||
type->BitSet.min = min_value;
|
type->BitSet.min = min_value;
|
||||||
|
|||||||
+1
-1
@@ -1044,7 +1044,7 @@ void add_type_info_type(CheckerContext *c, Type *t) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_BitSet:
|
case Type_BitSet:
|
||||||
add_type_info_type(c, bt->BitSet.base_type);
|
add_type_info_type(c, bt->BitSet.base);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_Union:
|
case Type_Union:
|
||||||
|
|||||||
+6
-7
@@ -1758,8 +1758,7 @@ void ir_emit_defer_stmts(irProcedure *proc, irDeferExitKind kind, irBlock *block
|
|||||||
isize i = count;
|
isize i = count;
|
||||||
while (i --> 0) {
|
while (i --> 0) {
|
||||||
irDefer d = proc->defer_stmts[i];
|
irDefer d = proc->defer_stmts[i];
|
||||||
if (d.context_stack_count >= 0) {
|
if (proc->context_stack.count >= d.context_stack_count) {
|
||||||
GB_ASSERT(proc->context_stack.count >= d.context_stack_count);
|
|
||||||
proc->context_stack.count = d.context_stack_count;
|
proc->context_stack.count = d.context_stack_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4910,7 +4909,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
|
|||||||
{
|
{
|
||||||
ir_emit_comment(proc, str_lit("bit_set in"));
|
ir_emit_comment(proc, str_lit("bit_set in"));
|
||||||
|
|
||||||
Type *key_type = rt->BitSet.base_type;
|
Type *key_type = rt->BitSet.base;
|
||||||
GB_ASSERT(are_types_identical(ir_type(left), key_type));
|
GB_ASSERT(are_types_identical(ir_type(left), key_type));
|
||||||
|
|
||||||
Type *it = bit_set_to_int(rt);
|
Type *it = bit_set_to_int(rt);
|
||||||
@@ -5662,9 +5661,9 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
|
|||||||
|
|
||||||
Type *et = nullptr;
|
Type *et = nullptr;
|
||||||
switch (bt->kind) {
|
switch (bt->kind) {
|
||||||
case Type_Array: et = bt->Array.elem; break;
|
case Type_Array: et = bt->Array.elem; break;
|
||||||
case Type_Slice: et = bt->Slice.elem; break;
|
case Type_Slice: et = bt->Slice.elem; break;
|
||||||
case Type_BitSet: et = bt->BitSet.base_type; break;
|
case Type_BitSet: et = bt->BitSet.base; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String proc_name = {};
|
String proc_name = {};
|
||||||
@@ -8117,7 +8116,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
|||||||
case Type_BitSet:
|
case Type_BitSet:
|
||||||
ir_emit_comment(proc, str_lit("Type_Info_Bit_Set"));
|
ir_emit_comment(proc, str_lit("Type_Info_Bit_Set"));
|
||||||
tag = ir_emit_conv(proc, variant_ptr, t_type_info_bit_set_ptr);
|
tag = ir_emit_conv(proc, variant_ptr, t_type_info_bit_set_ptr);
|
||||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), ir_get_type_info_ptr(proc, t->BitSet.base_type));
|
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), ir_get_type_info_ptr(proc, t->BitSet.base));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-24
@@ -347,7 +347,7 @@ Ast *clone_ast(Ast *node) {
|
|||||||
n->BitFieldType.align = clone_ast(n->BitFieldType.align);
|
n->BitFieldType.align = clone_ast(n->BitFieldType.align);
|
||||||
break;
|
break;
|
||||||
case Ast_BitSetType:
|
case Ast_BitSetType:
|
||||||
n->BitSetType.base_type = clone_ast(n->BitSetType.base_type);
|
n->BitSetType.base = clone_ast(n->BitSetType.base);
|
||||||
break;
|
break;
|
||||||
case Ast_MapType:
|
case Ast_MapType:
|
||||||
n->MapType.count = clone_ast(n->MapType.count);
|
n->MapType.count = clone_ast(n->MapType.count);
|
||||||
@@ -927,10 +927,10 @@ Ast *ast_bit_field_type(AstFile *f, Token token, Array<Ast *> fields, Ast *align
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ast *ast_bit_set_type(AstFile *f, Token token, Ast *base_type) {
|
Ast *ast_bit_set_type(AstFile *f, Token token, Ast *base) {
|
||||||
Ast *result = alloc_ast_node(f, Ast_BitSetType);
|
Ast *result = alloc_ast_node(f, Ast_BitSetType);
|
||||||
result->BitSetType.token = token;
|
result->BitSetType.token = token;
|
||||||
result->BitSetType.base_type = base_type;
|
result->BitSetType.base = base;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1901,27 +1901,10 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Token_enum: {
|
case Token_enum: {
|
||||||
// bool is_export = false;
|
|
||||||
Token token = expect_token(f, Token_enum);
|
Token token = expect_token(f, Token_enum);
|
||||||
Ast *base_type = nullptr;
|
Ast *base_type = nullptr;
|
||||||
if (f->curr_token.kind != Token_OpenBrace) {
|
if (f->curr_token.kind != Token_OpenBrace) {
|
||||||
if (f->curr_token.kind != Token_Hash) {
|
base_type = parse_type(f);
|
||||||
base_type = parse_type(f);
|
|
||||||
}
|
|
||||||
// while (allow_token(f, Token_Hash)) {
|
|
||||||
// Token tag = f->curr_token;
|
|
||||||
// if (!allow_token(f, Token_Ident) && !allow_token(f, Token_export)) {
|
|
||||||
// expect_token_after(f, Token_Ident, "#");
|
|
||||||
// }
|
|
||||||
// if (tag.string == "export") {
|
|
||||||
// if (is_export) {
|
|
||||||
// syntax_error(tag, "Duplicate enum tag '#%.*s'", LIT(tag.string));
|
|
||||||
// }
|
|
||||||
// is_export = true;
|
|
||||||
// } else {
|
|
||||||
// syntax_error(tag, "Invalid enum tag '#%.*s'", LIT(tag.string));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Token open = expect_token(f, Token_OpenBrace);
|
Token open = expect_token(f, Token_OpenBrace);
|
||||||
|
|
||||||
@@ -1978,11 +1961,11 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
|
|
||||||
case Token_bit_set: {
|
case Token_bit_set: {
|
||||||
Token token = expect_token(f, Token_bit_set);
|
Token token = expect_token(f, Token_bit_set);
|
||||||
Token open = expect_token(f, Token_OpenBracket);
|
Token open = expect_token(f, Token_OpenBracket);
|
||||||
Ast *base_type = parse_type(f);
|
Ast * base = parse_type(f);
|
||||||
Token close = expect_token(f, Token_CloseBracket);
|
Token close = expect_token(f, Token_CloseBracket);
|
||||||
|
|
||||||
return ast_bit_set_type(f, token, base_type);
|
return ast_bit_set_type(f, token, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
+1
-1
@@ -483,7 +483,7 @@ AST_KIND(_TypeBegin, "", bool) \
|
|||||||
}) \
|
}) \
|
||||||
AST_KIND(BitSetType, "bit set type", struct { \
|
AST_KIND(BitSetType, "bit set type", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
Ast * base_type; \
|
Ast * base; \
|
||||||
}) \
|
}) \
|
||||||
AST_KIND(MapType, "map type", struct { \
|
AST_KIND(MapType, "map type", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
|
|||||||
+4
-4
@@ -179,7 +179,7 @@ struct TypeStruct {
|
|||||||
i64 custom_align; \
|
i64 custom_align; \
|
||||||
}) \
|
}) \
|
||||||
TYPE_KIND(BitSet, struct { \
|
TYPE_KIND(BitSet, struct { \
|
||||||
Type *base_type; \
|
Type *base; \
|
||||||
i64 min; \
|
i64 min; \
|
||||||
i64 max; \
|
i64 max; \
|
||||||
}) \
|
}) \
|
||||||
@@ -1277,7 +1277,7 @@ bool are_types_identical(Type *x, Type *y) {
|
|||||||
|
|
||||||
case Type_BitSet:
|
case Type_BitSet:
|
||||||
if (y->kind == Type_BitSet) {
|
if (y->kind == Type_BitSet) {
|
||||||
return are_types_identical(x->BitSet.base_type, y->BitSet.base_type);
|
return are_types_identical(x->BitSet.base, y->BitSet.base);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -2616,8 +2616,8 @@ gbString write_type_to_string(gbString str, Type *type) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_BitSet:
|
case Type_BitSet:
|
||||||
str = gb_string_appendc(str, "bit_field[");
|
str = gb_string_appendc(str, "bit_set[");
|
||||||
str = write_type_to_string(str, type->BitSet.base_type);
|
str = write_type_to_string(str, type->BitSet.base);
|
||||||
str = gb_string_appendc(str, "]");
|
str = gb_string_appendc(str, "]");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user