diff options
-rw-r--r-- | eval.c | 15 | ||||
-rw-r--r-- | main.c | 41 |
2 files changed, 53 insertions, 3 deletions
@@ -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; @@ -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 <signal.h> +#include <execinfo.h> +#include <unistd.h> +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 |