From 2e769d81cf90ce648521146f69bb7fd2c77b3c0d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 10 Apr 2015 09:32:01 -0600 Subject: [PATCH] Get return_value_handling fully working --- include/chaiscript/dispatchkit/boxed_number.hpp | 6 +++--- include/chaiscript/dispatchkit/dispatchkit.hpp | 7 ++++++- include/chaiscript/language/chaiscript_eval.hpp | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 0042751..1d164e3 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -232,9 +232,9 @@ namespace chaiscript if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { return boolean::go(t_oper, *static_cast(t_lhs.get_const_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); - } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const()) { + } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { return binary::go(t_oper, *static_cast(t_lhs.get_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); - } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag && !t_lhs.is_const()) { + } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { return binary_int::go(t_oper, *static_cast(t_lhs.get_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); } else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) { return const_binary_int::go(t_oper, *static_cast(t_lhs.get_const_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); @@ -254,7 +254,7 @@ namespace chaiscript if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { return boolean::go(t_oper, *static_cast(t_lhs.get_const_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); - } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const()) { + } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { return binary::go(t_oper, *static_cast(t_lhs.get_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag) { throw chaiscript::detail::exception::bad_any_cast(); diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 46155ca..cb80acf 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -795,7 +795,12 @@ namespace chaiscript Boxed_Value call_function(const std::string &t_name, const std::vector ¶ms) const { - return dispatch::dispatch(get_function(t_name), params, m_conversions); + Boxed_Value bv = dispatch::dispatch(get_function(t_name), params, m_conversions); + // the result of a clone is never to be marked as a return_value + if (t_name == "clone") { + bv.reset_return_value(); + } + return bv; } Boxed_Value call_function(const std::string &t_name) const diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index b7eb0a6..59e09ba 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -558,6 +558,10 @@ namespace chaiscript throw exception::eval_error("Error with unsupported arithmetic assignment operation"); } } else if (m_oper == Operators::assign) { + if (lhs.is_return_value()) { + throw exception::eval_error("Error, cannot assign to temporary value."); + } + try { if (lhs.is_undef()) { if (!this->children.empty() && @@ -567,14 +571,14 @@ namespace chaiscript /// \todo This does not handle the case of an unassigned reference variable /// being assigned outside of its declaration lhs.assign(rhs); + lhs.reset_return_value(); return rhs; } else { if (!rhs.is_return_value()) { rhs = t_ss.call_function("clone", rhs); - } else { - rhs.reset_return_value(); } + rhs.reset_return_value(); } }