From 2122cb628d12da97c3e2214a1466bce7d2ccd71a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 28 Apr 2020 20:50:55 +0200 Subject: [PATCH] Change variables() into a free function. --- src/wren/vm.hpp | 57 ++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/wren/vm.hpp b/src/wren/vm.hpp index cde1b46..2cb6594 100644 --- a/src/wren/vm.hpp +++ b/src/wren/vm.hpp @@ -61,15 +61,7 @@ namespace wren { void interpret (const char* module_name, const char* script); void interpret (const std::string& module_name, const std::string& script); void release (Handle& handle) noexcept; - template T slot (int slot_num); -#if __cpp_concepts >= 201907 - template -#else - template -#endif - std::tuple variables(Params&&... modules_names); - void ensure_slots(int num_slots); void variable(const char* module, const char* name, int slot); void variable(const ModuleAndName& mod_and_name, int slot); @@ -118,6 +110,29 @@ namespace wren { return (*M)(args...); } }; + +#if __cpp_concepts >= 201907 + template +#else + template +#endif + inline std::tuple variables_impl ( + VM& vm, + std::integer_sequence, + Params&&... modules_names + ) { + if constexpr (sizeof...(Outs) == 0) { + return {}; + } + else { + static_assert(sizeof...(Params) == sizeof...(Outs), "Expected a module/name pair per requested output"); + static_assert(sizeof...(Outs) == sizeof...(Indices), "Mismatching index count"); + + vm.ensure_slots(sizeof...(Outs)); + (vm.variable(modules_names, Indices), ...); + return std::tuple(vm.slot(Indices)...); + } + } } //namespace detail template @@ -165,29 +180,7 @@ namespace wren { #else template #endif - std::tuple VM::variables(Params&&... modules_names) { - return variables_impl(std::make_integer_sequence(), std::forward(modules_names)...); - } - -#if __cpp_concepts >= 201907 - template -#else - template -#endif - inline std::tuple VM::variables_impl ( - std::integer_sequence, - Params&&... modules_names - ) { - if constexpr (sizeof...(Outs) == 0) { - return {}; - } - else { - static_assert(sizeof...(Params) == sizeof...(Outs), "Expected a module/name pair per requested output"); - static_assert(sizeof...(Outs) == sizeof...(Indices), "Mismatching index count"); - - ensure_slots(sizeof...(Outs)); - (this->variable(modules_names, Indices), ...); - return std::tuple(this->slot(Indices)...); - } + std::tuple variables(VM& vm, Params&&... modules_names) { + return detail::variables_impl(vm, std::make_integer_sequence(), std::forward(modules_names)...); } } //namespace wren