remove the call() specializations per-vartype
parent
6a892b4b2c
commit
fa5e38afad
|
@ -220,9 +220,6 @@ struct LIBCUBESCRIPT_EXPORT integer_var: builtin_var {
|
||||||
state &cs, integer_type val, bool do_write = true, bool trigger = true
|
state &cs, integer_type val, bool do_write = true, bool trigger = true
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @brief Call override for integer vars. */
|
|
||||||
any_value call(span_type<any_value> args, state &cs);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
integer_var() = default;
|
integer_var() = default;
|
||||||
};
|
};
|
||||||
|
@ -247,9 +244,6 @@ struct LIBCUBESCRIPT_EXPORT float_var: builtin_var {
|
||||||
state &cs, float_type val, bool do_write = true, bool trigger = true
|
state &cs, float_type val, bool do_write = true, bool trigger = true
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @brief Call override for float vars. */
|
|
||||||
any_value call(span_type<any_value> args, state &cs);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float_var() = default;
|
float_var() = default;
|
||||||
};
|
};
|
||||||
|
@ -274,9 +268,6 @@ struct LIBCUBESCRIPT_EXPORT string_var: builtin_var {
|
||||||
state &cs, string_ref val, bool do_write = true, bool trigger = true
|
state &cs, string_ref val, bool do_write = true, bool trigger = true
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @brief Call override for string vars. */
|
|
||||||
any_value call(span_type<any_value> args, state &cs);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string_var() = default;
|
string_var() = default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -277,7 +277,36 @@ LIBCUBESCRIPT_EXPORT void builtin_var::save(state &cs) {
|
||||||
LIBCUBESCRIPT_EXPORT any_value builtin_var::call(
|
LIBCUBESCRIPT_EXPORT any_value builtin_var::call(
|
||||||
span_type<any_value> args, state &cs
|
span_type<any_value> args, state &cs
|
||||||
) {
|
) {
|
||||||
return ident::call(args, cs);
|
command *hid;
|
||||||
|
switch (static_cast<var_impl *>(p_impl)->p_storage.type()) {
|
||||||
|
case value_type::INTEGER:
|
||||||
|
hid = state_p{cs}.ts().istate->cmd_ivar;
|
||||||
|
break;
|
||||||
|
case value_type::FLOAT:
|
||||||
|
hid = state_p{cs}.ts().istate->cmd_fvar;
|
||||||
|
break;
|
||||||
|
case value_type::STRING:
|
||||||
|
hid = state_p{cs}.ts().istate->cmd_svar;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort(); /* unreachable unless we have a bug */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
any_value ret{};
|
||||||
|
auto &ts = state_p{cs}.ts();
|
||||||
|
auto *cimp = static_cast<command_impl *>(hid);
|
||||||
|
auto &targs = ts.vmstack;
|
||||||
|
auto osz = targs.size();
|
||||||
|
auto anargs = std::size_t(cimp->arg_count());
|
||||||
|
auto nargs = args.size();
|
||||||
|
targs.resize(
|
||||||
|
osz + std::max(args.size(), anargs + 1)
|
||||||
|
);
|
||||||
|
for (std::size_t i = 0; i < nargs; ++i) {
|
||||||
|
targs[osz + i + 1] = args[i];
|
||||||
|
}
|
||||||
|
exec_command(ts, cimp, this, &targs[osz], ret, nargs + 1, false);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT any_value builtin_var::value() const {
|
LIBCUBESCRIPT_EXPORT any_value builtin_var::value() const {
|
||||||
|
@ -325,32 +354,6 @@ LIBCUBESCRIPT_EXPORT void integer_var::set_value(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline any_value call_var(
|
|
||||||
ident &id, command *hid, span_type<any_value> &args, state &cs
|
|
||||||
) {
|
|
||||||
any_value ret{};
|
|
||||||
auto &ts = state_p{cs}.ts();
|
|
||||||
auto *cimp = static_cast<command_impl *>(hid);
|
|
||||||
auto &targs = ts.vmstack;
|
|
||||||
auto osz = targs.size();
|
|
||||||
auto anargs = std::size_t(cimp->arg_count());
|
|
||||||
auto nargs = args.size();
|
|
||||||
targs.resize(
|
|
||||||
osz + std::max(args.size(), anargs + 1)
|
|
||||||
);
|
|
||||||
for (std::size_t i = 0; i < nargs; ++i) {
|
|
||||||
targs[osz + i + 1] = args[i];
|
|
||||||
}
|
|
||||||
exec_command(ts, cimp, &id, &targs[osz], ret, nargs + 1, false);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT any_value integer_var::call(
|
|
||||||
span_type<any_value> args, state &cs
|
|
||||||
) {
|
|
||||||
return call_var(*this, state_p{cs}.ts().istate->cmd_ivar, args, cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT void float_var::set_value(
|
LIBCUBESCRIPT_EXPORT void float_var::set_value(
|
||||||
state &cs, float_type val, bool do_write, bool trigger
|
state &cs, float_type val, bool do_write, bool trigger
|
||||||
) {
|
) {
|
||||||
|
@ -372,12 +375,6 @@ LIBCUBESCRIPT_EXPORT void float_var::set_value(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT any_value float_var::call(
|
|
||||||
span_type<any_value> args, state &cs
|
|
||||||
) {
|
|
||||||
return call_var(*this, state_p{cs}.ts().istate->cmd_fvar, args, cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT void string_var::set_value(
|
LIBCUBESCRIPT_EXPORT void string_var::set_value(
|
||||||
state &cs, string_ref val, bool do_write, bool trigger
|
state &cs, string_ref val, bool do_write, bool trigger
|
||||||
) {
|
) {
|
||||||
|
@ -399,12 +396,6 @@ LIBCUBESCRIPT_EXPORT void string_var::set_value(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT any_value string_var::call(
|
|
||||||
span_type<any_value> args, state &cs
|
|
||||||
) {
|
|
||||||
return call_var(*this, state_p{cs}.ts().istate->cmd_svar, args, cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT any_value alias::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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue