From: Brendan Hansen Date: Fri, 6 May 2022 03:11:53 +0000 (-0500) Subject: added '#not' to interface constraints X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3a5c7f677d0286e0b209efdb10a38b17c3a4b06e;p=onyx.git added '#not' to interface constraints --- diff --git a/include/astnodes.h b/include/astnodes.h index b209ce0e..2fac9425 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -1049,6 +1049,8 @@ typedef struct InterfaceConstraint { AstTyped *expr; AstType *expected_type_expr; Type *expected_type; + + b32 invert_condition: 1; } InterfaceConstraint; struct AstInterface { diff --git a/src/checker.c b/src/checker.c index 5ca6d15e..8a8fd1c7 100644 --- a/src/checker.c +++ b/src/checker.c @@ -2754,6 +2754,7 @@ CheckStatus check_constraint(AstConstraint *constraint) { InterfaceConstraint new_ic = {0}; new_ic.expr = (AstTyped *) ast_clone(context.ast_alloc, (AstNode *) ic->expr); new_ic.expected_type_expr = (AstType *) ast_clone(context.ast_alloc, (AstNode *) ic->expected_type_expr); + new_ic.invert_condition = ic->invert_condition; bh_arr_push(constraint->exprs, new_ic); } @@ -2793,7 +2794,11 @@ CheckStatus check_constraint(AstConstraint *constraint) { return cs; } - if (cs == Check_Error) { + if (cs == Check_Error && !ic->invert_condition) { + goto constraint_error; + } + + if (cs == Check_Success && ic->invert_condition) { goto constraint_error; } @@ -2809,7 +2814,8 @@ CheckStatus check_constraint(AstConstraint *constraint) { } TYPE_CHECK(&ic->expr, ic->expected_type) { - goto constraint_error; + if (!ic->invert_condition) + goto constraint_error; } } @@ -2819,11 +2825,12 @@ CheckStatus check_constraint(AstConstraint *constraint) { constraint_error: // HACK HACK HACK onyx_clear_errors(); - *constraint->report_status = Constraint_Check_Status_Failed; return Check_Failed; } + // HACK HACK HACK + onyx_clear_errors(); *constraint->report_status = Constraint_Check_Status_Success; return Check_Complete; } diff --git a/src/parser.c b/src/parser.c index 27972445..d0537d5b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2141,6 +2141,10 @@ static AstInterface* parse_interface(OnyxParser* parser) { if (parser->hit_unexpected_token) return interface; InterfaceConstraint ic = {0}; + if (parse_possible_directive(parser, "not")) { + ic.invert_condition = 1; + } + if (consume_token_if_next(parser, '{')) { ic.expr = parse_expression(parser, 0);