Background and Concepts
WebAssembly is a simple machine model and executable format with an extensive specification.
As a programming language, WebAssembly is comprised of two formats: The binary format and the text format.
Both represent a common structure, albeit in different ways. The text format (generally called
S-expressions, which bears some resemblance to languages like Clojure or Racket.
The binary format
wasm is a lower level format, being itself the assembly code which is run by the interpreters.
For reference, here is a factorial function in
(module (func $fac (param f64) (result f64) get_local 0 f64.const 1 f64.lt if (result f64) f64.const 1 else get_local 0 get_local 0 f64.const 1 f64.sub call $fac f64.mul end) (export "fac" (func $fac)))
If you're curious about how a
wasm file looks like you can use wat2wasm demo with the above code.
WebAssembly has a very simple memory model. At the moment, a wasm module has access to a single "linear memory", which is essentially a flat array of a fixed numeric type. This memory can be grown by a multiple of the page size (64K), and cannot be shrunk.