forked from OctaForge/libcubescript
more cleanups
parent
f28fab7a97
commit
a2091bdbbd
24
command.cc
24
command.cc
|
@ -170,9 +170,9 @@ void Ident::clean_code() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange debugline(CsState &cs, ostd::ConstCharRange p,
|
ostd::ConstCharRange debug_line(CsState &cs, ostd::ConstCharRange p,
|
||||||
ostd::ConstCharRange fmt,
|
ostd::ConstCharRange fmt,
|
||||||
ostd::CharRange buf) {
|
ostd::CharRange buf) {
|
||||||
if (cs.src_str.empty()) return fmt;
|
if (cs.src_str.empty()) return fmt;
|
||||||
ostd::Size num = 1;
|
ostd::Size num = 1;
|
||||||
ostd::ConstCharRange line(cs.src_str);
|
ostd::ConstCharRange line(cs.src_str);
|
||||||
|
@ -199,19 +199,29 @@ ostd::ConstCharRange debugline(CsState &cs, ostd::ConstCharRange p,
|
||||||
|
|
||||||
int dbgalias = variable("dbgalias", 0, 4, 1000, &dbgalias, nullptr, 0);
|
int dbgalias = variable("dbgalias", 0, 4, 1000, &dbgalias, nullptr, 0);
|
||||||
|
|
||||||
void debugalias(CsState &cs) {
|
void debug_alias(CsState &cs) {
|
||||||
if (!dbgalias) return;
|
if (!dbgalias) return;
|
||||||
int total = 0, depth = 0;
|
int total = 0, depth = 0;
|
||||||
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) total++;
|
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) total++;
|
||||||
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) {
|
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) {
|
||||||
Ident *id = l->id;
|
Ident *id = l->id;
|
||||||
++depth;
|
++depth;
|
||||||
if (depth < dbgalias) fprintf(stderr, " %d) %s\n", total - depth + 1, id->name.data());
|
if (depth < dbgalias)
|
||||||
else if (l->next == &cs.noalias) fprintf(stderr, depth == dbgalias ? " %d) %s\n" : " ..%d) %s\n", total - depth + 1, id->name.data());
|
ostd::err.writefln(" %d) %s", total - depth + 1, id->name);
|
||||||
|
else if (l->next == &cs.noalias)
|
||||||
|
ostd::err.writefln(depth == dbgalias ? " %d) %s"
|
||||||
|
: " ..%d) %s",
|
||||||
|
total - depth + 1, id->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ICOMMAND(nodebug, "e", (CsState &cs, ostd::uint *body), { cs.nodebug++; executeret(body, *cs.result); cs.nodebug--; });
|
void init_lib_base(CsState &cs) {
|
||||||
|
cs.add_command("nodebug", "e", [](CsState &cs, ostd::uint *body) {
|
||||||
|
++cs.nodebug;
|
||||||
|
executeret(body, *cs.result);
|
||||||
|
--cs.nodebug;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void pusharg(Ident &id, const TaggedValue &v, IdentStack &stack) {
|
void pusharg(Ident &id, const TaggedValue &v, IdentStack &stack) {
|
||||||
stack.val = id.val;
|
stack.val = id.val;
|
||||||
|
|
15
command.hh
15
command.hh
|
@ -286,8 +286,8 @@ struct IdentLink {
|
||||||
IdentStack *argstack;
|
IdentStack *argstack;
|
||||||
};
|
};
|
||||||
|
|
||||||
void debugalias(CsState &cs);
|
void debug_alias(CsState &cs);
|
||||||
ostd::ConstCharRange debugline(CsState &cs, ostd::ConstCharRange p,
|
ostd::ConstCharRange debug_line(CsState &cs, ostd::ConstCharRange p,
|
||||||
ostd::ConstCharRange fmt,
|
ostd::ConstCharRange fmt,
|
||||||
ostd::CharRange buf);
|
ostd::CharRange buf);
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ struct CsState {
|
||||||
void debug_code(ostd::ConstCharRange fmt, A &&...args) {
|
void debug_code(ostd::ConstCharRange fmt, A &&...args) {
|
||||||
if (nodebug) return;
|
if (nodebug) return;
|
||||||
ostd::err.writefln(fmt, ostd::forward<A>(args)...);
|
ostd::err.writefln(fmt, ostd::forward<A>(args)...);
|
||||||
debugalias(*this);
|
debug_alias(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
|
@ -376,11 +376,11 @@ struct CsState {
|
||||||
ostd::ConstCharRange fmt, A &&...args) {
|
ostd::ConstCharRange fmt, A &&...args) {
|
||||||
if (nodebug) return;
|
if (nodebug) return;
|
||||||
ostd::Array<char, 256> buf;
|
ostd::Array<char, 256> buf;
|
||||||
ostd::err.writefln(debugline(*this, p, fmt,
|
ostd::err.writefln(debug_line(*this, p, fmt,
|
||||||
ostd::CharRange(buf.data(),
|
ostd::CharRange(buf.data(),
|
||||||
buf.size())),
|
buf.size())),
|
||||||
ostd::forward<A>(args)...);
|
ostd::forward<A>(args)...);
|
||||||
debugalias(*this);
|
debug_alias(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -597,6 +597,7 @@ void poparg(Ident &id);
|
||||||
#define ICOMMAND(name, nargs, proto, b) ICOMMANDN(name, ICOMMANDNAME(name), nargs, proto, b)
|
#define ICOMMAND(name, nargs, proto, b) ICOMMANDN(name, ICOMMANDNAME(name), nargs, proto, b)
|
||||||
#define ICOMMANDS(name, nargs, proto, b) ICOMMANDNS(name, ICOMMANDSNAME, nargs, proto, b)
|
#define ICOMMANDS(name, nargs, proto, b) ICOMMANDNS(name, ICOMMANDSNAME, nargs, proto, b)
|
||||||
|
|
||||||
|
void init_lib_base(CsState &cs);
|
||||||
void init_lib_io(CsState &cs);
|
void init_lib_io(CsState &cs);
|
||||||
void init_lib_math(CsState &cs);
|
void init_lib_math(CsState &cs);
|
||||||
void init_lib_shell(CsState &cs);
|
void init_lib_shell(CsState &cs);
|
Loading…
Reference in New Issue