Difference between revisions of "WebAssembly"

From Free Pascal wiki
Jump to navigationJump to search
(→‎WebAssembly: Add brief explanation of WebAssembly)
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
== WebAssembly ==
 +
 +
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications. For more information on WebAssembly, see the [https://webassembly.org WebAssembly] website.
 +
 
==Assemblers==
 
==Assemblers==
 +
 
There are different assemblers available, from Wabt and emscripten.org.  
 
There are different assemblers available, from Wabt and emscripten.org.  
 
The expected format is a slightly different between those two:
 
The expected format is a slightly different between those two:
Line 5: Line 10:
 
===wat2wasm (Wabt)===
 
===wat2wasm (Wabt)===
 
Example:
 
Example:
 +
<source lang="lisp">
 
  (module
 
  (module
 
   (func $add (param $lhs i32) (param $rhs i32) (result i32)
 
   (func $add (param $lhs i32) (param $rhs i32) (result i32)
Line 13: Line 19:
 
   (export "add" (func $add))
 
   (export "add" (func $add))
 
  )
 
  )
 +
</source>
 
According to the official site "Wabt" is using it's own format of the Wasm.
 
According to the official site "Wabt" is using it's own format of the Wasm.
 
It's slightly different from the official documentation. The most current version of Wabt matches the specs, as well as supports the old syntax.
 
It's slightly different from the official documentation. The most current version of Wabt matches the specs, as well as supports the old syntax.
Line 25: Line 32:
 
===wasm-as (emscripten)===
 
===wasm-as (emscripten)===
 
The assembler is recommended for the use in a compiler by the WebAssembly.org
 
The assembler is recommended for the use in a compiler by the WebAssembly.org
 +
<source lang="lisp">
 
  (module
 
  (module
 
   (func $add (param $lhs i32) (param $rhs i32) (result i32)
 
   (func $add (param $lhs i32) (param $rhs i32) (result i32)
Line 35: Line 43:
 
   (export "add" (func $add))
 
   (export "add" (func $add))
 
  )
 
  )
 +
</source>
 +
 +
==Use on the Wiki==
 +
WebAssembly is using s-expressions as its textual format (for either Wabt or Emscript) .
 +
it's handy to use syntax highlighter for the code and use "lisp" language to set colors.
 +
<pre>
 +
  <source lang="lisp">
 +
    ;; web assembly goes here
 +
  </source>
 +
</pre>
 
==See Also==
 
==See Also==
 +
* [[WebAssembly/Roadmap]]
 +
* [[WebAssembly/Compiler]] - getting the compiler
 
* [[WebAssembly/JS]]
 
* [[WebAssembly/JS]]
 +
* [[WebAssembly/Internals]]
 +
* [[WebAssembly/Instructions]] - Instructions of the WASM code
 
* https://webassembly.org/ - the official site
 
* https://webassembly.org/ - the official site
 
* https://webassembly.github.io/spec/core/text/index.html - text format (S-Expression) specs
 
* https://webassembly.github.io/spec/core/text/index.html - text format (S-Expression) specs
 
* https://webassembly.github.io/spec/core/binary/index.html - binary format specs
 
* https://webassembly.github.io/spec/core/binary/index.html - binary format specs
 +
* https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format
 +
 
* https://rsms.me/wasm-intro - introduction to webassembly
 
* https://rsms.me/wasm-intro - introduction to webassembly
 +
* https://blog.scottlogic.com/2018/04/26/webassembly-by-hand.html
 
[[Category:WebAssembly]]
 
[[Category:WebAssembly]]

Revision as of 04:12, 21 January 2021

WebAssembly

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications. For more information on WebAssembly, see the WebAssembly website.

Assemblers

There are different assemblers available, from Wabt and emscripten.org. The expected format is a slightly different between those two:

wat2wasm (Wabt)

Example:

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

According to the official site "Wabt" is using it's own format of the Wasm. It's slightly different from the official documentation. The most current version of Wabt matches the specs, as well as supports the old syntax.

Online studio, that's using the older version of wabt syntax. https://webassembly.studio/

For example. instead of

local.get

it's using

get_local

wasm-as (emscripten)

The assembler is recommended for the use in a compiler by the WebAssembly.org

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

Use on the Wiki

WebAssembly is using s-expressions as its textual format (for either Wabt or Emscript) . it's handy to use syntax highlighter for the code and use "lisp" language to set colors.

  <source lang="lisp">
    ;; web assembly goes here
  </source>

See Also