Ast_Flag_Symbol_Invisible = BH_BIT(18),
Ast_Flag_Header_Check_No_Error = BH_BIT(19),
+
+ Ast_Flag_Decl_Followed_By_Init = BH_BIT(20),
} AstFlags;
typedef enum UnaryOp {
YIELD(typed_stmt->token->pos, "Waiting for local variable's type.");
}
+
+ if (typed_stmt->next != NULL && typed_stmt->next->kind == Ast_Kind_Binary_Op) {
+ AstBinaryOp *next = (AstBinaryOp *) typed_stmt->next;
+ if (next->operation == Binary_Op_Assign && next->left == typed_stmt) {
+ typed_stmt->flags |= Ast_Flag_Decl_Followed_By_Init;
+ }
+ }
return Check_Success;
}
}
EMIT_FUNC(local_allocation, AstTyped* stmt) {
- bh_imap_put(&mod->local_map, (u64) stmt, local_allocate(mod->local_alloc, stmt));
+ u64 local_idx = local_allocate(mod->local_alloc, stmt);
+ bh_imap_put(&mod->local_map, (u64) stmt, local_idx);
+
+ if (stmt->kind == Ast_Kind_Local && !(stmt->flags & Ast_Flag_Decl_Followed_By_Init)) {
+ bh_arr(WasmInstruction) code = *pcode;
+ if (local_is_wasm_local(stmt)) {
+ emit_zero_value(mod, &code, onyx_type_to_wasm_type(stmt->type));
+ WIL(WI_LOCAL_SET, local_idx);
+
+ } else {
+ emit_location(mod, &code, stmt);
+ WID(WI_I32_CONST, 0);
+ WID(WI_I32_CONST, type_size_of(stmt->type));
+ if (context.options->use_post_mvp_features) {
+ WID(WI_MEMORY_FILL, 0x00);
+ } else {
+ emit_intrinsic_memory_fill(mod, &code);
+ }
+ }
+
+ *pcode = code;
+ }
bh_arr_push(mod->local_allocations, ((AllocatedSpace) {
.depth = bh_arr_length(mod->structured_jump_target),