With C++ enum classes, the size of an enum object can vary depending
on the compiler generation mechanism (choosing the most optimal storage size
to contain all the variants) or a user-defined storage type. In wasm we
can only send int32_t and int64_t. That means, the enums using this
integer width for storage must also work properly. At runtime this works
flawlessly, the functions in wasm can return these values safely and
they are even converted back on the C++ side to their enum
representations, thanks to the code in wasm3 which does a cast an
integer cast. But when it comes to generating the code for function
arguments, the defined data structure is not enough to generalize the
code to allow enum classes even if they are of a proper (allowed) width.
This commit changes the defined data structure to create a data
structure literal for wasm so that it allows enum classes as well as
already defined data types.
Previously moodule::link used the function pointer as a template
argument, because the function linked through m3_LinkRawFunctionEx
didn't receive any context pointer, so each linked function needed
a unique wrapper.
With the introduction of m3_LinkRawFunctionEx, it is possible to move
the function pointer to a regular argument.
This reduces code size when linking many functions with the same
signature.
This also makes it possible to later support arbitrary callable
objects instead of function pointers, using the same API.
Co-authored-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com>
* cpp: env.parse_module: ensure the file is opened without skipws
Closes https://github.com/wasm3/wasm3/issues/124
* cpp: demonstrate loading a module from file
* cpp: remove leftover note about function::call doing string conversion
* cpp: add missing return value checks for m3_GetResults
* cpp: use m3ApiGetArg, m3ApiReturn, m3_GetResults for stack access
Still relies on an internal m3_api_defs.h, but at least less likely
to get broken, and doesn't depend on M3Runtime internals.
* cpp: use m3_Call in function::call, getting rid of string conversions
When function::call was first written, m3_Call did not exist yet, and
the only way to call functions was through m3_CallArgv which takes
arguments as strings. Now that m3_Call is available, string conversion
can be removed.
Closes https://github.com/wasm3/wasm3/issues/219