sizeof and alignof are compile time known
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 03:46:53 +0000 (22:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 03:46:53 +0000 (22:46 -0500)
src/checker.c
src/wasm.c

index 8b175999e5c000223e8a58171440fd4dd2a3ed43..91faf648dc64b109432bbb132109afe42149063a 100644 (file)
@@ -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;
 }
index a28613173297804fb66a7fe9671def42b179952a..796bc328684251819f7a27747f2a22271e5aa17b 100644 (file)
@@ -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