aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 16:42:42 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 16:42:42 -0400
commit835eb7e89627eea923bfd57bdacba7065c6b1d4c (patch)
tree68fd9832252e728ccf0c7277a5a2f492e41c261c /compile.c
parentfb37b0ee4253651cab10b41cc2e1f536b17b26d4 (diff)
Add optional:or_exit(...)
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index de5531cc..3aeebfd6 100644
--- a/compile.c
+++ b/compile.c
@@ -2817,6 +2817,16 @@ CORD compile(env_t *env, ast_t *ast)
(long)(call->self->end - call->self->file->text),
compile_arguments(env, ast, arg_spec, call->args)),
optional_into_nonnull(self_value_t, "opt"), "; })");
+ } else if (streq(call->name, "or_exit")) {
+ CORD self = compile_to_pointer_depth(env, call->self, 0, false);
+ arg_t *arg_spec = new(arg_t, .name="message", .type=Type(OptionalType, .type=TEXT_TYPE),
+ .default_val=FakeAST(Null, .type=new(type_ast_t, .tag=VarTypeAST, .__data.VarTypeAST.name="Text")),
+ .next=new(arg_t, .name="code", .type=Type(IntType, .bits=TYPE_IBITS32),
+ .default_val=FakeAST(Int, .bits=IBITS32, .str="1")));
+ return CORD_all("({ ", compile_declaration(self_value_t, "opt"), " = ", self, "; ",
+ "if (", check_null(self_value_t, "opt"), ")\n",
+ "tomo_exit(", compile_arguments(env, ast, arg_spec, call->args), ");\n",
+ optional_into_nonnull(self_value_t, "opt"), "; })");
}
code_err(ast, "There is no '%s' method for optional %T values", call->name, nonnull);
}