bugfix with foreign globals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Dec 2020 16:49:40 +0000 (10:49 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Dec 2020 16:49:40 +0000 (10:49 -0600)
docs/todo
onyx
src/onyxparser.c
src/onyxsymres.c
src/onyxwasm.c

index 9a7dea09a44960f716c144cebedb5d1f7aa6214a..4f97f4924fbed96f0fc56eb9d143cc81302f2ec2 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -73,7 +73,7 @@ API Expansion:
         - 'core.array' contains a lot of functionality that would also apply to
           slices. 'core.slice' should contain this functionality and 'core.array'
           can provide wrappers that convert the array to a slice.
-        - 'core.str' is a bad name, it should be 'core.string'. The issue is that
+         'core.str' is a bad name, it should be 'core.string'. The issue is that
           it conflicts with 'builtin.string'. These two should be switched. Type
           name should be 'str' and package name should be 'string'
 
diff --git a/onyx b/onyx
index be7fee5fe0d7b92d25f8655bd21302f261b227fa..2248b973e3042199fa153786766d78384f7d5a81 100755 (executable)
Binary files a/onyx and b/onyx differ
index ff8fc4664921cb5d2f35a47a6678e71514c2a5ea..903311c907b3bcf866df71edf2d24e9b4ca7e359 100644 (file)
@@ -2015,7 +2015,10 @@ static AstNode* parse_top_level_statement(OnyxParser* parser) {
                     return (AstNode *) include;
                 }
                 else {
-                    onyx_report_error(dir_token->pos, "unknown directive '#%b'.", dir_token->text, dir_token->length);
+                    OnyxToken* directive_token = expect_token(parser, '#');
+                    OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol);
+
+                    onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length);
                     return NULL;
                 }
             }
index a963d6b36dabafad0f51e5a54cbd328629a2d0ba..7d054a2ee03bc1e66a7a4360693bdd7554735277 100644 (file)
@@ -102,7 +102,7 @@ AstType* symres_type(AstType* type) {
             AstStructMember *member = s_node->members[i];
             member->type_node = symres_type(member->type_node);
 
-            if (!node_is_type(member->type_node)) {
+            if (!node_is_type((AstNode *) member->type_node)) {
                 onyx_report_error(member->token->pos, "Member type is not a type.");
                 return type;
             }
@@ -791,9 +791,11 @@ void symres_entity(Entity* ent) {
         case Entity_Type_Foreign_Function_Header:
         case Entity_Type_Function:            symres_function(ent->function); break;
 
+        case Entity_Type_Foreign_Global_Header:
+        case Entity_Type_Global_Header:       symres_global(ent->global); break;
+
         case Entity_Type_Use_Package:         symres_use_package(ent->use_package); break;
         case Entity_Type_Overloaded_Function: symres_overloaded_function(ent->overloaded_function); break;
-        case Entity_Type_Global:              symres_global(ent->global); break;
         case Entity_Type_Expression:          symres_expression(&ent->expr); break;
         case Entity_Type_Type_Alias:          ent->type_alias = symres_type(ent->type_alias); break;
         case Entity_Type_Enum:                symres_enum(ent->enum_type); break;
index 0048a2b1af58d3d007a327ec6b150ad62f656352..7428f6f4160ecc52e32e4e7d824791b45d15d0dd 100644 (file)
@@ -2801,16 +2801,12 @@ static void emit_global(OnyxWasmModule* module, AstGlobal* global) {
         default: assert(("Invalid global type", 0)); break;
     }
 
-    bh_arr_grow(module->globals, global_idx + 1);
-    module->globals[global_idx] = glob;
-    bh_arr_set_length(module->globals, bh_max(bh_arr_length(module->globals), global_idx + 1));
-
     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(bh_arr_length(module->globals), global_idx - module->foreign_global_count + 1));
 
     if (global->flags & Ast_Flag_Global_Stack_Top)
-        module->stack_top_ptr = &module->globals[global_idx].initial_value[0].data.i1;
+        module->stack_top_ptr = &module->globals[global_idx - module->foreign_global_count].initial_value[0].data.i1;
 }
 
 static void emit_foreign_global(OnyxWasmModule* module, AstGlobal* global) {