From bd1e7825d8ccfdf4b1d2b152f1b6049844e483f5 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 5 May 2021 03:16:32 +0200 Subject: [PATCH] be consistent with usage of get_/set_ prefixes --- include/cubescript/cubescript/error.hh | 4 +- include/cubescript/cubescript/ident.hh | 36 ++++++------- include/cubescript/cubescript/state.hh | 38 +++++-------- include/cubescript/cubescript/util.hh | 18 +++---- include/cubescript/cubescript/value.hh | 2 +- src/cs_bcode.cc | 16 +++--- src/cs_bcode.hh | 4 +- src/cs_error.cc | 2 +- src/cs_gen.cc | 16 +++--- src/cs_ident.cc | 74 +++++++++++++------------- src/cs_parser.cc | 22 ++++---- src/cs_state.cc | 68 +++++++++++------------ src/cs_thread.cc | 2 +- src/cs_val.cc | 36 ++++++------- src/cs_vm.cc | 68 +++++++++++------------ src/lib_base.cc | 20 +++---- src/lib_list.cc | 50 ++++++++--------- tools/edit_fallback.hh | 2 +- tools/edit_linenoise.hh | 6 +-- tools/repl.cc | 18 +++---- 20 files changed, 246 insertions(+), 256 deletions(-) diff --git a/include/cubescript/cubescript/error.hh b/include/cubescript/cubescript/error.hh index 7fdfcd8..da175ec 100644 --- a/include/cubescript/cubescript/error.hh +++ b/include/cubescript/cubescript/error.hh @@ -114,12 +114,12 @@ struct LIBCUBESCRIPT_EXPORT error { } /** @brief Get a reference to the call stack state. */ - stack_state &get_stack() { + stack_state &stack() { return p_stack; } /** @brief Get a reference to the call stack state. */ - stack_state const &get_stack() const { + stack_state const &stack() const { return p_stack; } diff --git a/include/cubescript/cubescript/ident.hh b/include/cubescript/cubescript/ident.hh index 1eb7a1a..9555c7d 100644 --- a/include/cubescript/cubescript/ident.hh +++ b/include/cubescript/cubescript/ident.hh @@ -47,10 +47,10 @@ enum class ident_type { */ struct LIBCUBESCRIPT_EXPORT ident { /** @brief Get the cubescript::ident_type of this ident. */ - ident_type get_type() const; + ident_type type() const; /** @brief Get a view to the name of the ident. */ - std::string_view get_name() const; + std::string_view name() const; /** @brief Get the index of the ident. * @@ -59,7 +59,7 @@ struct LIBCUBESCRIPT_EXPORT ident { * with an integer (it is guaranteed that once created, it will stay the * same for the whole lifetime of the main thread). */ - int get_index() const; + int index() const; /** @brief Check if the idents are the same. */ bool operator==(ident &other) const; @@ -69,44 +69,44 @@ struct LIBCUBESCRIPT_EXPORT ident { /** @brief Check if the ident is a cubescript::alias. * - * Effectively like `get_type() == ident_type::ALIAS`. + * Effectively like `type() == ident_type::ALIAS`. */ bool is_alias() const; /** @brief Check if the ident is a cubescript::command. * - * Effectively like `get_type() == ident_type::COMMAND`. + * Effectively like `type() == ident_type::COMMAND`. */ bool is_command() const; /** @brief Check if the ident is a special ident. * - * Effectively like `get_type() == ident_type::SPECIAL`. + * Effectively like `type() == ident_type::SPECIAL`. */ bool is_special() const; /** @brief Check if the ident is a cubescript::global_var. * - * This will return `true` if ident::get_type() returns either + * This will return `true` if ident::type() returns either * ident_type::IVAR, ident_type::FVAR or ident_type::SVAR. */ bool is_var() const; /** @brief Check if the ident is a cubescript::integer_var. * - * Effectively like `get_type() == ident_type::IVAR`. + * Effectively like `type() == ident_type::IVAR`. */ bool is_ivar() const; /** @brief Check if the ident is a cubescript::float_var. * - * Effectively like `get_type() == ident_type::FVAR`. + * Effectively like `type() == ident_type::FVAR`. */ bool is_fvar() const; /** @brief Check if the ident is a cubescript::string_var. * - * Effectively like `get_type() == ident_type::SVAR`. + * Effectively like `type() == ident_type::SVAR`. */ bool is_svar() const; @@ -192,12 +192,12 @@ struct LIBCUBESCRIPT_EXPORT global_var: ident { /** @brief Get whether the variable is overridable. * - * Equivalent to `get_variable_type() == var_type::OVERRIDABLE`. + * Equivalent to `variable_type() == var_type::OVERRIDABLE`. */ bool is_overridable() const; /** @brief Get the cubescript::var_type of the variable. */ - var_type get_variable_type() const; + var_type variable_type() const; /** @brief Save the variable. * @@ -231,7 +231,7 @@ protected: */ struct LIBCUBESCRIPT_EXPORT integer_var: global_var { /** @brief Get the value of the variable. */ - integer_type get_value() const; + integer_type value() const; /** @brief Set the value of the variable. * @@ -268,7 +268,7 @@ protected: */ struct LIBCUBESCRIPT_EXPORT float_var: global_var { /** @brief Get the value of the variable. */ - float_type get_value() const; + float_type value() const; /** @brief Set the value of the variable. * @@ -305,7 +305,7 @@ protected: */ struct LIBCUBESCRIPT_EXPORT string_var: global_var { /** @brief Get the value of the variable. */ - string_ref get_value() const; + string_ref value() const; /** @brief Set the value of the variable. * @@ -354,7 +354,7 @@ struct LIBCUBESCRIPT_EXPORT alias: ident { bool is_arg() const; /** @brief Get the value of the alias for the given thread. */ - any_value get_value(state &cs) const; + any_value value(state &cs) const; /** @brief Set the value of the alias for the given thread. */ void set_value(state &cs, any_value v); @@ -377,14 +377,14 @@ protected: */ struct LIBCUBESCRIPT_EXPORT command: ident { /** @brief Get the argument list. */ - std::string_view get_args() const; + std::string_view args() const; /** @brief Get the number of arguments the command expects. * * Only non-variadic arguments count here (i.e. no repeated arguments, * no `C`, no `V`; everything else counts as one argument). */ - int get_num_args() const; + int arg_count() const; /** @brief Call a command. * diff --git a/include/cubescript/cubescript/state.hh b/include/cubescript/cubescript/state.hh index e655dbf..56996c8 100644 --- a/include/cubescript/cubescript/state.hh +++ b/include/cubescript/cubescript/state.hh @@ -141,17 +141,17 @@ struct LIBCUBESCRIPT_EXPORT state { * interrupting execution from the side in an interactive interpreter. */ template - hook_func set_call_hook(F &&f) { - return set_call_hook( + hook_func call_hook(F &&f) { + return call_hook( hook_func{std::forward(f), callable_alloc, this} ); } /** @brief Get a reference to the call hook */ - hook_func const &get_call_hook() const; + hook_func const &call_hook() const; /** @brief Get a reference to the call hook */ - hook_func &get_call_hook(); + hook_func &call_hook(); /** @brief Clear override state for the given ident * @@ -395,15 +395,12 @@ struct LIBCUBESCRIPT_EXPORT state { * Keep in mind that if an alias is pushed, its flags will be cleared once * popped. * - * @see set_override_mode() + * @see override_mode() */ - bool get_override_mode() const; + bool override_mode() const; - /** @brief Set the thread's override mode - * - * @see get_override_mode() - */ - bool set_override_mode(bool v); + /** @brief Set the thread's override mode */ + bool override_mode(bool v); /** @brief Get if the thread is in persist most * @@ -414,25 +411,18 @@ struct LIBCUBESCRIPT_EXPORT state { * * Keep in mind that if an alias is pushed, its flags will be cleared once * popped. - * - * @see set_persist_mode() */ - bool get_persist_mode() const; + bool persist_mode() const; - /** @brief Set the thread's persist mode - * - * @see get_persist_mode() - */ - bool set_persist_mode(bool v); + /** @brief Set the thread's persist mode */ + bool persist_mode(bool v); /** @brief Get the maximum call depth of the VM * * If zero, it is unlimited, otherwise it specifies how much the VM is * allowed to recurse. By default, it is zero. - * - * @see set_max_call_depth() */ - std::size_t get_max_call_depth() const; + std::size_t max_call_depth() const; /** @brief Set the maximum call depth ov the VM * @@ -442,14 +432,14 @@ struct LIBCUBESCRIPT_EXPORT state { * * @return the old value */ - std::size_t set_max_call_depth(std::size_t v); + std::size_t max_call_depth(std::size_t v); private: friend struct state_p; LIBCUBESCRIPT_LOCAL state(void *is); - hook_func set_call_hook(hook_func func); + hook_func call_hook(hook_func func); command &new_command( std::string_view name, std::string_view args, command_func func diff --git a/include/cubescript/cubescript/util.hh b/include/cubescript/cubescript/util.hh index ca60857..806bd4a 100644 --- a/include/cubescript/cubescript/util.hh +++ b/include/cubescript/cubescript/util.hh @@ -63,7 +63,7 @@ struct LIBCUBESCRIPT_EXPORT list_parser { * * The already read items will not be contained in the result. */ - std::string_view get_input() const { + std::string_view input() const { return std::string_view{ p_input_beg, std::size_t(p_input_end - p_input_beg) }; @@ -89,8 +89,8 @@ struct LIBCUBESCRIPT_EXPORT list_parser { * If the item was quoted with double quotes, the contents will be run * through cubescript::unescape_string() first. * - * @see get_raw_item() - * @see get_quoted_item() + * @see raw_item() + * @see quoted_item() */ string_ref get_item() const; @@ -100,21 +100,21 @@ struct LIBCUBESCRIPT_EXPORT list_parser { * circumstances and represents simply a slice of the original input. * * @see get_item() - * @see get_quoted_item() + * @see quoted_item() */ - std::string_view get_raw_item() const { + std::string_view raw_item() const { return std::string_view{p_ibeg, std::size_t(p_iend - p_ibeg)}; } /** @brief Get the currently parsed raw item * - * Like get_raw_item(), but contains the quotes too, if there were any. + * Like raw_item(), but contains the quotes too, if there were any. * Likewise, the resulting view is just a slice of the original input. * * @see get_item() - * @see get_raw_item() + * @see raw_item() */ - std::string_view get_quoted_item() const { + std::string_view quoted_item() const { return std::string_view{p_qbeg, std::size_t(p_qend - p_qbeg)}; } @@ -297,7 +297,7 @@ inline R print_stack(R writer, stack_state const &st) { char buf[32] = {0}; auto nd = st.get(); while (nd) { - auto name = nd->id->get_name(); + auto name = nd->id->name(); *writer++ = ' '; *writer++ = ' '; if ((nd->index == 1) && st.gap()) { diff --git a/include/cubescript/cubescript/value.hh b/include/cubescript/cubescript/value.hh index bda79c9..17e8587 100644 --- a/include/cubescript/cubescript/value.hh +++ b/include/cubescript/cubescript/value.hh @@ -329,7 +329,7 @@ struct LIBCUBESCRIPT_EXPORT any_value { any_value &operator=(any_value &&); /** @brief Get the type of the value. */ - value_type get_type() const; + value_type type() const; /** @brief Set the value to an integer. * diff --git a/src/cs_bcode.cc b/src/cs_bcode.cc index 511f655..92b8d57 100644 --- a/src/cs_bcode.cc +++ b/src/cs_bcode.cc @@ -7,29 +7,29 @@ namespace cubescript { /* public API impls */ LIBCUBESCRIPT_EXPORT bcode_ref::bcode_ref(bcode *v): p_code(v) { - bcode_addref(v->get_raw()); + bcode_addref(v->raw()); } LIBCUBESCRIPT_EXPORT bcode_ref::bcode_ref(bcode_ref const &v): p_code(v.p_code) { - bcode_addref(p_code->get_raw()); + bcode_addref(p_code->raw()); } LIBCUBESCRIPT_EXPORT bcode_ref::~bcode_ref() { - bcode_unref(p_code->get_raw()); + bcode_unref(p_code->raw()); } LIBCUBESCRIPT_EXPORT bcode_ref &bcode_ref::operator=( bcode_ref const &v ) { - bcode_unref(p_code->get_raw()); + bcode_unref(p_code->raw()); p_code = v.p_code; - bcode_addref(p_code->get_raw()); + bcode_addref(p_code->raw()); return *this; } LIBCUBESCRIPT_EXPORT bcode_ref &bcode_ref::operator=(bcode_ref &&v) { - bcode_unref(p_code->get_raw()); + bcode_unref(p_code->raw()); p_code = v.p_code; v.p_code = nullptr; return *this; @@ -39,7 +39,7 @@ LIBCUBESCRIPT_EXPORT bool bcode_ref::empty() const { if (!p_code) { return true; } - return (*p_code->get_raw() & BC_INST_OP_MASK) == BC_INST_EXIT; + return (*p_code->raw() & BC_INST_OP_MASK) == BC_INST_EXIT; } LIBCUBESCRIPT_EXPORT bcode_ref::operator bool() const { @@ -48,7 +48,7 @@ LIBCUBESCRIPT_EXPORT bcode_ref::operator bool() const { LIBCUBESCRIPT_EXPORT any_value bcode_ref::call(state &cs) const { any_value ret{}; - vm_exec(state_p{cs}.ts(), p_code->get_raw(), ret); + vm_exec(state_p{cs}.ts(), p_code->raw(), ret); return ret; } diff --git a/src/cs_bcode.hh b/src/cs_bcode.hh index bf42ed1..cfd1a53 100644 --- a/src/cs_bcode.hh +++ b/src/cs_bcode.hh @@ -13,11 +13,11 @@ struct internal_state; struct bcode { std::uint32_t init; - std::uint32_t *get_raw() { + std::uint32_t *raw() { return &init; } - std::uint32_t const *get_raw() const { + std::uint32_t const *raw() const { return &init; } }; diff --git a/src/cs_error.cc b/src/cs_error.cc index acba612..295bef2 100644 --- a/src/cs_error.cc +++ b/src/cs_error.cc @@ -87,7 +87,7 @@ LIBCUBESCRIPT_EXPORT stack_state error::save_stack(state &cs) { auto &ts = state_p{cs}.ts(); integer_var *dalias = ts.istate->ivar_dbgalias; auto dval = std::clamp( - dalias->get_value(), integer_type(0), integer_type(1000) + dalias->value(), integer_type(0), integer_type(1000) ); if (!dval) { return stack_state{cs, nullptr, !!ts.callstack}; diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 3977013..bc68165 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -283,7 +283,7 @@ void gen_state::gen_val_ident() { } void gen_state::gen_val_ident(ident &i) { - code.push_back(BC_INST_IDENT | (i.get_index() << 8)); + code.push_back(BC_INST_IDENT | (i.index() << 8)); } void gen_state::gen_val_ident(std::string_view v) { @@ -330,25 +330,25 @@ void gen_state::gen_val( void gen_state::gen_lookup_ivar(ident &id, int ltype) { code.push_back( - BC_INST_IVAR | ret_code(ltype, BC_RET_INT) | (id.get_index() << 8) + BC_INST_IVAR | ret_code(ltype, BC_RET_INT) | (id.index() << 8) ); } void gen_state::gen_lookup_fvar(ident &id, int ltype) { code.push_back( - BC_INST_FVAR | ret_code(ltype, BC_RET_FLOAT) | (id.get_index() << 8) + BC_INST_FVAR | ret_code(ltype, BC_RET_FLOAT) | (id.index() << 8) ); } void gen_state::gen_lookup_svar(ident &id, int ltype) { code.push_back( - BC_INST_SVAR | ret_code(ltype, BC_RET_STRING) | (id.get_index() << 8) + BC_INST_SVAR | ret_code(ltype, BC_RET_STRING) | (id.index() << 8) ); } void gen_state::gen_lookup_alias(ident &id, int ltype, int dtype) { code.push_back( - BC_INST_LOOKUP | ret_code(ltype, ret_code(dtype)) | (id.get_index() << 8) + BC_INST_LOOKUP | ret_code(ltype, ret_code(dtype)) | (id.index() << 8) ); } @@ -357,7 +357,7 @@ void gen_state::gen_lookup_ident(int ltype) { } void gen_state::gen_assign_alias(ident &id) { - code.push_back(BC_INST_ALIAS | (id.get_index() << 8)); + code.push_back(BC_INST_ALIAS | (id.index() << 8)); } void gen_state::gen_assign() { @@ -394,14 +394,14 @@ void gen_state::gen_concat(std::size_t concs, bool space, int ltype) { void gen_state::gen_command_call( ident &id, int comt, int ltype, std::uint32_t nargs ) { - code.push_back(comt | ret_code(ltype) | (id.get_index() << 8)); + code.push_back(comt | ret_code(ltype) | (id.index() << 8)); if (comt != BC_INST_COM) { code.push_back(nargs); } } void gen_state::gen_alias_call(ident &id, std::uint32_t nargs) { - code.push_back(BC_INST_CALL | (id.get_index() << 8)); + code.push_back(BC_INST_CALL | (id.index() << 8)); code.push_back(nargs); } diff --git a/src/cs_ident.cc b/src/cs_ident.cc index 43d75b9..6555682 100644 --- a/src/cs_ident.cc +++ b/src/cs_ident.cc @@ -91,15 +91,15 @@ void var_changed(thread_state &ts, ident *id, any_value &oldval) { any_value val[3] = {}; val[0].set_ident(*id); val[1] = std::move(oldval); - switch (id->get_type()) { + switch (id->type()) { case ident_type::IVAR: - val[2].set_integer(static_cast(id)->get_value()); + val[2].set_integer(static_cast(id)->value()); break; case ident_type::FVAR: - val[2].set_float(static_cast(id)->get_value()); + val[2].set_float(static_cast(id)->value()); break; case ident_type::SVAR: - val[2].set_string(static_cast(id)->get_value()); + val[2].set_string(static_cast(id)->value()); break; default: return; @@ -138,7 +138,7 @@ bool ident_is_used_arg(ident const *id, thread_state &ts) { if (!ts.callstack) { return true; } - return ts.callstack->usedargs[id->get_index()]; + return ts.callstack->usedargs[id->index()]; } void alias_stack::push(ident_stack &st) { @@ -155,7 +155,7 @@ void alias_stack::set_arg(alias *a, thread_state &ts, any_value &v) { node->code = bcode_ref{}; } else { push(ts.idstack.emplace_back()); - ts.callstack->usedargs[a->get_index()] = true; + ts.callstack->usedargs[a->index()] = true; } node->val_s = std::move(v); } @@ -174,18 +174,18 @@ void alias_stack::set_alias(alias *a, thread_state &ts, any_value &v) { LIBCUBESCRIPT_EXPORT ident::~ident() {} -LIBCUBESCRIPT_EXPORT ident_type ident::get_type() const { +LIBCUBESCRIPT_EXPORT ident_type ident::type() const { if (p_impl->p_type > ID_ALIAS) { return ident_type::SPECIAL; } return ident_type(p_impl->p_type); } -LIBCUBESCRIPT_EXPORT std::string_view ident::get_name() const { +LIBCUBESCRIPT_EXPORT std::string_view ident::name() const { return p_impl->p_name; } -LIBCUBESCRIPT_EXPORT int ident::get_index() const { +LIBCUBESCRIPT_EXPORT int ident::index() const { return p_impl->p_index; } @@ -198,19 +198,19 @@ LIBCUBESCRIPT_EXPORT bool ident::operator!=(ident &other) const { } LIBCUBESCRIPT_EXPORT bool ident::is_alias() const { - return get_type() == ident_type::ALIAS; + return type() == ident_type::ALIAS; } LIBCUBESCRIPT_EXPORT bool ident::is_command() const { - return get_type() == ident_type::COMMAND; + return type() == ident_type::COMMAND; } LIBCUBESCRIPT_EXPORT bool ident::is_special() const { - return get_type() == ident_type::SPECIAL; + return type() == ident_type::SPECIAL; } LIBCUBESCRIPT_EXPORT bool ident::is_var() const { - switch (get_type()) { + switch (type()) { case ident_type::IVAR: case ident_type::FVAR: case ident_type::SVAR: @@ -222,19 +222,19 @@ LIBCUBESCRIPT_EXPORT bool ident::is_var() const { } LIBCUBESCRIPT_EXPORT bool ident::is_ivar() const { - return get_type() == ident_type::IVAR; + return type() == ident_type::IVAR; } LIBCUBESCRIPT_EXPORT bool ident::is_fvar() const { - return get_type() == ident_type::FVAR; + return type() == ident_type::FVAR; } LIBCUBESCRIPT_EXPORT bool ident::is_svar() const { - return get_type() == ident_type::SVAR; + return type() == ident_type::SVAR; } LIBCUBESCRIPT_EXPORT bool ident::is_overridden(state &cs) const { - switch (get_type()) { + switch (type()) { case ident_type::IVAR: case ident_type::FVAR: case ident_type::SVAR: @@ -250,7 +250,7 @@ LIBCUBESCRIPT_EXPORT bool ident::is_overridden(state &cs) const { } LIBCUBESCRIPT_EXPORT bool ident::is_persistent(state &cs) const { - switch (get_type()) { + switch (type()) { case ident_type::IVAR: case ident_type::FVAR: case ident_type::SVAR: @@ -277,7 +277,7 @@ LIBCUBESCRIPT_EXPORT bool global_var::is_overridable() const { return (p_impl->p_flags & IDENT_FLAG_OVERRIDE); } -LIBCUBESCRIPT_EXPORT var_type global_var::get_variable_type() const { +LIBCUBESCRIPT_EXPORT var_type global_var::variable_type() const { if (p_impl->p_flags & IDENT_FLAG_OVERRIDE) { return var_type::OVERRIDABLE; } else if (p_impl->p_flags & IDENT_FLAG_PERSIST) { @@ -293,7 +293,7 @@ LIBCUBESCRIPT_EXPORT void global_var::save(state &cs) { if (p_impl->p_flags & IDENT_FLAG_PERSIST) { throw error{ cs, "cannot override persistent variable '%s'", - get_name().data() + name().data() }; } if (!(p_impl->p_flags & IDENT_FLAG_OVERRIDDEN)) { @@ -311,7 +311,7 @@ LIBCUBESCRIPT_EXPORT any_value global_var::call( return ident::call(args, cs); } -LIBCUBESCRIPT_EXPORT integer_type integer_var::get_value() const { +LIBCUBESCRIPT_EXPORT integer_type integer_var::value() const { return static_cast(this)->p_storage; } @@ -320,14 +320,14 @@ LIBCUBESCRIPT_EXPORT void integer_var::set_value( ) { if (is_read_only()) { throw error{ - cs, "variable '%s' is read only", get_name().data() + cs, "variable '%s' is read only", name().data() }; } if (!do_write) { return; } save(cs); - auto oldv = get_value(); + auto oldv = value(); set_raw_value(val); if (trigger) { any_value v; @@ -348,7 +348,7 @@ inline any_value call_var( auto *cimp = static_cast(hid); auto &targs = ts.vmstack; auto osz = targs.size(); - auto anargs = std::size_t(cimp->get_num_args()); + auto anargs = std::size_t(cimp->arg_count()); auto nargs = args.size(); targs.resize( osz + std::max(args.size(), anargs + 1) @@ -366,7 +366,7 @@ LIBCUBESCRIPT_EXPORT any_value integer_var::call( return call_var(*this, state_p{cs}.ts().istate->cmd_ivar, args, cs); } -LIBCUBESCRIPT_EXPORT float_type float_var::get_value() const { +LIBCUBESCRIPT_EXPORT float_type float_var::value() const { return static_cast(this)->p_storage; } @@ -375,14 +375,14 @@ LIBCUBESCRIPT_EXPORT void float_var::set_value( ) { if (is_read_only()) { throw error{ - cs, "variable '%s' is read only", get_name().data() + cs, "variable '%s' is read only", name().data() }; } if (!do_write) { return; } save(cs); - auto oldv = get_value(); + auto oldv = value(); set_raw_value(val); if (trigger) { any_value v; @@ -401,7 +401,7 @@ LIBCUBESCRIPT_EXPORT any_value float_var::call( return call_var(*this, state_p{cs}.ts().istate->cmd_fvar, args, cs); } -LIBCUBESCRIPT_EXPORT string_ref string_var::get_value() const { +LIBCUBESCRIPT_EXPORT string_ref string_var::value() const { return static_cast(this)->p_storage; } @@ -410,14 +410,14 @@ LIBCUBESCRIPT_EXPORT void string_var::set_value( ) { if (is_read_only()) { throw error{ - cs, "variable '%s' is read only", get_name().data() + cs, "variable '%s' is read only", name().data() }; } if (!do_write) { return; } save(cs); - auto oldv = get_value(); + auto oldv = value(); set_raw_value(std::move(val)); if (trigger) { any_value v; @@ -436,7 +436,7 @@ LIBCUBESCRIPT_EXPORT any_value string_var::call( return call_var(*this, state_p{cs}.ts().istate->cmd_svar, args, cs); } -LIBCUBESCRIPT_EXPORT any_value alias::get_value(state &cs) const { +LIBCUBESCRIPT_EXPORT any_value alias::value(state &cs) const { return state_p{cs}.ts().get_astack(this).node->val_s; } @@ -466,11 +466,11 @@ LIBCUBESCRIPT_EXPORT any_value alias::call( return ret; } -LIBCUBESCRIPT_EXPORT std::string_view command::get_args() const { +LIBCUBESCRIPT_EXPORT std::string_view command::args() const { return static_cast(this)->p_cargs; } -LIBCUBESCRIPT_EXPORT int command::get_num_args() const { +LIBCUBESCRIPT_EXPORT int command::arg_count() const { return static_cast(this)->p_numargs; } @@ -484,11 +484,11 @@ LIBCUBESCRIPT_EXPORT any_value command::call( } auto nargs = args.size(); auto &ts = state_p{cs}.ts(); - if (nargs < std::size_t(cimpl.get_num_args())) { + if (nargs < std::size_t(cimpl.arg_count())) { stack_guard s{ts}; /* restore after call */ auto &targs = ts.vmstack; auto osz = targs.size(); - targs.resize(osz + cimpl.get_num_args()); + targs.resize(osz + cimpl.arg_count()); for (std::size_t i = 0; i < nargs; ++i) { targs[osz + i] = args[i]; } @@ -503,7 +503,7 @@ LIBCUBESCRIPT_EXPORT any_value command::call( LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, ident &a) { if (!a.is_alias()) { - throw error{cs, "ident '%s' is not an alias", a.get_name().data()}; + throw error{cs, "ident '%s' is not an alias", a.name().data()}; } auto &ts = state_p{cs}.ts(); p_alias = static_cast(&a); @@ -519,7 +519,7 @@ LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, std::string_view name): LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, any_value const &v): alias_local{cs, ( - v.get_type() == value_type::IDENT + v.type() == value_type::IDENT ) ? v.get_ident(cs) : cs.new_ident(v.get_string(cs))} {} diff --git a/src/cs_parser.cc b/src/cs_parser.cc index 10bf5af..5c4deee 100644 --- a/src/cs_parser.cc +++ b/src/cs_parser.cc @@ -479,7 +479,7 @@ lookup_id: ident &id = ts.istate->new_ident( *ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN ); - switch (id.get_type()) { + switch (id.type()) { case ident_type::IVAR: if (ltype == VAL_POP) { return; @@ -532,7 +532,7 @@ lookup_id: return; case ident_type::COMMAND: { std::uint32_t comtype = BC_INST_COM, numargs = 0; - auto fmt = static_cast(id).get_args(); + auto fmt = static_cast(id).args(); for (char c: fmt) { switch (c) { case '$': @@ -603,7 +603,7 @@ lookup_id: ident &id = ts.istate->new_ident( *ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN ); - switch (id.get_type()) { + switch (id.type()) { case ident_type::IVAR: gs.gen_lookup_ivar(id); return true; @@ -956,7 +956,7 @@ bool parser_state::parse_call_command( command_impl *id, ident &self, int rettype ) { std::uint32_t comtype = BC_INST_COM, numargs = 0, fakeargs = 0; - auto fmt = id->get_args(); + auto fmt = id->args(); bool more = true, rep = false; for (auto it = fmt.begin(); it != fmt.end(); ++it) { switch (*it) { @@ -1258,7 +1258,7 @@ static bool parse_no_id(parser_state &ps, int term) { static bool parse_assign_var( parser_state &ps, command_impl *id, ident &var, int ltype ) { - auto fmt = id->get_args(); + auto fmt = id->args(); std::uint32_t comtype = BC_INST_COM; std::uint32_t nargs = 0; bool more = true, got = false, rep = false; @@ -1337,7 +1337,7 @@ bool parser_state::parse_assign( *ts.pstate, idname.str_term(), IDENT_FLAG_UNKNOWN ); /* check what we're assigning */ - switch (id.get_type()) { + switch (id.type()) { case ident_type::ALIAS: { /* alias assignment: parse out any one argument */ bool more = parse_arg(VAL_ANY); @@ -1477,7 +1477,7 @@ LIBCUBESCRIPT_EXPORT bool list_parser::parse() { switch (*p_input_beg) { case '"': { char const *qi = p_input_beg; - p_input_beg = parse_string(*p_state, get_input()); + p_input_beg = parse_string(*p_state, input()); p_qbeg = qi; p_qend = p_input_beg; p_ibeg = p_qbeg + 1; @@ -1502,7 +1502,7 @@ LIBCUBESCRIPT_EXPORT bool list_parser::parse() { case '"': /* the quote is needed in str parsing */ --p_input_beg; - p_input_beg = parse_string(*p_state, get_input()); + p_input_beg = parse_string(*p_state, input()); break; case '/': if ( @@ -1541,7 +1541,7 @@ endblock: case ']': return false; default: { - char const *e = parse_word(*p_state, get_input()); + char const *e = parse_word(*p_state, input()); p_ibeg = p_qbeg = p_input_beg; p_iend = p_qend = e; p_input_beg = e; @@ -1566,10 +1566,10 @@ LIBCUBESCRIPT_EXPORT std::size_t list_parser::count() { LIBCUBESCRIPT_EXPORT string_ref list_parser::get_item() const { if ((p_qbeg != p_qend) && (*p_qbeg == '"')) { charbuf buf{*p_state}; - unescape_string(std::back_inserter(buf), get_raw_item()); + unescape_string(std::back_inserter(buf), raw_item()); return string_ref{*p_state, buf.str()}; } - return string_ref{*p_state, get_raw_item()}; + return string_ref{*p_state, raw_item()}; } LIBCUBESCRIPT_EXPORT void list_parser::skip_until_item() { diff --git a/src/cs_state.cc b/src/cs_state.cc index 907afc3..a4a5ef4 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -48,7 +48,7 @@ ident *internal_state::add_ident(ident *id, ident_impl *impl) { return nullptr; } ident_p{*id}.impl(impl); - idents[id->get_name()] = id; + idents[id->name()] = id; impl->p_index = int(identmap.size()); identmap.push_back(id); return identmap.back(); @@ -126,8 +126,8 @@ state::state(alloc_func func, void *data) { ) { auto &iv = static_cast(args[0].get_ident(cs)); if (args[2].get_integer() <= 1) { - std::printf("%s = ", iv.get_name().data()); - std::printf(INTEGER_FORMAT, iv.get_value()); + std::printf("%s = ", iv.name().data()); + std::printf(INTEGER_FORMAT, iv.value()); std::printf("\n"); } else { iv.set_value(cs, args[1].get_integer()); @@ -139,8 +139,8 @@ state::state(alloc_func func, void *data) { ) { auto &fv = static_cast(args[0].get_ident(cs)); if (args[2].get_integer() <= 1) { - auto val = fv.get_value(); - std::printf("%s = ", fv.get_name().data()); + auto val = fv.value(); + std::printf("%s = ", fv.name().data()); if (std::floor(val) == val) { std::printf(ROUND_FLOAT_FORMAT, val); } else { @@ -157,11 +157,11 @@ state::state(alloc_func func, void *data) { ) { auto &sv = static_cast(args[0].get_ident(cs)); if (args[2].get_integer() <= 1) { - auto val = sv.get_value(); + auto val = sv.value(); if (val.view().find('"') == std::string_view::npos) { - std::printf("%s = \"%s\"\n", sv.get_name().data(), val.data()); + std::printf("%s = \"%s\"\n", sv.name().data(), val.data()); } else { - std::printf("%s = [%s]\n", sv.get_name().data(), val.data()); + std::printf("%s = [%s]\n", sv.name().data(), val.data()); } } else { sv.set_value(cs, args[1].get_string(cs)); @@ -299,15 +299,15 @@ LIBCUBESCRIPT_EXPORT state state::new_thread() { return state{p_tstate->istate}; } -LIBCUBESCRIPT_EXPORT hook_func state::set_call_hook(hook_func func) { +LIBCUBESCRIPT_EXPORT hook_func state::call_hook(hook_func func) { return p_tstate->set_hook(std::move(func)); } -LIBCUBESCRIPT_EXPORT hook_func const &state::get_call_hook() const { +LIBCUBESCRIPT_EXPORT hook_func const &state::call_hook() const { return p_tstate->get_hook(); } -LIBCUBESCRIPT_EXPORT hook_func &state::get_call_hook() { +LIBCUBESCRIPT_EXPORT hook_func &state::call_hook() { return p_tstate->get_hook(); } @@ -341,7 +341,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) { if (!id.is_overridden(*this)) { return; } - switch (id.get_type()) { + switch (id.type()) { case ident_type::ALIAS: { auto &ast = p_tstate->get_astack(static_cast(&id)); ast.node->val_s.set_string("", *this); @@ -352,7 +352,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) { case ident_type::IVAR: { any_value oldv; ivar_impl &iv = static_cast(id); - oldv.set_integer(iv.get_value()); + oldv.set_integer(iv.value()); iv.set_raw_value(iv.p_override); var_changed(*p_tstate, &id, oldv); static_cast( @@ -363,7 +363,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) { case ident_type::FVAR: { any_value oldv; fvar_impl &fv = static_cast(id); - oldv.set_float(fv.get_value()); + oldv.set_float(fv.value()); fv.set_raw_value(fv.p_override); var_changed(*p_tstate, &id, oldv); static_cast( @@ -374,7 +374,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) { case ident_type::SVAR: { any_value oldv; svar_impl &sv = static_cast(id); - oldv.set_string(sv.get_value()); + oldv.set_string(sv.value()); sv.set_raw_value(sv.p_override); var_changed(*p_tstate, &id, oldv); static_cast( @@ -483,7 +483,7 @@ LIBCUBESCRIPT_EXPORT void state::assign_value( ) { auto id = get_ident(name); if (id) { - switch (id->get().get_type()) { + switch (id->get().type()) { case ident_type::ALIAS: { static_cast(id->get()).set_value(*this, std::move(v)); return; @@ -496,7 +496,7 @@ LIBCUBESCRIPT_EXPORT void state::assign_value( default: throw error{ *this, "cannot redefine builtin %s with an alias", - id->get().get_name().data() + id->get().name().data() }; } } else if (!is_valid_name(name)) { @@ -520,7 +520,7 @@ LIBCUBESCRIPT_EXPORT any_value state::lookup_value(std::string_view name) { } alias_stack *ast; if (id) { - switch(id->get_type()) { + switch(id->type()) { case ident_type::ALIAS: { auto *a = static_cast(id); ast = &p_tstate->get_astack(static_cast(id)); @@ -534,17 +534,17 @@ LIBCUBESCRIPT_EXPORT any_value state::lookup_value(std::string_view name) { } case ident_type::SVAR: { any_value val{}; - val.set_string(static_cast(id)->get_value()); + val.set_string(static_cast(id)->value()); return val; } case ident_type::IVAR: { any_value val{}; - val.set_integer(static_cast(id)->get_value()); + val.set_integer(static_cast(id)->value()); return val; } case ident_type::FVAR: { any_value val{}; - val.set_float(static_cast(id)->get_value()); + val.set_float(static_cast(id)->value()); return val; } case ident_type::COMMAND: { @@ -555,7 +555,7 @@ LIBCUBESCRIPT_EXPORT any_value state::lookup_value(std::string_view name) { auto &args = p_tstate->vmstack; auto osz = args.size(); /* pad with as many empty values as we need */ - args.resize(osz + cimpl->get_num_args()); + args.resize(osz + cimpl->arg_count()); exec_command( *p_tstate, cimpl, cimpl, &args[osz], val, 0, true ); @@ -589,15 +589,15 @@ LIBCUBESCRIPT_EXPORT void state::touch_value(std::string_view name) { } auto &idr = id->get(); any_value v; - switch (idr.get_type()) { + switch (idr.type()) { case ident_type::IVAR: - v.set_integer(static_cast(idr).get_value()); + v.set_integer(static_cast(idr).value()); break; case ident_type::FVAR: - v.set_float(static_cast(idr).get_value()); + v.set_float(static_cast(idr).value()); break; case ident_type::SVAR: - v.set_string(static_cast(idr).get_value()); + v.set_string(static_cast(idr).value()); break; default: return; @@ -723,12 +723,12 @@ LIBCUBESCRIPT_EXPORT bcode_ref state::compile( return gs.steal_ref(); } -LIBCUBESCRIPT_EXPORT bool state::get_override_mode() const { +LIBCUBESCRIPT_EXPORT bool state::override_mode() const { return (p_tstate->ident_flags & IDENT_FLAG_OVERRIDDEN); } -LIBCUBESCRIPT_EXPORT bool state::set_override_mode(bool v) { - bool was = get_override_mode(); +LIBCUBESCRIPT_EXPORT bool state::override_mode(bool v) { + bool was = override_mode(); if (v) { p_tstate->ident_flags |= IDENT_FLAG_OVERRIDDEN; } else { @@ -737,12 +737,12 @@ LIBCUBESCRIPT_EXPORT bool state::set_override_mode(bool v) { return was; } -LIBCUBESCRIPT_EXPORT bool state::get_persist_mode() const { +LIBCUBESCRIPT_EXPORT bool state::persist_mode() const { return (p_tstate->ident_flags & IDENT_FLAG_PERSIST); } -LIBCUBESCRIPT_EXPORT bool state::set_persist_mode(bool v) { - bool was = get_persist_mode(); +LIBCUBESCRIPT_EXPORT bool state::persist_mode(bool v) { + bool was = persist_mode(); if (v) { p_tstate->ident_flags |= IDENT_FLAG_PERSIST; } else { @@ -751,11 +751,11 @@ LIBCUBESCRIPT_EXPORT bool state::set_persist_mode(bool v) { return was; } -LIBCUBESCRIPT_EXPORT std::size_t state::get_max_call_depth() const { +LIBCUBESCRIPT_EXPORT std::size_t state::max_call_depth() const { return p_tstate->max_call_depth; } -LIBCUBESCRIPT_EXPORT std::size_t state::set_max_call_depth(std::size_t v) { +LIBCUBESCRIPT_EXPORT std::size_t state::max_call_depth(std::size_t v) { auto old = p_tstate->max_call_depth; p_tstate->max_call_depth = v; return old; diff --git a/src/cs_thread.cc b/src/cs_thread.cc index 8477a65..1eefca5 100644 --- a/src/cs_thread.cc +++ b/src/cs_thread.cc @@ -16,7 +16,7 @@ hook_func thread_state::set_hook(hook_func f) { } alias_stack &thread_state::get_astack(alias const *a) { - auto it = astacks.try_emplace(a->get_index()); + auto it = astacks.try_emplace(a->index()); if (it.second) { auto *imp = const_cast( static_cast(a) diff --git a/src/cs_val.cc b/src/cs_val.cc index 77ebbeb..2845f49 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -98,7 +98,7 @@ any_value::any_value(any_value &&v): any_value{} { any_value &any_value::operator=(any_value const &v) { csv_cleanup(p_type, &p_stor); p_type = value_type::NONE; - switch (v.get_type()) { + switch (v.type()) { case value_type::INTEGER: case value_type::FLOAT: case value_type::IDENT: @@ -125,7 +125,7 @@ any_value &any_value::operator=(any_value &&v) { return *this; } -value_type any_value::get_type() const { +value_type any_value::type() const { return p_type; } @@ -162,7 +162,7 @@ void any_value::set_code(bcode_ref const &val) { bcode *p = bcode_p{val}.get(); csv_cleanup(p_type, &p_stor); p_type = value_type::CODE; - bcode_addref(p->get_raw()); + bcode_addref(p->raw()); csv_get(&p_stor) = p; } @@ -173,14 +173,14 @@ void any_value::set_ident(ident &val) { } void any_value::force_none() { - if (get_type() == value_type::NONE) { + if (type() == value_type::NONE) { return; } set_none(); } void any_value::force_plain() { - switch (get_type()) { + switch (type()) { case value_type::FLOAT: case value_type::INTEGER: case value_type::STRING: @@ -193,7 +193,7 @@ void any_value::force_plain() { float_type any_value::force_float() { float_type rf = 0.0f; - switch (get_type()) { + switch (type()) { case value_type::INTEGER: rf = float_type(csv_get(&p_stor)); break; @@ -211,7 +211,7 @@ float_type any_value::force_float() { integer_type any_value::force_integer() { integer_type ri = 0; - switch (get_type()) { + switch (type()) { case value_type::FLOAT: ri = integer_type(std::floor(csv_get(&p_stor))); break; @@ -230,7 +230,7 @@ integer_type any_value::force_integer() { std::string_view any_value::force_string(state &cs) { charbuf rs{cs}; std::string_view str; - switch (get_type()) { + switch (type()) { case value_type::FLOAT: str = floatstr(csv_get(&p_stor), rs); break; @@ -248,7 +248,7 @@ std::string_view any_value::force_string(state &cs) { } bcode_ref any_value::force_code(state &cs, std::string_view source) { - switch (get_type()) { + switch (type()) { case value_type::CODE: return bcode_p::make_ref(csv_get(&p_stor)); default: @@ -262,7 +262,7 @@ bcode_ref any_value::force_code(state &cs, std::string_view source) { } ident &any_value::force_ident(state &cs) { - switch (get_type()) { + switch (type()) { case value_type::IDENT: return *csv_get(&p_stor); default: @@ -276,7 +276,7 @@ ident &any_value::force_ident(state &cs) { } integer_type any_value::get_integer() const { - switch (get_type()) { + switch (type()) { case value_type::FLOAT: return integer_type(csv_get(&p_stor)); case value_type::INTEGER: @@ -290,7 +290,7 @@ integer_type any_value::get_integer() const { } float_type any_value::get_float() const { - switch (get_type()) { + switch (type()) { case value_type::FLOAT: return csv_get(&p_stor); case value_type::INTEGER: @@ -306,21 +306,21 @@ float_type any_value::get_float() const { } bcode_ref any_value::get_code() const { - if (get_type() != value_type::CODE) { + if (type() != value_type::CODE) { return bcode_ref{}; } return bcode_p::make_ref(csv_get(&p_stor)); } ident &any_value::get_ident(state &cs) const { - if (get_type() != value_type::IDENT) { + if (type() != value_type::IDENT) { return *state_p{cs}.ts().istate->id_dummy; } return *csv_get(&p_stor); } string_ref any_value::get_string(state &cs) const { - switch (get_type()) { + switch (type()) { case value_type::STRING: return string_ref{csv_get(&p_stor)}; case value_type::INTEGER: { @@ -342,7 +342,7 @@ string_ref any_value::get_string(state &cs) const { } any_value any_value::get_plain() const { - switch (get_type()) { + switch (type()) { case value_type::STRING: case value_type::INTEGER: case value_type::FLOAT: @@ -354,7 +354,7 @@ any_value any_value::get_plain() const { } bool any_value::get_bool() const { - switch (get_type()) { + switch (type()) { case value_type::FLOAT: return csv_get(&p_stor) != 0; case value_type::INTEGER: @@ -390,7 +390,7 @@ LIBCUBESCRIPT_EXPORT string_ref concat_values( ) { charbuf buf{cs}; for (std::size_t i = 0; i < vals.size(); ++i) { - switch (vals[i].get_type()) { + switch (vals[i].type()) { case value_type::INTEGER: case value_type::FLOAT: case value_type::STRING: { diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 2d994ad..f2ffaf6 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -27,17 +27,17 @@ static inline void pop_alias(thread_state &ts, ident &id) { static inline void force_arg(state &cs, any_value &v, int type) { switch (type) { case BC_RET_STRING: - if (v.get_type() != value_type::STRING) { + if (v.type() != value_type::STRING) { v.force_string(cs); } break; case BC_RET_INT: - if (v.get_type() != value_type::INTEGER) { + if (v.type() != value_type::INTEGER) { v.force_integer(); } break; case BC_RET_FLOAT: - if (v.get_type() != value_type::FLOAT) { + if (v.type() != value_type::FLOAT) { v.force_float(); } break; @@ -50,7 +50,7 @@ void exec_command( ) { int i = -1, fakeargs = 0, numargs = int(nargs); bool rep = false; - auto fmt = id->get_args(); + auto fmt = id->args(); auto set_fake = [&i, &fakeargs, &rep, args, numargs]() { if (++i >= numargs) { if (rep) { @@ -84,7 +84,7 @@ void exec_command( break; case 'c': if (set_fake()) { - if (args[i].get_type() == value_type::STRING) { + if (args[i].type() == value_type::STRING) { auto str = args[i].get_string(*ts.pstate); if (str.empty()) { args[i].set_integer(0); @@ -139,12 +139,12 @@ bool exec_alias( ) { auto &aast = ts.get_astack(a); if (ncheck) { - if (aast.node->val_s.get_type() == value_type::NONE) { + if (aast.node->val_s.type() == value_type::NONE) { return false; } } else if (aast.flags & IDENT_FLAG_UNKNOWN) { throw error { - *ts.pstate, "unknown command: %s", a->get_name().data() + *ts.pstate, "unknown command: %s", a->name().data() }; } /* excess arguments get ignored (make error maybe?) */ @@ -161,7 +161,7 @@ bool exec_alias( st.val_s = std::move(args[offset + i]); uargs[i] = true; } - auto oldargs = anargs->get_value(); + auto oldargs = anargs->value(); auto oldflags = ts.ident_flags; ts.ident_flags = aast.flags; anargs->set_raw_value(integer_type(callargs)); @@ -197,7 +197,7 @@ bool exec_alias( nargs = offset - skip; }; try { - vm_exec(ts, bcode_p{coderef}.get()->get_raw(), result); + vm_exec(ts, bcode_p{coderef}.get()->raw(), result); } catch (...) { cleanup(); throw; @@ -230,7 +230,7 @@ static inline alias *get_lookup_id( ast = &ts.get_astack(static_cast(id)); if (ast->flags & IDENT_FLAG_UNKNOWN) { throw error{ - *ts.pstate, "unknown alias lookup: %s", id->get_name().data() + *ts.pstate, "unknown alias lookup: %s", id->name().data() }; } } @@ -245,7 +245,7 @@ std::uint32_t *vm_exec( call_depth_guard level{ts}; /* incr and decr on scope exit */ stack_guard guard{ts}; /* resize back to original */ auto &args = ts.vmstack; - auto &chook = cs.get_call_hook(); + auto &chook = cs.call_hook(); if (chook) { chook(cs); } @@ -495,7 +495,7 @@ std::uint32_t *vm_exec( std::uint32_t len = op >> 8; auto v = std::move(args.back()); args.pop_back(); - if (v.get_type() == value_type::CODE) { + if (v.type() == value_type::CODE) { result = v.get_code().call(cs); } else { result = std::move(v); @@ -509,7 +509,7 @@ std::uint32_t *vm_exec( std::uint32_t len = op >> 8; auto v = std::move(args.back()); args.pop_back(); - if (v.get_type() == value_type::CODE) { + if (v.type() == value_type::CODE) { result = v.get_code().call(cs); } else { result = std::move(v); @@ -567,7 +567,7 @@ std::uint32_t *vm_exec( case BC_INST_COMPILE: { any_value &arg = args.back(); gen_state gs{ts}; - switch (arg.get_type()) { + switch (arg.type()) { case value_type::INTEGER: gs.gen_main_integer(arg.get_integer()); break; @@ -587,7 +587,7 @@ std::uint32_t *vm_exec( case BC_INST_COND: { any_value &arg = args.back(); - switch (arg.get_type()) { + switch (arg.type()) { case value_type::STRING: { std::string_view s = arg.get_string(cs); if (!s.empty()) { @@ -611,7 +611,7 @@ std::uint32_t *vm_exec( ); if (a->is_arg() && !ident_is_used_arg(a, ts)) { ts.get_astack(a).push(ts.idstack.emplace_back()); - ts.callstack->usedargs[a->get_index()] = true; + ts.callstack->usedargs[a->index()] = true; } args.emplace_back().set_ident(*a); continue; @@ -619,7 +619,7 @@ std::uint32_t *vm_exec( case BC_INST_IDENT_U: { any_value &arg = args.back(); ident *id = ts.istate->id_dummy; - if (arg.get_type() == value_type::STRING) { + if (arg.type() == value_type::STRING) { id = &ts.istate->new_ident( cs, arg.get_string(cs), IDENT_FLAG_UNKNOWN ); @@ -627,7 +627,7 @@ std::uint32_t *vm_exec( alias *a = static_cast(id); if (a->is_arg() && !ident_is_used_arg(id, ts)) { ts.get_astack(a).push(ts.idstack.emplace_back()); - ts.callstack->usedargs[id->get_index()] = true; + ts.callstack->usedargs[id->index()] = true; } arg.set_ident(*id); continue; @@ -714,20 +714,20 @@ std::uint32_t *vm_exec( case BC_INST_SVAR | BC_RET_NULL: args.emplace_back().set_string(static_cast( ts.istate->identmap[op >> 8] - )->get_value()); + )->value()); continue; case BC_INST_SVAR | BC_RET_INT: args.emplace_back().set_integer(parse_int( static_cast( ts.istate->identmap[op >> 8] - )->get_value() + )->value() )); continue; case BC_INST_SVAR | BC_RET_FLOAT: args.emplace_back().set_float(parse_float( static_cast( ts.istate->identmap[op >> 8] - )->get_value() + )->value() )); continue; @@ -735,13 +735,13 @@ std::uint32_t *vm_exec( case BC_INST_IVAR | BC_RET_NULL: args.emplace_back().set_integer(static_cast( ts.istate->identmap[op >> 8] - )->get_value()); + )->value()); continue; case BC_INST_IVAR | BC_RET_STRING: { auto &v = args.emplace_back(); v.set_integer(static_cast( ts.istate->identmap[op >> 8] - )->get_value()); + )->value()); v.force_string(cs); continue; } @@ -749,7 +749,7 @@ std::uint32_t *vm_exec( args.emplace_back().set_float(float_type( static_cast( ts.istate->identmap[op >> 8] - )->get_value() + )->value() )); continue; @@ -757,13 +757,13 @@ std::uint32_t *vm_exec( case BC_INST_FVAR | BC_RET_NULL: args.emplace_back().set_float(static_cast( ts.istate->identmap[op >> 8] - )->get_value()); + )->value()); continue; case BC_INST_FVAR | BC_RET_STRING: { auto &v = args.emplace_back(); v.set_float(static_cast( ts.istate->identmap[op >> 8] - )->get_value()); + )->value()); v.force_string(cs); continue; } @@ -771,7 +771,7 @@ std::uint32_t *vm_exec( args.emplace_back().set_integer( integer_type(std::floor(static_cast( ts.istate->identmap[op >> 8] - )->get_value())) + )->value())) ); continue; @@ -829,7 +829,7 @@ std::uint32_t *vm_exec( std::size_t nnargs = args.size(); std::size_t offset = nnargs - callargs; any_value &idarg = args[offset - 1]; - if (idarg.get_type() != value_type::STRING) { + if (idarg.type() != value_type::STRING) { litval: result = std::move(idarg); force_arg(cs, result, op & BC_INST_RET_MASK); @@ -862,7 +862,7 @@ noid: case ID_COMMAND: { auto *cimp = static_cast(&id->get()); args.resize(offset + std::max( - std::size_t(cimp->get_num_args()), callargs + std::size_t(cimp->arg_count()), callargs )); exec_command( ts, cimp, cimp, &args[offset], result, callargs @@ -900,7 +900,7 @@ noid: /* the $ argument */ args.insert(offset, any_value{}); args.resize(offset + std::max( - std::size_t(cimp->get_num_args()), callargs + std::size_t(cimp->arg_count()), callargs )); exec_command( ts, cimp, &id->get(), &args[offset], @@ -916,7 +916,7 @@ noid: /* the $ argument */ args.insert(offset, any_value{}); args.resize(offset + std::max( - std::size_t(cimp->get_num_args()), callargs + std::size_t(cimp->arg_count()), callargs )); exec_command( ts, cimp, &id->get(), &args[offset], @@ -932,7 +932,7 @@ noid: /* the $ argument */ args.insert(offset, any_value{}); args.resize(offset + std::max( - std::size_t(cimp->get_num_args()), callargs + std::size_t(cimp->arg_count()), callargs )); exec_command( ts, cimp, &id->get(), &args[offset], @@ -968,10 +968,10 @@ noid: command_impl *id = static_cast( ts.istate->identmap[op >> 8] ); - std::size_t offset = args.size() - id->get_num_args(); + std::size_t offset = args.size() - id->arg_count(); result.force_none(); id->call(ts, span_type{ - &args[offset], std::size_t(id->get_num_args()) + &args[offset], std::size_t(id->arg_count()) }, result); force_arg(cs, result, op & BC_INST_RET_MASK); args.resize(offset); diff --git a/src/lib_base.cc b/src/lib_base.cc index 59ca7c7..e068e0b 100644 --- a/src/lib_base.cc +++ b/src/lib_base.cc @@ -72,10 +72,10 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { auto &cret = args[1].get_ident(cs); auto &css = args[2].get_ident(cs); if (!cret.is_alias()) { - throw error{cs, "'%s' is not an alias", cret.get_name().data()}; + throw error{cs, "'%s' is not an alias", cret.name().data()}; } if (!css.is_alias()) { - throw error{cs, "'%s' is not an alias", css.get_name().data()}; + throw error{cs, "'%s' is not an alias", css.name().data()}; } any_value result{}, tback{}; bool rc = true; @@ -83,9 +83,9 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { result = args[0].get_code().call(cs); } catch (error const &e) { result.set_string(e.what(), cs); - if (e.get_stack().get()) { + if (e.stack().get()) { charbuf buf{cs}; - print_stack(std::back_inserter(buf), e.get_stack()); + print_stack(std::back_inserter(buf), e.stack()); tback.set_string(buf.str(), cs); } rc = false; @@ -124,7 +124,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { integer_type val = args[0].get_integer(); for (size_t i = 1; (i + 1) < args.size(); i += 2) { if ( - (args[i].get_type() == value_type::NONE) || + (args[i].type() == value_type::NONE) || (args[i].get_integer() == val) ) { res = args[i + 1].get_code().call(cs); @@ -137,7 +137,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { float_type val = args[0].get_float(); for (size_t i = 1; (i + 1) < args.size(); i += 2) { if ( - (args[i].get_type() == value_type::NONE) || + (args[i].type() == value_type::NONE) || (args[i].get_float() == val) ) { res = args[i + 1].get_code().call(cs); @@ -150,7 +150,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { string_ref val = args[0].get_string(cs); for (size_t i = 1; (i + 1) < args.size(); i += 2) { if ( - (args[i].get_type() == value_type::NONE) || + (args[i].type() == value_type::NONE) || (args[i].get_string(cs) == val) ) { res = args[i + 1].get_code().call(cs); @@ -342,13 +342,13 @@ end: new_cmd_quiet(gcs, "getalias", "s", [](auto &cs, auto args, auto &res) { auto &id = cs.new_ident(args[0].get_string(cs)); - if (id.get_type() != ident_type::ALIAS) { - throw error{cs, "'%s' is not an alias", id.get_name().data()}; + if (id.type() != ident_type::ALIAS) { + throw error{cs, "'%s' is not an alias", id.name().data()}; } if (ident_p{id}.impl().p_flags & IDENT_FLAG_UNKNOWN) { return; } - res = static_cast(id).get_value(cs); + res = static_cast(id).value(cs); }); } diff --git a/src/lib_list.cc b/src/lib_list.cc index cd433ab..943de95 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -106,7 +106,7 @@ int list_includes( ) { int offset = 0; for (list_parser p{cs, list}; p.parse();) { - if (p.get_raw_item() == needle) { + if (p.raw_item() == needle) { return offset; } ++offset; @@ -128,11 +128,11 @@ static inline void list_merge( std::swap(list, elems); } for (list_parser p{cs, list}; p.parse();) { - if (cmp(list_includes(cs, elems, p.get_raw_item()), 0)) { + if (cmp(list_includes(cs, elems, p.raw_item()), 0)) { if (!buf.empty()) { buf.push_back(' '); } - buf.append(p.get_quoted_item()); + buf.append(p.quoted_item()); } } res.set_string(buf.str(), cs); @@ -188,18 +188,18 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { if (offset > 0) { p.skip_until_item(); } - res.set_string(p.get_input(), cs); + res.set_string(p.input(), cs); return; } - char const *list = p.get_input().data(); + char const *list = p.input().data(); if (len > 0 && p.parse()) { while (--len > 0 && p.parse()); } else { res.set_string("", cs); return; } - auto quote = p.get_quoted_item(); + auto quote = p.quoted_item(); auto *qend = "e[quote.size()]; res.set_string(make_str_view(list, qend), cs); }); @@ -211,7 +211,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { int n = -1; for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) { ++n; - idv.set_string(p.get_raw_item(), cs); + idv.set_string(p.raw_item(), cs); st.set(std::move(idv)); if (body.call(cs).get_bool()) { res.set_integer(integer_type(n)); @@ -228,7 +228,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { int n = -1; for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) { ++n; - idv.set_string(p.get_raw_item(), cs); + idv.set_string(p.raw_item(), cs); st.set(std::move(idv)); if (body.call(cs).get_bool()) { if (p.parse()) { @@ -245,21 +245,21 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { new_cmd_quiet(gcs, "listfind=", "i", [](auto &cs, auto args, auto &res) { list_find( cs, args, res, [](list_parser const &p, integer_type val) { - return parse_int(p.get_raw_item()) == val; + return parse_int(p.raw_item()) == val; } ); }); new_cmd_quiet(gcs, "listfind=f", "f", [](auto &cs, auto args, auto &res) { list_find( cs, args, res, [](list_parser const &p, float_type val) { - return parse_float(p.get_raw_item()) == val; + return parse_float(p.raw_item()) == val; } ); }); new_cmd_quiet(gcs, "listfind=s", "s", [](auto &cs, auto args, auto &res) { list_find( cs, args, res, [](list_parser const &p, std::string_view val) { - return p.get_raw_item() == val; + return p.raw_item() == val; } ); }); @@ -267,21 +267,21 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { new_cmd_quiet(gcs, "listassoc=", "i", [](auto &cs, auto args, auto &res) { list_assoc( cs, args, res, [](list_parser const &p, integer_type val) { - return parse_int(p.get_raw_item()) == val; + return parse_int(p.raw_item()) == val; } ); }); new_cmd_quiet(gcs, "listassoc=f", "f", [](auto &cs, auto args, auto &res) { list_assoc( cs, args, res, [](list_parser const &p, float_type val) { - return parse_float(p.get_raw_item()) == val; + return parse_float(p.raw_item()) == val; } ); }); new_cmd_quiet(gcs, "listassoc=s", "s", [](auto &cs, auto args, auto &res) { list_assoc( cs, args, res, [](list_parser const &p, std::string_view val) { - return p.get_raw_item() == val; + return p.raw_item() == val; } ); }); @@ -385,13 +385,13 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { charbuf r{cs}; int n = 0; for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { - idv.set_string(p.get_raw_item(), cs); + idv.set_string(p.raw_item(), cs); st.set(std::move(idv)); if (body.call(cs).get_bool()) { if (r.size()) { r.push_back(' '); } - r.append(p.get_quoted_item()); + r.append(p.quoted_item()); } } res.set_string(r.str(), cs); @@ -403,7 +403,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { auto body = args[2].get_code(); int n = 0, r = 0; for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { - idv.set_string(p.get_raw_item(), cs); + idv.set_string(p.raw_item(), cs); st.set(std::move(idv)); if (body.call(cs).get_bool()) { r++; @@ -420,11 +420,11 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { size_t len = p.count(); size_t n = 0; for (p.set_input(s); p.parse(); ++n) { - auto qi = p.get_quoted_item(); + auto qi = p.quoted_item(); if (!qi.empty() && (qi.front() == '"')) { - unescape_string(std::back_inserter(buf), p.get_raw_item()); + unescape_string(std::back_inserter(buf), p.raw_item()); } else { - buf.append(p.get_raw_item()); + buf.append(p.raw_item()); } if ((n + 1) < len) { if ((len > 2) || conj.empty()) { @@ -472,7 +472,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { break; } } - std::string_view quote = p.get_quoted_item(); + std::string_view quote = p.quoted_item(); char const *qend = !quote.empty() ? "e[quote.size()] : list; charbuf buf{cs}; if (qend > list) { @@ -490,8 +490,8 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { } } p.skip_until_item(); - if (!p.get_input().empty()) { - switch (p.get_input().front()) { + if (!p.input().empty()) { + switch (p.input().front()) { case ')': case ']': break; @@ -499,7 +499,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) { if (!buf.empty()) { buf.push_back(' '); } - buf.append(p.get_input()); + buf.append(p.input()); break; } } @@ -543,7 +543,7 @@ static void list_sort( size_t total = 0; for (list_parser p{cs, list}; p.parse();) { - ListSortItem item = { p.get_raw_item(), p.get_quoted_item() }; + ListSortItem item = { p.raw_item(), p.quoted_item() }; items.push_back(item); total += item.quote.size(); } diff --git a/tools/edit_fallback.hh b/tools/edit_fallback.hh index 938653c..9dd88a3 100644 --- a/tools/edit_fallback.hh +++ b/tools/edit_fallback.hh @@ -10,7 +10,7 @@ inline void init_lineedit(cs::state &, std::string_view) { inline std::optional read_line(cs::state &, cs::string_var &pr) { std::string lbuf; char buf[512]; - printf("%s", pr.get_value().data()); + printf("%s", pr.value().data()); std::fflush(stdout); while (fgets(buf, sizeof(buf), stdin)) { lbuf += static_cast(buf); diff --git a/tools/edit_linenoise.hh b/tools/edit_linenoise.hh index 0a25c2d..c955094 100644 --- a/tools/edit_linenoise.hh +++ b/tools/edit_linenoise.hh @@ -19,7 +19,7 @@ inline void ln_complete(char const *buf, std::vector &lc) { if (!id->is_command()) { continue; } - std::string_view idname = id->get_name(); + std::string_view idname = id->name(); if (idname.size() <= cmd.size()) { continue; } @@ -35,7 +35,7 @@ inline std::string ln_hint(char const *buf, int &color, int &bold) { return std::string{}; } std::string args = " ["; - fill_cmd_args(args, cmd->get_args()); + fill_cmd_args(args, cmd->args()); args += ']'; color = 35; bold = 1; @@ -52,7 +52,7 @@ inline void init_lineedit(cs::state &cs, std::string_view) { inline std::optional read_line(cs::state &, cs::string_var &pr) { std::string line; - auto quit = linenoise::Readline(pr.get_value().data(), line); + auto quit = linenoise::Readline(pr.value().data(), line); if (quit) { /* linenoise traps ctrl-c, detect it and let the user exit */ if (errno == EAGAIN) { diff --git a/tools/repl.cc b/tools/repl.cc index 009374d..153ed73 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -183,8 +183,8 @@ static cs::state *scs = nullptr; static void do_sigint(int n) { /* in case another SIGINT happens, terminate normally */ signal(n, SIG_DFL); - scs->set_call_hook([](cs::state &css) { - css.set_call_hook(nullptr); + scs->call_hook([](cs::state &css) { + css.call_hook(nullptr); throw cs::error{css, ""}; }); } @@ -253,16 +253,16 @@ static bool do_call(cs::state &cs, std::string_view line, bool file = false) { std::printf( "%s%s\n", !is_lnum ? "stdin: " : "stdin:", e.what().data() ); - if (e.get_stack().get()) { + if (e.stack().get()) { std::string str; - cs::print_stack(std::back_inserter(str), e.get_stack()); + cs::print_stack(std::back_inserter(str), e.stack()); std::printf("%s\n", str.data()); } return false; } signal(SIGINT, SIG_DFL); scs = nullptr; - if (ret.get_type() != cs::value_type::NONE) { + if (ret.type() != cs::value_type::NONE) { std::printf("%s\n", std::string_view{ret.get_string(cs)}.data()); } return false; @@ -320,15 +320,15 @@ int main(int argc, char **argv) { auto &iv = static_cast(args[0].get_ident(css)); auto nargs = args[4].get_integer(); if (nargs <= 1) { - auto val = iv.get_value(); + auto val = iv.value(); if ((val >= 0) && (val < 0xFFFFFF)) { std::printf( "%s = %d (0x%.6X: %d, %d, %d)\n", - iv.get_name().data(), val, val, + iv.name().data(), val, val, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF ); } else { - std::printf("%s = %d\n", iv.get_name().data(), val); + std::printf("%s = %d\n", iv.name().data(), val); } return; } @@ -350,7 +350,7 @@ int main(int argc, char **argv) { gcs.new_command("//var_changed", "$aa", [](auto &css, auto args, auto &) { std::printf( "changed var trigger: %s (was: '%s', now: '%s')\n", - args[0].get_ident(css).get_name().data(), + args[0].get_ident(css).name().data(), args[1].get_string(css).data(), args[2].get_string(css).data() );