diff --git a/command.cc b/command.cc index fed21b24..4b49ef37 100644 --- a/command.cc +++ b/command.cc @@ -170,9 +170,9 @@ void Ident::clean_code() { } } -ostd::ConstCharRange debugline(CsState &cs, ostd::ConstCharRange p, - ostd::ConstCharRange fmt, - ostd::CharRange buf) { +ostd::ConstCharRange debug_line(CsState &cs, ostd::ConstCharRange p, + ostd::ConstCharRange fmt, + ostd::CharRange buf) { if (cs.src_str.empty()) return fmt; ostd::Size num = 1; 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); -void debugalias(CsState &cs) { +void debug_alias(CsState &cs) { if (!dbgalias) return; 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) { Ident *id = l->id; ++depth; - if (depth < dbgalias) fprintf(stderr, " %d) %s\n", total - depth + 1, id->name.data()); - else if (l->next == &cs.noalias) fprintf(stderr, depth == dbgalias ? " %d) %s\n" : " ..%d) %s\n", total - depth + 1, id->name.data()); + if (depth < dbgalias) + 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) { stack.val = id.val; diff --git a/command.hh b/command.hh index b079b0a9..3b9af753 100644 --- a/command.hh +++ b/command.hh @@ -286,8 +286,8 @@ struct IdentLink { IdentStack *argstack; }; -void debugalias(CsState &cs); -ostd::ConstCharRange debugline(CsState &cs, ostd::ConstCharRange p, +void debug_alias(CsState &cs); +ostd::ConstCharRange debug_line(CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt, ostd::CharRange buf); @@ -368,7 +368,7 @@ struct CsState { void debug_code(ostd::ConstCharRange fmt, A &&...args) { if (nodebug) return; ostd::err.writefln(fmt, ostd::forward(args)...); - debugalias(*this); + debug_alias(*this); } template @@ -376,11 +376,11 @@ struct CsState { ostd::ConstCharRange fmt, A &&...args) { if (nodebug) return; ostd::Array buf; - ostd::err.writefln(debugline(*this, p, fmt, - ostd::CharRange(buf.data(), - buf.size())), + ostd::err.writefln(debug_line(*this, p, fmt, + ostd::CharRange(buf.data(), + buf.size())), ostd::forward(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 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_math(CsState &cs); void init_lib_shell(CsState &cs); \ No newline at end of file