better handling for type solidification in compound expressions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 12 Jan 2021 21:22:45 +0000 (15:22 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 12 Jan 2021 21:22:45 +0000 (15:22 -0600)
bin/onyx
core/io/stream.onyx
onyx.exe
src/onyxastnodes.c
src/onyxchecker.c

index c7649f401ecd16b611485336879e01b5844687f1..fa138759c5940329f7bec9dcf00e2b74cd7f1cc2 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 2dc30240890d0652312393347e7972dcfd6c90c5..2a43d372ae37c03efeefc39dee67bf02ef265572 100644 (file)
@@ -62,7 +62,7 @@ stream_read_at :: proc (use s: ^Stream, at: u32, buffer: [] u8) -> (Error, u32)
 
 stream_read_byte :: proc (use s: ^Stream) -> (Error, u8) {
     if vtable == null do return Error.NoVtable, cast(u8) 0;
-    if vtable.read_byte == null_proc do return Error.NotImplemented, cast(u8) 0;
+    if vtable.read_byte == null_proc do return Error.NotImplemented, 0;
     
     return vtable.read_byte(s);
 }
@@ -121,10 +121,10 @@ stream_peek_byte :: proc (use s: ^Stream) -> (Error, u8) {
     err : io.Error;
 
     err, out = stream_read_byte(s);
-    if err != Error.None do return err, cast(u8) 0;
+    if err != Error.None do return err, 0;
 
     err = stream_unread_byte(s);
-    if err != Error.None do return err, cast(u8) 0;
+    if err != Error.None do return err, 0;
 
     return Error.None, out;
 }
@@ -202,11 +202,11 @@ string_stream_vtable := Stream_Vtable.{
         return Error.None, bytes_to_read;
     },
 
-    read_byte = proc (s: ^Stream) -> (Error, u8) #export "DEBUG ME" {
+    read_byte = proc (s: ^Stream) -> (Error, u8) {
         ss : ^StringStream = ~~s;
         use ss;
 
-        if curr_pos >= data.count do return Error.EOF, cast(u8) 0;
+        if curr_pos >= data.count do return Error.EOF, 0;
 
         defer curr_pos += 1;
         return Error.None, data[curr_pos];
@@ -362,7 +362,7 @@ dynamic_string_stream_vtable := Stream_Vtable.{
         dss : ^DynamicStringStream = ~~s;
         use dss;
 
-        if curr_pos >= data.count do return Error.EOF, cast(u8) 0;
+        if curr_pos >= data.count do return Error.EOF, 0;
 
         defer curr_pos += 1;
         return Error.None, data[curr_pos];
index d2fe583915c0dc725b09cd180c3801b0dfa5d763..4613b4b08fc53e8493676c1537d264caab6e9033 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index b94cc535df4488ea4be849303cbb98902d180b66..8f8edcdef2e20dacbbe8287db377cbcb7ad3aecf 100644 (file)
@@ -439,11 +439,33 @@ b32 type_check_or_auto_cast(AstTyped** pnode, Type* type) {
     else if (node->kind == Ast_Kind_NumLit) {
         if (convert_numlit_to_type((AstNumLit *) node, type)) return 1;
     }
+    else if (node->kind == Ast_Kind_Compound) {
+        if (type->kind != Type_Kind_Compound) return 0;
+
+        AstCompound* compound = (AstCompound *) node;
+
+        u32 expr_count = bh_arr_length(compound->exprs);
+        if (expr_count != type->Compound.count) return 0;
+
+        fori (i, 0, (i64) expr_count) {
+            if (!type_check_or_auto_cast(&compound->exprs[i], type->Compound.types[i])) return 0;
+        }
+
+        compound->type = type_build_compound_type(semstate.node_allocator, compound);
+        
+        return 1;
+    }
 
     return 0;
 }
 
 Type* resolve_expression_type(AstTyped* node) {
+    if (node->kind == Ast_Kind_Compound) {
+        bh_arr_each(AstTyped *, expr, ((AstCompound *) node)->exprs) {
+            resolve_expression_type(*expr);
+        }
+    }
+
     if (node->type == NULL)
         node->type = type_build_from_ast(semstate.allocator, node->type_node);
 
index d5b7cf12f4e2c64389d90ddb8d83db12b8bdeaed..324be12bfa358cb94008b749e0f181266f52d167 100644 (file)
@@ -1132,7 +1132,6 @@ CheckStatus check_range_literal(AstRangeLiteral** prange) {
 CheckStatus check_compound(AstCompound* compound) {
     bh_arr_each(AstTyped *, expr, compound->exprs) {
         CHECK(expression, expr);
-        resolve_expression_type(*expr);
     }
 
     compound->type = type_build_compound_type(semstate.node_allocator, compound);