Difference between revisions of "WebAssembly"

From Free Pascal wiki
Jump to navigationJump to search
(Added section "Free Pascal support")
(Focus the page on FPC.)
Line 1: Line 1:
 
== WebAssembly ==
 
== 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.
+
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. See the [https://webassembly.org WebAssembly] website for more information.
  
== Free Pascal support ==
+
== Free Pascal and WebAssembly ==
  
For FPC's support for WebAssembly, see the [[WebAssembly/Compiler]] page.
+
FPC supports two Wasm compilation targets: WASI and embedded. See [[WebAssembly/Compiler]] on how to build and install FPC for Wasm.
  
==Assemblers==
+
[https://wasi.dev WASI] - the WebAssembly System Interface - defines an API for operating system-like features, including files and filesystems, network sockets, clocks and random numbers. These features, when implemented in web browsers as well as standalone Wasm runtimes on desktops, servers, and serverless cloud computing units, are available to Pascal programs and libraries compiled by FPC to Wasm for the WASI target.
  
There are different assemblers available, from Wabt, emscripten.org and LLVM.  
+
With respect to the embedded target, there are presently (2022) early efforts to create Wasm-related standards for cross-device/platform/architecture embedded applications.  
The expected format is a slightly different between those two:
 
  
===wat2wasm (Wabt)===
+
Overall, FPC's Wasm support adds to FPC's already [https://www.freepascal.org/ extensive list of compilation targets], potentially allowing Pascal programs to run in even more environments than they already do.
Example:
 
<source lang="lisp">
 
(module
 
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
 
    local.get $lhs
 
    local.get $rhs
 
    i32.add
 
  )
 
  (export "add" (func $add))
 
)
 
</source>
 
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
 
<source lang="lisp">
 
(module
 
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
 
    (
 
    local.get $lhs
 
    local.get $rhs
 
    i32.add
 
    )
 
  )
 
  (export "add" (func $add))
 
)
 
</source>
 
 
=== llvm-mc ===
 
 
This is the assembler from the LLVM project. It uses a GAS-like syntax.
 
 
==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/Compiler]] - getting the compiler
 
* [[WebAssembly/Roadmap]]
 
* [[WebAssembly/Roadmap]]
* [[WebAssembly/Compiler]] - getting the compiler
 
 
* [[WebAssembly/JS]]
 
* [[WebAssembly/JS]]
 
* [[WebAssembly/Internals]]
 
* [[WebAssembly/Internals]]

Revision as of 17:01, 1 April 2022

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. See the WebAssembly website for more information.

Free Pascal and WebAssembly

FPC supports two Wasm compilation targets: WASI and embedded. See WebAssembly/Compiler on how to build and install FPC for Wasm.

WASI - the WebAssembly System Interface - defines an API for operating system-like features, including files and filesystems, network sockets, clocks and random numbers. These features, when implemented in web browsers as well as standalone Wasm runtimes on desktops, servers, and serverless cloud computing units, are available to Pascal programs and libraries compiled by FPC to Wasm for the WASI target.

With respect to the embedded target, there are presently (2022) early efforts to create Wasm-related standards for cross-device/platform/architecture embedded applications.

Overall, FPC's Wasm support adds to FPC's already extensive list of compilation targets, potentially allowing Pascal programs to run in even more environments than they already do.

See Also