bh_allocator token_alloc, ast_alloc;
bh_arr(bh_file_contents) loaded_files;
+
+ // NOTE: This is defined in onyxwasm.h
+ struct OnyxWasmModule* wasm_module;
};
extern Context context;
b32 has_stack_locals : 1;
} OnyxWasmModule;
-extern OnyxWasmModule global_wasm_module;
-
OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc);
void onyx_wasm_module_compile(OnyxWasmModule* module);
void onyx_wasm_module_free(OnyxWasmModule* module);
bh_arena_init(&context.ast_arena, global_heap_allocator, 16 * 1024 * 1024); // 16MB
context.ast_alloc = bh_arena_allocator(&context.ast_arena);
- // HACK
- // MOVE TO CONTEXT
- global_wasm_module = onyx_wasm_module_create(context.options->allocator);
+ context.wasm_module = bh_alloc_item(global_heap_allocator, OnyxWasmModule);
+ *context.wasm_module = onyx_wasm_module_create(global_heap_allocator);
// NOTE: Add builtin entities to pipeline.
entity_heap_insert(&context.entities, ((Entity) {
if (context.options->verbose_output)
bh_printf("Outputting to WASM file: %s\n", output_file.filename);
- onyx_wasm_module_write_to_file(&global_wasm_module, output_file);
+ onyx_wasm_module_write_to_file(context.wasm_module, output_file);
u64 duration = bh_time_duration(start_time);
onyx_report_error(param->local->token->pos, "Can only 'use' structures or pointers to structures.");
} else {
+ // :ExplicitTyping
onyx_report_error(param->local->token->pos, "Cannot deduce type of parameter '%b'; Try adding it explicitly.",
param->local->token->text,
param->local->token->length);
(*member)->type = type_build_from_ast(alloc, (*member)->type_node);
if ((*member)->type == NULL) {
+ // :ExplicitTyping
onyx_report_error((*member)->token->pos, "Unable to resolve member type. Try adding it explicitly.");
s_node->stcache = NULL;
return NULL;
bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
Type* cs_type = type_build_from_ast(context.ast_alloc, (AstType *) concrete_struct);
- cs_type->Struct.poly_sln = NULL;
- bh_arr_new(global_heap_allocator, cs_type->Struct.poly_sln, bh_arr_length(slns));
- fori (i, 0, bh_arr_length(slns)) bh_arr_push(cs_type->Struct.poly_sln, slns[i]);
+ // CLEANUP: This should not be necessary since the only place this function can be
+ // called from is type_build_from_ast in the Ast_Kind_Poly_Call_Type case, which
+ // allocates the 'slns' array on the heap. So, duplicating it should not be necessary.
+ cs_type->Struct.poly_sln = bh_arr_copy(global_heap_allocator, slns);
cs_type->Struct.name = build_poly_struct_name(ps_type, cs_type);
return concrete_struct;
#include "onyxwasm.h"
#include "onyxutils.h"
-OnyxWasmModule global_wasm_module;
-
// NOTE: Allows easier testing of types since most of the characters
// corresponding to these values are not printable
#if 1
}
void emit_entity(Entity* ent) {
- OnyxWasmModule* module = &global_wasm_module;
+ OnyxWasmModule* module = context.wasm_module;
if (module->stack_top_ptr) {
*module->stack_top_ptr = module->next_datum_offset;