From 15cb7385611194bd74803e65acf455a644cdb0a6 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 16 Dec 2020 12:17:00 -0600 Subject: [PATCH] fixed a NASTY stack and local bug --- src/onyxsymres.c | 6 +++--- src/onyxwasm.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 9107fe66..4eae838e 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -446,7 +446,7 @@ static void symres_if(AstIfWhile* ifnode) { ifnode->scope = scope_create(semstate.node_allocator, semstate.curr_scope, ifnode->token->pos); scope_enter(ifnode->scope); - symbol_introduce(semstate.curr_scope, ifnode->local->token, (AstNode *) ifnode->local); + symres_local(&ifnode->local); symres_statement((AstNode **) &ifnode->assignment); } @@ -464,7 +464,7 @@ static void symres_while(AstIfWhile* whilenode) { whilenode->scope = scope_create(semstate.node_allocator, semstate.curr_scope, whilenode->token->pos); scope_enter(whilenode->scope); - symbol_introduce(semstate.curr_scope, whilenode->local->token, (AstNode *) whilenode->local); + symres_local(&whilenode->local); symres_statement((AstNode **) &whilenode->assignment); } @@ -483,7 +483,7 @@ static void symres_for(AstFor* fornode) { symres_expression(&fornode->iter); - symbol_introduce(semstate.curr_scope, fornode->var->token, (AstNode *) fornode->var); + symres_local(&fornode->var); symres_block(fornode->stmt); diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 9b9b35c5..55c8f59a 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -1010,6 +1010,7 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { if (!type_is_structlike(var->type)) { emit_store_instruction(mod, &code, var->type, offset); } else { + offset = 0; emit_local_location(mod, &code, var, &offset); emit_store_instruction(mod, &code, var->type, offset); } @@ -3071,7 +3072,8 @@ OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) { .next_global_idx = 0, .data = NULL, - .next_datum_offset = 0, + .next_datum_offset = 32, // Starting offset so null pointers don't immediately + // break constant data. - brendanfh 2020/12/16 .elems = NULL, .next_elem_idx = 0, -- 2.25.1