diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 23:41:32 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 23:41:32 -0400 |
| commit | da9cc93c466c65e0294b4b29bec6603b2d4552eb (patch) | |
| tree | bfd266d559365366802eaf1a285d7983b426f9c8 /builtins | |
| parent | 46a2aa2ffc71820767f0cdaead84c26dc240c893 (diff) | |
Make functions print with `func name(...)->... [file:line]` info
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/functions.c | 12 | ||||
| -rw-r--r-- | builtins/functions.h | 6 | ||||
| -rw-r--r-- | builtins/types.c | 6 |
3 files changed, 22 insertions, 2 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index a2b17807..edbea33b 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -43,6 +43,18 @@ public void tomo_init(void) errx(1, "Couldn't set printf specifier"); } +static Table_t function_names = {}; + +public void register_function(void *fn, Text_t name) +{ + Table$set(&function_names, &fn, &name, Table$info(Function$info("???"), &Text$info)); +} + +public Text_t *get_function_name(void *fn) +{ + return Table$get(function_names, &fn, Table$info(Function$info("???"), &Text$info)); +} + void print_stack_trace(FILE *out, int start, int stop) { // Print stack trace: diff --git a/builtins/functions.h b/builtins/functions.h index b79c596a..16e1cd22 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -11,6 +11,9 @@ #include "util.h" void tomo_init(void); +void register_function(void *fn, Text_t name); +Text_t *get_function_name(void *fn); + __attribute__((format(printf, 1, 2))) _Noreturn void fail(const char *fmt, ...); __attribute__((format(printf, 4, 5))) @@ -20,7 +23,8 @@ void start_test(const char *filename, int64_t start, int64_t end); void end_test(const void *expr, const TypeInfo *type, const char *expected, const char *filename, int64_t start, int64_t end); #define test(expr, typeinfo, expected, start, end) {\ start_test(__SOURCE_FILE__, start, end); \ - end_test((__typeof__(expr)[1]){expr}, typeinfo, expected, __SOURCE_FILE__, start, end); } + auto _expr = expr; \ + end_test(&_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); diff --git a/builtins/types.c b/builtins/types.c index 512fdfc3..307b4756 100644 --- a/builtins/types.c +++ b/builtins/types.c @@ -39,7 +39,11 @@ public Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo *type) { (void)fn; Text_t text = Text$from_str(type->FunctionInfo.type_str); - if (fn) text = Text$concat(text, Text(": ...")); + if (fn) { + Text_t *name = get_function_name(*(void**)fn); + if (name) + text = *name; + } if (fn && colorize) text = Text$concat(Text("\x1b[32;1m"), text, Text("\x1b[m")); return text; |
