From 7f1d01b23ef8e3ab2a8383cbf4e7607fb827f047 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 31 Dec 2024 10:17:48 -0600 Subject: [PATCH] added: `#error` in statements; `Set.from` --- compiler/src/library_main.c | 6 +----- compiler/src/parser.c | 9 +++++++++ core/container/iter.onyx | 3 +++ core/container/set.onyx | 11 +++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/compiler/src/library_main.c b/compiler/src/library_main.c index e4c03057..ee36d898 100644 --- a/compiler/src/library_main.c +++ b/compiler/src/library_main.c @@ -487,7 +487,7 @@ onyx_pump_t onyx_pump(onyx_context_t *ctx) { // cycle detection algorithm must be used. // if (!changed) { - if (!context->watermarked_node) { + if (!context->watermarked_node || context->watermarked_node->macro_attempts < ent->macro_attempts) { context->watermarked_node = ent; context->highest_watermark = bh_max(context->highest_watermark, ent->macro_attempts); } @@ -506,10 +506,6 @@ onyx_pump_t onyx_pump(onyx_context_t *ctx) { context->cycle_almost_detected += 1; } } - else if (context->watermarked_node->macro_attempts < ent->macro_attempts) { - context->watermarked_node = ent; - context->highest_watermark = bh_max(context->highest_watermark, ent->macro_attempts); - } } else { context->watermarked_node = NULL; context->cycle_almost_detected = 0; diff --git a/compiler/src/parser.c b/compiler/src/parser.c index 7f0d4fad..021c0be5 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -2143,6 +2143,15 @@ static AstNode* parse_statement(OnyxParser* parser) { break; } + if (parse_possible_directive(parser, "error")) { + AstDirectiveError *error = make_node(AstDirectiveError, Ast_Kind_Directive_Error); + error->token = parser->curr - 2; + error->error_msg = expect_token(parser, Token_Type_Literal_String); + + ENTITY_SUBMIT(error); + break; + } + if (next_tokens_are(parser, 2, '#', Token_Type_Symbol)) { retval = (AstNode *) parse_factor(parser); break; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index f78205a2..9557440d 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -52,6 +52,9 @@ Iterator.generator_no_copy :: generator_no_copy Iterator.comp :: comp Iterator.prod :: prod +Iterator.single :: single +Iterator.const :: const + /// The standard function to convert something to an Iterator. diff --git a/core/container/set.onyx b/core/container/set.onyx index 97a61e67..5bc42f82 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -36,6 +36,17 @@ Set.make :: ($T: type_expr, allocator := context.allocator) -> Set(T) { return set; } +Set.from :: (arr: [] $T, allocator := context.allocator) -> Set(T) { + set : Set(T) + Set.init(&set, allocator=allocator) + + for a in arr { + Set.insert(&set, a) + } + + return set +} + #overload builtin.__make_overload :: macro (x: &Set, allocator: Allocator) => #this_package.Set.make(x.Elem_Type, allocator = allocator);