From: Brendan Hansen Date: Tue, 5 Jan 2021 01:51:10 +0000 (-0600) Subject: compiling with more warnings for cleaner code X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ae111cd93b95e4cc0b13ce2824a284de496eea5d;p=onyx.git compiling with more warnings for cleaner code --- diff --git a/bin/onyx b/bin/onyx index 77fdb3f1..1d3b6254 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/build.sh b/build.sh index 9462fc75..bbde6c6d 100644 --- a/build.sh +++ b/build.sh @@ -4,10 +4,12 @@ C_FILES="onyx onyxbuiltins onyxchecker onyxclone onyxdoc onyxentities onyxerrors TARGET='./bin/onyx' CC='gcc' +WARNINGS='-Wimplicit -Wmisleading-indentation -Wmultistatement-macros -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op' + if [ "$1" = "debug" ]; then FLAGS='-g3 -I./include' else - FLAGS='-O3 -I./include' + FLAGS="$WARNINGS -O3 -I./include" fi BUILD_DIR='./build' diff --git a/include/bh.h b/include/bh.h index d356e5ec..bdc5ced9 100644 --- a/include/bh.h +++ b/include/bh.h @@ -92,6 +92,7 @@ i64 chars_match(char* ptr1, char* ptr2); #define bh_min(a, b) ((a) < (b) ? (a) : (b)) #define bh_clamp(v, a, b) (bh_min((b), bh_max((a), (v)))) #define bh_abs(x) ((x) < 0 ? -(x) : (x)) +#define size_of(x) (isize) sizeof(x) static inline u64 log2_dumb(u64 n) { switch (n) { @@ -960,7 +961,7 @@ BH_ALLOCATOR_PROC(bh_managed_heap_allocator_proc) { // ARENA ALLOCATOR IMPLEMENTATION void bh_arena_init(bh_arena* alloc, bh_allocator backing, isize arena_size) { - arena_size = bh_max(arena_size, sizeof(ptr)); + arena_size = bh_max(arena_size, size_of(ptr)); ptr data = bh_alloc(backing, arena_size); alloc->backing = backing; @@ -1004,7 +1005,7 @@ BH_ALLOCATOR_PROC(bh_arena_allocator_proc) { // TODO: Do this better because right now bh__align is bad // size = bh__align(size, alignment); - if (size > alloc_arena->arena_size - sizeof(ptr)) { + if (size > alloc_arena->arena_size - size_of(ptr)) { // Size too large for the arena return NULL; } @@ -1229,7 +1230,7 @@ char* bh_strdup(bh_allocator a, char* str) { char* buf = bh_alloc(a, len + 1); char* t = buf; - while (*t++ = *str++); + while ((*t++ = *str++)); return buf; } @@ -1699,7 +1700,7 @@ isize bh__printi64(char* str, isize n, bh__print_format format, i64 value) { char* walker = buf + 127; u32 base = format.base ? format.base : 10, tmp; - b32 negative = value < 0; + b32 negative = value < 0 ? 1 : 0; if (negative) value = -value; if (value == 0) { @@ -2068,7 +2069,7 @@ b32 bh__table_init(bh_allocator allocator, bh__table **table, i32 table_size) { b32 bh__table_free(bh__table **table) { if (*table == NULL) return 0; - for (i32 i = 0; i < (*table)->table_size; i++) { + for (u64 i = 0; i < (*table)->table_size; i++) { if ((*table)->arrs[i] != NULL) { bh_arr_free((*table)->arrs[i]); } @@ -2219,7 +2220,7 @@ found_matching: } void bh__table_clear(bh__table *table) { - for (i32 i = 0; i < table->table_size; i++) { + for (u64 i = 0; i < table->table_size; i++) { if (table->arrs[i] != NULL) { // NOTE: Set length property to 0 *((u64 *) table->arrs[i]) = 0; diff --git a/onyx.exe b/onyx.exe index 6378ea27..30854881 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyx.c b/src/onyx.c index 6a1f1e26..2f081ef2 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -208,6 +208,8 @@ static void compiler_state_free(CompilerState* cs) { bh_arena_free(&cs->ast_arena); bh_arena_free(&cs->sp_arena); bh_table_free(cs->loaded_files); + + compile_opts_free(cs->options); } // NOTE: This should not be called until immediately before using the return value. diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 4a1af12a..b3e1303f 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -187,7 +187,7 @@ b32 check_for(AstFor* fornode) { return 0; } -static b32 add_case_to_switch_statement(AstSwitch* switchnode, i64 case_value, AstBlock* block, OnyxFilePos pos) { +static b32 add_case_to_switch_statement(AstSwitch* switchnode, u64 case_value, AstBlock* block, OnyxFilePos pos) { switchnode->min_case = bh_min(switchnode->min_case, case_value); switchnode->max_case = bh_max(switchnode->max_case, case_value); @@ -426,7 +426,7 @@ b32 check_call(AstCall* call) { AstParam* variadic_param = NULL; ArgState arg_state = AS_Expecting_Exact; - i32 arg_pos = 0; + u32 arg_pos = 0; while (1) { switch (arg_state) { case AS_Expecting_Exact: { @@ -445,7 +445,7 @@ b32 check_call(AstCall* call) { continue; } - if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done; + if (arg_pos >= (u32) bh_arr_length(arg_arr)) goto type_checking_done; if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, formal_params[arg_pos])) { onyx_report_error(arg_arr[arg_pos]->token->pos, "The procedure '%s' expects a value of type '%s' for %d%s parameter, got '%s'.", @@ -464,7 +464,7 @@ b32 check_call(AstCall* call) { case AS_Expecting_Typed_VA: { call->va_kind = VA_Kind_Typed; - if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done; + if (arg_pos >= (u32) bh_arr_length(arg_arr)) goto type_checking_done; if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, variadic_type)) { onyx_report_error(arg_arr[arg_pos]->token->pos, "The procedure '%s' expects a value of type '%s' for the variadic parameter, '%b', got '%s'.", @@ -483,7 +483,7 @@ b32 check_call(AstCall* call) { case AS_Expecting_Untyped_VA: { call->va_kind = VA_Kind_Untyped; - if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done; + if (arg_pos >= (u32) bh_arr_length(arg_arr)) goto type_checking_done; resolve_expression_type(arg_arr[arg_pos]->value); arg_arr[arg_pos]->va_kind = VA_Kind_Untyped; @@ -501,7 +501,7 @@ type_checking_done: return 1; } - if (arg_pos < bh_arr_length(arg_arr)) { + if (arg_pos < (u32) bh_arr_length(arg_arr)) { onyx_report_error(call->token->pos, "Too many arguments to function call."); return 1; } @@ -908,7 +908,7 @@ b32 check_unaryop(AstUnaryOp** punop) { b32 check_struct_literal(AstStructLiteral* sl) { fill_in_type((AstTyped *) sl); - u32 mem_count = type_structlike_mem_count(sl->type); + i32 mem_count = type_structlike_mem_count(sl->type); if (mem_count != bh_arr_length(sl->values)) { onyx_report_error(sl->token->pos, @@ -960,7 +960,7 @@ b32 check_array_literal(AstArrayLiteral* al) { assert(al->type->kind == Type_Kind_Array); - if (al->type->Array.count != bh_arr_length(al->values)) { + if (al->type->Array.count != (u32) bh_arr_length(al->values)) { onyx_report_error(al->token->pos, "Wrong array size (%d) for number of values (%d).", al->type->Array.count, bh_arr_length(al->values)); return 1; diff --git a/src/onyxclone.c b/src/onyxclone.c index c6dbb8c6..6ae1ccda 100644 --- a/src/onyxclone.c +++ b/src/onyxclone.c @@ -341,7 +341,7 @@ AstNode* ast_clone(bh_allocator a, void* n) { case Ast_Kind_Function_Type: ((AstFunctionType *) nn)->return_type = (AstType *) ast_clone(a, ((AstFunctionType *) node)->return_type); ((AstFunctionType *) nn)->param_count = ((AstFunctionType *) node)->param_count; - fori (i, 0, ((AstFunctionType *) nn)->param_count) { + fori (i, 0, (i64) ((AstFunctionType *) nn)->param_count) { ((AstFunctionType *) nn)->params[i] = (AstType *) ast_clone(a, ((AstFunctionType *) node)->params[i]); } break; diff --git a/src/onyxlex.c b/src/onyxlex.c index 65b5b6fb..cf1d286b 100644 --- a/src/onyxlex.c +++ b/src/onyxlex.c @@ -97,7 +97,7 @@ static inline b32 token_lit(OnyxTokenizer* tokenizer, OnyxToken* tk, char* lit, while (*ptr2 != '\0' && *ptr1 == *ptr2) ptr1++, ptr2++, len++; if (*ptr2 != '\0') return 0; - if (is_word && char_is_alphanum(*ptr1) || *ptr1 == '_') + if (is_word && (char_is_alphanum(*ptr1) || *ptr1 == '_')) return 0; tk->type = type; diff --git a/src/onyxparser.c b/src/onyxparser.c index 407b05f6..55504902 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -98,19 +98,6 @@ static OnyxToken* expect_token(OnyxParser* parser, TokenType token_type) { return token; } -static OnyxToken* soft_expect_token(OnyxParser* parser, TokenType token_type) { - if (parser->hit_unexpected_token) return NULL; - - OnyxToken* token = parser->curr; - - if (token->type == token_type) { - consume_token(parser); - return token; - } - - return NULL; -} - static void add_node_to_process(OnyxParser* parser, AstNode* node) { Scope* scope = parser->file_scope; @@ -138,15 +125,6 @@ static AstNumLit* make_int_literal(bh_allocator a, i64 i) { return num; } -static AstUnaryOp* wrap_in_auto_cast(bh_allocator a, AstTyped* expr) { - AstUnaryOp* ac = onyx_ast_node_new(a, sizeof(AstUnaryOp), Ast_Kind_Unary_Op); - ac->operation = Unary_Op_Auto_Cast; - ac->token = expr->token; - ac->expr = expr; - return ac; -} - - static AstNumLit* parse_int_literal(OnyxParser* parser) { AstNumLit* int_node = make_node(AstNumLit, Ast_Kind_NumLit); int_node->token = expect_token(parser, Token_Type_Literal_Integer); @@ -738,7 +716,7 @@ static AstTyped* parse_expression(OnyxParser* parser) { while (1) { if (parser->hit_unexpected_token) return root; - bin_op_kind = -1; + bin_op_kind = Binary_Op_Count; switch ((u16) parser->curr->type) { case Token_Type_Equal_Equal: bin_op_kind = Binary_Op_Equal; break; case Token_Type_Not_Equal: bin_op_kind = Binary_Op_Not_Equal; break; @@ -781,7 +759,7 @@ static AstTyped* parse_expression(OnyxParser* parser) { default: goto expression_done; } - if (bin_op_kind != -1) { + if (bin_op_kind != Binary_Op_Count) { bin_op_tok = parser->curr; consume_token(parser); @@ -1452,7 +1430,7 @@ static AstType* parse_type(OnyxParser* parser) { return_type = parse_type(parser); } - u64 param_count = bh_arr_length(params); + i64 param_count = bh_arr_length(params); AstFunctionType* new = onyx_ast_node_new(parser->allocator, sizeof(AstFunctionType) + sizeof(AstType*) * param_count, Ast_Kind_Function_Type); @@ -1755,7 +1733,7 @@ static b32 parse_possible_directive(OnyxParser* parser, const char* dir) { expect_token(parser, '#'); OnyxToken* sym = expect_token(parser, Token_Type_Symbol); - b32 match = (strlen(dir) == sym->length) && (strncmp(dir, sym->text, sym->length) == 0); + b32 match = (strlen(dir) == (u64) sym->length) && (strncmp(dir, sym->text, sym->length) == 0); if (!match) { unconsume_token(parser); unconsume_token(parser); diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 81f5984c..9c408f0d 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -87,7 +87,7 @@ AstType* symres_type(AstType* type) { ftype->return_type = symres_type(ftype->return_type); if (ftype->param_count > 0) - fori (i, 0, ftype->param_count) { + fori (i, 0, (i64) ftype->param_count) { ftype->params[i] = symres_type(ftype->params[i]); } @@ -928,7 +928,7 @@ static void symres_polyproc(AstPolyProc* pp) { void symres_entity(Entity* ent) { if (ent->package) semstate.curr_package = ent->package; - Scope* old_scope; + Scope* old_scope = NULL; if (ent->scope) { old_scope = semstate.curr_scope; scope_enter(ent->scope); diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 66d35f0c..10765a19 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -285,7 +285,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { func_type->Function.return_type = type_build_from_ast(alloc, ftype_node->return_type); if (param_count > 0) - fori (i, 0, param_count) { + fori (i, 0, (i64) param_count) { func_type->Function.params[i] = type_build_from_ast(alloc, ftype_node->params[i]); } diff --git a/src/onyxutils.c b/src/onyxutils.c index fb5ef248..2c47a3c8 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -493,7 +493,7 @@ static Type* solve_poly_type(AstNode* target, AstType* type_expr, Type* actual) AstFunctionType* ft = (AstFunctionType *) elem.type_expr; - fori (i, 0, ft->param_count) { + fori (i, 0, (i64) ft->param_count) { bh_arr_push(elem_queue, ((PolySolveElem) { .type_expr = ft->params[i], .actual = elem.actual->Function.params[i], @@ -528,7 +528,6 @@ static Type* solve_poly_type(AstNode* target, AstType* type_expr, Type* actual) } } -solving_done: bh_arr_free(elem_queue); return result; @@ -563,7 +562,7 @@ AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lo return NULL; } - fori (i, 0, param->idx) arg = (AstArgument *) arg->next; + fori (i, 0, (i64) param->idx) arg = (AstArgument *) arg->next; actual_type = resolve_expression_type(arg->value); } diff --git a/src/onyxwasm.c b/src/onyxwasm.c index b95bb834..4941588e 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -21,188 +21,6 @@ OnyxWasmModule global_wasm_module; #define WASM_TYPE_VOID 'E' #endif -static const char* wi_string(WasmInstructionType wit) { - switch (wit) { - case WI_UNREACHABLE: return "WI_UNREACHABLE"; - case WI_NOP: return "WI_NOP"; - case WI_BLOCK_START: return "WI_BLOCK_START"; - case WI_BLOCK_END: return "WI_BLOCK_END"; - case WI_LOOP_START: return "WI_LOOP_START"; - case WI_IF_START: return "WI_IF_START"; - case WI_ELSE: return "WI_ELSE"; - case WI_JUMP: return "WI_JUMP"; - case WI_COND_JUMP: return "WI_COND_JUMP"; - case WI_JUMP_TABLE: return "WI_JUMP_TABLE"; - case WI_RETURN: return "WI_RETURN"; - case WI_CALL: return "WI_CALL"; - case WI_CALL_INDIRECT: return "WI_CALL_INDIRECT"; - case WI_DROP: return "WI_DROP"; - case WI_SELECT: return "WI_SELECT"; - case WI_LOCAL_GET: return "WI_LOCAL_GET"; - case WI_LOCAL_SET: return "WI_LOCAL_SET"; - case WI_LOCAL_TEE: return "WI_LOCAL_TEE"; - case WI_GLOBAL_GET: return "WI_GLOBAL_GET"; - case WI_GLOBAL_SET: return "WI_GLOBAL_SET"; - case WI_I32_LOAD: return "WI_I32_LOAD"; - case WI_I64_LOAD: return "WI_I64_LOAD"; - case WI_F32_LOAD: return "WI_F32_LOAD"; - case WI_F64_LOAD: return "WI_F64_LOAD"; - case WI_I32_LOAD_8_S: return "WI_I32_LOAD_8_S"; - case WI_I32_LOAD_8_U: return "WI_I32_LOAD_8_U"; - case WI_I32_LOAD_16_S: return "WI_I32_LOAD_16_S"; - case WI_I32_LOAD_16_U: return "WI_I32_LOAD_16_U"; - case WI_I64_LOAD_8_S: return "WI_I64_LOAD_8_S"; - case WI_I64_LOAD_8_U: return "WI_I64_LOAD_8_U"; - case WI_I64_LOAD_16_S: return "WI_I64_LOAD_16_S"; - case WI_I64_LOAD_16_U: return "WI_I64_LOAD_16_U"; - case WI_I64_LOAD_32_S: return "WI_I64_LOAD_32_S"; - case WI_I64_LOAD_32_U: return "WI_I64_LOAD_32_U"; - case WI_I32_STORE: return "WI_I32_STORE"; - case WI_I64_STORE: return "WI_I64_STORE"; - case WI_F32_STORE: return "WI_F32_STORE"; - case WI_F64_STORE: return "WI_F64_STORE"; - case WI_I32_STORE_8: return "WI_I32_STORE_8"; - case WI_I32_STORE_16: return "WI_I32_STORE_16"; - case WI_I64_STORE_8: return "WI_I64_STORE_8"; - case WI_I64_STORE_16: return "WI_I64_STORE_16"; - case WI_I64_STORE_32: return "WI_I64_STORE_32"; - case WI_MEMORY_SIZE: return "WI_MEMORY_SIZE"; - case WI_MEMORY_GROW: return "WI_MEMORY_GROW"; - case WI_I32_CONST: return "WI_I32_CONST"; - case WI_I64_CONST: return "WI_I64_CONST"; - case WI_F32_CONST: return "WI_F32_CONST"; - case WI_F64_CONST: return "WI_F64_CONST"; - case WI_I32_EQZ: return "WI_I32_EQZ"; - case WI_I32_EQ: return "WI_I32_EQ"; - case WI_I32_NE: return "WI_I32_NE"; - case WI_I32_LT_S: return "WI_I32_LT_S"; - case WI_I32_LT_U: return "WI_I32_LT_U"; - case WI_I32_GT_S: return "WI_I32_GT_S"; - case WI_I32_GT_U: return "WI_I32_GT_U"; - case WI_I32_LE_S: return "WI_I32_LE_S"; - case WI_I32_LE_U: return "WI_I32_LE_U"; - case WI_I32_GE_S: return "WI_I32_GE_S"; - case WI_I32_GE_U: return "WI_I32_GE_U"; - case WI_I64_EQZ: return "WI_I64_EQZ"; - case WI_I64_EQ: return "WI_I64_EQ"; - case WI_I64_NE: return "WI_I64_NE"; - case WI_I64_LT_S: return "WI_I64_LT_S"; - case WI_I64_LT_U: return "WI_I64_LT_U"; - case WI_I64_GT_S: return "WI_I64_GT_S"; - case WI_I64_GT_U: return "WI_I64_GT_U"; - case WI_I64_LE_S: return "WI_I64_LE_S"; - case WI_I64_LE_U: return "WI_I64_LE_U"; - case WI_I64_GE_S: return "WI_I64_GE_S"; - case WI_I64_GE_U: return "WI_I64_GE_U"; - case WI_F32_EQ: return "WI_F32_EQ"; - case WI_F32_NE: return "WI_F32_NE"; - case WI_F32_LT: return "WI_F32_LT"; - case WI_F32_GT: return "WI_F32_GT"; - case WI_F32_LE: return "WI_F32_LE"; - case WI_F32_GE: return "WI_F32_GE"; - case WI_F64_EQ: return "WI_F64_EQ"; - case WI_F64_NE: return "WI_F64_NE"; - case WI_F64_LT: return "WI_F64_LT"; - case WI_F64_GT: return "WI_F64_GT"; - case WI_F64_LE: return "WI_F64_LE"; - case WI_F64_GE: return "WI_F64_GE"; - case WI_I32_CLZ: return "WI_I32_CLZ"; - case WI_I32_CTZ: return "WI_I32_CTZ"; - case WI_I32_POPCNT: return "WI_I32_POPCNT"; - case WI_I32_ADD: return "WI_I32_ADD"; - case WI_I32_SUB: return "WI_I32_SUB"; - case WI_I32_MUL: return "WI_I32_MUL"; - case WI_I32_DIV_S: return "WI_I32_DIV_S"; - case WI_I32_DIV_U: return "WI_I32_DIV_U"; - case WI_I32_REM_S: return "WI_I32_REM_S"; - case WI_I32_REM_U: return "WI_I32_REM_U"; - case WI_I32_AND: return "WI_I32_AND"; - case WI_I32_OR: return "WI_I32_OR"; - case WI_I32_XOR: return "WI_I32_XOR"; - case WI_I32_SHL: return "WI_I32_SHL"; - case WI_I32_SHR_S: return "WI_I32_SHR_S"; - case WI_I32_SHR_U: return "WI_I32_SHR_U"; - case WI_I32_ROTL: return "WI_I32_ROTL"; - case WI_I32_ROTR: return "WI_I32_ROTR"; - case WI_I64_CLZ: return "WI_I64_CLZ"; - case WI_I64_CTZ: return "WI_I64_CTZ"; - case WI_I64_POPCNT: return "WI_I64_POPCNT"; - case WI_I64_ADD: return "WI_I64_ADD"; - case WI_I64_SUB: return "WI_I64_SUB"; - case WI_I64_MUL: return "WI_I64_MUL"; - case WI_I64_DIV_S: return "WI_I64_DIV_S"; - case WI_I64_DIV_U: return "WI_I64_DIV_U"; - case WI_I64_REM_S: return "WI_I64_REM_S"; - case WI_I64_REM_U: return "WI_I64_REM_U"; - case WI_I64_AND: return "WI_I64_AND"; - case WI_I64_OR: return "WI_I64_OR"; - case WI_I64_XOR: return "WI_I64_XOR"; - case WI_I64_SHL: return "WI_I64_SHL"; - case WI_I64_SHR_S: return "WI_I64_SHR_S"; - case WI_I64_SHR_U: return "WI_I64_SHR_U"; - case WI_I64_ROTL: return "WI_I64_ROTL"; - case WI_I64_ROTR: return "WI_I64_ROTR"; - case WI_F32_ABS: return "WI_F32_ABS"; - case WI_F32_NEG: return "WI_F32_NEG"; - case WI_F32_CEIL: return "WI_F32_CEIL"; - case WI_F32_FLOOR: return "WI_F32_FLOOR"; - case WI_F32_TRUNC: return "WI_F32_TRUNC"; - case WI_F32_NEAREST: return "WI_F32_NEAREST"; - case WI_F32_SQRT: return "WI_F32_SQRT"; - case WI_F32_ADD: return "WI_F32_ADD"; - case WI_F32_SUB: return "WI_F32_SUB"; - case WI_F32_MUL: return "WI_F32_MUL"; - case WI_F32_DIV: return "WI_F32_DIV"; - case WI_F32_MIN: return "WI_F32_MIN"; - case WI_F32_MAX: return "WI_F32_MAX"; - case WI_F32_COPYSIGN: return "WI_F32_COPYSIGN"; - case WI_F64_ABS: return "WI_F64_ABS"; - case WI_F64_NEG: return "WI_F64_NEG"; - case WI_F64_CEIL: return "WI_F64_CEIL"; - case WI_F64_FLOOR: return "WI_F64_FLOOR"; - case WI_F64_TRUNC: return "WI_F64_TRUNC"; - case WI_F64_NEAREST: return "WI_F64_NEAREST"; - case WI_F64_SQRT: return "WI_F64_SQRT"; - case WI_F64_ADD: return "WI_F64_ADD"; - case WI_F64_SUB: return "WI_F64_SUB"; - case WI_F64_MUL: return "WI_F64_MUL"; - case WI_F64_DIV: return "WI_F64_DIV"; - case WI_F64_MIN: return "WI_F64_MIN"; - case WI_F64_MAX: return "WI_F64_MAX"; - case WI_F64_COPYSIGN: return "WI_F64_COPYSIGN"; - case WI_I32_FROM_I64: return "WI_I32_FROM_I64"; - case WI_I32_FROM_F32_S: return "WI_I32_FROM_F32_S"; - case WI_I32_FROM_F32_U: return "WI_I32_FROM_F32_U"; - case WI_I32_FROM_F64_S: return "WI_I32_FROM_F64_S"; - case WI_I32_FROM_F64_U: return "WI_I32_FROM_F64_U"; - case WI_I64_FROM_I32_S: return "WI_I64_FROM_I32_S"; - case WI_I64_FROM_I32_U: return "WI_I64_FROM_I32_U"; - case WI_I64_FROM_F32_S: return "WI_I64_FROM_F32_S"; - case WI_I64_FROM_F32_U: return "WI_I64_FROM_F32_U"; - case WI_I64_FROM_F64_S: return "WI_I64_FROM_F64_S"; - case WI_I64_FROM_F64_U: return "WI_I64_FROM_F64_U"; - case WI_F32_FROM_I32_S: return "WI_F32_FROM_I32_S"; - case WI_F32_FROM_I32_U: return "WI_F32_FROM_I32_U"; - case WI_F32_FROM_I64_S: return "WI_F32_FROM_I64_S"; - case WI_F32_FROM_I64_U: return "WI_F32_FROM_I64_U"; - case WI_F32_FROM_F64: return "WI_F32_FROM_F64"; - case WI_F64_FROM_I32_S: return "WI_F64_FROM_I32_S"; - case WI_F64_FROM_I32_U: return "WI_F64_FROM_I32_U"; - case WI_F64_FROM_I64_S: return "WI_F64_FROM_I64_S"; - case WI_F64_FROM_I64_U: return "WI_F64_FROM_I64_U"; - case WI_F64_FROM_F32: return "WI_F64_FROM_F32"; - case WI_I32_REINTERPRET_F32: return "WI_I32_REINTERPRET_F32"; - case WI_I64_REINTERPRET_F64: return "WI_I64_REINTERPRET_F64"; - case WI_F32_REINTERPRET_I32: return "WI_F32_REINTERPRET_I32"; - case WI_F64_REINTERPRET_I64: return "WI_F64_REINTERPRET_I64"; - case WI_I32_EXTEND_8_S: return "WI_I32_EXTEND_8_S"; - case WI_I32_EXTEND_16_S: return "WI_I32_EXTEND_16_S"; - case WI_I64_EXTEND_8_S: return "WI_I64_EXTEND_8_S"; - case WI_I64_EXTEND_16_S: return "WI_I64_EXTEND_16_S"; - case WI_I64_EXTEND_32_S: return "WI_I64_EXTEND_32_S"; - } -} - static WasmType onyx_type_to_wasm_type(Type* type) { if (type->kind == Type_Kind_Struct) { return WASM_TYPE_VOID; @@ -321,7 +139,7 @@ static u64 local_allocate(LocalAllocator* la, AstTyped* local) { if (size % alignment != 0) size += alignment - (size % alignment); - if (la->max_stack - la->curr_stack >= size) { + if (la->max_stack - la->curr_stack >= (i32) size) { la->curr_stack += size; } else { la->max_stack += size - (la->max_stack - la->curr_stack); @@ -617,7 +435,7 @@ EMIT_FUNC(assignment_of_array, AstBinaryOp* assign) { if (!type_is_structlike(elem_type)) WIL(WI_LOCAL_GET, lptr_local); - if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == rptr_local) + if (bh_arr_last(code).type == WI_LOCAL_SET && (u64) bh_arr_last(code).data.l == rptr_local) bh_arr_last(code).type = WI_LOCAL_TEE; else WIL(WI_LOCAL_GET, rptr_local); @@ -1415,7 +1233,7 @@ EMIT_FUNC(call, AstCall* call) { u64 stack_top_idx = bh_imap_get(&mod->index_map, (u64) &builtin_stack_top); u32 vararg_count = 0; - u32 vararg_offset = -1; + u32 vararg_offset = 0xffffffff; u64 stack_top_store_local; bh_arr_each(AstArgument *, parg, call->arg_arr) { @@ -1425,7 +1243,7 @@ EMIT_FUNC(call, AstCall* call) { b32 arg_is_struct = type_is_structlike(arg->value->type); if (arg->va_kind != VA_Kind_Not_VA) { - if (vararg_offset == -1) vararg_offset = stack_grow_amm; + if (vararg_offset == 0xffffffff) vararg_offset = stack_grow_amm; place_on_stack = 1; } if (type_get_param_pass(arg->value->type) == Param_Pass_By_Implicit_Pointer) place_on_stack = 1; @@ -2101,7 +1919,7 @@ EMIT_FUNC(struct_store, Type* type, u64 offset) { type_lookup_member_by_idx(type, i, &smem); if (type_is_structlike_strict(smem.type)) { - if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == loc_idx) { + if (bh_arr_last(code).type == WI_LOCAL_SET && (u64) bh_arr_last(code).data.l == loc_idx) { bh_arr_last(code).type = WI_LOCAL_TEE; } else { WIL(WI_LOCAL_GET, loc_idx); @@ -2273,7 +2091,7 @@ EMIT_FUNC(expression, AstTyped* expr) { u64 tmp = bh_imap_get(&mod->local_map, (u64) expr); if (tmp & LOCAL_IS_WASM) { - if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == tmp) { + if (bh_arr_last(code).type == WI_LOCAL_SET && (u64) bh_arr_last(code).data.l == tmp) { bh_arr_last(code).type = WI_LOCAL_TEE; } else { WIL(WI_LOCAL_GET, tmp); @@ -2884,7 +2702,7 @@ static void emit_function(OnyxWasmModule* mod, AstFunction* fd) { // HACK: This is gross bh_arr_grow(mod->funcs, func_idx - mod->foreign_function_count + 1); mod->funcs[func_idx - mod->foreign_function_count] = wasm_func; - bh_arr_set_length(mod->funcs, bh_max(bh_arr_length(mod->funcs), func_idx - mod->foreign_function_count + 1)); + bh_arr_set_length(mod->funcs, bh_max((u32) bh_arr_length(mod->funcs), func_idx - mod->foreign_function_count + 1)); // NOTE: Clear the local map on exit of generating this function bh_imap_clear(&mod->local_map); @@ -2943,7 +2761,7 @@ static void emit_global(OnyxWasmModule* module, AstGlobal* global) { bh_arr_grow(module->globals, global_idx - module->foreign_global_count + 1); module->globals[global_idx - module->foreign_global_count] = glob; - bh_arr_set_length(module->globals, bh_max(bh_arr_length(module->globals), global_idx - module->foreign_global_count + 1)); + bh_arr_set_length(module->globals, bh_max((u32) bh_arr_length(module->globals), global_idx - module->foreign_global_count + 1)); if (global->flags & Ast_Flag_Global_Stack_Top) module->stack_top_ptr = &module->globals[global_idx - module->foreign_global_count].initial_value[0].data.i1;