From 5247de7d1b87c5f3b539d23cfee8f69f26b852f9 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 11 Mar 2016 10:21:39 -0700 Subject: [PATCH] use a global void value for returning unknown values --- .../chaiscript/dispatchkit/boxed_value.hpp | 5 ++++ .../chaiscript/dispatchkit/handle_return.hpp | 2 +- .../chaiscript/language/chaiscript_eval.hpp | 24 +++++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 70bfe12..7388c13 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -411,6 +411,11 @@ namespace chaiscript return detail::const_var_impl(t); } + inline Boxed_Value void_var() { + static const auto v = Boxed_Value(Boxed_Value::Void_Type()); + return v; + } + inline Boxed_Value const_var(bool b) { static const auto t = detail::const_var_impl(true); static const auto f = detail::const_var_impl(false); diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 2650e3b..17c6d4e 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -268,7 +268,7 @@ namespace chaiscript { static Boxed_Value handle() { - return Boxed_Value(Boxed_Value::Void_Type()); + return void_var(); } }; } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index efbcc99..d7bc7e0 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -752,7 +752,7 @@ namespace chaiscript } catch (const exception::name_conflict_error &e) { throw exception::eval_error("Function redefined '" + e.name() + "'"); } - return Boxed_Value(); + return void_var(); } }; @@ -778,7 +778,7 @@ namespace chaiscript // loop was broken intentionally } - return Boxed_Value(); + return void_var(); } }; @@ -795,7 +795,7 @@ namespace chaiscript children[1]->eval(t_ss); - return Boxed_Value(); + return void_var(); } }; @@ -839,7 +839,7 @@ namespace chaiscript } } - return Boxed_Value(); + return void_var(); } }; @@ -871,7 +871,7 @@ namespace chaiscript // loop broken } - return Boxed_Value(); + return void_var(); } }; @@ -913,7 +913,7 @@ namespace chaiscript } ++currentCase; } - return Boxed_Value(); + return void_var(); } mutable std::atomic_uint_fast32_t m_loc; @@ -929,7 +929,7 @@ namespace chaiscript children[1]->eval(t_ss); - return Boxed_Value(); + return void_var(); } }; @@ -943,7 +943,7 @@ namespace chaiscript children[0]->eval(t_ss); - return Boxed_Value(); + return void_var(); } }; @@ -1019,7 +1019,7 @@ namespace chaiscript throw detail::Return_Value(children[0]->eval(t_ss)); } else { - throw detail::Return_Value(Boxed_Value()); + throw detail::Return_Value(void_var()); } } }; @@ -1038,7 +1038,7 @@ namespace chaiscript } return children.back()->eval(t_ss); } else { - return Boxed_Value(); + return void_var(); } } catch (const detail::Continue_Loop &) { throw exception::eval_error("Unexpected `continue` statement outside of a loop"); @@ -1362,7 +1362,7 @@ namespace chaiscript } catch (const exception::name_conflict_error &e) { throw exception::eval_error("Method redefined '" + e.name() + "'"); } - return Boxed_Value(); + return void_var(); } }; @@ -1397,7 +1397,7 @@ namespace chaiscript } catch (const exception::name_conflict_error &e) { throw exception::eval_error("Attribute redefined '" + e.name() + "'"); } - return Boxed_Value(); + return void_var(); } };