From: Brendan Hansen Date: Tue, 12 Jan 2021 21:22:45 +0000 (-0600) Subject: better handling for type solidification in compound expressions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=1a547551a3588f5904a0c06f1de50ecb0d54d4cc;p=onyx.git better handling for type solidification in compound expressions --- diff --git a/bin/onyx b/bin/onyx index c7649f40..fa138759 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 2dc30240..2a43d372 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -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]; diff --git a/onyx.exe b/onyx.exe index d2fe5839..4613b4b0 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index b94cc535..8f8edcde 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -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); diff --git a/src/onyxchecker.c b/src/onyxchecker.c index d5b7cf12..324be12b 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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);