Array methods

This commit is contained in:
Bruce Hill 2024-03-08 14:25:17 -05:00
parent 07c2b0ec26
commit 55eacb8a04
2 changed files with 6 additions and 3 deletions

View File

@ -715,6 +715,12 @@ CORD compile(env_t *env, ast_t *ast)
.next=new(arg_t, .name="at", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=0, .bits=64)));
return CORD_all("Array__insert(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ",
compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "insert_all")) {
CORD self = compile_to_pointer_depth(env, call->self, 1, false);
arg_t *arg_spec = new(arg_t, .name="items", .type=self_value_t,
.next=new(arg_t, .name="at", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=0, .bits=64)));
return CORD_all("Array__insert_all(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ",
compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "remove")) {
CORD self = compile_to_pointer_depth(env, call->self, 1, false);
arg_t *arg_spec = new(arg_t, .name="index", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=-1, .bits=64),

View File

@ -414,10 +414,7 @@ type_t *get_type(env_t *env, ast_t *ast)
else if (streq(call->name, "random"))
return Type(PointerType, .pointed=Match(self_value_t, ArrayType)->item_type, .is_optional=true, .is_readonly=true);
else if (streq(call->name, "clear")) return Type(VoidType);
else if (streq(call->name, "compact")) return Type(VoidType);
else if (streq(call->name, "contains")) return Type(VoidType);
else if (streq(call->name, "slice")) return self_value_t;
else if (streq(call->name, "concat")) return self_value_t;
else code_err(ast, "There is no '%s' method for arrays", call->name);
}
case TableType: {