From 8d94800921520a45284164e09e5dd21da6115973 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 12 Feb 2020 20:12:31 -0500 Subject: continued working on circular type function dependencies also added system for printing backtrace on SIGABRT/SEGV! --- eval.c | 15 +++++++++++++-- main.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/eval.c b/eval.c index 65fb4c6..b9001fc 100644 --- a/eval.c +++ b/eval.c @@ -1575,6 +1575,12 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { return true; } else { ret_val = i->ret_val = evalr_calloc(ev, 1, sizeof *ret_val); + if (type_is_builtin(&e->type, BUILTIN_TYPE)) { + /* placeholder type, overwritten when done */ + ret_val->type = evalr_calloc(ev, 1, sizeof *ret_val); + ret_val->type->kind = TYPE_UNKNOWN; + ret_val->type->flags = TYPE_IS_RESOLVED; + } } } @@ -1636,8 +1642,13 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { decl_remove_val(p); arr_foreach(fn->ret_decls, Declaration, d) decl_remove_val(d); - if (fn->flags & FN_EXPR_CACHE) - *ret_val = *v; + if (fn->flags & FN_EXPR_CACHE) { + if (type_is_builtin(&e->type, BUILTIN_TYPE)) { + *ret_val->type = *v->type; + } else { + *ret_val = *v; + } + } } break; case EXPR_SLICE: { SliceExpr *s = &e->slice; diff --git a/main.c b/main.c index 223c8d5..391475f 100644 --- a/main.c +++ b/main.c @@ -18,7 +18,7 @@ /* TODO: -struct parameters - to allow circular dependencies in types +allow circular dependencies in types foo, _ := bar(); nice syntax for #including something into a namespace run stuff at compile time without assigning it to a constant @@ -42,8 +42,47 @@ allow omission of trailing ; in foo ::= fn() {...} or foo ::= nms {...} ? #include "toc.c" +#if defined TOC_DEBUG && defined __linux__ +#include +#include +#include +static void signal_handler(int num) { + switch (num) { + case SIGABRT: + fprintf(stderr, "Aborted.\n"); + break; + case SIGSEGV: + fprintf(stderr, "Segmentation fault.\n"); + break; + default: + fprintf(stderr, "Terminated for unknown reason.\n"); + break; + } + fprintf(stderr, "Stack trace:\n"); + + static void *addrs[30]; + int naddrs = (int)(sizeof addrs / sizeof *addrs); + naddrs = backtrace(addrs, naddrs); + char **syms = backtrace_symbols(addrs, naddrs); + + + for (int i = 4; i < naddrs; ++i) { + fprintf(stderr,"\t%s - ",syms[i]); + char buf[256]; + snprintf(buf, sizeof buf, "addr2line -e toc %p", addrs[i]); + system(buf); + } + + free(syms); + +} +#endif + int main(int argc, char **argv) { #ifdef TOC_DEBUG + signal(SIGABRT, signal_handler); + signal(SIGSEGV, signal_handler); + test_all(); #endif -- cgit v1.2.3