From 779a627ff1634dfc9a0ac3ce3a0f2acc501add1f Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 28 Feb 2022 22:28:16 -0600 Subject: [PATCH] '#persist' in structs; map bugfix --- core/container/map.onyx | 4 ++-- src/parser.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/container/map.onyx b/core/container/map.onyx index 51219c3a..621817dd 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -68,8 +68,8 @@ init :: (use map: ^Map($K, $V), default := __zero_value(V)) { } free :: (use map: ^Map) { - memory.free_slice(^hashes, allocator=allocator); - array.free(^entries); + if map.hashes.data != null do memory.free_slice(^hashes, allocator=allocator); + if map.entries.data != null do array.free(^entries); } put :: (use map: ^Map, key: map.Key_Type, value: map.Value_Type) { diff --git a/src/parser.c b/src/parser.c index 9e90474b..583492ee 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1968,6 +1968,19 @@ static AstStructType* parse_struct(OnyxParser* parser) { continue; } + if (parse_possible_directive(parser, "persist")) { + b32 thread_local = parse_possible_directive(parser, "thread_local"); + + OnyxToken* symbol = expect_token(parser, Token_Type_Symbol); + AstMemRes* memres = parse_memory_reservation(parser, symbol, thread_local); + + AstBinding* binding = make_node(AstBinding, Ast_Kind_Binding); + binding->token = memres->token; + binding->node = (AstNode *) memres; + ENTITY_SUBMIT(binding); + continue; + } + if (next_tokens_are(parser, 3, Token_Type_Symbol, ':', ':')) { if (!s_node->scope) { s_node->scope = scope_create(context.ast_alloc, parser->current_scope, s_node->token->pos); -- 2.25.1