C code to Wat

The upper-left pane in the following screenshot contains a simple C function that adds 2 to the number specified as a parameter. The lower-left pane contains the corresponding Wat:

C function and the corresponding Wat

If this looks familiar, it's because this same code was used for the explanation of Wat's s-expressions in the beginning of this chapter. Digging a little deeper, you can see how the C code corresponds to the Wat output. The addTwo() function is exported from the module as a string on line 5. Line 5 also contains (func $addTwo), which references the $addTwo function on line 6. Line 6 specifies that a single parameter of type i32 (an integer) can be passed in and the result returned is also an i32. Pressing the Build button in the upper-right corner (or above the C/C++ editor) will compile the C code into a Wasm file. The Wasm will be available for download or interaction with JavaScript once the build is completed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset