From 5ff82fc1132a05d76592e8e21db98913cd498f64 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Jan 2022 15:11:42 +0000 Subject: Correct tuple name checking for doc writing --- src/exact_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/exact_value.cpp') diff --git a/src/exact_value.cpp b/src/exact_value.cpp index fd90278e5..e979e3d45 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -9,7 +9,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y); +bool are_types_identical(Type *x, Type *y, bool check_tuple_names=false); struct Complex128 { f64 real, imag; -- cgit v1.2.3 From ecdaac9921fbf351bfddaf920553855ae6a5d58f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Jan 2022 15:14:15 +0000 Subject: Unify `are_types_identical_unique_tuples` --- src/checker.cpp | 4 ++-- src/docs_writer.cpp | 2 +- src/exact_value.cpp | 2 +- src/types.cpp | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 44dc90c67..63a697072 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1253,7 +1253,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { // TODO(bill): This is O(n) and can be very slow for_array(i, info->type_info_map.entries){ auto *e = &info->type_info_map.entries[i]; - if (are_types_identical(e->key, type)) { + if (are_types_identical_unique_tuples(e->key, type)) { entry_index = e->value; // NOTE(bill): Add it to the search map map_set(&info->type_info_map, type, entry_index); @@ -1601,7 +1601,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { isize ti_index = -1; for_array(i, c->info->type_info_map.entries) { auto *e = &c->info->type_info_map.entries[i]; - if (are_types_identical(t, e->key)) { + if (are_types_identical_unique_tuples(t, e->key)) { // Duplicate entry ti_index = e->value; prev = true; diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index f1f110a57..c2d07dc12 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -483,7 +483,7 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { for_array(i, w->type_cache.entries) { // NOTE(bill): THIS IS SLOW Type *other = w->type_cache.entries[i].key; - if (are_types_identical(type, other, true)) { + if (are_types_identical_unique_tuples(type, other)) { OdinDocTypeIndex index = w->type_cache.entries[i].value; map_set(&w->type_cache, type, index); return index; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index e979e3d45..fd90278e5 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -9,7 +9,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y, bool check_tuple_names=false); +bool are_types_identical(Type *x, Type *y); struct Complex128 { f64 real, imag; diff --git a/src/types.cpp b/src/types.cpp index 98dc30703..07951196a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -694,7 +694,7 @@ gbString type_to_string (Type *type); i64 type_size_of_internal(Type *t, TypePath *path); void init_map_internal_types(Type *type); Type * bit_set_to_int(Type *t); -bool are_types_identical(Type *x, Type *y, bool check_tuple_names/*=false*/); +bool are_types_identical(Type *x, Type *y); bool is_type_pointer(Type *t); bool is_type_proc(Type *t); @@ -2338,7 +2338,17 @@ Type *strip_type_aliasing(Type *x) { return x; } -bool are_types_identical(Type *x, Type *y, bool check_tuple_names) { +bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); + +bool are_types_identical(Type *x, Type *y) { + return are_types_identical_internal(x, y, false); +} +bool are_types_identical_unique_tuples(Type *x, Type *y) { + return are_types_identical_internal(x, y, true); +} + + +bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { if (x == y) { return true; } -- cgit v1.2.3 From 62d232d798fff25597b6e3591c6a178c32fa440e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 22 Feb 2022 22:59:00 +0000 Subject: Correct `ExactValue_Pointer` --- src/exact_value.cpp | 17 ++++++++++++--- src/parser.cpp | 63 ----------------------------------------------------- 2 files changed, 14 insertions(+), 66 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/exact_value.cpp b/src/exact_value.cpp index fd90278e5..3dae96853 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -630,6 +630,9 @@ void match_exact_values(ExactValue *x, ExactValue *y) { case ExactValue_Bool: case ExactValue_String: case ExactValue_Quaternion: + case ExactValue_Pointer: + case ExactValue_Procedure: + case ExactValue_Typeid: return; case ExactValue_Integer: @@ -671,9 +674,6 @@ void match_exact_values(ExactValue *x, ExactValue *y) { return; } break; - - case ExactValue_Procedure: - return; } compiler_error("match_exact_values: How'd you get here? Invalid ExactValueKind %d", x->kind); @@ -932,6 +932,17 @@ bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) { break; } + case ExactValue_Pointer: { + switch (op) { + case Token_CmpEq: return x.value_pointer == y.value_pointer; + case Token_NotEq: return x.value_pointer != y.value_pointer; + case Token_Lt: return x.value_pointer < y.value_pointer; + case Token_LtEq: return x.value_pointer <= y.value_pointer; + case Token_Gt: return x.value_pointer > y.value_pointer; + case Token_GtEq: return x.value_pointer >= y.value_pointer; + } + } + case ExactValue_Typeid: switch (op) { case Token_CmpEq: return are_types_identical(x.value_typeid, y.value_typeid); diff --git a/src/parser.cpp b/src/parser.cpp index c214df782..9659e8c18 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3013,69 +3013,6 @@ i32 token_precedence(AstFile *f, TokenKind t) { return 0; } -// Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { -// Ast *expr = parse_unary_expr(f, lhs); -// for (i32 prec = token_precedence(f, f->curr_token.kind); prec >= prec_in; prec--) { -// for (;;) { -// Token op = f->curr_token; -// i32 op_prec = token_precedence(f, op.kind); -// if (op_prec != prec) { -// // NOTE(bill): This will also catch operators that are not valid "binary" operators -// break; -// } -// Token prev = f->prev_token; -// switch (op.kind) { -// case Token_if: -// case Token_when: -// if (prev.pos.line < op.pos.line) { -// // NOTE(bill): Check to see if the `if` or `when` is on the same line of the `lhs` condition -// goto loop_end; -// } -// break; -// } -// expect_operator(f); // NOTE(bill): error checks too - -// if (op.kind == Token_Question) { -// Ast *cond = expr; -// // Token_Question -// Ast *x = parse_expr(f, lhs); -// Token token_c = expect_token(f, Token_Colon); -// Ast *y = parse_expr(f, lhs); -// expr = ast_ternary_if_expr(f, x, cond, y); -// } else if (op.kind == Token_if || op.kind == Token_when) { -// Ast *x = expr; -// Ast *cond = parse_expr(f, lhs); -// Token tok_else = expect_token(f, Token_else); -// Ast *y = parse_expr(f, lhs); - -// switch (op.kind) { -// case Token_if: -// expr = ast_ternary_if_expr(f, x, cond, y); -// break; -// case Token_when: -// expr = ast_ternary_when_expr(f, x, cond, y); -// break; -// } -// } else { -// Ast *right = parse_binary_expr(f, false, prec+1); -// if (right == nullptr) { -// syntax_error(op, "Expected expression on the right-hand side of the binary operator '%.*s'", LIT(op.string)); -// } -// if (op.kind == Token_or_else) { -// // NOTE(bill): easier to handle its logic different with its own AST kind -// expr = ast_or_else_expr(f, expr, op, right); -// } else { -// expr = ast_binary_expr(f, op, expr, right); -// } -// } - -// lhs = false; -// } -// loop_end:; -// } -// return expr; -// } - Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { Ast *expr = parse_unary_expr(f, lhs); for (;;) { -- cgit v1.2.3 From 83f7a887b7ab9313e520211521297a9352c408b9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 22 Feb 2022 23:03:04 +0000 Subject: Move comment --- src/exact_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 3dae96853..f6df48951 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -50,9 +50,9 @@ struct ExactValue { union { bool value_bool; String value_string; - BigInt value_integer; // NOTE(bill): This must be an integer and not a pointer + BigInt value_integer; f64 value_float; - i64 value_pointer; + i64 value_pointer; // NOTE(bill): This must be an integer and not a pointer Complex128 *value_complex; Quaternion256 *value_quaternion; Ast * value_compound; -- cgit v1.2.3 From 8a9f7fc684b39c803cab184344a8a017308ed63a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 14 Apr 2022 15:09:03 +0100 Subject: Fix #1713 --- src/check_expr.cpp | 5 ++++- src/exact_value.cpp | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/exact_value.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index dcf17af39..336a711d4 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -8161,7 +8161,10 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type * case Type_Basic: { if (!is_type_any(t)) { if (cl->elems.count != 0) { - error(node, "Illegal compound literal"); + gbString s = type_to_string(t); + error(node, "Illegal compound literal, %s cannot be used as a compound literal with fields", s); + gb_string_free(s); + is_constant = false; } break; } diff --git a/src/exact_value.cpp b/src/exact_value.cpp index f6df48951..cedef48c4 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -591,6 +591,7 @@ failure: i32 exact_value_order(ExactValue const &v) { switch (v.kind) { case ExactValue_Invalid: + case ExactValue_Compound: return 0; case ExactValue_Bool: case ExactValue_String: @@ -607,8 +608,6 @@ i32 exact_value_order(ExactValue const &v) { return 6; case ExactValue_Procedure: return 7; - // case ExactValue_Compound: - // return 8; default: GB_PANIC("How'd you get here? Invalid Value.kind %d", v.kind); -- cgit v1.2.3