// 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;
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 {
// 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;
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]);
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);
*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);
}