parent
4531fc04b8
commit
61d700b73d
|
@ -781,7 +781,7 @@ static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
|
|||
char c = gs.next_char();
|
||||
switch (c) {
|
||||
case '\0':
|
||||
cs_debug_code_line(gs, line, "missing \"]\"");
|
||||
cs_debug_code_line(gs.cs, line, "missing \"]\"");
|
||||
gs.source--;
|
||||
goto done;
|
||||
case '\"':
|
||||
|
@ -810,7 +810,7 @@ static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
|
|||
if (brak > level) {
|
||||
continue;
|
||||
} else if (brak < level) {
|
||||
cs_debug_code_line(gs, line, "too many @s");
|
||||
cs_debug_code_line(gs.cs, line, "too many @s");
|
||||
}
|
||||
if (!concs && prevargs >= MaxResults) {
|
||||
gs.code.push(CODE_ENTER);
|
||||
|
@ -1667,7 +1667,7 @@ endstatement:
|
|||
switch (c) {
|
||||
case '\0':
|
||||
if (c != brak) {
|
||||
cs_debug_code_line(gs, line, "missing \"%c\"", brak);
|
||||
cs_debug_code_line(gs.cs, line, "missing \"%c\"", brak);
|
||||
}
|
||||
gs.source--;
|
||||
return;
|
||||
|
@ -1676,7 +1676,7 @@ endstatement:
|
|||
if (c == brak) {
|
||||
return;
|
||||
}
|
||||
cs_debug_code_line(gs, line, "unexpected \"%c\"", c);
|
||||
cs_debug_code_line(gs.cs, line, "unexpected \"%c\"", c);
|
||||
break;
|
||||
case '/':
|
||||
if (gs.current() == '/') {
|
||||
|
|
34
cs_vm.cc
34
cs_vm.cc
|
@ -27,15 +27,14 @@ static inline void cs_pop_alias(Ident *id) {
|
|||
}
|
||||
|
||||
ostd::ConstCharRange cs_debug_line(
|
||||
ostd::ConstCharRange src_file, ostd::ConstCharRange src_str,
|
||||
ostd::ConstCharRange p, ostd::ConstCharRange fmt,
|
||||
CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt,
|
||||
ostd::CharRange buf
|
||||
) {
|
||||
if (src_str.empty()) {
|
||||
if (cs.src_str.empty()) {
|
||||
return fmt;
|
||||
}
|
||||
ostd::Size num = 1;
|
||||
ostd::ConstCharRange line(src_str);
|
||||
ostd::ConstCharRange line(cs.src_str);
|
||||
for (;;) {
|
||||
ostd::ConstCharRange end = ostd::find(line, '\n');
|
||||
if (!end.empty()) {
|
||||
|
@ -43,8 +42,8 @@ ostd::ConstCharRange cs_debug_line(
|
|||
}
|
||||
if (&p[0] >= &line[0] && &p[0] <= &line[line.size()]) {
|
||||
ostd::CharRange r(buf);
|
||||
if (!src_file.empty()) {
|
||||
ostd::format(r, "%s:%d: %s", src_file, num, fmt);
|
||||
if (!cs.src_file.empty()) {
|
||||
ostd::format(r, "%s:%d: %s", cs.src_file, num, fmt);
|
||||
} else {
|
||||
ostd::format(r, "%d: %s", num, fmt);
|
||||
}
|
||||
|
@ -1570,26 +1569,17 @@ void CsState::run_ret(Bytecode const *code, CsValue &ret) {
|
|||
runcode(*this, reinterpret_cast<ostd::Uint32 const *>(code), ret);
|
||||
}
|
||||
|
||||
static void cs_run_ret(
|
||||
CsState &cs, ostd::ConstCharRange code, ostd::ConstCharRange src_file,
|
||||
ostd::ConstCharRange src_str, CsValue &ret
|
||||
) {
|
||||
GenState gs(cs);
|
||||
gs.src_file = src_file;
|
||||
gs.src_str = src_str;
|
||||
void CsState::run_ret(ostd::ConstCharRange code, CsValue &ret) {
|
||||
GenState gs(*this);
|
||||
gs.code.reserve(64);
|
||||
/* FIXME range */
|
||||
gs.gen_main(code.data(), VAL_ANY);
|
||||
runcode(cs, gs.code.data() + 1, ret);
|
||||
runcode(*this, gs.code.data() + 1, ret);
|
||||
if (int(gs.code[0]) >= 0x100) {
|
||||
gs.code.disown();
|
||||
}
|
||||
}
|
||||
|
||||
void CsState::run_ret(ostd::ConstCharRange code, CsValue &ret) {
|
||||
cs_run_ret(*this, code, ostd::ConstCharRange(), ostd::ConstCharRange(), ret);
|
||||
}
|
||||
|
||||
void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
|
||||
int nargs = int(args.size());
|
||||
ret.set_null();
|
||||
|
@ -1782,6 +1772,7 @@ void CsState::run(Ident *id, CsValueRange args) {
|
|||
static bool cs_run_file(
|
||||
CsState &cs, ostd::ConstCharRange fname, CsValue &ret
|
||||
) {
|
||||
ostd::ConstCharRange oldsrcfile = cs.src_file, oldsrcstr = cs.src_str;
|
||||
ostd::Box<char[]> buf;
|
||||
ostd::Size len;
|
||||
|
||||
|
@ -1797,8 +1788,11 @@ static bool cs_run_file(
|
|||
}
|
||||
buf[len] = '\0';
|
||||
|
||||
ostd::ConstCharRange src_str = ostd::ConstCharRange(buf.get(), len);
|
||||
cs_run_ret(cs, src_str, fname, src_str, ret);
|
||||
cs.src_file = fname;
|
||||
cs.src_str = ostd::ConstCharRange(buf.get(), len);
|
||||
cs.run_ret(cs.src_str, ret);
|
||||
cs.src_file = oldsrcfile;
|
||||
cs.src_str = oldsrcstr;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
71
cs_vm.hh
71
cs_vm.hh
|
@ -105,18 +105,46 @@ static void cs_do_args(CsState &cs, F body) {
|
|||
}
|
||||
}
|
||||
|
||||
ostd::ConstCharRange cs_debug_line(
|
||||
CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt,
|
||||
ostd::CharRange buf
|
||||
);
|
||||
|
||||
void cs_debug_alias(CsState &cs);
|
||||
|
||||
template<typename ...A>
|
||||
void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) {
|
||||
if (cs.nodebug) {
|
||||
return;
|
||||
}
|
||||
ostd::err.writefln(fmt, ostd::forward<A>(args)...);
|
||||
cs_debug_alias(cs);
|
||||
}
|
||||
|
||||
template<typename ...A>
|
||||
void cs_debug_code_line(
|
||||
CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt, A &&...args
|
||||
) {
|
||||
if (cs.nodebug) {
|
||||
return;
|
||||
}
|
||||
ostd::Array<char, 256> buf;
|
||||
ostd::err.writefln(
|
||||
cs_debug_line(cs, p, fmt, ostd::CharRange(buf.data(), buf.size())),
|
||||
ostd::forward<A>(args)...
|
||||
);
|
||||
cs_debug_alias(cs);
|
||||
}
|
||||
|
||||
ostd::Uint32 *compilecode(CsState &cs, ostd::ConstCharRange str);
|
||||
|
||||
struct GenState {
|
||||
CsState &cs;
|
||||
ostd::ConstCharRange src_file, src_str;
|
||||
CsVector<ostd::Uint32> code;
|
||||
char const *source;
|
||||
|
||||
GenState() = delete;
|
||||
GenState(CsState &csr):
|
||||
cs(csr), src_file(), src_str(), code(), source(nullptr)
|
||||
{}
|
||||
GenState(CsState &csr): cs(csr), code(), source(nullptr) {}
|
||||
|
||||
void gen_str(ostd::ConstCharRange word, bool macro = false) {
|
||||
if (word.size() <= 3 && !macro) {
|
||||
|
@ -211,41 +239,6 @@ struct GenState {
|
|||
}
|
||||
};
|
||||
|
||||
ostd::ConstCharRange cs_debug_line(
|
||||
ostd::ConstCharRange src_file, ostd::ConstCharRange src_str,
|
||||
ostd::ConstCharRange p, ostd::ConstCharRange fmt,
|
||||
ostd::CharRange buf
|
||||
);
|
||||
|
||||
void cs_debug_alias(CsState &cs);
|
||||
|
||||
template<typename ...A>
|
||||
void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) {
|
||||
if (cs.nodebug) {
|
||||
return;
|
||||
}
|
||||
ostd::err.writefln(fmt, ostd::forward<A>(args)...);
|
||||
cs_debug_alias(cs);
|
||||
}
|
||||
|
||||
template<typename ...A>
|
||||
void cs_debug_code_line(
|
||||
GenState &gs, ostd::ConstCharRange p, ostd::ConstCharRange fmt, A &&...args
|
||||
) {
|
||||
if (gs.cs.nodebug) {
|
||||
return;
|
||||
}
|
||||
ostd::Array<char, 256> buf;
|
||||
ostd::err.writefln(
|
||||
cs_debug_line(
|
||||
gs.src_file, gs.src_str, p, fmt,
|
||||
ostd::CharRange(buf.data(), buf.size())
|
||||
),
|
||||
ostd::forward<A>(args)...
|
||||
);
|
||||
cs_debug_alias(gs.cs);
|
||||
}
|
||||
|
||||
CsString intstr(int v);
|
||||
CsString floatstr(CsFloat v);
|
||||
|
||||
|
|
|
@ -380,6 +380,9 @@ struct OSTD_EXPORT CsState {
|
|||
IdentLink noalias;
|
||||
IdentLink *p_stack = &noalias;
|
||||
|
||||
ostd::ConstCharRange src_file;
|
||||
ostd::ConstCharRange src_str;
|
||||
|
||||
int identflags = 0;
|
||||
int nodebug = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue