Bug fix from Function_Params refactor

This commit is contained in:
Jason Turner 2017-11-19 06:20:27 -07:00
parent 92ae85c3e8
commit c6021f3e61
3 changed files with 17 additions and 7 deletions

View File

@ -84,7 +84,7 @@ namespace chaiscript {
// construct/copy/destruct
constexpr Any() noexcept = default;
Any(Any &&) noexcept = default;
Any &operator=(Any &&t_any) noexcept = default;
Any &operator=(Any &&t_any) = default;
Any(const Any &t_any)
: m_data(t_any.empty() ? nullptr : t_any.m_data->clone())
@ -93,7 +93,7 @@ namespace chaiscript {
template<typename ValueType,
typename = std::enable_if_t<!std::is_same_v<Any, std::decay_t<ValueType>>>>
explicit Any(ValueType &&t_value) noexcept(is_nothrow_forward_constructible_v<decltype(t_value), std::decay_t<ValueType>>)
explicit Any(ValueType &&t_value)
: m_data(std::make_unique<Data_Impl<std::decay_t<ValueType>>>(std::forward<ValueType>(t_value)))
{
}

View File

@ -1053,7 +1053,7 @@ namespace chaiscript
tmp_params.insert(tmp_params.begin() + 1, var(t_name));
return do_attribute_call(2, Function_Params(tmp_params), functions, t_conversions);
} else {
std::array<Boxed_Value, 3> p{params[0], var(t_name), var(std::vector<Boxed_Value>(params.begin()+1, params.end()))};
std::array p{params[0], var(t_name), var(std::vector<Boxed_Value>(params.begin()+1, params.end()))};
return dispatch::dispatch(functions, Function_Params{p}, t_conversions);
}
} catch (const dispatch::option_explicit_set &e) {
@ -1077,7 +1077,7 @@ namespace chaiscript
Boxed_Value call_function(const std::string_view &t_name, std::atomic_uint_fast32_t &t_loc, Function_Params params,
Boxed_Value call_function(const std::string_view &t_name, std::atomic_uint_fast32_t &t_loc, const Function_Params &params,
const Type_Conversions_State &t_conversions) const
{
uint_fast32_t loc = t_loc;

View File

@ -428,10 +428,20 @@ namespace chaiscript
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
std::array params{this->children[0]->eval(t_ss), this->children[1]->eval(t_ss)};
auto params = [&](){
// The RHS *must* be evaluated before the LHS
// consider `var range = range(x)`
// if we declare the variable in scope first, then the name lookup fails
// for the RHS
auto rhs = this->children[1]->eval(t_ss);
auto lhs = this->children[0]->eval(t_ss);
std::array p{std::move(lhs), std::move(rhs)};
return p;
}();
if (m_oper != Operators::Opers::invalid && params[0].get_type_info().is_arithmetic() &&
params[0].get_type_info().is_arithmetic())
params[1].get_type_info().is_arithmetic())
{
try {
return Boxed_Number::do_oper(m_oper, params[0], params[1]);
@ -452,7 +462,7 @@ namespace chaiscript
&& this->children[0]->children[0]->identifier == AST_Node_Type::Reference)
)
)
{
/// \todo This does not handle the case of an unassigned reference variable
/// being assigned outside of its declaration