From: Brendan Hansen Date: Fri, 29 Jan 2021 15:30:04 +0000 (-0600) Subject: more robust static struct bindings; zero size struct bug fix X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=7de806ffb0ce01749f5619937ca737c609909852;p=onyx.git more robust static struct bindings; zero size struct bug fix --- diff --git a/bin/onyx b/bin/onyx index 6198097d..3d0a779d 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index 872f78ca..ba6ded1d 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxparser.c b/src/onyxparser.c index 3534177f..731a0ec2 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -1845,15 +1845,16 @@ static AstStructType* parse_struct(OnyxParser* parser) { expect_token(parser, ':'); if (parser->curr->type == ':' && !member_is_used) { - consume_token(parser); if (!s_node->scope) { // NOTE: The parent scope will be filled out during symbol resolution. s_node->scope = scope_create(context.ast_alloc, NULL, s_node->token->pos); } - AstTyped* expression = parse_top_level_expression(parser); - symbol_introduce(s_node->scope, member_name, (AstNode *) expression); + AstBinding* binding = parse_top_level_binding(parser, member_name); + symbol_introduce(s_node->scope, binding->token, binding->node); + + if (parser->curr->type == ';') consume_token(parser); } else { AstStructMember* mem = make_node(AstStructMember, Ast_Kind_Struct_Member); diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 75f20d9a..c6c466a4 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -1805,7 +1805,7 @@ EMIT_FUNC(struct_lval, AstTyped* lval) { EMIT_FUNC(compound_load, Type* type, u64 offset) { bh_arr(WasmInstruction) code = *pcode; - u32 mem_count = type_linear_member_count(type); + i32 mem_count = type_linear_member_count(type); TypeWithOffset two; if (mem_count == 1) { @@ -1838,7 +1838,7 @@ EMIT_FUNC(compound_store, Type* type, u64 offset, b32 location_first) { u64 loc_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); if (location_first) WIL(WI_LOCAL_SET, loc_idx); - u32 elem_count = type_linear_member_count(type); + i32 elem_count = type_linear_member_count(type); forir (i, elem_count - 1, 0) { type_linear_member_lookup(type, i, &two);