2014-08-25 00:38:09 -04:00
|
|
|
/**
|
|
|
|
* See Copyright Notice in picrin.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "picrin.h"
|
2017-03-28 10:09:40 -04:00
|
|
|
#include "object.h"
|
|
|
|
#include "state.h"
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-19 13:26:52 -05:00
|
|
|
pic_value
|
2014-08-25 00:38:09 -04:00
|
|
|
pic_get_backtrace(pic_state *pic)
|
|
|
|
{
|
2016-02-19 02:17:13 -05:00
|
|
|
size_t ai = pic_enter(pic);
|
2016-02-21 06:32:00 -05:00
|
|
|
struct callinfo *ci;
|
2016-02-19 13:26:52 -05:00
|
|
|
pic_value trace;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-18 09:49:16 -05:00
|
|
|
trace = pic_lit_value(pic, "");
|
2014-08-25 00:38:09 -04:00
|
|
|
|
|
|
|
for (ci = pic->ci; ci != pic->cibase; --ci) {
|
2016-02-19 10:03:16 -05:00
|
|
|
pic_value proc = ci->fp[0];
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-18 09:49:16 -05:00
|
|
|
trace = pic_str_cat(pic, trace, pic_lit_value(pic, " at "));
|
|
|
|
trace = pic_str_cat(pic, trace, pic_lit_value(pic, "(anonymous lambda)"));
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2017-03-30 10:29:08 -04:00
|
|
|
if (pic_proc_func_p(pic, proc)) {
|
2016-02-18 09:49:16 -05:00
|
|
|
trace = pic_str_cat(pic, trace, pic_lit_value(pic, " (native function)\n"));
|
2016-02-19 10:03:16 -05:00
|
|
|
} else {
|
2016-02-18 09:49:16 -05:00
|
|
|
trace = pic_str_cat(pic, trace, pic_lit_value(pic, " (unknown location)\n")); /* TODO */
|
2014-08-25 00:38:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-19 02:17:13 -05:00
|
|
|
pic_leave(pic, ai);
|
2016-02-19 13:26:52 -05:00
|
|
|
pic_protect(pic, trace);
|
2014-08-25 00:38:09 -04:00
|
|
|
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
2016-02-22 14:37:58 -05:00
|
|
|
#if PIC_USE_WRITE
|
|
|
|
|
2014-08-25 00:38:09 -04:00
|
|
|
void
|
2016-06-19 15:49:01 -04:00
|
|
|
pic_print_error(pic_state *pic, pic_value port, pic_value err)
|
2014-08-25 00:38:09 -04:00
|
|
|
{
|
2016-02-20 10:30:40 -05:00
|
|
|
if (! pic_error_p(pic, err)) {
|
2016-02-23 00:15:42 -05:00
|
|
|
pic_fprintf(pic, port, "raise: ~s", err);
|
2014-09-16 11:28:55 -04:00
|
|
|
} else {
|
2016-02-21 06:32:00 -05:00
|
|
|
struct error *e;
|
2015-06-19 13:34:00 -04:00
|
|
|
pic_value elem, it;
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2016-02-20 10:30:40 -05:00
|
|
|
e = pic_error_ptr(pic, err);
|
2017-03-28 19:32:28 -04:00
|
|
|
if (! pic_eq_p(pic, obj_value(pic, e->type), pic_intern_lit(pic, ""))) {
|
|
|
|
pic_fprintf(pic, port, "~s-", obj_value(pic, e->type));
|
2014-09-16 11:28:55 -04:00
|
|
|
}
|
2017-03-28 19:32:28 -04:00
|
|
|
pic_fprintf(pic, port, "error: ~s", obj_value(pic, e->msg));
|
2014-08-25 00:38:09 -04:00
|
|
|
|
2015-06-19 13:34:00 -04:00
|
|
|
pic_for_each (elem, e->irrs, it) { /* print error irritants */
|
2016-02-22 14:24:42 -05:00
|
|
|
pic_fprintf(pic, port, " ~s", elem);
|
2015-06-19 13:34:00 -04:00
|
|
|
}
|
2017-03-28 19:32:28 -04:00
|
|
|
pic_fprintf(pic, port, "\n%s", pic_str(pic, obj_value(pic, e->stack), NULL));
|
2014-09-16 11:28:55 -04:00
|
|
|
}
|
2014-08-25 00:38:09 -04:00
|
|
|
}
|
2016-02-22 14:37:58 -05:00
|
|
|
|
|
|
|
#endif
|