be consistent with usage of get_/set_ prefixes

master
Daniel Kolesa 2021-05-05 03:16:32 +02:00
parent 03325af1e6
commit bd1e7825d8
20 changed files with 246 additions and 256 deletions

View File

@ -114,12 +114,12 @@ struct LIBCUBESCRIPT_EXPORT error {
} }
/** @brief Get a reference to the call stack state. */ /** @brief Get a reference to the call stack state. */
stack_state &get_stack() { stack_state &stack() {
return p_stack; return p_stack;
} }
/** @brief Get a reference to the call stack state. */ /** @brief Get a reference to the call stack state. */
stack_state const &get_stack() const { stack_state const &stack() const {
return p_stack; return p_stack;
} }

View File

@ -47,10 +47,10 @@ enum class ident_type {
*/ */
struct LIBCUBESCRIPT_EXPORT ident { struct LIBCUBESCRIPT_EXPORT ident {
/** @brief Get the cubescript::ident_type of this 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. */ /** @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. /** @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 * with an integer (it is guaranteed that once created, it will stay the
* same for the whole lifetime of the main thread). * same for the whole lifetime of the main thread).
*/ */
int get_index() const; int index() const;
/** @brief Check if the idents are the same. */ /** @brief Check if the idents are the same. */
bool operator==(ident &other) const; bool operator==(ident &other) const;
@ -69,44 +69,44 @@ struct LIBCUBESCRIPT_EXPORT ident {
/** @brief Check if the ident is a cubescript::alias. /** @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; bool is_alias() const;
/** @brief Check if the ident is a cubescript::command. /** @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; bool is_command() const;
/** @brief Check if the ident is a special ident. /** @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; bool is_special() const;
/** @brief Check if the ident is a cubescript::global_var. /** @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. * ident_type::IVAR, ident_type::FVAR or ident_type::SVAR.
*/ */
bool is_var() const; bool is_var() const;
/** @brief Check if the ident is a cubescript::integer_var. /** @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; bool is_ivar() const;
/** @brief Check if the ident is a cubescript::float_var. /** @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; bool is_fvar() const;
/** @brief Check if the ident is a cubescript::string_var. /** @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; bool is_svar() const;
@ -192,12 +192,12 @@ struct LIBCUBESCRIPT_EXPORT global_var: ident {
/** @brief Get whether the variable is overridable. /** @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; bool is_overridable() const;
/** @brief Get the cubescript::var_type of the variable. */ /** @brief Get the cubescript::var_type of the variable. */
var_type get_variable_type() const; var_type variable_type() const;
/** @brief Save the variable. /** @brief Save the variable.
* *
@ -231,7 +231,7 @@ protected:
*/ */
struct LIBCUBESCRIPT_EXPORT integer_var: global_var { struct LIBCUBESCRIPT_EXPORT integer_var: global_var {
/** @brief Get the value of the variable. */ /** @brief Get the value of the variable. */
integer_type get_value() const; integer_type value() const;
/** @brief Set the value of the variable. /** @brief Set the value of the variable.
* *
@ -268,7 +268,7 @@ protected:
*/ */
struct LIBCUBESCRIPT_EXPORT float_var: global_var { struct LIBCUBESCRIPT_EXPORT float_var: global_var {
/** @brief Get the value of the variable. */ /** @brief Get the value of the variable. */
float_type get_value() const; float_type value() const;
/** @brief Set the value of the variable. /** @brief Set the value of the variable.
* *
@ -305,7 +305,7 @@ protected:
*/ */
struct LIBCUBESCRIPT_EXPORT string_var: global_var { struct LIBCUBESCRIPT_EXPORT string_var: global_var {
/** @brief Get the value of the variable. */ /** @brief Get the value of the variable. */
string_ref get_value() const; string_ref value() const;
/** @brief Set the value of the variable. /** @brief Set the value of the variable.
* *
@ -354,7 +354,7 @@ struct LIBCUBESCRIPT_EXPORT alias: ident {
bool is_arg() const; bool is_arg() const;
/** @brief Get the value of the alias for the given thread. */ /** @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. */ /** @brief Set the value of the alias for the given thread. */
void set_value(state &cs, any_value v); void set_value(state &cs, any_value v);
@ -377,14 +377,14 @@ protected:
*/ */
struct LIBCUBESCRIPT_EXPORT command: ident { struct LIBCUBESCRIPT_EXPORT command: ident {
/** @brief Get the argument list. */ /** @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. /** @brief Get the number of arguments the command expects.
* *
* Only non-variadic arguments count here (i.e. no repeated arguments, * Only non-variadic arguments count here (i.e. no repeated arguments,
* no `C`, no `V`; everything else counts as one argument). * no `C`, no `V`; everything else counts as one argument).
*/ */
int get_num_args() const; int arg_count() const;
/** @brief Call a command. /** @brief Call a command.
* *

View File

@ -141,17 +141,17 @@ struct LIBCUBESCRIPT_EXPORT state {
* interrupting execution from the side in an interactive interpreter. * interrupting execution from the side in an interactive interpreter.
*/ */
template<typename F> template<typename F>
hook_func set_call_hook(F &&f) { hook_func call_hook(F &&f) {
return set_call_hook( return call_hook(
hook_func{std::forward<F>(f), callable_alloc, this} hook_func{std::forward<F>(f), callable_alloc, this}
); );
} }
/** @brief Get a reference to the call hook */ /** @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 */ /** @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 /** @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 * Keep in mind that if an alias is pushed, its flags will be cleared once
* popped. * popped.
* *
* @see set_override_mode() * @see override_mode()
*/ */
bool get_override_mode() const; bool override_mode() const;
/** @brief Set the thread's override mode /** @brief Set the thread's override mode */
* bool override_mode(bool v);
* @see get_override_mode()
*/
bool set_override_mode(bool v);
/** @brief Get if the thread is in persist most /** @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 * Keep in mind that if an alias is pushed, its flags will be cleared once
* popped. * popped.
*
* @see set_persist_mode()
*/ */
bool get_persist_mode() const; bool persist_mode() const;
/** @brief Set the thread's persist mode /** @brief Set the thread's persist mode */
* bool persist_mode(bool v);
* @see get_persist_mode()
*/
bool set_persist_mode(bool v);
/** @brief Get the maximum call depth of the VM /** @brief Get the maximum call depth of the VM
* *
* If zero, it is unlimited, otherwise it specifies how much the VM is * If zero, it is unlimited, otherwise it specifies how much the VM is
* allowed to recurse. By default, it is zero. * 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 /** @brief Set the maximum call depth ov the VM
* *
@ -442,14 +432,14 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* @return the old value * @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: private:
friend struct state_p; friend struct state_p;
LIBCUBESCRIPT_LOCAL state(void *is); LIBCUBESCRIPT_LOCAL state(void *is);
hook_func set_call_hook(hook_func func); hook_func call_hook(hook_func func);
command &new_command( command &new_command(
std::string_view name, std::string_view args, command_func func std::string_view name, std::string_view args, command_func func

View File

@ -63,7 +63,7 @@ struct LIBCUBESCRIPT_EXPORT list_parser {
* *
* The already read items will not be contained in the result. * 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{ return std::string_view{
p_input_beg, std::size_t(p_input_end - p_input_beg) 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 * If the item was quoted with double quotes, the contents will be run
* through cubescript::unescape_string() first. * through cubescript::unescape_string() first.
* *
* @see get_raw_item() * @see raw_item()
* @see get_quoted_item() * @see quoted_item()
*/ */
string_ref get_item() const; string_ref get_item() const;
@ -100,21 +100,21 @@ struct LIBCUBESCRIPT_EXPORT list_parser {
* circumstances and represents simply a slice of the original input. * circumstances and represents simply a slice of the original input.
* *
* @see get_item() * @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)}; return std::string_view{p_ibeg, std::size_t(p_iend - p_ibeg)};
} }
/** @brief Get the currently parsed raw item /** @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. * Likewise, the resulting view is just a slice of the original input.
* *
* @see get_item() * @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)}; 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}; char buf[32] = {0};
auto nd = st.get(); auto nd = st.get();
while (nd) { while (nd) {
auto name = nd->id->get_name(); auto name = nd->id->name();
*writer++ = ' '; *writer++ = ' ';
*writer++ = ' '; *writer++ = ' ';
if ((nd->index == 1) && st.gap()) { if ((nd->index == 1) && st.gap()) {

View File

@ -329,7 +329,7 @@ struct LIBCUBESCRIPT_EXPORT any_value {
any_value &operator=(any_value &&); any_value &operator=(any_value &&);
/** @brief Get the type of the value. */ /** @brief Get the type of the value. */
value_type get_type() const; value_type type() const;
/** @brief Set the value to an integer. /** @brief Set the value to an integer.
* *

View File

@ -7,29 +7,29 @@ namespace cubescript {
/* public API impls */ /* public API impls */
LIBCUBESCRIPT_EXPORT bcode_ref::bcode_ref(bcode *v): p_code(v) { 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): LIBCUBESCRIPT_EXPORT bcode_ref::bcode_ref(bcode_ref const &v):
p_code(v.p_code) p_code(v.p_code)
{ {
bcode_addref(p_code->get_raw()); bcode_addref(p_code->raw());
} }
LIBCUBESCRIPT_EXPORT bcode_ref::~bcode_ref() { LIBCUBESCRIPT_EXPORT bcode_ref::~bcode_ref() {
bcode_unref(p_code->get_raw()); bcode_unref(p_code->raw());
} }
LIBCUBESCRIPT_EXPORT bcode_ref &bcode_ref::operator=( LIBCUBESCRIPT_EXPORT bcode_ref &bcode_ref::operator=(
bcode_ref const &v bcode_ref const &v
) { ) {
bcode_unref(p_code->get_raw()); bcode_unref(p_code->raw());
p_code = v.p_code; p_code = v.p_code;
bcode_addref(p_code->get_raw()); bcode_addref(p_code->raw());
return *this; return *this;
} }
LIBCUBESCRIPT_EXPORT bcode_ref &bcode_ref::operator=(bcode_ref &&v) { 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; p_code = v.p_code;
v.p_code = nullptr; v.p_code = nullptr;
return *this; return *this;
@ -39,7 +39,7 @@ LIBCUBESCRIPT_EXPORT bool bcode_ref::empty() const {
if (!p_code) { if (!p_code) {
return true; 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 { 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 { LIBCUBESCRIPT_EXPORT any_value bcode_ref::call(state &cs) const {
any_value ret{}; 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; return ret;
} }

View File

@ -13,11 +13,11 @@ struct internal_state;
struct bcode { struct bcode {
std::uint32_t init; std::uint32_t init;
std::uint32_t *get_raw() { std::uint32_t *raw() {
return &init; return &init;
} }
std::uint32_t const *get_raw() const { std::uint32_t const *raw() const {
return &init; return &init;
} }
}; };

View File

@ -87,7 +87,7 @@ LIBCUBESCRIPT_EXPORT stack_state error::save_stack(state &cs) {
auto &ts = state_p{cs}.ts(); auto &ts = state_p{cs}.ts();
integer_var *dalias = ts.istate->ivar_dbgalias; integer_var *dalias = ts.istate->ivar_dbgalias;
auto dval = std::clamp( auto dval = std::clamp(
dalias->get_value(), integer_type(0), integer_type(1000) dalias->value(), integer_type(0), integer_type(1000)
); );
if (!dval) { if (!dval) {
return stack_state{cs, nullptr, !!ts.callstack}; return stack_state{cs, nullptr, !!ts.callstack};

View File

@ -283,7 +283,7 @@ void gen_state::gen_val_ident() {
} }
void gen_state::gen_val_ident(ident &i) { 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) { 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) { void gen_state::gen_lookup_ivar(ident &id, int ltype) {
code.push_back( 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) { void gen_state::gen_lookup_fvar(ident &id, int ltype) {
code.push_back( 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) { void gen_state::gen_lookup_svar(ident &id, int ltype) {
code.push_back( 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) { void gen_state::gen_lookup_alias(ident &id, int ltype, int dtype) {
code.push_back( 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) { 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() { 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( void gen_state::gen_command_call(
ident &id, int comt, int ltype, std::uint32_t nargs 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) { if (comt != BC_INST_COM) {
code.push_back(nargs); code.push_back(nargs);
} }
} }
void gen_state::gen_alias_call(ident &id, std::uint32_t 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); code.push_back(nargs);
} }

View File

@ -91,15 +91,15 @@ void var_changed(thread_state &ts, ident *id, any_value &oldval) {
any_value val[3] = {}; any_value val[3] = {};
val[0].set_ident(*id); val[0].set_ident(*id);
val[1] = std::move(oldval); val[1] = std::move(oldval);
switch (id->get_type()) { switch (id->type()) {
case ident_type::IVAR: case ident_type::IVAR:
val[2].set_integer(static_cast<integer_var *>(id)->get_value()); val[2].set_integer(static_cast<integer_var *>(id)->value());
break; break;
case ident_type::FVAR: case ident_type::FVAR:
val[2].set_float(static_cast<float_var *>(id)->get_value()); val[2].set_float(static_cast<float_var *>(id)->value());
break; break;
case ident_type::SVAR: case ident_type::SVAR:
val[2].set_string(static_cast<string_var *>(id)->get_value()); val[2].set_string(static_cast<string_var *>(id)->value());
break; break;
default: default:
return; return;
@ -138,7 +138,7 @@ bool ident_is_used_arg(ident const *id, thread_state &ts) {
if (!ts.callstack) { if (!ts.callstack) {
return true; return true;
} }
return ts.callstack->usedargs[id->get_index()]; return ts.callstack->usedargs[id->index()];
} }
void alias_stack::push(ident_stack &st) { 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{}; node->code = bcode_ref{};
} else { } else {
push(ts.idstack.emplace_back()); push(ts.idstack.emplace_back());
ts.callstack->usedargs[a->get_index()] = true; ts.callstack->usedargs[a->index()] = true;
} }
node->val_s = std::move(v); 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::~ident() {}
LIBCUBESCRIPT_EXPORT ident_type ident::get_type() const { LIBCUBESCRIPT_EXPORT ident_type ident::type() const {
if (p_impl->p_type > ID_ALIAS) { if (p_impl->p_type > ID_ALIAS) {
return ident_type::SPECIAL; return ident_type::SPECIAL;
} }
return ident_type(p_impl->p_type); 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; return p_impl->p_name;
} }
LIBCUBESCRIPT_EXPORT int ident::get_index() const { LIBCUBESCRIPT_EXPORT int ident::index() const {
return p_impl->p_index; return p_impl->p_index;
} }
@ -198,19 +198,19 @@ LIBCUBESCRIPT_EXPORT bool ident::operator!=(ident &other) const {
} }
LIBCUBESCRIPT_EXPORT bool ident::is_alias() 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 { 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 { 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 { LIBCUBESCRIPT_EXPORT bool ident::is_var() const {
switch (get_type()) { switch (type()) {
case ident_type::IVAR: case ident_type::IVAR:
case ident_type::FVAR: case ident_type::FVAR:
case ident_type::SVAR: case ident_type::SVAR:
@ -222,19 +222,19 @@ LIBCUBESCRIPT_EXPORT bool ident::is_var() const {
} }
LIBCUBESCRIPT_EXPORT bool ident::is_ivar() 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 { 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 { 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 { LIBCUBESCRIPT_EXPORT bool ident::is_overridden(state &cs) const {
switch (get_type()) { switch (type()) {
case ident_type::IVAR: case ident_type::IVAR:
case ident_type::FVAR: case ident_type::FVAR:
case ident_type::SVAR: 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 { LIBCUBESCRIPT_EXPORT bool ident::is_persistent(state &cs) const {
switch (get_type()) { switch (type()) {
case ident_type::IVAR: case ident_type::IVAR:
case ident_type::FVAR: case ident_type::FVAR:
case ident_type::SVAR: case ident_type::SVAR:
@ -277,7 +277,7 @@ LIBCUBESCRIPT_EXPORT bool global_var::is_overridable() const {
return (p_impl->p_flags & IDENT_FLAG_OVERRIDE); 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) { if (p_impl->p_flags & IDENT_FLAG_OVERRIDE) {
return var_type::OVERRIDABLE; return var_type::OVERRIDABLE;
} else if (p_impl->p_flags & IDENT_FLAG_PERSIST) { } 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) { if (p_impl->p_flags & IDENT_FLAG_PERSIST) {
throw error{ throw error{
cs, "cannot override persistent variable '%s'", cs, "cannot override persistent variable '%s'",
get_name().data() name().data()
}; };
} }
if (!(p_impl->p_flags & IDENT_FLAG_OVERRIDDEN)) { if (!(p_impl->p_flags & IDENT_FLAG_OVERRIDDEN)) {
@ -311,7 +311,7 @@ LIBCUBESCRIPT_EXPORT any_value global_var::call(
return ident::call(args, cs); 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<ivar_impl const *>(this)->p_storage; return static_cast<ivar_impl const *>(this)->p_storage;
} }
@ -320,14 +320,14 @@ LIBCUBESCRIPT_EXPORT void integer_var::set_value(
) { ) {
if (is_read_only()) { if (is_read_only()) {
throw error{ throw error{
cs, "variable '%s' is read only", get_name().data() cs, "variable '%s' is read only", name().data()
}; };
} }
if (!do_write) { if (!do_write) {
return; return;
} }
save(cs); save(cs);
auto oldv = get_value(); auto oldv = value();
set_raw_value(val); set_raw_value(val);
if (trigger) { if (trigger) {
any_value v; any_value v;
@ -348,7 +348,7 @@ inline any_value call_var(
auto *cimp = static_cast<command_impl *>(hid); auto *cimp = static_cast<command_impl *>(hid);
auto &targs = ts.vmstack; auto &targs = ts.vmstack;
auto osz = targs.size(); 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(); auto nargs = args.size();
targs.resize( targs.resize(
osz + std::max(args.size(), anargs + 1) 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); 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<fvar_impl const *>(this)->p_storage; return static_cast<fvar_impl const *>(this)->p_storage;
} }
@ -375,14 +375,14 @@ LIBCUBESCRIPT_EXPORT void float_var::set_value(
) { ) {
if (is_read_only()) { if (is_read_only()) {
throw error{ throw error{
cs, "variable '%s' is read only", get_name().data() cs, "variable '%s' is read only", name().data()
}; };
} }
if (!do_write) { if (!do_write) {
return; return;
} }
save(cs); save(cs);
auto oldv = get_value(); auto oldv = value();
set_raw_value(val); set_raw_value(val);
if (trigger) { if (trigger) {
any_value v; 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); 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<svar_impl const *>(this)->p_storage; return static_cast<svar_impl const *>(this)->p_storage;
} }
@ -410,14 +410,14 @@ LIBCUBESCRIPT_EXPORT void string_var::set_value(
) { ) {
if (is_read_only()) { if (is_read_only()) {
throw error{ throw error{
cs, "variable '%s' is read only", get_name().data() cs, "variable '%s' is read only", name().data()
}; };
} }
if (!do_write) { if (!do_write) {
return; return;
} }
save(cs); save(cs);
auto oldv = get_value(); auto oldv = value();
set_raw_value(std::move(val)); set_raw_value(std::move(val));
if (trigger) { if (trigger) {
any_value v; 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); 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; return state_p{cs}.ts().get_astack(this).node->val_s;
} }
@ -466,11 +466,11 @@ LIBCUBESCRIPT_EXPORT any_value alias::call(
return ret; return ret;
} }
LIBCUBESCRIPT_EXPORT std::string_view command::get_args() const { LIBCUBESCRIPT_EXPORT std::string_view command::args() const {
return static_cast<command_impl const *>(this)->p_cargs; return static_cast<command_impl const *>(this)->p_cargs;
} }
LIBCUBESCRIPT_EXPORT int command::get_num_args() const { LIBCUBESCRIPT_EXPORT int command::arg_count() const {
return static_cast<command_impl const *>(this)->p_numargs; return static_cast<command_impl const *>(this)->p_numargs;
} }
@ -484,11 +484,11 @@ LIBCUBESCRIPT_EXPORT any_value command::call(
} }
auto nargs = args.size(); auto nargs = args.size();
auto &ts = state_p{cs}.ts(); 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 */ stack_guard s{ts}; /* restore after call */
auto &targs = ts.vmstack; auto &targs = ts.vmstack;
auto osz = targs.size(); 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) { for (std::size_t i = 0; i < nargs; ++i) {
targs[osz + i] = args[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) { LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, ident &a) {
if (!a.is_alias()) { 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(); auto &ts = state_p{cs}.ts();
p_alias = static_cast<alias *>(&a); p_alias = static_cast<alias *>(&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): LIBCUBESCRIPT_EXPORT alias_local::alias_local(state &cs, any_value const &v):
alias_local{cs, ( 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))} ) ? v.get_ident(cs) : cs.new_ident(v.get_string(cs))}
{} {}

View File

@ -479,7 +479,7 @@ lookup_id:
ident &id = ts.istate->new_ident( ident &id = ts.istate->new_ident(
*ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN *ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN
); );
switch (id.get_type()) { switch (id.type()) {
case ident_type::IVAR: case ident_type::IVAR:
if (ltype == VAL_POP) { if (ltype == VAL_POP) {
return; return;
@ -532,7 +532,7 @@ lookup_id:
return; return;
case ident_type::COMMAND: { case ident_type::COMMAND: {
std::uint32_t comtype = BC_INST_COM, numargs = 0; std::uint32_t comtype = BC_INST_COM, numargs = 0;
auto fmt = static_cast<command_impl &>(id).get_args(); auto fmt = static_cast<command_impl &>(id).args();
for (char c: fmt) { for (char c: fmt) {
switch (c) { switch (c) {
case '$': case '$':
@ -603,7 +603,7 @@ lookup_id:
ident &id = ts.istate->new_ident( ident &id = ts.istate->new_ident(
*ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN *ts.pstate, lookup.str_term(), IDENT_FLAG_UNKNOWN
); );
switch (id.get_type()) { switch (id.type()) {
case ident_type::IVAR: case ident_type::IVAR:
gs.gen_lookup_ivar(id); gs.gen_lookup_ivar(id);
return true; return true;
@ -956,7 +956,7 @@ bool parser_state::parse_call_command(
command_impl *id, ident &self, int rettype command_impl *id, ident &self, int rettype
) { ) {
std::uint32_t comtype = BC_INST_COM, numargs = 0, fakeargs = 0; 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; bool more = true, rep = false;
for (auto it = fmt.begin(); it != fmt.end(); ++it) { for (auto it = fmt.begin(); it != fmt.end(); ++it) {
switch (*it) { switch (*it) {
@ -1258,7 +1258,7 @@ static bool parse_no_id(parser_state &ps, int term) {
static bool parse_assign_var( static bool parse_assign_var(
parser_state &ps, command_impl *id, ident &var, int ltype 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 comtype = BC_INST_COM;
std::uint32_t nargs = 0; std::uint32_t nargs = 0;
bool more = true, got = false, rep = false; bool more = true, got = false, rep = false;
@ -1337,7 +1337,7 @@ bool parser_state::parse_assign(
*ts.pstate, idname.str_term(), IDENT_FLAG_UNKNOWN *ts.pstate, idname.str_term(), IDENT_FLAG_UNKNOWN
); );
/* check what we're assigning */ /* check what we're assigning */
switch (id.get_type()) { switch (id.type()) {
case ident_type::ALIAS: { case ident_type::ALIAS: {
/* alias assignment: parse out any one argument */ /* alias assignment: parse out any one argument */
bool more = parse_arg(VAL_ANY); bool more = parse_arg(VAL_ANY);
@ -1477,7 +1477,7 @@ LIBCUBESCRIPT_EXPORT bool list_parser::parse() {
switch (*p_input_beg) { switch (*p_input_beg) {
case '"': { case '"': {
char const *qi = p_input_beg; 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_qbeg = qi;
p_qend = p_input_beg; p_qend = p_input_beg;
p_ibeg = p_qbeg + 1; p_ibeg = p_qbeg + 1;
@ -1502,7 +1502,7 @@ LIBCUBESCRIPT_EXPORT bool list_parser::parse() {
case '"': case '"':
/* the quote is needed in str parsing */ /* the quote is needed in str parsing */
--p_input_beg; --p_input_beg;
p_input_beg = parse_string(*p_state, get_input()); p_input_beg = parse_string(*p_state, input());
break; break;
case '/': case '/':
if ( if (
@ -1541,7 +1541,7 @@ endblock:
case ']': case ']':
return false; return false;
default: { 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_ibeg = p_qbeg = p_input_beg;
p_iend = p_qend = e; p_iend = p_qend = e;
p_input_beg = 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 { LIBCUBESCRIPT_EXPORT string_ref list_parser::get_item() const {
if ((p_qbeg != p_qend) && (*p_qbeg == '"')) { if ((p_qbeg != p_qend) && (*p_qbeg == '"')) {
charbuf buf{*p_state}; 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, 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() { LIBCUBESCRIPT_EXPORT void list_parser::skip_until_item() {

View File

@ -48,7 +48,7 @@ ident *internal_state::add_ident(ident *id, ident_impl *impl) {
return nullptr; return nullptr;
} }
ident_p{*id}.impl(impl); ident_p{*id}.impl(impl);
idents[id->get_name()] = id; idents[id->name()] = id;
impl->p_index = int(identmap.size()); impl->p_index = int(identmap.size());
identmap.push_back(id); identmap.push_back(id);
return identmap.back(); return identmap.back();
@ -126,8 +126,8 @@ state::state(alloc_func func, void *data) {
) { ) {
auto &iv = static_cast<integer_var &>(args[0].get_ident(cs)); auto &iv = static_cast<integer_var &>(args[0].get_ident(cs));
if (args[2].get_integer() <= 1) { if (args[2].get_integer() <= 1) {
std::printf("%s = ", iv.get_name().data()); std::printf("%s = ", iv.name().data());
std::printf(INTEGER_FORMAT, iv.get_value()); std::printf(INTEGER_FORMAT, iv.value());
std::printf("\n"); std::printf("\n");
} else { } else {
iv.set_value(cs, args[1].get_integer()); iv.set_value(cs, args[1].get_integer());
@ -139,8 +139,8 @@ state::state(alloc_func func, void *data) {
) { ) {
auto &fv = static_cast<float_var &>(args[0].get_ident(cs)); auto &fv = static_cast<float_var &>(args[0].get_ident(cs));
if (args[2].get_integer() <= 1) { if (args[2].get_integer() <= 1) {
auto val = fv.get_value(); auto val = fv.value();
std::printf("%s = ", fv.get_name().data()); std::printf("%s = ", fv.name().data());
if (std::floor(val) == val) { if (std::floor(val) == val) {
std::printf(ROUND_FLOAT_FORMAT, val); std::printf(ROUND_FLOAT_FORMAT, val);
} else { } else {
@ -157,11 +157,11 @@ state::state(alloc_func func, void *data) {
) { ) {
auto &sv = static_cast<string_var &>(args[0].get_ident(cs)); auto &sv = static_cast<string_var &>(args[0].get_ident(cs));
if (args[2].get_integer() <= 1) { if (args[2].get_integer() <= 1) {
auto val = sv.get_value(); auto val = sv.value();
if (val.view().find('"') == std::string_view::npos) { 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 { } else {
std::printf("%s = [%s]\n", sv.get_name().data(), val.data()); std::printf("%s = [%s]\n", sv.name().data(), val.data());
} }
} else { } else {
sv.set_value(cs, args[1].get_string(cs)); sv.set_value(cs, args[1].get_string(cs));
@ -299,15 +299,15 @@ LIBCUBESCRIPT_EXPORT state state::new_thread() {
return state{p_tstate->istate}; 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)); 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(); 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(); return p_tstate->get_hook();
} }
@ -341,7 +341,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) {
if (!id.is_overridden(*this)) { if (!id.is_overridden(*this)) {
return; return;
} }
switch (id.get_type()) { switch (id.type()) {
case ident_type::ALIAS: { case ident_type::ALIAS: {
auto &ast = p_tstate->get_astack(static_cast<alias *>(&id)); auto &ast = p_tstate->get_astack(static_cast<alias *>(&id));
ast.node->val_s.set_string("", *this); ast.node->val_s.set_string("", *this);
@ -352,7 +352,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) {
case ident_type::IVAR: { case ident_type::IVAR: {
any_value oldv; any_value oldv;
ivar_impl &iv = static_cast<ivar_impl &>(id); ivar_impl &iv = static_cast<ivar_impl &>(id);
oldv.set_integer(iv.get_value()); oldv.set_integer(iv.value());
iv.set_raw_value(iv.p_override); iv.set_raw_value(iv.p_override);
var_changed(*p_tstate, &id, oldv); var_changed(*p_tstate, &id, oldv);
static_cast<ivar_impl *>( static_cast<ivar_impl *>(
@ -363,7 +363,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) {
case ident_type::FVAR: { case ident_type::FVAR: {
any_value oldv; any_value oldv;
fvar_impl &fv = static_cast<fvar_impl &>(id); fvar_impl &fv = static_cast<fvar_impl &>(id);
oldv.set_float(fv.get_value()); oldv.set_float(fv.value());
fv.set_raw_value(fv.p_override); fv.set_raw_value(fv.p_override);
var_changed(*p_tstate, &id, oldv); var_changed(*p_tstate, &id, oldv);
static_cast<fvar_impl *>( static_cast<fvar_impl *>(
@ -374,7 +374,7 @@ LIBCUBESCRIPT_EXPORT void state::clear_override(ident &id) {
case ident_type::SVAR: { case ident_type::SVAR: {
any_value oldv; any_value oldv;
svar_impl &sv = static_cast<svar_impl &>(id); svar_impl &sv = static_cast<svar_impl &>(id);
oldv.set_string(sv.get_value()); oldv.set_string(sv.value());
sv.set_raw_value(sv.p_override); sv.set_raw_value(sv.p_override);
var_changed(*p_tstate, &id, oldv); var_changed(*p_tstate, &id, oldv);
static_cast<svar_impl *>( static_cast<svar_impl *>(
@ -483,7 +483,7 @@ LIBCUBESCRIPT_EXPORT void state::assign_value(
) { ) {
auto id = get_ident(name); auto id = get_ident(name);
if (id) { if (id) {
switch (id->get().get_type()) { switch (id->get().type()) {
case ident_type::ALIAS: { case ident_type::ALIAS: {
static_cast<alias &>(id->get()).set_value(*this, std::move(v)); static_cast<alias &>(id->get()).set_value(*this, std::move(v));
return; return;
@ -496,7 +496,7 @@ LIBCUBESCRIPT_EXPORT void state::assign_value(
default: default:
throw error{ throw error{
*this, "cannot redefine builtin %s with an alias", *this, "cannot redefine builtin %s with an alias",
id->get().get_name().data() id->get().name().data()
}; };
} }
} else if (!is_valid_name(name)) { } else if (!is_valid_name(name)) {
@ -520,7 +520,7 @@ LIBCUBESCRIPT_EXPORT any_value state::lookup_value(std::string_view name) {
} }
alias_stack *ast; alias_stack *ast;
if (id) { if (id) {
switch(id->get_type()) { switch(id->type()) {
case ident_type::ALIAS: { case ident_type::ALIAS: {
auto *a = static_cast<alias_impl *>(id); auto *a = static_cast<alias_impl *>(id);
ast = &p_tstate->get_astack(static_cast<alias *>(id)); ast = &p_tstate->get_astack(static_cast<alias *>(id));
@ -534,17 +534,17 @@ LIBCUBESCRIPT_EXPORT any_value state::lookup_value(std::string_view name) {
} }
case ident_type::SVAR: { case ident_type::SVAR: {
any_value val{}; any_value val{};
val.set_string(static_cast<string_var *>(id)->get_value()); val.set_string(static_cast<string_var *>(id)->value());
return val; return val;
} }
case ident_type::IVAR: { case ident_type::IVAR: {
any_value val{}; any_value val{};
val.set_integer(static_cast<integer_var *>(id)->get_value()); val.set_integer(static_cast<integer_var *>(id)->value());
return val; return val;
} }
case ident_type::FVAR: { case ident_type::FVAR: {
any_value val{}; any_value val{};
val.set_float(static_cast<float_var *>(id)->get_value()); val.set_float(static_cast<float_var *>(id)->value());
return val; return val;
} }
case ident_type::COMMAND: { 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 &args = p_tstate->vmstack;
auto osz = args.size(); auto osz = args.size();
/* pad with as many empty values as we need */ /* pad with as many empty values as we need */
args.resize(osz + cimpl->get_num_args()); args.resize(osz + cimpl->arg_count());
exec_command( exec_command(
*p_tstate, cimpl, cimpl, &args[osz], val, 0, true *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(); auto &idr = id->get();
any_value v; any_value v;
switch (idr.get_type()) { switch (idr.type()) {
case ident_type::IVAR: case ident_type::IVAR:
v.set_integer(static_cast<integer_var &>(idr).get_value()); v.set_integer(static_cast<integer_var &>(idr).value());
break; break;
case ident_type::FVAR: case ident_type::FVAR:
v.set_float(static_cast<float_var &>(idr).get_value()); v.set_float(static_cast<float_var &>(idr).value());
break; break;
case ident_type::SVAR: case ident_type::SVAR:
v.set_string(static_cast<string_var &>(idr).get_value()); v.set_string(static_cast<string_var &>(idr).value());
break; break;
default: default:
return; return;
@ -723,12 +723,12 @@ LIBCUBESCRIPT_EXPORT bcode_ref state::compile(
return gs.steal_ref(); 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); return (p_tstate->ident_flags & IDENT_FLAG_OVERRIDDEN);
} }
LIBCUBESCRIPT_EXPORT bool state::set_override_mode(bool v) { LIBCUBESCRIPT_EXPORT bool state::override_mode(bool v) {
bool was = get_override_mode(); bool was = override_mode();
if (v) { if (v) {
p_tstate->ident_flags |= IDENT_FLAG_OVERRIDDEN; p_tstate->ident_flags |= IDENT_FLAG_OVERRIDDEN;
} else { } else {
@ -737,12 +737,12 @@ LIBCUBESCRIPT_EXPORT bool state::set_override_mode(bool v) {
return was; 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); return (p_tstate->ident_flags & IDENT_FLAG_PERSIST);
} }
LIBCUBESCRIPT_EXPORT bool state::set_persist_mode(bool v) { LIBCUBESCRIPT_EXPORT bool state::persist_mode(bool v) {
bool was = get_persist_mode(); bool was = persist_mode();
if (v) { if (v) {
p_tstate->ident_flags |= IDENT_FLAG_PERSIST; p_tstate->ident_flags |= IDENT_FLAG_PERSIST;
} else { } else {
@ -751,11 +751,11 @@ LIBCUBESCRIPT_EXPORT bool state::set_persist_mode(bool v) {
return was; 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; 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; auto old = p_tstate->max_call_depth;
p_tstate->max_call_depth = v; p_tstate->max_call_depth = v;
return old; return old;

View File

@ -16,7 +16,7 @@ hook_func thread_state::set_hook(hook_func f) {
} }
alias_stack &thread_state::get_astack(alias const *a) { 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) { if (it.second) {
auto *imp = const_cast<alias_impl *>( auto *imp = const_cast<alias_impl *>(
static_cast<alias_impl const *>(a) static_cast<alias_impl const *>(a)

View File

@ -98,7 +98,7 @@ any_value::any_value(any_value &&v): any_value{} {
any_value &any_value::operator=(any_value const &v) { any_value &any_value::operator=(any_value const &v) {
csv_cleanup(p_type, &p_stor); csv_cleanup(p_type, &p_stor);
p_type = value_type::NONE; p_type = value_type::NONE;
switch (v.get_type()) { switch (v.type()) {
case value_type::INTEGER: case value_type::INTEGER:
case value_type::FLOAT: case value_type::FLOAT:
case value_type::IDENT: case value_type::IDENT:
@ -125,7 +125,7 @@ any_value &any_value::operator=(any_value &&v) {
return *this; return *this;
} }
value_type any_value::get_type() const { value_type any_value::type() const {
return p_type; return p_type;
} }
@ -162,7 +162,7 @@ void any_value::set_code(bcode_ref const &val) {
bcode *p = bcode_p{val}.get(); bcode *p = bcode_p{val}.get();
csv_cleanup(p_type, &p_stor); csv_cleanup(p_type, &p_stor);
p_type = value_type::CODE; p_type = value_type::CODE;
bcode_addref(p->get_raw()); bcode_addref(p->raw());
csv_get<bcode *>(&p_stor) = p; csv_get<bcode *>(&p_stor) = p;
} }
@ -173,14 +173,14 @@ void any_value::set_ident(ident &val) {
} }
void any_value::force_none() { void any_value::force_none() {
if (get_type() == value_type::NONE) { if (type() == value_type::NONE) {
return; return;
} }
set_none(); set_none();
} }
void any_value::force_plain() { void any_value::force_plain() {
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
case value_type::INTEGER: case value_type::INTEGER:
case value_type::STRING: case value_type::STRING:
@ -193,7 +193,7 @@ void any_value::force_plain() {
float_type any_value::force_float() { float_type any_value::force_float() {
float_type rf = 0.0f; float_type rf = 0.0f;
switch (get_type()) { switch (type()) {
case value_type::INTEGER: case value_type::INTEGER:
rf = float_type(csv_get<integer_type>(&p_stor)); rf = float_type(csv_get<integer_type>(&p_stor));
break; break;
@ -211,7 +211,7 @@ float_type any_value::force_float() {
integer_type any_value::force_integer() { integer_type any_value::force_integer() {
integer_type ri = 0; integer_type ri = 0;
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
ri = integer_type(std::floor(csv_get<float_type>(&p_stor))); ri = integer_type(std::floor(csv_get<float_type>(&p_stor)));
break; break;
@ -230,7 +230,7 @@ integer_type any_value::force_integer() {
std::string_view any_value::force_string(state &cs) { std::string_view any_value::force_string(state &cs) {
charbuf rs{cs}; charbuf rs{cs};
std::string_view str; std::string_view str;
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
str = floatstr(csv_get<float_type>(&p_stor), rs); str = floatstr(csv_get<float_type>(&p_stor), rs);
break; 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) { bcode_ref any_value::force_code(state &cs, std::string_view source) {
switch (get_type()) { switch (type()) {
case value_type::CODE: case value_type::CODE:
return bcode_p::make_ref(csv_get<bcode *>(&p_stor)); return bcode_p::make_ref(csv_get<bcode *>(&p_stor));
default: default:
@ -262,7 +262,7 @@ bcode_ref any_value::force_code(state &cs, std::string_view source) {
} }
ident &any_value::force_ident(state &cs) { ident &any_value::force_ident(state &cs) {
switch (get_type()) { switch (type()) {
case value_type::IDENT: case value_type::IDENT:
return *csv_get<ident *>(&p_stor); return *csv_get<ident *>(&p_stor);
default: default:
@ -276,7 +276,7 @@ ident &any_value::force_ident(state &cs) {
} }
integer_type any_value::get_integer() const { integer_type any_value::get_integer() const {
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
return integer_type(csv_get<float_type>(&p_stor)); return integer_type(csv_get<float_type>(&p_stor));
case value_type::INTEGER: case value_type::INTEGER:
@ -290,7 +290,7 @@ integer_type any_value::get_integer() const {
} }
float_type any_value::get_float() const { float_type any_value::get_float() const {
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
return csv_get<float_type>(&p_stor); return csv_get<float_type>(&p_stor);
case value_type::INTEGER: case value_type::INTEGER:
@ -306,21 +306,21 @@ float_type any_value::get_float() const {
} }
bcode_ref any_value::get_code() const { bcode_ref any_value::get_code() const {
if (get_type() != value_type::CODE) { if (type() != value_type::CODE) {
return bcode_ref{}; return bcode_ref{};
} }
return bcode_p::make_ref(csv_get<bcode *>(&p_stor)); return bcode_p::make_ref(csv_get<bcode *>(&p_stor));
} }
ident &any_value::get_ident(state &cs) const { 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 *state_p{cs}.ts().istate->id_dummy;
} }
return *csv_get<ident *>(&p_stor); return *csv_get<ident *>(&p_stor);
} }
string_ref any_value::get_string(state &cs) const { string_ref any_value::get_string(state &cs) const {
switch (get_type()) { switch (type()) {
case value_type::STRING: case value_type::STRING:
return string_ref{csv_get<char const *>(&p_stor)}; return string_ref{csv_get<char const *>(&p_stor)};
case value_type::INTEGER: { case value_type::INTEGER: {
@ -342,7 +342,7 @@ string_ref any_value::get_string(state &cs) const {
} }
any_value any_value::get_plain() const { any_value any_value::get_plain() const {
switch (get_type()) { switch (type()) {
case value_type::STRING: case value_type::STRING:
case value_type::INTEGER: case value_type::INTEGER:
case value_type::FLOAT: case value_type::FLOAT:
@ -354,7 +354,7 @@ any_value any_value::get_plain() const {
} }
bool any_value::get_bool() const { bool any_value::get_bool() const {
switch (get_type()) { switch (type()) {
case value_type::FLOAT: case value_type::FLOAT:
return csv_get<float_type>(&p_stor) != 0; return csv_get<float_type>(&p_stor) != 0;
case value_type::INTEGER: case value_type::INTEGER:
@ -390,7 +390,7 @@ LIBCUBESCRIPT_EXPORT string_ref concat_values(
) { ) {
charbuf buf{cs}; charbuf buf{cs};
for (std::size_t i = 0; i < vals.size(); ++i) { 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::INTEGER:
case value_type::FLOAT: case value_type::FLOAT:
case value_type::STRING: { case value_type::STRING: {

View File

@ -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) { static inline void force_arg(state &cs, any_value &v, int type) {
switch (type) { switch (type) {
case BC_RET_STRING: case BC_RET_STRING:
if (v.get_type() != value_type::STRING) { if (v.type() != value_type::STRING) {
v.force_string(cs); v.force_string(cs);
} }
break; break;
case BC_RET_INT: case BC_RET_INT:
if (v.get_type() != value_type::INTEGER) { if (v.type() != value_type::INTEGER) {
v.force_integer(); v.force_integer();
} }
break; break;
case BC_RET_FLOAT: case BC_RET_FLOAT:
if (v.get_type() != value_type::FLOAT) { if (v.type() != value_type::FLOAT) {
v.force_float(); v.force_float();
} }
break; break;
@ -50,7 +50,7 @@ void exec_command(
) { ) {
int i = -1, fakeargs = 0, numargs = int(nargs); int i = -1, fakeargs = 0, numargs = int(nargs);
bool rep = false; bool rep = false;
auto fmt = id->get_args(); auto fmt = id->args();
auto set_fake = [&i, &fakeargs, &rep, args, numargs]() { auto set_fake = [&i, &fakeargs, &rep, args, numargs]() {
if (++i >= numargs) { if (++i >= numargs) {
if (rep) { if (rep) {
@ -84,7 +84,7 @@ void exec_command(
break; break;
case 'c': case 'c':
if (set_fake()) { 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); auto str = args[i].get_string(*ts.pstate);
if (str.empty()) { if (str.empty()) {
args[i].set_integer(0); args[i].set_integer(0);
@ -139,12 +139,12 @@ bool exec_alias(
) { ) {
auto &aast = ts.get_astack(a); auto &aast = ts.get_astack(a);
if (ncheck) { if (ncheck) {
if (aast.node->val_s.get_type() == value_type::NONE) { if (aast.node->val_s.type() == value_type::NONE) {
return false; return false;
} }
} else if (aast.flags & IDENT_FLAG_UNKNOWN) { } else if (aast.flags & IDENT_FLAG_UNKNOWN) {
throw error { 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?) */ /* excess arguments get ignored (make error maybe?) */
@ -161,7 +161,7 @@ bool exec_alias(
st.val_s = std::move(args[offset + i]); st.val_s = std::move(args[offset + i]);
uargs[i] = true; uargs[i] = true;
} }
auto oldargs = anargs->get_value(); auto oldargs = anargs->value();
auto oldflags = ts.ident_flags; auto oldflags = ts.ident_flags;
ts.ident_flags = aast.flags; ts.ident_flags = aast.flags;
anargs->set_raw_value(integer_type(callargs)); anargs->set_raw_value(integer_type(callargs));
@ -197,7 +197,7 @@ bool exec_alias(
nargs = offset - skip; nargs = offset - skip;
}; };
try { try {
vm_exec(ts, bcode_p{coderef}.get()->get_raw(), result); vm_exec(ts, bcode_p{coderef}.get()->raw(), result);
} catch (...) { } catch (...) {
cleanup(); cleanup();
throw; throw;
@ -230,7 +230,7 @@ static inline alias *get_lookup_id(
ast = &ts.get_astack(static_cast<alias *>(id)); ast = &ts.get_astack(static_cast<alias *>(id));
if (ast->flags & IDENT_FLAG_UNKNOWN) { if (ast->flags & IDENT_FLAG_UNKNOWN) {
throw error{ 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 */ call_depth_guard level{ts}; /* incr and decr on scope exit */
stack_guard guard{ts}; /* resize back to original */ stack_guard guard{ts}; /* resize back to original */
auto &args = ts.vmstack; auto &args = ts.vmstack;
auto &chook = cs.get_call_hook(); auto &chook = cs.call_hook();
if (chook) { if (chook) {
chook(cs); chook(cs);
} }
@ -495,7 +495,7 @@ std::uint32_t *vm_exec(
std::uint32_t len = op >> 8; std::uint32_t len = op >> 8;
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
if (v.get_type() == value_type::CODE) { if (v.type() == value_type::CODE) {
result = v.get_code().call(cs); result = v.get_code().call(cs);
} else { } else {
result = std::move(v); result = std::move(v);
@ -509,7 +509,7 @@ std::uint32_t *vm_exec(
std::uint32_t len = op >> 8; std::uint32_t len = op >> 8;
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
if (v.get_type() == value_type::CODE) { if (v.type() == value_type::CODE) {
result = v.get_code().call(cs); result = v.get_code().call(cs);
} else { } else {
result = std::move(v); result = std::move(v);
@ -567,7 +567,7 @@ std::uint32_t *vm_exec(
case BC_INST_COMPILE: { case BC_INST_COMPILE: {
any_value &arg = args.back(); any_value &arg = args.back();
gen_state gs{ts}; gen_state gs{ts};
switch (arg.get_type()) { switch (arg.type()) {
case value_type::INTEGER: case value_type::INTEGER:
gs.gen_main_integer(arg.get_integer()); gs.gen_main_integer(arg.get_integer());
break; break;
@ -587,7 +587,7 @@ std::uint32_t *vm_exec(
case BC_INST_COND: { case BC_INST_COND: {
any_value &arg = args.back(); any_value &arg = args.back();
switch (arg.get_type()) { switch (arg.type()) {
case value_type::STRING: { case value_type::STRING: {
std::string_view s = arg.get_string(cs); std::string_view s = arg.get_string(cs);
if (!s.empty()) { if (!s.empty()) {
@ -611,7 +611,7 @@ std::uint32_t *vm_exec(
); );
if (a->is_arg() && !ident_is_used_arg(a, ts)) { if (a->is_arg() && !ident_is_used_arg(a, ts)) {
ts.get_astack(a).push(ts.idstack.emplace_back()); 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); args.emplace_back().set_ident(*a);
continue; continue;
@ -619,7 +619,7 @@ std::uint32_t *vm_exec(
case BC_INST_IDENT_U: { case BC_INST_IDENT_U: {
any_value &arg = args.back(); any_value &arg = args.back();
ident *id = ts.istate->id_dummy; ident *id = ts.istate->id_dummy;
if (arg.get_type() == value_type::STRING) { if (arg.type() == value_type::STRING) {
id = &ts.istate->new_ident( id = &ts.istate->new_ident(
cs, arg.get_string(cs), IDENT_FLAG_UNKNOWN cs, arg.get_string(cs), IDENT_FLAG_UNKNOWN
); );
@ -627,7 +627,7 @@ std::uint32_t *vm_exec(
alias *a = static_cast<alias *>(id); alias *a = static_cast<alias *>(id);
if (a->is_arg() && !ident_is_used_arg(id, ts)) { if (a->is_arg() && !ident_is_used_arg(id, ts)) {
ts.get_astack(a).push(ts.idstack.emplace_back()); 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); arg.set_ident(*id);
continue; continue;
@ -714,20 +714,20 @@ std::uint32_t *vm_exec(
case BC_INST_SVAR | BC_RET_NULL: case BC_INST_SVAR | BC_RET_NULL:
args.emplace_back().set_string(static_cast<string_var *>( args.emplace_back().set_string(static_cast<string_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value()); )->value());
continue; continue;
case BC_INST_SVAR | BC_RET_INT: case BC_INST_SVAR | BC_RET_INT:
args.emplace_back().set_integer(parse_int( args.emplace_back().set_integer(parse_int(
static_cast<string_var *>( static_cast<string_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value() )->value()
)); ));
continue; continue;
case BC_INST_SVAR | BC_RET_FLOAT: case BC_INST_SVAR | BC_RET_FLOAT:
args.emplace_back().set_float(parse_float( args.emplace_back().set_float(parse_float(
static_cast<string_var *>( static_cast<string_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value() )->value()
)); ));
continue; continue;
@ -735,13 +735,13 @@ std::uint32_t *vm_exec(
case BC_INST_IVAR | BC_RET_NULL: case BC_INST_IVAR | BC_RET_NULL:
args.emplace_back().set_integer(static_cast<integer_var *>( args.emplace_back().set_integer(static_cast<integer_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value()); )->value());
continue; continue;
case BC_INST_IVAR | BC_RET_STRING: { case BC_INST_IVAR | BC_RET_STRING: {
auto &v = args.emplace_back(); auto &v = args.emplace_back();
v.set_integer(static_cast<integer_var *>( v.set_integer(static_cast<integer_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value()); )->value());
v.force_string(cs); v.force_string(cs);
continue; continue;
} }
@ -749,7 +749,7 @@ std::uint32_t *vm_exec(
args.emplace_back().set_float(float_type( args.emplace_back().set_float(float_type(
static_cast<integer_var *>( static_cast<integer_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value() )->value()
)); ));
continue; continue;
@ -757,13 +757,13 @@ std::uint32_t *vm_exec(
case BC_INST_FVAR | BC_RET_NULL: case BC_INST_FVAR | BC_RET_NULL:
args.emplace_back().set_float(static_cast<float_var *>( args.emplace_back().set_float(static_cast<float_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value()); )->value());
continue; continue;
case BC_INST_FVAR | BC_RET_STRING: { case BC_INST_FVAR | BC_RET_STRING: {
auto &v = args.emplace_back(); auto &v = args.emplace_back();
v.set_float(static_cast<float_var *>( v.set_float(static_cast<float_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value()); )->value());
v.force_string(cs); v.force_string(cs);
continue; continue;
} }
@ -771,7 +771,7 @@ std::uint32_t *vm_exec(
args.emplace_back().set_integer( args.emplace_back().set_integer(
integer_type(std::floor(static_cast<float_var *>( integer_type(std::floor(static_cast<float_var *>(
ts.istate->identmap[op >> 8] ts.istate->identmap[op >> 8]
)->get_value())) )->value()))
); );
continue; continue;
@ -829,7 +829,7 @@ std::uint32_t *vm_exec(
std::size_t nnargs = args.size(); std::size_t nnargs = args.size();
std::size_t offset = nnargs - callargs; std::size_t offset = nnargs - callargs;
any_value &idarg = args[offset - 1]; any_value &idarg = args[offset - 1];
if (idarg.get_type() != value_type::STRING) { if (idarg.type() != value_type::STRING) {
litval: litval:
result = std::move(idarg); result = std::move(idarg);
force_arg(cs, result, op & BC_INST_RET_MASK); force_arg(cs, result, op & BC_INST_RET_MASK);
@ -862,7 +862,7 @@ noid:
case ID_COMMAND: { case ID_COMMAND: {
auto *cimp = static_cast<command_impl *>(&id->get()); auto *cimp = static_cast<command_impl *>(&id->get());
args.resize(offset + std::max( args.resize(offset + std::max(
std::size_t(cimp->get_num_args()), callargs std::size_t(cimp->arg_count()), callargs
)); ));
exec_command( exec_command(
ts, cimp, cimp, &args[offset], result, callargs ts, cimp, cimp, &args[offset], result, callargs
@ -900,7 +900,7 @@ noid:
/* the $ argument */ /* the $ argument */
args.insert(offset, any_value{}); args.insert(offset, any_value{});
args.resize(offset + std::max( args.resize(offset + std::max(
std::size_t(cimp->get_num_args()), callargs std::size_t(cimp->arg_count()), callargs
)); ));
exec_command( exec_command(
ts, cimp, &id->get(), &args[offset], ts, cimp, &id->get(), &args[offset],
@ -916,7 +916,7 @@ noid:
/* the $ argument */ /* the $ argument */
args.insert(offset, any_value{}); args.insert(offset, any_value{});
args.resize(offset + std::max( args.resize(offset + std::max(
std::size_t(cimp->get_num_args()), callargs std::size_t(cimp->arg_count()), callargs
)); ));
exec_command( exec_command(
ts, cimp, &id->get(), &args[offset], ts, cimp, &id->get(), &args[offset],
@ -932,7 +932,7 @@ noid:
/* the $ argument */ /* the $ argument */
args.insert(offset, any_value{}); args.insert(offset, any_value{});
args.resize(offset + std::max( args.resize(offset + std::max(
std::size_t(cimp->get_num_args()), callargs std::size_t(cimp->arg_count()), callargs
)); ));
exec_command( exec_command(
ts, cimp, &id->get(), &args[offset], ts, cimp, &id->get(), &args[offset],
@ -968,10 +968,10 @@ noid:
command_impl *id = static_cast<command_impl *>( command_impl *id = static_cast<command_impl *>(
ts.istate->identmap[op >> 8] 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(); result.force_none();
id->call(ts, span_type<any_value>{ id->call(ts, span_type<any_value>{
&args[offset], std::size_t(id->get_num_args()) &args[offset], std::size_t(id->arg_count())
}, result); }, result);
force_arg(cs, result, op & BC_INST_RET_MASK); force_arg(cs, result, op & BC_INST_RET_MASK);
args.resize(offset); args.resize(offset);

View File

@ -72,10 +72,10 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
auto &cret = args[1].get_ident(cs); auto &cret = args[1].get_ident(cs);
auto &css = args[2].get_ident(cs); auto &css = args[2].get_ident(cs);
if (!cret.is_alias()) { 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()) { 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{}; any_value result{}, tback{};
bool rc = true; bool rc = true;
@ -83,9 +83,9 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
result = args[0].get_code().call(cs); result = args[0].get_code().call(cs);
} catch (error const &e) { } catch (error const &e) {
result.set_string(e.what(), cs); result.set_string(e.what(), cs);
if (e.get_stack().get()) { if (e.stack().get()) {
charbuf buf{cs}; 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); tback.set_string(buf.str(), cs);
} }
rc = false; rc = false;
@ -124,7 +124,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
integer_type val = args[0].get_integer(); integer_type val = args[0].get_integer();
for (size_t i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == value_type::NONE) || (args[i].type() == value_type::NONE) ||
(args[i].get_integer() == val) (args[i].get_integer() == val)
) { ) {
res = args[i + 1].get_code().call(cs); 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(); float_type val = args[0].get_float();
for (size_t i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == value_type::NONE) || (args[i].type() == value_type::NONE) ||
(args[i].get_float() == val) (args[i].get_float() == val)
) { ) {
res = args[i + 1].get_code().call(cs); 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); string_ref val = args[0].get_string(cs);
for (size_t i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == value_type::NONE) || (args[i].type() == value_type::NONE) ||
(args[i].get_string(cs) == val) (args[i].get_string(cs) == val)
) { ) {
res = args[i + 1].get_code().call(cs); 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) { new_cmd_quiet(gcs, "getalias", "s", [](auto &cs, auto args, auto &res) {
auto &id = cs.new_ident(args[0].get_string(cs)); auto &id = cs.new_ident(args[0].get_string(cs));
if (id.get_type() != ident_type::ALIAS) { if (id.type() != ident_type::ALIAS) {
throw error{cs, "'%s' is not an alias", id.get_name().data()}; throw error{cs, "'%s' is not an alias", id.name().data()};
} }
if (ident_p{id}.impl().p_flags & IDENT_FLAG_UNKNOWN) { if (ident_p{id}.impl().p_flags & IDENT_FLAG_UNKNOWN) {
return; return;
} }
res = static_cast<alias &>(id).get_value(cs); res = static_cast<alias &>(id).value(cs);
}); });
} }

View File

@ -106,7 +106,7 @@ int list_includes(
) { ) {
int offset = 0; int offset = 0;
for (list_parser p{cs, list}; p.parse();) { for (list_parser p{cs, list}; p.parse();) {
if (p.get_raw_item() == needle) { if (p.raw_item() == needle) {
return offset; return offset;
} }
++offset; ++offset;
@ -128,11 +128,11 @@ static inline void list_merge(
std::swap(list, elems); std::swap(list, elems);
} }
for (list_parser p{cs, list}; p.parse();) { 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()) { if (!buf.empty()) {
buf.push_back(' '); buf.push_back(' ');
} }
buf.append(p.get_quoted_item()); buf.append(p.quoted_item());
} }
} }
res.set_string(buf.str(), cs); res.set_string(buf.str(), cs);
@ -188,18 +188,18 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
if (offset > 0) { if (offset > 0) {
p.skip_until_item(); p.skip_until_item();
} }
res.set_string(p.get_input(), cs); res.set_string(p.input(), cs);
return; return;
} }
char const *list = p.get_input().data(); char const *list = p.input().data();
if (len > 0 && p.parse()) { if (len > 0 && p.parse()) {
while (--len > 0 && p.parse()); while (--len > 0 && p.parse());
} else { } else {
res.set_string("", cs); res.set_string("", cs);
return; return;
} }
auto quote = p.get_quoted_item(); auto quote = p.quoted_item();
auto *qend = &quote[quote.size()]; auto *qend = &quote[quote.size()];
res.set_string(make_str_view(list, qend), cs); res.set_string(make_str_view(list, qend), cs);
}); });
@ -211,7 +211,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
int n = -1; int n = -1;
for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) { for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) {
++n; ++n;
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (body.call(cs).get_bool()) { if (body.call(cs).get_bool()) {
res.set_integer(integer_type(n)); res.set_integer(integer_type(n));
@ -228,7 +228,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
int n = -1; int n = -1;
for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) { for (list_parser p{cs, args[1].get_string(cs)}; p.parse();) {
++n; ++n;
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (body.call(cs).get_bool()) { if (body.call(cs).get_bool()) {
if (p.parse()) { 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) { new_cmd_quiet(gcs, "listfind=", "i", [](auto &cs, auto args, auto &res) {
list_find<integer_type>( list_find<integer_type>(
cs, args, res, [](list_parser const &p, integer_type val) { 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) { new_cmd_quiet(gcs, "listfind=f", "f", [](auto &cs, auto args, auto &res) {
list_find<float_type>( list_find<float_type>(
cs, args, res, [](list_parser const &p, float_type val) { 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) { new_cmd_quiet(gcs, "listfind=s", "s", [](auto &cs, auto args, auto &res) {
list_find<std::string_view>( list_find<std::string_view>(
cs, args, res, [](list_parser const &p, std::string_view val) { 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) { new_cmd_quiet(gcs, "listassoc=", "i", [](auto &cs, auto args, auto &res) {
list_assoc<integer_type>( list_assoc<integer_type>(
cs, args, res, [](list_parser const &p, integer_type val) { 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) { new_cmd_quiet(gcs, "listassoc=f", "f", [](auto &cs, auto args, auto &res) {
list_assoc<float_type>( list_assoc<float_type>(
cs, args, res, [](list_parser const &p, float_type val) { 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) { new_cmd_quiet(gcs, "listassoc=s", "s", [](auto &cs, auto args, auto &res) {
list_assoc<std::string_view>( list_assoc<std::string_view>(
cs, args, res, [](list_parser const &p, std::string_view val) { 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}; charbuf r{cs};
int n = 0; int n = 0;
for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { 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)); st.set(std::move(idv));
if (body.call(cs).get_bool()) { if (body.call(cs).get_bool()) {
if (r.size()) { if (r.size()) {
r.push_back(' '); r.push_back(' ');
} }
r.append(p.get_quoted_item()); r.append(p.quoted_item());
} }
} }
res.set_string(r.str(), cs); res.set_string(r.str(), cs);
@ -403,7 +403,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
auto body = args[2].get_code(); auto body = args[2].get_code();
int n = 0, r = 0; int n = 0, r = 0;
for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { 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)); st.set(std::move(idv));
if (body.call(cs).get_bool()) { if (body.call(cs).get_bool()) {
r++; r++;
@ -420,11 +420,11 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
size_t len = p.count(); size_t len = p.count();
size_t n = 0; size_t n = 0;
for (p.set_input(s); p.parse(); ++n) { for (p.set_input(s); p.parse(); ++n) {
auto qi = p.get_quoted_item(); auto qi = p.quoted_item();
if (!qi.empty() && (qi.front() == '"')) { 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 { } else {
buf.append(p.get_raw_item()); buf.append(p.raw_item());
} }
if ((n + 1) < len) { if ((n + 1) < len) {
if ((len > 2) || conj.empty()) { if ((len > 2) || conj.empty()) {
@ -472,7 +472,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
break; break;
} }
} }
std::string_view quote = p.get_quoted_item(); std::string_view quote = p.quoted_item();
char const *qend = !quote.empty() ? &quote[quote.size()] : list; char const *qend = !quote.empty() ? &quote[quote.size()] : list;
charbuf buf{cs}; charbuf buf{cs};
if (qend > list) { if (qend > list) {
@ -490,8 +490,8 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
} }
} }
p.skip_until_item(); p.skip_until_item();
if (!p.get_input().empty()) { if (!p.input().empty()) {
switch (p.get_input().front()) { switch (p.input().front()) {
case ')': case ')':
case ']': case ']':
break; break;
@ -499,7 +499,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
if (!buf.empty()) { if (!buf.empty()) {
buf.push_back(' '); buf.push_back(' ');
} }
buf.append(p.get_input()); buf.append(p.input());
break; break;
} }
} }
@ -543,7 +543,7 @@ static void list_sort(
size_t total = 0; size_t total = 0;
for (list_parser p{cs, list}; p.parse();) { 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); items.push_back(item);
total += item.quote.size(); total += item.quote.size();
} }

View File

@ -10,7 +10,7 @@ inline void init_lineedit(cs::state &, std::string_view) {
inline std::optional<std::string> read_line(cs::state &, cs::string_var &pr) { inline std::optional<std::string> read_line(cs::state &, cs::string_var &pr) {
std::string lbuf; std::string lbuf;
char buf[512]; char buf[512];
printf("%s", pr.get_value().data()); printf("%s", pr.value().data());
std::fflush(stdout); std::fflush(stdout);
while (fgets(buf, sizeof(buf), stdin)) { while (fgets(buf, sizeof(buf), stdin)) {
lbuf += static_cast<char const *>(buf); lbuf += static_cast<char const *>(buf);

View File

@ -19,7 +19,7 @@ inline void ln_complete(char const *buf, std::vector<std::string> &lc) {
if (!id->is_command()) { if (!id->is_command()) {
continue; continue;
} }
std::string_view idname = id->get_name(); std::string_view idname = id->name();
if (idname.size() <= cmd.size()) { if (idname.size() <= cmd.size()) {
continue; continue;
} }
@ -35,7 +35,7 @@ inline std::string ln_hint(char const *buf, int &color, int &bold) {
return std::string{}; return std::string{};
} }
std::string args = " ["; std::string args = " [";
fill_cmd_args(args, cmd->get_args()); fill_cmd_args(args, cmd->args());
args += ']'; args += ']';
color = 35; color = 35;
bold = 1; bold = 1;
@ -52,7 +52,7 @@ inline void init_lineedit(cs::state &cs, std::string_view) {
inline std::optional<std::string> read_line(cs::state &, cs::string_var &pr) { inline std::optional<std::string> read_line(cs::state &, cs::string_var &pr) {
std::string line; std::string line;
auto quit = linenoise::Readline(pr.get_value().data(), line); auto quit = linenoise::Readline(pr.value().data(), line);
if (quit) { if (quit) {
/* linenoise traps ctrl-c, detect it and let the user exit */ /* linenoise traps ctrl-c, detect it and let the user exit */
if (errno == EAGAIN) { if (errno == EAGAIN) {

View File

@ -183,8 +183,8 @@ static cs::state *scs = nullptr;
static void do_sigint(int n) { static void do_sigint(int n) {
/* in case another SIGINT happens, terminate normally */ /* in case another SIGINT happens, terminate normally */
signal(n, SIG_DFL); signal(n, SIG_DFL);
scs->set_call_hook([](cs::state &css) { scs->call_hook([](cs::state &css) {
css.set_call_hook(nullptr); css.call_hook(nullptr);
throw cs::error{css, "<execution interrupted>"}; throw cs::error{css, "<execution interrupted>"};
}); });
} }
@ -253,16 +253,16 @@ static bool do_call(cs::state &cs, std::string_view line, bool file = false) {
std::printf( std::printf(
"%s%s\n", !is_lnum ? "stdin: " : "stdin:", e.what().data() "%s%s\n", !is_lnum ? "stdin: " : "stdin:", e.what().data()
); );
if (e.get_stack().get()) { if (e.stack().get()) {
std::string str; 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()); std::printf("%s\n", str.data());
} }
return false; return false;
} }
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
scs = nullptr; 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()); std::printf("%s\n", std::string_view{ret.get_string(cs)}.data());
} }
return false; return false;
@ -320,15 +320,15 @@ int main(int argc, char **argv) {
auto &iv = static_cast<cs::integer_var &>(args[0].get_ident(css)); auto &iv = static_cast<cs::integer_var &>(args[0].get_ident(css));
auto nargs = args[4].get_integer(); auto nargs = args[4].get_integer();
if (nargs <= 1) { if (nargs <= 1) {
auto val = iv.get_value(); auto val = iv.value();
if ((val >= 0) && (val < 0xFFFFFF)) { if ((val >= 0) && (val < 0xFFFFFF)) {
std::printf( std::printf(
"%s = %d (0x%.6X: %d, %d, %d)\n", "%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 (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF
); );
} else { } else {
std::printf("%s = %d\n", iv.get_name().data(), val); std::printf("%s = %d\n", iv.name().data(), val);
} }
return; return;
} }
@ -350,7 +350,7 @@ int main(int argc, char **argv) {
gcs.new_command("//var_changed", "$aa", [](auto &css, auto args, auto &) { gcs.new_command("//var_changed", "$aa", [](auto &css, auto args, auto &) {
std::printf( std::printf(
"changed var trigger: %s (was: '%s', now: '%s')\n", "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[1].get_string(css).data(),
args[2].get_string(css).data() args[2].get_string(css).data()
); );