remove unnecessary func, allow formatted errors

master
Daniel Kolesa 2016-09-10 01:11:02 +02:00
parent 32c53a31a0
commit 879737ce83
4 changed files with 15 additions and 31 deletions

View File

@ -385,7 +385,14 @@ struct OSTD_EXPORT CsState {
}, error, stack, &func);
}
void error(CsString msg);
void error(ostd::ConstCharRange msg);
template<typename ...A>
void error(ostd::ConstCharRange msg, A &&...args) {
auto app = ostd::appender<CsString>();
ostd::format(app, msg, ostd::forward<A>(args)...);
error(app.get());
}
void clear_override(CsIdent &id);
void clear_overrides();

View File

@ -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<CsIvar *>(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;

View File

@ -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<typename ...A>
@ -113,7 +111,8 @@ void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) {
return;
}
cs.get_err().writefln(fmt, ostd::forward<A>(args)...);
cs_debug_alias(cs);
auto st = cs_save_stack(cs);
cscript::util::print_stack(cs.get_err().iter(), st);
}
template<typename ...A>
@ -128,7 +127,8 @@ void cs_debug_code_line(
cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size())),
ostd::forward<A>(args)...
);
cs_debug_alias(cs);
auto st = cs_save_stack(cs);
cscript::util::print_stack(cs.get_err().iter(), st);
}
struct GenState {

View File

@ -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);
}