diff options
author | Chad Austin <caustin@gmail.com> | 2014-04-12 21:06:54 -0700 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2014-04-13 09:24:08 -0700 |
commit | 521216f211165e962664f49be3890e2fc22d8efd (patch) | |
tree | 74a00a3948b9e3fd7f71fb9191d765687c51130f /system | |
parent | 50bcf89f21c098aa54033733b33cb66c6c56d7ce (diff) |
checkpoint asm.js-style function lookup by signature string
Diffstat (limited to 'system')
-rw-r--r-- | system/include/emscripten/bind.h | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 872f279b..8a8b7d69 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -20,6 +20,8 @@ namespace emscripten { namespace internal { typedef long GenericEnumValue; + typedef void (*GenericFunction)(); + // Implemented in JavaScript. Don't call these directly. extern "C" { void _embind_fatal_error( @@ -70,6 +72,7 @@ namespace emscripten { const char* name, unsigned argCount, TYPEID argTypes[], + const char* signature, GenericFunction invoker, GenericFunction function); @@ -291,6 +294,63 @@ namespace emscripten { } //////////////////////////////////////////////////////////////////////////////// + // SignatureCode, SignatureString + //////////////////////////////////////////////////////////////////////////////// + + namespace internal { + template<typename T> + struct SignatureCode { + static constexpr char get() { + return 'i'; + } + }; + + template<> + struct SignatureCode<void> { + static constexpr char get() { + return 'v'; + } + }; + + template<> + struct SignatureCode<float> { + static constexpr char get() { + return 'd'; + } + }; + + template<> + struct SignatureCode<double> { + static constexpr char get() { + return 'd'; + } + }; + + template<typename... T> + struct SignatureString; + + template<> + struct SignatureString<> { + char c = 0; + }; + + template<typename First, typename... Rest> + struct SignatureString<First, Rest...> { + constexpr SignatureString() + : c(SignatureCode<First>::get()) + {} + char c; + SignatureString<Rest...> rest; + }; + + template<typename Return, typename... Args> + const char* getSignature(Return (*)(Args...)) { + static constexpr SignatureString<Return, Args...> sig; + return &sig.c; + } + } + + //////////////////////////////////////////////////////////////////////////////// // FUNCTIONS //////////////////////////////////////////////////////////////////////////////// @@ -302,11 +362,13 @@ namespace emscripten { void function(const char* name, ReturnType (*fn)(Args...), Policies...) { using namespace internal; typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; + auto invoker = &Invoker<ReturnType, Args...>::invoke; _embind_register_function( name, args.count, args.types, - reinterpret_cast<GenericFunction>(&Invoker<ReturnType, Args...>::invoke), + getSignature(invoker), + reinterpret_cast<GenericFunction>(invoker), reinterpret_cast<GenericFunction>(fn)); } |