Sign in Join
Wiki copytemporary

WebAssembly: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: WebAssembly

OldNewLine
1+# WebAssembly
2+
3+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](https://webassembly.org) website for more information.
4+
5+# Free Pascal and WebAssembly
6+
7+FPC supports two Wasm compilation targets: WASI and embedded. See [[WebAssembly/Compiler]] on how to build and install FPC for Wasm.
8+
9+[WASI](https://wasi.dev) - 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.
10+
11+The FPC WASI RTL consists of these units:
12+
13+- fcl-base
14+- fcl-css
15+- fcl-db
16+- fcl-hash
17+- fcl-js
18+- fcl-json
19+- fcl-mustache
20+- fcl-passrc
21+- fcl-registry
22+- fcl-sdo
23+- fcl-sound
24+- fcl-stl
25+- fcl-xml
26+- hash
27+- libtar
28+- regexpr
29+- rtl
30+- rtl-extra
31+- rtl-objpas
32+- rtl-unicode
33+- symbolic
34+- tplylib
35+- webidl
36+
37+The FPC Wasm embedded RTL consists of these units:
38+
39+- rtl
40+- rtl-extra
41+- tplylib
42+
43+With respect to the embedded target, there are presently (2022) early efforts to create Wasm-related standards for cross-device/platform/architecture embedded applications.
44+
45+Overall, FPC's Wasm support adds to FPC's already [extensive list of compilation targets](https://www.freepascal.org/), potentially allowing Pascal programs to run in even more environments than they already do.
46+
47+# Demos
48+
49+## Running in Web Browsers
50+
51+In each demo, the driver program is transpiled from Pascal to Javascript using [[pas2js]], and the worker program/library is compiled from Pascal to Wasm using FPC WASI target.
52+
53+- [Simulated terminal input and output](https://www.freepascal.org/~michael/pas2js-demos/wasienv/terminal/)
54+- [Drawing on HTML canvas](https://www.freepascal.org/~michael/pas2js-demos/wasienv/canvas/)
55+- [Conway's Game of Life](https://github.com/PierceNg/wasm-demo/)
56+
57+The Free Pascal compiler itself run in the browser: ![](/wiki-images/f/f2/Fpcwasm-1.png)
58+
59+## With Standalone Runtime
60+
61+Free Pascal's source tree contains [examples](https://gitlab.com/freepascal.org/fpc/source/-/tree/main/packages/wasmtime/examples) embedding the [wasmtime](https://github.com/bytecodealliance/wasmtime) standalone Wasm runtime in Pascal host programs.
62+
63+# See Also
64+
65+- [[WebAssembly/Compiler]]
66+- [[WebAssembly/Roadmap]]
67+- [[WebAssembly/JS]]
68+- [[WebAssembly/Files]]
69+- [[WebAssembly/DOM]]
70+- [[WebAssembly/Threads]]
71+- [[WebAssembly/JS-Promise Integration]]
72+- [[WebAssembly/Reference types]]
73+
74+There is an external pet project to create a pascal interpreter, not related to Free Pascal:
75+
76+- [Making a budget Pascal compiler to WebAssembly](https://faizilham.github.io/making-budget-pascal-compiler)
77+
78+---
79+*From the Free Pascal wiki, page "WebAssembly", as it stood on 2023-10-22 after a change by Michael, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
80+Category: WebAssembly

Back to history