From: Brendan Hansen Date: Tue, 8 Dec 2020 18:01:20 +0000 (-0600) Subject: more bug fixes with numeric constants X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0bd79612b6aabc32bbd46b911edd0439e7beb992;p=onyx.git more bug fixes with numeric constants --- diff --git a/onyx b/onyx index a01c7ce4..203fd0b6 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 6b8648de..683524fa 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1378,8 +1378,8 @@ b32 check_memres(AstMemRes* memres) { if (memres->initial_value != NULL) { fill_in_type(memres->initial_value); - resolve_expression_type(memres->initial_value); check_expression(&memres->initial_value); + resolve_expression_type(memres->initial_value); if ((memres->initial_value->flags & Ast_Flag_Comptime) == 0) { onyx_report_error(memres->initial_value->token->pos, "Top level expressions must be compile time known."); @@ -1398,7 +1398,6 @@ b32 check_memres(AstMemRes* memres) { } else { memres->type = memres->initial_value->type; - bh_printf("Memres type: %s\n", type_get_name(memres->type)); } } diff --git a/src/onyxtypes.c b/src/onyxtypes.c index bc0a48a8..c1ff7363 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -305,6 +305,8 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { a_node->count_expr = ((AstUnaryOp *) a_node)->expr; } + resolve_expression_type((AstTyped *) a_node->count_expr); + // NOTE: Currently, the count_expr has to be an I32 literal if (a_node->count_expr->kind != Ast_Kind_NumLit || a_node->count_expr->type->kind != Type_Kind_Basic diff --git a/src/onyxutils.c b/src/onyxutils.c index 4288c717..f626db5d 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -246,11 +246,11 @@ void scope_clear(Scope* scope) { #define REDUCE_BINOP_ALL(op) \ if (type_is_small_integer(res->type) || type_is_bool(res->type)) { \ res->value.i = left->value.i op right->value.i; \ - } else if (type_is_integer(res->type)) { \ + } else if (type_is_integer(res->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \ res->value.l = left->value.l op right->value.l; \ } else if (res->type->Basic.kind == Basic_Kind_F32) { \ res->value.f = left->value.f op right->value.f; \ - } else if (res->type->Basic.kind == Basic_Kind_F64) { \ + } else if (res->type->Basic.kind == Basic_Kind_F64 || res->type->Basic.kind == Basic_Kind_Float_Unsized) { \ res->value.d = left->value.d op right->value.d; \ } \ break; @@ -258,7 +258,7 @@ void scope_clear(Scope* scope) { #define REDUCE_BINOP_INT(op) \ if (type_is_small_integer(res->type) || type_is_bool(res->type)) { \ res->value.i = left->value.i op right->value.i; \ - } else if (type_is_integer(res->type)) { \ + } else if (type_is_integer(res->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \ res->value.l = left->value.l op right->value.l; \ } \ break; @@ -318,11 +318,11 @@ AstNumLit* ast_reduce_binop(bh_allocator a, AstBinaryOp* node) { #define REDUCE_UNOP(op) \ if (type_is_small_integer(unop->type) || type_is_bool(unop->type)) { \ res->value.i = op ((AstNumLit *) unop->expr)->value.i; \ - } else if (type_is_integer(unop->type)) { \ + } else if (type_is_integer(unop->type) || unop->type->Basic.kind == Basic_Kind_Int_Unsized) { \ res->value.l = op ((AstNumLit *) unop->expr)->value.l; \ } else if (unop->type->Basic.kind == Basic_Kind_F32) { \ res->value.f = op ((AstNumLit *) unop->expr)->value.f; \ - } else if (unop->type->Basic.kind == Basic_Kind_F64) { \ + } else if (unop->type->Basic.kind == Basic_Kind_F64 || unop->type->Basic.kind == Basic_Kind_Float_Unsized) { \ res->value.d = op ((AstNumLit *) unop->expr)->value.d; \ } \ break; @@ -714,12 +714,12 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* type) { i64 value = (i64) num->value.l; switch (type->Basic.size) { case 1: if (-128 <= value && value <= 127) { - num->value.i = (i8) value; + num->value.i = (i32) value; num->type = type; return 1; } break; case 2: if (-32768 <= value && value <= 32767) { - num->value.i = (i16) value; + num->value.i = (i32) value; num->type = type; return 1; } break;