aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-12-31 15:46:53 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-12-31 15:46:53 -0500
commit156d54a73e005eecbb9a4284b74994313a34e4aa (patch)
treeb54f5574213df750d2b7292a088172f43b9f86a5 /compile.c
parent4b11f1b2b63effe71ddac5aac0879c1512057e8b (diff)
Add array:pop()
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 94ef0513..2cc3284e 100644
--- a/compile.c
+++ b/compile.c
@@ -3013,6 +3013,12 @@ CORD compile(env_t *env, ast_t *ast)
self = compile_to_pointer_depth(env, call->self, 0, false);
(void)compile_arguments(env, ast, NULL, call->args);
return CORD_all("Table$from_entries(", self, ", Set$info(", compile_type_info(env, item_t), "))");
+ } else if (streq(call->name, "pop")) {
+ EXPECT_POINTER("an", "array");
+ arg_t *arg_spec = new(arg_t, .name="index", .type=INT_TYPE, .default_val=FakeAST(Int, "-1"));
+ CORD index = compile_arguments(env, ast, arg_spec, call->args);
+ return CORD_all("Array$pop(", self, ", ", index, ", ", compile_type(item_t), ", _, ",
+ promote_to_optional(item_t, "_"), ", ", compile_none(item_t), ", ", padded_item_size, ")");
} else if (streq(call->name, "counts")) {
self = compile_to_pointer_depth(env, call->self, 0, false);
(void)compile_arguments(env, ast, NULL, call->args);