more bug fixes with numeric constants
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 8 Dec 2020 18:01:20 +0000 (12:01 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 8 Dec 2020 18:02:03 +0000 (12:02 -0600)
onyx
src/onyxchecker.c
src/onyxtypes.c
src/onyxutils.c

diff --git a/onyx b/onyx
index a01c7ce4813781d6747076c5d368b654e2731305..203fd0b68d54cdedcc77f84ea9a66ff85238e1d9 100755 (executable)
Binary files a/onyx and b/onyx differ
index 6b8648deb494b8267f9d6616d0330d6d16ff2966..683524fa43ea4cad32003d5e108012d67de6a621 100644 (file)
@@ -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));
         }
     }
 
index bc0a48a87c35192d86fa49c644e5eeca368854e7..c1ff7363c45d586226b072310870320b48480952 100644 (file)
@@ -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
index 4288c717f3d79a8349e9792b0ac242437a98c8d4..f626db5d5d0b244472959c6f6a908e1e353749fe 100644 (file)
@@ -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;