Code Self Study Forum

How many people here are interested in WebAssembly? [POLL]

Please vote:

  • I’m interested in learning WebAssembly.
  • I’m not interested in learning WebAssembly.
  • What is WebAssembly?

0 voters

I’ve been to a couple of wasm meetups recently and have a suspicion that it’s about to fundamentally change web development.

For anyone who hasn’t heard of it yet, see here and here.

To learn more, see these threads:

Is anyone interested in working through Programming WebAssembly with Rust during the Wednesday meetups?

The subtitle is “Unified Development for Web, Mobile, and Embedded Applications”.

I read 50 pages already and it’s pretty interesting. So far it’s covering how to write a checkers game in the lower-level WebAssembly Text format, which looks like this:

  (func $getPiece (param $x i32) (param $y i32) (result i32)
        (if (result i32)
          (block (result i32)
                 (i32.and
                   (call $inRange
                         (i32.const 0)
                         (i32.const 7)
                         (get_local $x))
                   (call $inRange
                         (i32.const 0)
                         (i32.const 7)
                         (get_local $y))))
          (then
            (i32.load
              (call $offsetForPosition
                    (get_local $x)
                    (get_local $y))))
          (else
            (unreachable))))

It looks like the next section rewrites the checkers game in Rust. Then there is a Rouge-like game and maybe some robotics.

I’ve never done low-level programming before, and it’s very interesting. :thinking:

1 Like

So, is that code WebAssembly or something sort of above WebAssembly?

My only experience with any sort of low-level programming is the nand2tetris stuff, and your code example reminds me a little bit of their virtual machine language, which sits in between their assembly and their high level language (so, a stepping stone for the compiler, if that makes sense).

I should go back to nand2tetris soon.

According to this, “the textual format for WebAssembly modules is a rendering of their abstract syntax into S-expressions.”

You can write a C or C++ function in WasmExplorer and compile it to see an example.

This function:

int add(int a, int b) {
    return a + b;
}

will compile to:

(module
 (table 0 anyfunc)
 (memory $0 1)
 (export "memory" (memory $0))
 (export "_Z3addii" (func $_Z3addii))
 (func $_Z3addii (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
  (i32.add
   (get_local $1)
   (get_local $0)
  )
 )
)

and then clicking “download” will get you a binary .wasm file that can run in the browser.

If you have the WebAssembly Binary Toolkit installed, you can convert back and forth between wat and wasm formats. You can write raw WebAssembly Text, but I think WebAssembly is meant to be written in Rust/C/C++ or other languages.

Edit: here’s a page that explains it:

1 Like

Oh, OK. Thanks for the links. So WebAssembly text format does look quite a bit like the stack-based virtual machine language from nand2tetris . I guess from the name, I assumed .wasm files were in some sort of assembly, but evidently they are in binary?

These low level languages are interesting to learn a bit about, at least for me to have some idea what might be going on underneath the surface when I create something in a higher language. I’ve recently learned that Julia has two commands that reveal the generated LLVM code and x86 assembly for any Julia function (even user defined ones).

And I guess WebAssembly is yet another place I could put some C to use, and so yet another reason to (re)learn that.

1 Like

I got the ebook below when it was on sale for $5 – it covers WebAssembly with C and C++ (also Vue.js and d3.js). I didn’t read it yet, but it looks interesting. I’m going to read the other Rust/Wasm book first.

1 Like

If anyone is interested in the Programming WebAssembly with Rust ebook, it’s on sale until April 3 for $15 if you use the discount code aintnofool2019. I think the coupon code will work with any of their new releases.

1 Like

Here is a giveaway for a free book on Fullstack Rust that includes WebAsssembly: Book Giveaway: Fullstack Rust – just click the poll in that post to enter the random drawing.