code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(85 lines)
1 // Built-in functions
3 #pragma once
5 #include <signal.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <stdio.h> // IWYU pragma: export
10 #include "datatypes.h"
11 #include "print.h"
12 #include "stacktrace.h" // IWYU pragma: export
13 #include "types.h"
15 extern bool USE_COLOR;
16 extern Text_t TOMO_VERSION_TEXT;
18 void tomo_configure(void);
19 void tomo_init(void);
20 void tomo_at_cleanup(Closure_t fn);
21 void tomo_cleanup(void);
23 #define fail(...) \
24 ({ \
25 tomo_cleanup(); \
26 fflush(stdout); \
27 if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \033[m\n\n", stderr); \
28 else fputs("==================== ERROR ====================\n\n", stderr); \
29 print_stacktrace(stderr, 1); \
30 if (USE_COLOR) fputs("\n\x1b[31;1m", stderr); \
31 else fputs("\n", stderr); \
32 fprint_inline(stderr, "Error: ", __VA_ARGS__); \
33 if (USE_COLOR) fputs("\x1b[m\n", stderr); \
34 else fputs("\n", stderr); \
35 fflush(stderr); \
36 raise(SIGABRT); \
37 exit(1); \
38 })
40 #define fail_source(filename, start, end, message) \
41 ({ \
42 tomo_cleanup(); \
43 fflush(stdout); \
44 if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \n\n\x1b[0;1m", stderr); \
45 else fputs("==================== ERROR ====================\n\n", stderr); \
46 print_stacktrace(stderr, 0); \
47 fputs("\n", stderr); \
48 if (USE_COLOR) fputs("\x1b[31;1m", stderr); \
49 Text$print(stderr, message); \
50 file_t *_file = (filename) ? load_file(filename) : NULL; \
51 if ((filename) && _file) { \
52 fputs("\n", stderr); \
53 highlight_error(_file, _file->text + (start), _file->text + (end), "\x1b[31;1m", 1, USE_COLOR); \
54 } \
55 if (USE_COLOR) fputs("\x1b[m", stderr); \
56 fflush(stderr); \
57 raise(SIGABRT); \
58 exit(1); \
59 })
61 _Noreturn void fail_text(Text_t message);
62 Text_t builtin_last_err();
63 __attribute__((nonnull)) void start_inspect(const char *filename, int64_t start, int64_t end);
64 void end_inspect(const void *expr, const TypeInfo_t *type);
65 #define inspect(type, expr, typeinfo, start, end) \
66 { \
67 start_inspect(__SOURCE_FILE__, start, end); \
68 type _expr = expr; \
69 end_inspect(&_expr, typeinfo); \
71 #define inspect_void(expr, typeinfo, start, end) \
72 { \
73 start_inspect(__SOURCE_FILE__, start, end); \
74 expr; \
75 end_inspect(NULL, typeinfo); \
78 void say(Text_t text, bool newline);
79 Text_t ask(Text_t prompt, bool bold, bool force_tty);
80 _Noreturn void tomo_exit(Text_t text, int32_t status);
82 Closure_t spawn(Closure_t fn);
83 void sleep_seconds(double seconds);
84 OptionalText_t getenv_text(Text_t name);
85 void setenv_text(Text_t name, Text_t value);