diff options
| -rw-r--r-- | builtins/functions.c | 7 | ||||
| -rw-r--r-- | builtins/functions.h | 1 | ||||
| -rw-r--r-- | environment.c | 4 |
3 files changed, 12 insertions, 0 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index bfa9465f..93c4abff 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -257,6 +257,13 @@ public void say(Text_t text, bool newline) fflush(stdout); } +public _Noreturn void tomo_exit(Text_t text, int32_t status) +{ + if (text.length > 0) + say(text, true); + _exit(status); +} + public Text_t ask(Text_t prompt, bool bold, bool force_tty) { Text_t ret = Text(""); diff --git a/builtins/functions.h b/builtins/functions.h index e41326c2..cc1f5a81 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -20,6 +20,7 @@ void end_test(const void *expr, const TypeInfo *type, const char *expected, cons end_test((__typeof__(expr)[1]){expr}, typeinfo, expected, __SOURCE_FILE__, start, end); } void say(Text_t text, bool newline); Text_t ask(Text_t prompt, bool bold, bool force_tty); +_Noreturn void tomo_exit(Text_t text, int32_t status); uint64_t generic_hash(const void *obj, const TypeInfo *type); int32_t generic_compare(const void *x, const void *y, const TypeInfo *type); diff --git a/environment.c b/environment.c index 11304d2b..d09f0a65 100644 --- a/environment.c +++ b/environment.c @@ -42,6 +42,10 @@ env_t *new_compilation_unit(CORD *libname) .next=new(arg_t, .name="force_tty", .type=Type(BoolType), .default_val=FakeAST(Bool, true)))), .ret=TEXT_TYPE)}}, + {"exit", {.code="tomo_exit", + .type=Type(FunctionType, .args=new(arg_t, .name="message", .type=Type(TextType), .default_val=FakeAST(TextLiteral), + .next=new(arg_t, .name="code", .type=Type(IntType, .bits=TYPE_IBITS32), + .default_val=FakeAST(Int, .bits=IBITS32, .str="0"))), .ret=Type(AbortType))}}, {"fail", {.code="fail", .type=Type(FunctionType, .args=new(arg_t, .name="message", .type=Type(CStringType)), .ret=Type(AbortType))}}, {"USE_COLOR", {.code="USE_COLOR", .type=Type(BoolType)}}, }; |
