From: Brendan Hansen Date: Fri, 15 Oct 2021 03:46:53 +0000 (-0500) Subject: sizeof and alignof are compile time known X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8b71df7ba8bcdd0ea45ed1b6205a957b69a4d268;p=onyx.git sizeof and alignof are compile time known --- diff --git a/src/checker.c b/src/checker.c index 8b175999..91faf648 100644 --- a/src/checker.c +++ b/src/checker.c @@ -1474,6 +1474,7 @@ CheckStatus check_size_of(AstSizeOf* so) { YIELD(so->token->pos, "Trying to resolve type to take the size of."); so->size = type_size_of(so->so_type); + so->flags |= Ast_Flag_Comptime; return Check_Success; } @@ -1486,6 +1487,7 @@ CheckStatus check_align_of(AstAlignOf* ao) { YIELD(ao->token->pos, "Trying to resolve type to take the alignment of."); ao->alignment = type_alignment_of(ao->ao_type); + ao->flags |= Ast_Flag_Comptime; return Check_Success; } diff --git a/src/wasm.c b/src/wasm.c index a2861317..796bc328 100644 --- a/src/wasm.c +++ b/src/wasm.c @@ -3386,6 +3386,18 @@ static b32 emit_raw_data_(OnyxWasmModule* mod, ptr data, AstTyped* node) { break; } + case Ast_Kind_Size_Of: { + AstSizeOf* so = (AstSizeOf *) node; + *((u32 *) data) = so->size; + break; + } + + case Ast_Kind_Align_Of: { + AstAlignOf* ao = (AstAlignOf *) node; + *((u32 *) data) = ao->alignment; + break; + } + case Ast_Kind_NumLit: { // NOTE: This makes a big assumption that we are running on a // little endian machine, since WebAssembly is little endian