From 06d577d4e83b5058501ce48dc694c0f6ab8f39ea Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 11 Dec 2020 17:06:42 -0600 Subject: [PATCH] forgot to add the important changes to the last commit --- docs/todo | 2 +- include/onyxastnodes.h | 1 + src/onyxparser.c | 58 +++++++++++++++++++++--------------------- src/onyxutils.c | 1 + 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/docs/todo b/docs/todo index 752156df..def77412 100644 --- 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, diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 34fd7623..9018dfd9 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -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, diff --git a/src/onyxparser.c b/src/onyxparser.c index 903311c9..a2028659 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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; diff --git a/src/onyxutils.c b/src/onyxutils.c index 666814e9..82c4e6f8 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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", -- 2.25.1