aboutsummaryrefslogtreecommitdiff
path: root/src/environment.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-27 17:26:51 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-27 17:26:51 -0400
commit3c52a756339a2d96824d21a7d3ad5de7fc1085a0 (patch)
treee5299a25ebb76186d6372b700710d7c8c7fe0728 /src/environment.h
parent2186e84de0c0fd47ba48eaa35f74ea2754c3b81f (diff)
Deprecate custom printf specifiers in favor of print() function that
uses _Generic() to generically convert any value to a string or print as a string.
Diffstat (limited to 'src/environment.h')
-rw-r--r--src/environment.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/environment.h b/src/environment.h
index fbd75c8e..549df87b 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -5,6 +5,8 @@
#include <gc/cord.h>
#include "types.h"
+#include "stdlib/print.h"
+#include "stdlib/stdlib.h"
#include "stdlib/tables.h"
typedef struct {
@@ -64,8 +66,23 @@ env_t *fresh_scope(env_t *env);
env_t *for_scope(env_t *env, ast_t *ast);
env_t *with_enum_scope(env_t *env, type_t *t);
env_t *namespace_env(env_t *env, const char *namespace_name);
-__attribute__((format(printf, 4, 5)))
-_Noreturn void compiler_err(file_t *f, const char *start, const char *end, const char *fmt, ...);
+#define compiler_err(f, start, end, ...) ({ \
+ file_t *_f = f; \
+ if (USE_COLOR) \
+ fputs("\x1b[31;7;1m", stderr); \
+ if (_f && start && end) \
+ fprint_inline(stderr, _f->relative_filename, ":", get_line_number(_f, start), ".", get_line_column(_f, start), ": "); \
+ fprint(stderr, __VA_ARGS__); \
+ if (USE_COLOR) \
+ fputs(" \x1b[m", stderr); \
+ fputs("\n\n", stderr); \
+ if (_f && start && end) \
+ highlight_error(_f, start, end, "\x1b[31;1m", 2, USE_COLOR); \
+ if (getenv("TOMO_STACKTRACE")) \
+ print_stack_trace(stderr, 1, 3); \
+ raise(SIGABRT); \
+ exit(1); \
+})
binding_t *get_binding(env_t *env, const char *name);
binding_t *get_constructor(env_t *env, type_t *t, arg_ast_t *args);
void set_binding(env_t *env, const char *name, type_t *type, CORD code);