In the Browser-based Hello World example, we call a Wasm module called
as-echo that does nothing more than receive a text string as an argument, and echo it back via standard out.
The real issue here centers on transferring 64-bit integers between the two runtime environments.
i64 in WebAssembly and
As a temporary fix, this data transfer issue is solved by the
Normally, you would discover what data types a native "OS" function interface uses by looking at the well-written interface documentation for the WebAssembly module.
Ok, back in reality...
In order to understand whether or not this module needs transformation, we need to take a look inside the WebAssembly module.
When converted to WebAssembly Text format, the first few lines look like this:
(module(type $t0 (func (param i32 i64 i32) (result i32)))(type $t1 (func (param i32 i32 i32 i32) (result i32)))(type $t2 (func))(import "wasi_unstable" "clock_time_get" (func $wasi_unstable.clock_time_get (type $t0)))(import "wasi_unstable" "fd_write" (func $wasi_unstable.fd_write (type $t1)));; snip...)
On line 2, we can see the declaration of a type definition called
$t0. This type definition represents the interface to some
function that takes three, signed integers as parameters and returns a signed integer.
(type $t0 (func (param i32 i64 i32) (result i32)))
Notice the data type of the second parameter. Uh oh! Its an
i64; that is, a 64-bit, signed integer!
So now we know that somewhere in this WebAssembly module, there is a call to function that uses this interface declaration.
Next, look a little further down to line 5. Here we can see an
(import "wasi_unstable" "clock_time_get" (func $wasi_unstable.clock_time_get (type $t0)))
import statement tells us several things:
This Wasm module needs to call an external function.
In this particular case, this is a native "OS" function accessible through WASI
The native "OS" function is called
clock_time_get and lives in an external library called
Within our WebAssembly module, this external function will be referred to using the alias
The interface to this function is described by the type declaration
We know from the definition of
$t0 (on line 2) that this function must be passed an
i64 as its second parameter; therefore, we can be certain that before this Wasm module can call function
clock_time_get (using the Wasmer-js polyfill), the interface must first be transformed.