From e2b65000d5ba1a2324010713252954e8b4298a9e Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 1 Apr 2021 04:19:00 +0200 Subject: [PATCH] hide value getter from public alias interface since this will become thread-specific, this API makes no sense --- include/cubescript/cubescript.hh | 2 -- src/cs_ident.cc | 6 +----- src/cs_state.cc | 14 ++++++++----- src/cs_vm.cc | 36 ++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 9e8a827..c088302 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -300,8 +300,6 @@ protected: }; struct LIBCUBESCRIPT_EXPORT alias: ident { - any_value get_value() const; - protected: alias() = default; }; diff --git a/src/cs_ident.cc b/src/cs_ident.cc index 3a59b0c..fc1c68b 100644 --- a/src/cs_ident.cc +++ b/src/cs_ident.cc @@ -176,7 +176,7 @@ bcode *alias_impl::compile_code(thread_state &ts) { if (!p_acode) { codegen_state gs(ts); gs.code.reserve(64); - gs.gen_main(get_value().get_str()); + gs.gen_main(p_astack->val_s.get_str()); /* i wish i could steal the memory somehow */ uint32_t *code = bcode_alloc(ts.istate, gs.code.size()); memcpy(code, gs.code.data(), gs.code.size() * sizeof(uint32_t)); @@ -397,10 +397,6 @@ LIBCUBESCRIPT_EXPORT void string_var::set_value(string_ref val) { static_cast(this)->p_storage = val; } -LIBCUBESCRIPT_EXPORT any_value alias::get_value() const { - return static_cast(this)->p_astack->val_s; -} - LIBCUBESCRIPT_EXPORT std::string_view command::get_args() const { return static_cast(this)->p_cargs; } diff --git a/src/cs_state.cc b/src/cs_state.cc index 7402b6a..175de22 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -196,8 +196,9 @@ LIBCUBESCRIPT_EXPORT void state::destroy() { ident *i = p.second; alias *a = i->get_alias(); if (a) { - a->get_value().force_none(); - static_cast(a)->clean_code(); + auto *aimp = static_cast(a); + aimp->p_astack->val_s.force_none(); + aimp->clean_code(); } sp->destroy(i->p_impl); } @@ -467,7 +468,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) { case ident_type::ALIAS: { alias_impl &a = static_cast(id); a.clean_code(); - a.get_value().set_str(""); + a.p_astack->val_s.set_str(""); break; } case ident_type::IVAR: { @@ -656,7 +657,7 @@ state::get_alias_val(std::string_view name) { if ((a->get_flags() & IDENT_FLAG_ARG) && !ident_is_used_arg(a, *p_tstate)) { return std::nullopt; } - return a->get_value().get_str(); + return static_cast(a)->p_astack->val_s.get_str(); } integer_type clamp_var(state &cs, integer_var *iv, integer_type v) { @@ -881,7 +882,10 @@ LIBCUBESCRIPT_EXPORT void state::run( ) { break; } - if (a->get_value().get_type() == value_type::NONE) { + if ( + static_cast(a)->p_astack->val_s.get_type() == + value_type::NONE + ) { break; } exec_alias( diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 111eeb2..0f6610f 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -770,7 +770,7 @@ std::uint32_t *vm_exec( any_value &arg = args.back(); switch (get_lookupu_type(ts, arg, id, op)) { case ID_ALIAS: - arg = static_cast(id)->get_value(); + arg = static_cast(id)->p_astack->val_s; arg.force_str(); continue; case ID_SVAR: @@ -798,7 +798,7 @@ std::uint32_t *vm_exec( args.emplace_back(cs).set_str(""); } else { auto &v = args.emplace_back(cs); - v = a->get_value(); + v = static_cast(a)->p_astack->val_s; v.force_str(); } continue; @@ -809,9 +809,9 @@ std::uint32_t *vm_exec( any_value &arg = args.back(); switch (get_lookupu_type(ts, arg, id, op)) { case ID_ALIAS: - arg.set_int( - static_cast(id)->get_value().get_int() - ); + arg.set_int(static_cast( + id + )->p_astack->val_s.get_int()); continue; case ID_SVAR: arg.set_int(parse_int( @@ -838,7 +838,9 @@ std::uint32_t *vm_exec( if (!a) { args.emplace_back(cs).set_int(0); } else { - args.emplace_back(cs).set_int(a->get_value().get_int()); + args.emplace_back(cs).set_int( + static_cast(a)->p_astack->val_s.get_int() + ); } continue; } @@ -847,9 +849,9 @@ std::uint32_t *vm_exec( any_value &arg = args.back(); switch (get_lookupu_type(ts, arg, id, op)) { case ID_ALIAS: - arg.set_float( - static_cast(id)->get_value().get_float() - ); + arg.set_float(static_cast( + id + )->p_astack->val_s.get_float()); continue; case ID_SVAR: arg.set_float(parse_float( @@ -878,7 +880,9 @@ std::uint32_t *vm_exec( if (!a) { args.emplace_back(cs).set_float(float_type(0)); } else { - args.emplace_back(cs).set_float(a->get_value().get_float()); + args.emplace_back(cs).set_float(static_cast( + a + )->p_astack->val_s.get_float()); } continue; } @@ -887,7 +891,9 @@ std::uint32_t *vm_exec( any_value &arg = args.back(); switch (get_lookupu_type(ts, arg, id, op)) { case ID_ALIAS: - static_cast(id)->get_value().get_val(arg); + static_cast( + id + )->p_astack->val_s.get_val(arg); continue; case ID_SVAR: arg.set_str(static_cast(id)->get_value()); @@ -912,7 +918,9 @@ std::uint32_t *vm_exec( if (!a) { args.emplace_back(cs).set_none(); } else { - a->get_value().get_val(args.emplace_back(cs)); + static_cast(a)->p_astack->val_s.get_val( + args.emplace_back(cs) + ); } continue; } @@ -1210,7 +1218,9 @@ noid: force_arg(result, op & BC_INST_RET_MASK); continue; } - if (a->get_value().get_type() == value_type::NONE) { + if (static_cast( + a + )->p_astack->val_s.get_type() == value_type::NONE) { goto noid; } exec_alias(