From 7c0b77605ed094e578eb933507359ae3c2ad2319 Mon Sep 17 00:00:00 2001 From: Sean Parent Date: Wed, 8 Jan 2025 14:04:40 -0800 Subject: [PATCH] Cleanup and docs. --- adobe/virtual_machine.hpp | 16 ++++++++++++++-- source/virtual_machine.cpp | 25 ------------------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/adobe/virtual_machine.hpp b/adobe/virtual_machine.hpp index c25ba51c..84961679 100644 --- a/adobe/virtual_machine.hpp +++ b/adobe/virtual_machine.hpp @@ -32,7 +32,8 @@ namespace adobe { /**************************************************************************************************/ -// todo: temporary hack to get around std::function not being comparable +/// Any function of the form `any_regular_t(const any_regular_t&)`. All function_t objects compare +/// equal so they can be placed in an `any_regular_t` object. class function_t : public std::function { public: using base_t = std::function; @@ -58,10 +59,12 @@ class function_t : public std::function { /**************************************************************************************************/ +/// Returns a simple name for the core types used by the virtual machine. const char* type_name(const std::type_info& type); /**************************************************************************************************/ +/// Does a runtime cast on an any_regular_t with better error reporting. template auto cast(adobe::any_regular_t& x) -> decltype(x.cast()) { if constexpr (!std::is_same_v) { @@ -72,6 +75,7 @@ auto cast(adobe::any_regular_t& x) -> decltype(x.cast()) { return x.cast(); } +/// Does a runtime cast on an any_regular_t with better error reporting. template auto cast(const adobe::any_regular_t& x) -> decltype(x.cast()) { if constexpr (!std::is_same_v) { @@ -84,6 +88,12 @@ auto cast(const adobe::any_regular_t& x) -> decltype(x.cast()) { /**************************************************************************************************/ +namespace detail { + +/// Provide an invoke function for an invocable F with a signature Sig, that will extract the +/// arguments from an array_t. An exception will be thrown if the number of items in the array +/// does not match the number of arguments in the signature, or if any of the argument types do +/// not match the corresponding array_t item type. template struct function_packager; @@ -103,13 +113,15 @@ struct function_packager { } }; +} // namespace detail + /**************************************************************************************************/ /// Create a function_t from an invocable object. template any_regular_t make_function(F&& f) { return function_t{[f = std::forward(f)](const any_regular_t& args) { - return function_packager::invoke(f, args.cast()); + return detail::function_packager::invoke(f, args.cast()); }}; } diff --git a/source/virtual_machine.cpp b/source/virtual_machine.cpp index d8bc08be..eb8010d8 100644 --- a/source/virtual_machine.cpp +++ b/source/virtual_machine.cpp @@ -399,20 +399,12 @@ class virtual_machine_t::implementation_t { static operator_table_t* operator_table_g; static variable_table_t* variable_table_g; -#if 0 - static array_function_table_t* array_function_table_g; - static dictionary_function_table_t* dictionary_function_table_g; -#endif }; /**************************************************************************************************/ operator_table_t* virtual_machine_t::implementation_t::operator_table_g; variable_table_t* virtual_machine_t::implementation_t::variable_table_g; -#if 0 -array_function_table_t* virtual_machine_t::implementation_t::array_function_table_g; -dictionary_function_table_t* virtual_machine_t::implementation_t::dictionary_function_table_g; -#endif /**************************************************************************************************/ @@ -832,23 +824,6 @@ void virtual_machine_t::push_scope(variable_scope_t&& scope) { /**************************************************************************************************/ -#if 0 -void virtual_machine_t::set_array_function_lookup(const array_function_lookup_t& function) { - object_m->array_function_lookup_m = function; -} -#endif - -/**************************************************************************************************/ - -#if 0 -void virtual_machine_t::set_dictionary_function_lookup( - const dictionary_function_lookup_t& function) { - object_m->dictionary_function_lookup_m = function; -} -#endif - -/**************************************************************************************************/ - void virtual_machine_t::set_named_index_lookup(const named_index_lookup_t& function) { object_m->named_index_lookup_m = function; }