aboutsummaryrefslogtreecommitdiff
path: root/src/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-07 15:56:49 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-07 15:56:49 -0400
commit15fabfb9be3e3620e4b96983a49017116cea40e2 (patch)
treeb57c9a1c17ff0fe47c089a419437136191cf42a2 /src/compile.c
parent0d2060717a21653deb3db03ba5b3fe62aa4c098e (diff)
Add table.get_or_set()
Diffstat (limited to 'src/compile.c')
-rw-r--r--src/compile.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compile.c b/src/compile.c
index 59c25f6a..3f6cb713 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -3312,6 +3312,15 @@ CORD compile(env_t *env, ast_t *ast)
compile_type(table->value_type), ", ", compile_arguments(env, ast, arg_spec, call->args), ", ",
"_, ", optional_into_nonnone(table->value_type, "(*_)"), ", ", compile_none(table->value_type), ", ",
compile_type_info(self_value_t), ")");
+ } else if (streq(call->name, "get_or_set")) {
+ self = compile_to_pointer_depth(env, call->self, 1, false);
+ arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type,
+ .next=new(arg_t, .name="default", .type=table->value_type, .default_val=table->default_value));
+ return CORD_all("*Table$get_or_setdefault(",
+ self, ", ", compile_type(table->key_type), ", ",
+ compile_type(table->value_type), ", ",
+ compile_arguments(env, ast, arg_spec, call->args), ", ",
+ compile_type_info(self_value_t), ")");
} else if (streq(call->name, "has")) {
self = compile_to_pointer_depth(env, call->self, 0, false);
arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type);