From: Brendan Hansen Date: Wed, 20 Jul 2022 18:06:17 +0000 (-0500) Subject: stack_size is in bytes; hex literals can be any size X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=87f15a4a6bba8048bde8ade0022ed90c425f53d9;p=onyx.git stack_size is in bytes; hex literals can be any size --- diff --git a/core/builtin.onyx b/core/builtin.onyx index c0ed2211..f13edc4b 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -296,7 +296,7 @@ __run_init_procedures :: () -> void --- // Should this be here? and/or should its name be so generic? Link_Options :: struct { stack_first := false; - stack_size := 16; // 16 pages * 65536 bytes per page = 1 MiB stack + stack_size := 16 * 65536; // 16 pages * 65536 bytes per page = 1 MiB stack stack_alignment := 16; null_reserve_size := 16; diff --git a/core/hash.onyx b/core/hash.onyx index 793b4bc9..3d85ed1a 100644 --- a/core/hash.onyx +++ b/core/hash.onyx @@ -3,7 +3,7 @@ package core.hash to_u32 :: #match { (key: rawptr) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, (key: i8) -> u32 { return ~~ key; }, - (key: i16) -> u32 { return 0x9ce7 ^ ~~ key; }, + (key: i16) -> u32 { return 0x9ce7 ^ cast(u32) key; }, (key: i32) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, (key: i64) -> u32 { return cast(u32) (cast(u64) 0xcbf29ce7 ^ cast(u64) key); }, (key: str) -> u32 { diff --git a/include/astnodes.h b/include/astnodes.h index 510698a1..6214b4b7 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -592,12 +592,22 @@ struct AstTyped { AstTyped_base; }; // Expression Nodes struct AstNamedValue { AstTyped_base; AstTyped* value; }; struct AstUnaryOp { AstTyped_base; UnaryOp operation; AstTyped *expr; }; -struct AstNumLit { AstTyped_base; union { i32 i; i64 l; f32 f; f64 d; } value; }; struct AstStrLit { AstTyped_base; u64 data_id; u64 length; b32 is_cstr: 1; }; struct AstLocal { AstTyped_base; }; struct AstDereference { AstTyped_base; AstTyped *expr; }; struct AstSizeOf { AstTyped_base; AstType *so_ast_type; Type *so_type; u64 size; }; struct AstAlignOf { AstTyped_base; AstType *ao_ast_type; Type *ao_type; u64 alignment; }; +struct AstNumLit { + AstTyped_base; + union { + i32 i; + i64 l; + f32 f; + f64 d; + } value; + + b32 was_hex_literal : 1; +}; struct AstBinaryOp { AstTyped_base; BinaryOp operation; diff --git a/src/astnodes.c b/src/astnodes.c index a888fa3f..c2ca3f07 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -886,10 +886,13 @@ Type* resolve_expression_type(AstTyped* node) { if (node->kind == Ast_Kind_NumLit && node->type->kind == Type_Kind_Basic) { if (node->type->Basic.kind == Basic_Kind_Int_Unsized) { - if (bh_abs(((AstNumLit *) node)->value.l) >= (1ull << 32)) - convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_I64]); - else - convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_I32]); + b32 big = bh_abs(((AstNumLit *) node)->value.l) >= (1ull << 32); + b32 unsign = ((AstNumLit *) node)->was_hex_literal; + + if ( big && !unsign) convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_I64]); + else if ( big && unsign) convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_U64]); + else if (!big && !unsign) convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_I32]); + else if (!big && unsign) convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_U32]); } else if (node->type->Basic.kind == Basic_Kind_Float_Unsized) { convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_F64]); diff --git a/src/parser.c b/src/parser.c index 7992ea9d..7f20a628 100644 --- a/src/parser.c +++ b/src/parser.c @@ -220,14 +220,11 @@ static AstNumLit* parse_int_literal(OnyxParser* parser) { int_node->value.l = value; + int_node->type_node = (AstType *) &basic_type_int_unsized; + // NOTE: Hex literals are unsigned. if (int_node->token->length >= 2 && int_node->token->text[1] == 'x') { - if ((u64) value >= ((u64) 1 << 32)) - int_node->type_node = (AstType *) &basic_type_u64; - else - int_node->type_node = (AstType *) &basic_type_u32; - } else { - int_node->type_node = (AstType *) &basic_type_int_unsized; + int_node->was_hex_literal = 1; } token_toggle_end(int_node->token); diff --git a/src/wasm_emit.c b/src/wasm_emit.c index b25eba7a..bc05fc95 100644 --- a/src/wasm_emit.c +++ b/src/wasm_emit.c @@ -4202,7 +4202,7 @@ void onyx_wasm_module_link(OnyxWasmModule *module, OnyxWasmLinkOptions *options) *module->stack_top_ptr = datum_offset; bh_align(*module->stack_top_ptr, options->stack_alignment); - *module->heap_start_ptr = *module->stack_top_ptr + (options->stack_size << 16); + *module->heap_start_ptr = *module->stack_top_ptr + options->stack_size; bh_align(*module->heap_start_ptr, 16); }