removed `#with` in interfaces; use T.{}
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 3 Oct 2022 19:35:45 +0000 (14:35 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 3 Oct 2022 19:35:45 +0000 (14:35 -0500)
compiler/include/astnodes.h
compiler/src/checker.c
compiler/src/parser.c
core/container/array.onyx
core/hash.onyx

index 246d4dc1b09a672c351f584ef6afad16dc404418..4ac685b28c1f67dfa06ee62412a682311ffce2f0 100644 (file)
@@ -1101,18 +1101,12 @@ typedef struct InterfaceConstraint {
     b32 invert_condition: 1;
 } InterfaceConstraint;
 
-typedef struct InterfaceVariable {
-    OnyxToken *symbol;
-    AstType   *type;
-} InterfaceVariable;
-
 struct AstInterface {
     AstTyped_base;
     char *name;
 
     bh_arr(InterfaceParam)      params;
     bh_arr(InterfaceConstraint) exprs;
-    bh_arr(InterfaceVariable)   vars;
 };
 
 typedef enum ConstraintPhase {
index cc0c9adba96ed46ef4d56fbd2bceb72745af7726..0854670cc77050d7e7b6ca8b355f1a79874de13b 100644 (file)
@@ -2969,16 +2969,6 @@ CheckStatus check_constraint(AstConstraint *constraint) {
                 symbol_introduce(constraint->scope, ip->type_token, (AstNode *) type_alias);
             }
 
-            fori (i, 0, bh_arr_length(constraint->interface->vars)) {
-                InterfaceVariable *iv = &constraint->interface->vars[i];
-
-                AstTyped *sentinel = onyx_ast_node_new(context.ast_alloc, sizeof(AstTyped), Ast_Kind_Constraint_Sentinel);
-                sentinel->token = iv->symbol;
-                sentinel->type_node = iv->type;
-
-                symbol_introduce(constraint->scope, iv->symbol, (AstNode *) sentinel);
-            }
-
             assert(constraint->entity);
             constraint->entity->scope = constraint->scope;
 
index 912312e9829f707a23862e44f5a21dbd078fcf51..246c9582f21a9a4255e422691be0e478ed512764 100644 (file)
@@ -2177,24 +2177,11 @@ static AstInterface* parse_interface(OnyxParser* parser) {
     }
 
     bh_arr_new(global_heap_allocator, interface->exprs, 2);
-    bh_arr_new(global_heap_allocator, interface->vars, 2);
 
     expect_token(parser, '{');
     while (!consume_token_if_next(parser, '}')) {
         if (parser->hit_unexpected_token) return interface;
 
-        if (parse_possible_directive(parser, "with")) {
-            InterfaceVariable v;
-            v.symbol = expect_token(parser, Token_Type_Symbol);
-            expect_token(parser, ':');
-
-            v.type = parse_type(parser);
-            expect_token(parser, ';');
-
-            bh_arr_push(interface->vars, v);
-            continue;
-        }
-
         InterfaceConstraint ic = {0};
         if (parse_possible_directive(parser, "not")) {
             ic.invert_condition = 1;
index 41e92972df3468b5a12f21fea076f3fa8fc44dbb..3d5f3169ac8784bedd859e5f44ae51adc6c7620d 100644 (file)
@@ -442,12 +442,22 @@ unique :: (arr: ^[] $T) {
 }
 
 
+fold :: #match #local {}
+
+#overload
 fold :: (arr: [] $T, init: $R, f: (T, R) -> R) -> R {
     val := init;
     for it: arr do val = f(it, val);
     return val;
 }
 
+#overload
+fold :: macro (arr: [] $T, init: $R, body: Code) -> R {
+    acc := init;
+    for it: arr do acc = #unquote body;
+    return acc;
+}
+
 map :: #match #locked {
     macro (arr: [] $T, f: (^T) -> void)                do for ^it: arr do f(it);,
     macro (arr: [] $T, f: (T) -> T)                    do for ^it: arr do *it = f(*it);,
index 8935dda7da54df6b4bee6799a8ea4e3583378a02..364ef6ae0f9849a40741d46d960c33b72ace5452 100644 (file)
@@ -21,6 +21,7 @@ Hashable :: interface (t: $T) {
     { to_u32(t) } -> u32;
 }
 
+#local
 HasHashMethod :: interface (t: $T) {
     { t->hash() } -> u32;
 }