Skip to content

Commit

Permalink
added: #error in statements; Set.from
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanfh committed Dec 31, 2024
1 parent 1367a45 commit 7f1d01b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 1 addition & 5 deletions compiler/src/library_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions compiler/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions core/container/iter.onyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions core/container/set.onyx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7f1d01b

Please sign in to comment.