integers are implicitly converted if they are the same size
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Jul 2020 02:26:10 +0000 (21:26 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Jul 2020 02:26:10 +0000 (21:26 -0500)
onyx
progs/arrays.onyx
src/onyxchecker.c
src/onyxtypes.c

diff --git a/onyx b/onyx
index deefae6b1fd5570dbcc721f8cf2e93d9430fd83d..69bdc1a0b091e26b8e1169024eacfb27ff0a1087 100755 (executable)
Binary files a/onyx and b/onyx differ
index 5b0f5d8ea3eba60a9150a87275a957ca1bfe53f0..6c84977511d76ecfcf3992f8d48971d158587533 100644 (file)
@@ -87,23 +87,23 @@ alloc :: proc (size: u32) -> rawptr {
     heap_u32    :: __heap_start as ^u32;
 
     curr_offset := *heap_u32;
-    if curr_offset == 0 as u32 curr_offset = 8 as u32;
+    if curr_offset == 0 curr_offset = 8;
 
     *heap_u32   = curr_offset + size;
 
     return ((__heap_start as u32) + curr_offset) as rawptr;
 }
 
-
+alloc_2darr :: proc (rows: u32, cols: u32) -> ^^i32 {
+    arr := alloc(rows * 4) as ^^i32;
+    for i: 0, cols arr[i] = alloc(cols * 4) as ^i32;
+    return arr;
+}
 
 
 
 multi_arr_test :: proc #export "main" {
-    arrs := alloc((10 * 4) as u32) as ^^i32;
-
-    for i: 0, 10 {
-        arrs[i] = alloc((10 * 4) as u32) as ^i32;
-    }
+    arrs := alloc_2darr(10, 10);
 
     for y: 0, 10 for x: 0, 10 arrs[y][x] = x + y * 10;
     for y: 0, 10 for x: 0, 10 print(arrs[x][y]);
index 1542cc99fa2bbe62d1b102a15c4e872b7612e9e4..d5626dcb1d99d1b5517a2f5a42a7c8ab8b32e615 100644 (file)
@@ -85,20 +85,29 @@ CHECK(for, AstFor* fornode) {
         if (check_expression(fornode->step)) return 1;
 
     // HACK
-    if (fornode->start->type != &basic_types[Basic_Kind_I32]) {
+    if (!types_are_compatible(fornode->start->type, &basic_types[Basic_Kind_I32])) {
         onyx_message_add(Msg_Type_Literal,
                 fornode->start->token->pos,
                 "expected expression of type i32 for start");
         return 1;
     }
 
-    if (fornode->end->type != &basic_types[Basic_Kind_I32]) {
+    if (!types_are_compatible(fornode->end->type, &basic_types[Basic_Kind_I32])) {
         onyx_message_add(Msg_Type_Literal,
                 fornode->end->token->pos,
                 "expected expression of type i32 for end");
         return 1;
     }
 
+    if (fornode->step)
+        if (!types_are_compatible(fornode->step->type, &basic_types[Basic_Kind_I32])) {
+            onyx_message_add(Msg_Type_Literal,
+                    fornode->start->token->pos,
+                    "expected expression of type i32 for step");
+            return 1;
+        }
+
+
     if (check_statement(fornode->stmt)) return 1;
 
     return 0;
index 118651e61df1832632056ea517dbae9aeb5a1ccd..f8e9cd3041d225987dfe206b730d4e441fa56019 100644 (file)
@@ -33,7 +33,11 @@ b32 types_are_compatible(Type* t1, Type* t2) {
         case Type_Kind_Basic:
             if (t2->kind == Type_Kind_Basic) {
                 // HACK: Not sure if this is right way to check this?
-                return t1 == t2;
+                if (t1 == t2) return 1;
+
+                if ((t1->Basic.flags & Basic_Flag_Integer) && (t2->Basic.flags & Basic_Flag_Integer)) {
+                    return t1->Basic.size == t2->Basic.size;
+                }
             }
             break;