aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-04-02 13:13:33 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-04-02 13:13:33 -0400
commit95100469b6c7f301bb14bcda5dbc16b93c9ce0dc (patch)
treef84837f45fdc90b3070bd17583329a89450f6f44 /compile.c
parentc73e96ff916209d74e2be9bd7d8de3758685ce4d (diff)
Add array:sorted()
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index c4983254..ff6a868d 100644
--- a/compile.c
+++ b/compile.c
@@ -1485,8 +1485,8 @@ CORD compile(env_t *env, ast_t *ast)
CORD self = compile_to_pointer_depth(env, call->self, 1, false);
(void)compile_arguments(env, ast, NULL, call->args);
return CORD_all("Array$shuffle(", self, ", ", compile_type_info(env, self_value_t), ")");
- } else if (streq(call->name, "sort")) {
- CORD self = compile_to_pointer_depth(env, call->self, 1, false);
+ } else if (streq(call->name, "sort") || streq(call->name, "sorted")) {
+ CORD self = compile_to_pointer_depth(env, call->self, streq(call->name, "sort") ? 1 : 0, false);
CORD comparison;
if (call->args) {
type_t *item_ptr = Type(PointerType, .pointed=item_t, .is_stack=true, .is_readonly=true);
@@ -1497,7 +1497,7 @@ CORD compile(env_t *env, ast_t *ast)
} else {
comparison = CORD_all("(closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "}");
}
- return CORD_all("Array$sort(", self, ", ", comparison, ", ", compile_type_info(env, self_value_t), ")");
+ return CORD_all("Array$", call->name, "(", self, ", ", comparison, ", ", compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "clear")) {
CORD self = compile_to_pointer_depth(env, call->self, 1, false);
(void)compile_arguments(env, ast, NULL, call->args);