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 {
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;
}
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;
}
+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);,
{ to_u32(t) } -> u32;
}
+#local
HasHashMethod :: interface (t: $T) {
{ t->hash() } -> u32;
}