stack_size is in bytes; hex literals can be any size
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Jul 2022 18:06:17 +0000 (13:06 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Jul 2022 18:06:17 +0000 (13:06 -0500)
core/builtin.onyx
core/hash.onyx
include/astnodes.h
src/astnodes.c
src/parser.c
src/wasm_emit.c

index c0ed221181a9d817dc2c1ce10a931de42f8d83a6..f13edc4b4905ba0313bb420d8c5d16297997fa23 100644 (file)
@@ -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;
index 793b4bc9a595577fb30bd31cb05f13ca077c36b9..3d85ed1af55b61e2aabe18751acdeedfc71ba2f8 100644 (file)
@@ -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 {
index 510698a1f9ac6f137d481e42339a08ad3015918e..6214b4b76262d151ad9f89f927396beeaa72afd1 100644 (file)
@@ -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;
index a888fa3f8c22c26fbd498d76b386363558a52f5b..c2ca3f0725011dc59dea22b8a399be34fd09b5fa 100644 (file)
@@ -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]);
index 7992ea9d2fc0de2bffb7e9150ad1c66b9d7ebe50..7f20a628d8cb8bce405d91a2114feacbb75a2ce0 100644 (file)
@@ -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);
index b25eba7a20aec315cffa36c776201082703f78b7..bc05fc95cbd2ca1dae4864d4ae3561e4475f5697 100644 (file)
@@ -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);
 }