From: Brendan Hansen Date: Thu, 15 Apr 2021 15:51:42 +0000 (-0500) Subject: better binary operator error messages X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2bc072fbed52183637e3754f956db68493596ef5;p=onyx.git better binary operator error messages --- diff --git a/bin/onyx b/bin/onyx index 944d40c2..548bc76d 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index 52a43c5f..4bc70bee 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -9,8 +9,10 @@ package core.alloc.heap #load "core/memory" #load "core/intrinsics/wasm" -use package core.intrinsics.wasm { memory_size, memory_grow } -#private_file memory :: package core.memory +use package core.intrinsics.wasm { + memory_size, memory_grow, + memory_copy, +} // The global heap state #private_file @@ -117,7 +119,7 @@ heap_resize :: (ptr: rawptr, new_size: u32, align: u32) -> rawptr { } new_ptr := heap_alloc(new_size, align); - memory.copy(new_ptr, ptr, old_size); + memory_copy(new_ptr, ptr, old_size); heap_free(ptr); return new_ptr; } diff --git a/src/onyx.c b/src/onyx.c index cbd19510..68d89d31 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -370,8 +370,8 @@ static void output_dummy_progress_bar() { if (bh_arr_length(eh->entities) == 0) return; static const char* state_colors[] = { - "\e[91m", "\e[93m", "\e[97m", "\e[93m", "\e[94m", - "\e[95m", "\e[94m", "\e[95m", "\e[96m", "\e[92m", + "\e[91m", "\e[93m", "\e[94m", "\e[93m", "\e[97m", + "\e[95m", "\e[97m", "\e[95m", "\e[96m", "\e[92m", }; printf("\e[2;1H"); diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 48f21eee..10e9607c 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -536,6 +536,13 @@ type_checking_done: return Check_Success; } +static void report_bad_binaryop(AstBinaryOp* binop) { + onyx_report_error(binop->token->pos, "Binary operator '%s' not understood for arguments of type '%s' and '%s'.", + binaryop_string[binop->operation], + node_get_type_name(binop->left), + node_get_type_name(binop->right)); +} + CheckStatus check_binop_assignment(AstBinaryOp* binop, b32 assignment_is_ok) { if (!assignment_is_ok) { onyx_report_error(binop->token->pos, "Assignment not valid in expression."); @@ -638,13 +645,9 @@ CheckStatus check_binop_assignment(AstBinaryOp* binop, b32 assignment_is_ok) { CheckStatus check_binaryop_compare(AstBinaryOp** pbinop) { AstBinaryOp* binop = *pbinop; - if (type_is_structlike_strict(binop->left->type)) { - onyx_report_error(binop->token->pos, "Invalid type for left side of comparison operator."); - return Check_Error; - } - - if (type_is_structlike_strict(binop->right->type)) { - onyx_report_error(binop->token->pos, "Invalid type for right side of comparison operator."); + if ( type_is_structlike_strict(binop->left->type) + || type_is_structlike_strict(binop->right->type)) { + report_bad_binaryop(binop); return Check_Error; } @@ -689,7 +692,7 @@ CheckStatus check_binaryop_bool(AstBinaryOp** pbinop) { AstBinaryOp* binop = *pbinop; if (!type_is_bool(binop->left->type) || !type_is_bool(binop->right->type)) { - onyx_report_error(binop->token->pos, "Boolean operator expects boolean types for both operands."); + report_bad_binaryop(binop); return Check_Error; } @@ -870,10 +873,7 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop, b32 assignment_is_ok) { return Check_Success; bad_binaryop: - onyx_report_error(binop->token->pos, "Binary operator '%s' not understood for arguments of type '%s' and '%s'.", - binaryop_string[binop->operation], - node_get_type_name(binop->left), - node_get_type_name(binop->right)); + report_bad_binaryop(binop); return Check_Error; }