diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 21a62ce8..a31d67a8 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -385,7 +385,14 @@ struct OSTD_EXPORT CsState { }, error, stack, &func); } - void error(CsString msg); + void error(ostd::ConstCharRange msg); + + template + void error(ostd::ConstCharRange msg, A &&...args) { + auto app = ostd::appender(); + ostd::format(app, msg, ostd::forward(args)...); + error(app.get()); + } void clear_override(CsIdent &id); void clear_overrides(); diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 18b53f04..391c3a34 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -132,29 +132,6 @@ CsStackState cs_save_stack(CsState &cs) { return CsStackState(ret, total != dalias->get_value()); } -void cs_debug_alias(CsState &cs) { - CsIvar *dalias = static_cast(cs.identmap[DbgaliasIdx]); - if (!dalias->get_value()) { - return; - } - int total = 0, depth = 0; - for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) { - total++; - } - for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) { - CsIdent *id = l->id; - ++depth; - if (depth < dalias->get_value()) { - cs.get_err().writefln(" %d) %s", total - depth + 1, id->get_name()); - } else if (l->next == &cs.noalias) { - cs.get_err().writefln( - depth == dalias->get_value() ? " %d) %s" : " ..%d) %s", - total - depth + 1, id->get_name() - ); - } - } -} - static void bcode_ref(ostd::Uint32 *code) { if (!code) { return; diff --git a/src/cs_vm.hh b/src/cs_vm.hh index c8c7c5e5..47dd07ce 100644 --- a/src/cs_vm.hh +++ b/src/cs_vm.hh @@ -103,8 +103,6 @@ ostd::ConstCharRange cs_debug_line( ostd::ConstCharRange p, ostd::ConstCharRange fmt, ostd::CharRange buf ); -void cs_debug_alias(CsState &cs); - CsStackState cs_save_stack(CsState &cs); template @@ -113,7 +111,8 @@ void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) { return; } cs.get_err().writefln(fmt, ostd::forward(args)...); - cs_debug_alias(cs); + auto st = cs_save_stack(cs); + cscript::util::print_stack(cs.get_err().iter(), st); } template @@ -128,7 +127,8 @@ void cs_debug_code_line( cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size())), ostd::forward(args)... ); - cs_debug_alias(cs); + auto st = cs_save_stack(cs); + cscript::util::print_stack(cs.get_err().iter(), st); } struct GenState { diff --git a/src/cubescript.cc b/src/cubescript.cc index 81e39a46..c34762f8 100644 --- a/src/cubescript.cc +++ b/src/cubescript.cc @@ -442,12 +442,12 @@ bool CsState::ipcall( return true; } -void CsState::error(CsString msg) { +void CsState::error(ostd::ConstCharRange msg) { if (protect) { - throw CsErrorException(ostd::move(msg), cs_save_stack(*this)); + throw CsErrorException(msg, cs_save_stack(*this)); } else { if (p_panicfunc) { - p_panicfunc(ostd::move(msg), cs_save_stack(*this)); + p_panicfunc(msg, cs_save_stack(*this)); } exit(EXIT_FAILURE); }