forked from OctaForge/libcubescript
remove unnecessary func, allow formatted errors
parent
32c53a31a0
commit
879737ce83
|
@ -385,7 +385,14 @@ struct OSTD_EXPORT CsState {
|
||||||
}, error, stack, &func);
|
}, 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_override(CsIdent &id);
|
||||||
void clear_overrides();
|
void clear_overrides();
|
||||||
|
|
23
src/cs_vm.cc
23
src/cs_vm.cc
|
@ -132,29 +132,6 @@ CsStackState cs_save_stack(CsState &cs) {
|
||||||
return CsStackState(ret, total != dalias->get_value());
|
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) {
|
static void bcode_ref(ostd::Uint32 *code) {
|
||||||
if (!code) {
|
if (!code) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -103,8 +103,6 @@ ostd::ConstCharRange cs_debug_line(
|
||||||
ostd::ConstCharRange p, ostd::ConstCharRange fmt, ostd::CharRange buf
|
ostd::ConstCharRange p, ostd::ConstCharRange fmt, ostd::CharRange buf
|
||||||
);
|
);
|
||||||
|
|
||||||
void cs_debug_alias(CsState &cs);
|
|
||||||
|
|
||||||
CsStackState cs_save_stack(CsState &cs);
|
CsStackState cs_save_stack(CsState &cs);
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
|
@ -113,7 +111,8 @@ void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cs.get_err().writefln(fmt, ostd::forward<A>(args)...);
|
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>
|
template<typename ...A>
|
||||||
|
@ -128,7 +127,8 @@ void cs_debug_code_line(
|
||||||
cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size())),
|
cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size())),
|
||||||
ostd::forward<A>(args)...
|
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 {
|
struct GenState {
|
||||||
|
|
|
@ -442,12 +442,12 @@ bool CsState::ipcall(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsState::error(CsString msg) {
|
void CsState::error(ostd::ConstCharRange msg) {
|
||||||
if (protect) {
|
if (protect) {
|
||||||
throw CsErrorException(ostd::move(msg), cs_save_stack(*this));
|
throw CsErrorException(msg, cs_save_stack(*this));
|
||||||
} else {
|
} else {
|
||||||
if (p_panicfunc) {
|
if (p_panicfunc) {
|
||||||
p_panicfunc(ostd::move(msg), cs_save_stack(*this));
|
p_panicfunc(msg, cs_save_stack(*this));
|
||||||
}
|
}
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue