aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-07-13 18:05:14 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-07-13 18:05:14 -0400
commitf64aaf5960287f776232f909e145ac3f72fec73c (patch)
tree1f6d7d36ed58ca4219a1bb89e7f63aeadf8cf0bb /typecheck.c
parent445f79cb70e72698283539b65e43fc71a47ad311 (diff)
Add array:pairs()
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/typecheck.c b/typecheck.c
index ba04ad53..0fda02e2 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -678,7 +678,11 @@ type_t *get_type(env_t *env, ast_t *ast)
else if (streq(call->name, "heapify")) return Type(VoidType);
else if (streq(call->name, "heap_push")) return Type(VoidType);
else if (streq(call->name, "heap_pop")) return Match(self_value_t, ArrayType)->item_type;
- else code_err(ast, "There is no '%s' method for arrays", call->name);
+ else if (streq(call->name, "pairs")) {
+ type_t *ref_t = Type(PointerType, .pointed=Match(self_value_t, ArrayType)->item_type, .is_stack=true);
+ arg_t *args = new(arg_t, .name="x", .type=ref_t, .next=new(arg_t, .name="y", .type=ref_t));
+ return Type(ClosureType, .fn=Type(FunctionType, .args=args, .ret=Type(BoolType)));
+ } else code_err(ast, "There is no '%s' method for arrays", call->name);
}
case TableType: {
auto table = Match(self_value_t, TableType);