From: Brendan Hansen Date: Sun, 24 Jan 2021 20:14:32 +0000 (-0600) Subject: cleaned up global_wasm_module X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6006e86c8af0de17cde588d3028081637c8d185c;p=onyx.git cleaned up global_wasm_module --- diff --git a/bin/onyx b/bin/onyx index c5b5e78d..72ff9a00 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 78cce094..c4b4c5c9 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -974,6 +974,9 @@ struct Context { 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; diff --git a/include/onyxwasm.h b/include/onyxwasm.h index 4e6dc719..3d966549 100644 --- a/include/onyxwasm.h +++ b/include/onyxwasm.h @@ -543,8 +543,6 @@ typedef struct OnyxWasmModule { 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); diff --git a/onyx.exe b/onyx.exe index 623482be..d09df0c3 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyx.c b/src/onyx.c index 9a6b0ccd..a46a6a62 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -148,9 +148,8 @@ static void context_init(CompileOptions* opts) { 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) { @@ -551,7 +550,7 @@ static i32 onyx_compile() { 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); diff --git a/src/onyxsymres.c b/src/onyxsymres.c index a755ae31..1fd4bfe6 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -753,6 +753,7 @@ void symres_function(AstFunction* func) { 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); diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 0b39bc40..32a88158 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -384,6 +384,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { (*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; diff --git a/src/onyxutils.c b/src/onyxutils.c index dc4dfdd6..6baf25ca 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -985,10 +985,11 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP 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; diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 6ed81983..f6176f40 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2,8 +2,6 @@ #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 @@ -3225,7 +3223,7 @@ OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) { } 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;