bh__arr_grow(bh_arr_allocator(arr), (void **) &(arr), sizeof(*(arr)), bh_arr_length(arr) + 1), \
arr[bh__arrhead(arr)->length++] = value)
+#define bh_arr_set_at(arr, n, value) ( \
+ bh__arr_grow(bh_arr_allocator(arr), (void **) &(arr), sizeof(*(arr)), (n) + 1), \
+ bh_arr_set_length((arr), bh_max(bh_arr_length(arr), (i32) (n) + 1)), \
+ arr[n] = value)
+
#define bh_arr_is_empty(arr) (arr ? bh__arrhead(arr)->length == 0 : 1)
#define bh_arr_clear(arr) (arr ? (bh__arrhead(arr)->length = 0) : 0)
bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_BLOCK_END, 0x00 }));
- // HACK: This is gross
- bh_arr_grow(mod->funcs, func_idx - mod->foreign_function_count + 1);
- mod->funcs[func_idx - mod->foreign_function_count] = wasm_func;
- bh_arr_set_length(mod->funcs, bh_max((u32) bh_arr_length(mod->funcs), func_idx - mod->foreign_function_count + 1));
+ bh_arr_set_at(mod->funcs, func_idx - mod->foreign_function_count, wasm_func);
// NOTE: Clear the local map on exit of generating this function
bh_imap_clear(&mod->local_map);
default: assert(("Invalid global type", 0)); break;
}
- bh_arr_grow(module->globals, global_idx - module->foreign_global_count + 1);
- module->globals[global_idx - module->foreign_global_count] = glob;
- bh_arr_set_length(module->globals, bh_max((u32) bh_arr_length(module->globals), global_idx - module->foreign_global_count + 1));
+ bh_arr_set_at(module->globals, global_idx - module->foreign_global_count, glob);
if (global->flags & Ast_Flag_Global_Stack_Top)
module->stack_top_ptr = &module->globals[global_idx - module->foreign_global_count].initial_value[0].data.i1;