forgot to add the important changes to the last commit
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Dec 2020 23:06:42 +0000 (17:06 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Dec 2020 23:06:42 +0000 (17:06 -0600)
docs/todo
include/onyxastnodes.h
src/onyxparser.c
src/onyxutils.c

index 752156df7071ab99de11966146ec0886b3c05e16..def77412db6347dfce219ba9660f14f84688a1f7 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -65,7 +65,7 @@ Language Cohesion:
         the underlying issue is fixed.
 
 API Expansion:
-    There are many differeny places where the standard API for WASI and JS
+    There are many different places where the standard API for WASI and JS
     backends could be improved. Here are some of the target areas.
 
     [ ] Rearrange APIs. There is a lot of functionality in the standard libraries,
index 34fd76232d3cb5585091568b67beec68fc4710c1..9018dfd9a7e21b5390a35e200277b0409f85fd1a 100644 (file)
@@ -719,6 +719,7 @@ typedef enum EntityType {
     Entity_Type_Enum,
     Entity_Type_Type_Alias,
     Entity_Type_Memory_Reservation,
+    Entity_Type_Use,
     Entity_Type_Polymorphic_Proc,
     Entity_Type_Foreign_Function_Header,
     Entity_Type_Foreign_Global_Header,
index 903311c907b3bcf866df71edf2d24e9b4ca7e359..a2028659d9f387c7c03127079011f1da23c66db3 100644 (file)
@@ -191,24 +191,26 @@ static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped** ret) {
 
     STORE_PARSER_STATE;
 
-    OnyxToken *symbol1 = NULL, *symbol2 = NULL;
-    symbol1 = expect_token(parser, Token_Type_Symbol);
+    bh_arr(OnyxToken *) syms = NULL;
+    bh_arr_new(global_heap_allocator, syms, 4);
 
-    if (!soft_expect_token(parser, '.')) {
-        RESTORE_PARSER_STATE;
-        return 0;
-    }
+    b32 success = 1;
+    while (parser->curr->type == Token_Type_Symbol) {
+        if (parser->hit_unexpected_token) break;
 
-    if (parser->curr->type == Token_Type_Symbol) {
-        symbol2 = soft_expect_token(parser, Token_Type_Symbol);
+        OnyxToken* symbol = soft_expect_token(parser, Token_Type_Symbol);
+        bh_arr_push(syms, symbol);
 
         if (!soft_expect_token(parser, '.')) {
-            RESTORE_PARSER_STATE;
-            return 0;
+            success = 0;
+            break;
         }
     }
 
-    if (parser->curr->type != '{') {
+    if (parser->curr->type != '{') success = 0;
+
+    if (!success) {
+        bh_arr_free(syms);
         RESTORE_PARSER_STATE;
         return 0;
     }
@@ -216,6 +218,17 @@ static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped** ret) {
     AstStructLiteral* sl = make_node(AstStructLiteral, Ast_Kind_Struct_Literal);
     sl->token = parser->curr;
 
+    sl->stnode = make_node(AstTyped, Ast_Kind_Symbol);
+    sl->stnode->token = syms[0];
+
+    for (i32 i = 1; i < bh_arr_length(syms); i++) {
+        AstFieldAccess* fa = make_node(AstFieldAccess, Ast_Kind_Field_Access);
+        fa->token = syms[i];
+        fa->expr = sl->stnode;
+        sl->stnode = (AstTyped *) fa;
+    }
+    bh_arr_free(syms);
+
     bh_arr_new(global_heap_allocator, sl->values, 4);
     bh_arr_new(global_heap_allocator, sl->named_values, 4);
     fori (i, 0, 4) {
@@ -223,21 +236,6 @@ static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped** ret) {
         sl->named_values[i] = NULL;
     }
 
-    if (symbol2 != NULL) {
-        AstTyped *package = make_node(AstTyped, Ast_Kind_Symbol);
-        package->token = symbol1;
-
-        AstFieldAccess *fa = make_node(AstFieldAccess, Ast_Kind_Field_Access);
-        fa->token = symbol2;
-        fa->expr = package;
-
-        sl->stnode = (AstTyped *) fa;
-
-    } else {
-        sl->stnode = make_node(AstTyped, Ast_Kind_Symbol);
-        sl->stnode->token = symbol1;
-    }
-
     expect_token(parser, '{');
     b32 is_named = ((parser->curr + 1)->type == '=');
 
@@ -272,7 +270,6 @@ static b32 parse_possible_struct_literal(OnyxParser* parser, AstTyped** ret) {
     expect_token(parser, '}');
 
     *ret = (AstTyped *) sl;
-
     return 1;
 }
 
@@ -922,7 +919,8 @@ static AstSwitch* parse_switch_stmt(OnyxParser* parser) {
     expect_token(parser, '{');
 
     AstTyped** batch_cases = NULL;
-    bh_arr_new(global_scratch_allocator, batch_cases, 16);
+    // NOTE: Look into bugs relating to switching this to the scratch allocator
+    bh_arr_new(global_heap_allocator, batch_cases, 16);
 
     while (parser->curr->type == Token_Type_Keyword_Case) {
         expect_token(parser, Token_Type_Keyword_Case);
@@ -960,6 +958,8 @@ static AstSwitch* parse_switch_stmt(OnyxParser* parser) {
         bh_arr_clear(batch_cases);
     }
 
+    bh_arr_free(batch_cases);
+
     expect_token(parser, '}');
     return switch_node;
 }
@@ -1282,7 +1282,7 @@ static AstType* parse_type(OnyxParser* parser) {
 
             u64 param_count = bh_arr_length(params);
             AstFunctionType* new = onyx_ast_node_new(parser->allocator,
-                    sizeof(AstFunctionType) + sizeof(AstType) * param_count,
+                    sizeof(AstFunctionType) + sizeof(AstType*) * param_count,
                     Ast_Kind_Function_Type);
             new->token = proc_token;
             new->param_count = param_count;
index 666814e9b42b670d7c01078f959cfc2e8ff4c8de..82c4e6f814fef8f88e81fc423fa68ac2374f1008 100644 (file)
@@ -115,6 +115,7 @@ const char* entity_type_strings[Entity_Type_Count] = {
     "Enum",
     "Type Alias",
     "Memory Reservation",
+    "Use",
     "Polymorphic Proc",
     "Foreign_Function Header",
     "Foreign_Global Header",