From: Brendan Hansen Date: Wed, 23 Dec 2020 02:09:32 +0000 (-0600) Subject: struct literals can be compile time known X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bf73ed9fe7ce5a41eccf9cfa328bdababcffd967;p=onyx.git struct literals can be compile time known --- diff --git a/onyx b/onyx index a876c611..20ed83eb 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index e2722741..c82b6ced 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -895,6 +895,8 @@ b32 check_struct_literal(AstStructLiteral* sl) { AstTyped** actual = sl->values; StructMember smem; + b32 all_comptime = 1; + fori (i, 0, mem_count) { if (check_expression(actual)) return 1; @@ -914,9 +916,15 @@ b32 check_struct_literal(AstStructLiteral* sl) { return 1; } + if (((*actual)->flags & Ast_Flag_Comptime) == 0) + all_comptime = 0; + actual++; } + if (all_comptime) + sl->flags |= Ast_Flag_Comptime; + return 0; } diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 000e8f27..3ae39b74 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2993,6 +2993,21 @@ static void emit_raw_data(OnyxWasmModule* mod, ptr data, AstTyped* node) { break; } + case Ast_Kind_Struct_Literal: { + AstStructLiteral* sl = (AstStructLiteral *) node; + + Type* sl_type = sl->type; + assert(sl_type->kind == Type_Kind_Struct); + + i32 i = 0; + bh_arr_each(AstTyped *, expr, sl->values) { + emit_raw_data(mod, bh_pointer_add(data, sl_type->Struct.memarr[i]->offset), *expr); + i++; + } + + break; + } + case Ast_Kind_StrLit: { AstStrLit* sl = (AstStrLit *) node;