From a789659387f47c48a2022bec23d6e85802df0da4 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 4 Apr 2021 05:36:19 +0200 Subject: [PATCH] minor cleanups --- src/cs_gen.cc | 8 ++++---- src/cs_ident.cc | 13 +++++++------ src/cs_ident.hh | 2 +- src/cs_vm.cc | 12 ++++++------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/cs_gen.cc b/src/cs_gen.cc index cc15d63..7c78cfe 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -22,7 +22,7 @@ std::string_view codegen_state::get_str() { } charbuf codegen_state::get_str_dup() { - charbuf buf{ts.istate}; + charbuf buf{ts}; unescape_string(std::back_inserter(buf), get_str()); return buf; } @@ -217,7 +217,7 @@ static bool compilearg( ); static void compilelookup(codegen_state &gs, int ltype) { - charbuf lookup{gs.ts.istate}; + charbuf lookup{gs.ts}; gs.next_char(); switch (gs.current()) { case '(': @@ -488,7 +488,7 @@ done: } static bool compileblocksub(codegen_state &gs) { - charbuf lookup{gs.ts.istate}; + charbuf lookup{gs.ts}; switch (gs.current()) { case '(': if (!compilearg(gs, VAL_ANY)) { @@ -1163,7 +1163,7 @@ static void compile_and_or( } static void compilestatements(codegen_state &gs, int rettype, int brak) { - charbuf idname{gs.ts.istate}; + charbuf idname{gs.ts}; for (;;) { gs.skip_comments(); idname.clear(); diff --git a/src/cs_ident.cc b/src/cs_ident.cc index 8ba778f..cf7b923 100644 --- a/src/cs_ident.cc +++ b/src/cs_ident.cc @@ -90,7 +90,7 @@ void var_changed(thread_state &ts, ident *id) { auto *cimp = static_cast(cid); any_value val{*ts.pstate}; val.set_ident(id); - cimp->call(*ts.pstate, std::span{&val, 1}, val); + cimp->call(ts, std::span{&val, 1}, val); } void ivar_impl::save_val() { @@ -105,16 +105,17 @@ void svar_impl::save_val() { p_override = std::move(p_storage); } -void command_impl::call(state &cs, std::span args, any_value &ret) { - auto &ts = *cs.thread_pointer(); +void command_impl::call( + thread_state &ts, std::span args, any_value &ret +) { auto idstsz = ts.idstack.size(); try { - p_cb_cftv(cs, args, ret); + p_cb_cftv(*ts.pstate, args, ret); } catch (...) { - ts.idstack.resize(idstsz, ident_stack{cs}); + ts.idstack.resize(idstsz, ident_stack{*ts.pstate}); throw; } - ts.idstack.resize(idstsz, ident_stack{cs}); + ts.idstack.resize(idstsz, ident_stack{*ts.pstate}); } bool ident_is_used_arg(ident *id, thread_state &ts) { diff --git a/src/cs_ident.hh b/src/cs_ident.hh index c96a21a..853d7f3 100644 --- a/src/cs_ident.hh +++ b/src/cs_ident.hh @@ -126,7 +126,7 @@ struct command_impl: ident_impl, command { string_ref name, string_ref args, int numargs, command_func func ); - void call(state &cs, std::span args, any_value &ret); + void call(thread_state &ts, std::span args, any_value &ret); string_ref p_cargs; command_func p_cb_cftv; diff --git a/src/cs_vm.cc b/src/cs_vm.cc index b12f1cf..c287de1 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -173,14 +173,14 @@ void exec_command( *ts.pstate, std::span{args, std::size_t(i)}, " " )); static_cast(id)->call( - *ts.pstate, std::span(&tv, &tv + 1), res + ts, std::span(&tv, &tv + 1), res ); return; } case 'V': i = std::max(i + 1, numargs); static_cast(id)->call( - *ts.pstate, std::span{args, std::size_t(i)}, res + ts, std::span{args, std::size_t(i)}, res ); return; case '1': @@ -196,7 +196,7 @@ void exec_command( } ++i; static_cast(id)->call( - *ts.pstate, std::span{args, std::size_t(i)}, res + ts, std::span{args, std::size_t(i)}, res ); } @@ -1227,7 +1227,7 @@ noid: ); std::size_t offset = args.size() - id->get_num_args(); result.force_none(); - id->call(cs, std::span{ + id->call(ts, std::span{ &args[offset], std::size_t(id->get_num_args()) }, result); force_arg(result, op & BC_INST_RET_MASK); @@ -1245,7 +1245,7 @@ noid: std::size_t callargs = *code++; std::size_t offset = args.size() - callargs; result.force_none(); - id->call(cs, std::span{&args[offset], callargs}, result); + id->call(ts, std::span{&args[offset], callargs}, result); force_arg(result, op & BC_INST_RET_MASK); args.resize(offset, any_value{cs}); continue; @@ -1265,7 +1265,7 @@ noid: tv.set_str(concat_values(cs, std::span{ &args[offset], callargs }, " ")); - id->call(cs, std::span{&tv, 1}, result); + id->call(ts, std::span{&tv, 1}, result); } force_arg(result, op & BC_INST_RET_MASK); args.resize(offset, any_value{cs});