cleaned up global_wasm_module
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 24 Jan 2021 20:14:32 +0000 (14:14 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 24 Jan 2021 20:14:32 +0000 (14:14 -0600)
bin/onyx
include/onyxastnodes.h
include/onyxwasm.h
onyx.exe
src/onyx.c
src/onyxsymres.c
src/onyxtypes.c
src/onyxutils.c
src/onyxwasm.c

index c5b5e78d17dde5602e99bcb85a68c5f64fd632de..72ff9a00bb26215a174a3993fda44b1cdd77a826 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 78cce0947444fe066204c5a94ede5d232ea61ff5..c4b4c5c9627a5c5f98a5b44b41d35d37820a4dca 100644 (file)
@@ -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;
index 4e6dc71934c8af30adc47219e43446c2dfaaa559..3d966549a19902584d30a4476dbc988f3a37463f 100644 (file)
@@ -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);
index 623482be9e94194e3603b651f580b888646476b1..d09df0c3b6339eb8582c0cc4090b9a3ef7c7ce47 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 9a6b0ccda7b1d75cc62b9a2ac73d17f6bdfffbc3..a46a6a62d99402b41ac8e495c339fa94a7dc1aea 100644 (file)
@@ -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);
     
index a755ae31520e27cddc32478a8687589c86d1d3d3..1fd4bfe6b6b69a1205d8d5de1799dfa4b2e12539 100644 (file)
@@ -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);
index 0b39bc40c8843aeb40a7ee1c22cc0c401fe2524b..32a881581c122b69029e677e267136bb1d1641f1 100644 (file)
@@ -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;
index dc4dfdd636a4a671d0f71d32f05b4981d52f5a24..6baf25ca21c24f3813fe7cccfe80e733a36f2361 100644 (file)
@@ -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;
index 6ed8198310bd0022c02494012e0962fd74709cf5..f6176f404a5fa0e03404a3e1fc0e58f994d3f7ca 100644 (file)
@@ -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;