Thank you for your detailed reply. I’m new to wasmex, please bear with these trivial questions.
Can you verify if the following statements are correct:
wasmex allows wasm32 code to call arbitrary Elixir functions
imports = %{
env: %{
sum3: {:fn, [:i32, :i32, :i32], [:i32], fn (_context, a, b, c) -> a + b + c end},
}
}
instance = start_supervised!({Wasmex, %{bytes: @import_test_bytes, imports: imports}})
{:ok, [6]} = Wasmex.call_function(instance, "use_the_imported_sum_fn", [1, 2, 3])
What is happening above is:
(1) we define a function in elixir (a + b + c)
(2) we can pass this fuhction to the wasm32 env
(3) when wasm32 invokes this function, the corresponding elixir code gets called
wasmex allows Elixir to read/write to wasm32 linear memory directly
{:ok, memory} = Wasmex.memory(instance, :uint8, 0)
index = 42
string = "hello, world"
Wasmex.Memory.write_binary(memory, index, string)
Here we are writing directly into the wasm32 memory, at index 42.
can we do dynamic code generation using wasmex ?
Ignoring Rust for a moment, and thinking in pure Elixir.
If I have an Elixir module that generates *.wast (the s-exp text format, not the binary format) code, can I load it in wasmex and execute it? The opens another route for doing dynamic code gen in Elixir, where for specialized routines, we can generate *.wast, copy the data into the linear memory, execute, and copy back. Is this possible?