mdn / webassembly-examples

Code examples that accompany the MDN WebAssembly documentation — see https://developer.mozilla.org/en-US/docs/WebAssembly.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Which format is relevant?

turhn opened this issue · comments

When I check the examples, the simple add function looks like below:

(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    get_local $lhs
    get_local $rhs
    i32.add)
  (export "add" (func $add))
)

But other examples use the format below:

(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    (i32.add
      (get_local $lhs)
      (get_local $rhs))
  (export "add" (func $add))
)

For instance: https://cdn.rawgit.com/WebAssembly/sexpr-wasm-prototype/2bb13aa785be9908b95d0e2e09950b39a26004fa/demo/index.html

Both are valid syntax, the latter uses the Folded Instructions syntactic sugar. But maybe your point is that perhaps we should regularly use the sugar or not?

In fact, that was a question, and I got my answer. Thank you.

I didn't know it was also a valid syntax. The link I shared does not accept the syntactic sugar. That is why I got confused and thought that format with folded instruction might be deprecated.

Ah great. Yes, I think sexpr-wasm-prototype is pretty out of date. I'd use wabt or binaryen instead.