Difference between revisions of "WebAssembly"

From Lazarus wiki
Jump to navigationJump to search
(Focus the See Also links on Pascal.)
 
(7 intermediate revisions by 3 users not shown)
Line 12: Line 12:
 
* fcl-base
 
* fcl-base
 
* fcl-css
 
* fcl-css
 +
* fcl-db
 
* fcl-hash
 
* fcl-hash
 +
* fcl-js
 +
* fcl-json
 +
* fcl-mustache
 +
* fcl-passrc
 
* fcl-registry
 
* fcl-registry
 +
* fcl-sdo
 
* fcl-sound
 
* fcl-sound
 
* fcl-stl
 
* fcl-stl
 
* fcl-xml
 
* fcl-xml
 
* hash
 
* hash
 +
* libtar
 
* regexpr
 
* regexpr
 
* rtl
 
* rtl
Line 23: Line 30:
 
* rtl-objpas
 
* rtl-objpas
 
* rtl-unicode
 
* rtl-unicode
 +
* symbolic
 
* tplylib
 
* tplylib
 +
* webidl
  
The FPC Wasm embedded RTL, in line with FPC's support for [[TARGET_Embedded|embedded targets]], consists of these units:
+
The FPC Wasm embedded RTL consists of these units:
 
* rtl
 
* rtl
 
* rtl-extra
 
* rtl-extra
Line 42: Line 51:
 
* [https://www.freepascal.org/~michael/pas2js-demos/wasienv/canvas/ Drawing on HTML canvas]
 
* [https://www.freepascal.org/~michael/pas2js-demos/wasienv/canvas/ Drawing on HTML canvas]
 
* [https://github.com/PierceNg/wasm-demo/ Conway's Game of Life]
 
* [https://github.com/PierceNg/wasm-demo/ Conway's Game of Life]
 +
 +
The Free Pascal compiler itself run in the browser:
 +
[[File:fpcwasm-1.png]]
  
 
== With Standalone Runtime ==
 
== With Standalone Runtime ==
Line 51: Line 63:
 
* [[WebAssembly/Roadmap]]
 
* [[WebAssembly/Roadmap]]
 
* [[WebAssembly/JS]]
 
* [[WebAssembly/JS]]
 +
* [[WebAssembly/Files]]
 +
* [[WebAssembly/DOM]]
 +
* [[WebAssembly/Threads]]
 +
* [[WebAssembly/JS-Promise_Integration]]
 +
* [[WebAssembly/Reference types]]
 +
 +
There is an external pet project to create a pascal interpreter, not related to Free Pascal:
 
* [https://faizilham.github.io/making-budget-pascal-compiler Making a budget Pascal compiler to WebAssembly]
 
* [https://faizilham.github.io/making-budget-pascal-compiler Making a budget Pascal compiler to WebAssembly]
 +
 
[[Category:WebAssembly]]
 
[[Category:WebAssembly]]

Latest revision as of 12:18, 22 October 2023

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.

The FPC WASI RTL consists of these units:

  • fcl-base
  • fcl-css
  • fcl-db
  • fcl-hash
  • fcl-js
  • fcl-json
  • fcl-mustache
  • fcl-passrc
  • fcl-registry
  • fcl-sdo
  • fcl-sound
  • fcl-stl
  • fcl-xml
  • hash
  • libtar
  • regexpr
  • rtl
  • rtl-extra
  • rtl-objpas
  • rtl-unicode
  • symbolic
  • tplylib
  • webidl

The FPC Wasm embedded RTL consists of these units:

  • rtl
  • rtl-extra
  • tplylib

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.

Demos

Running in Web Browsers

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.

The Free Pascal compiler itself run in the browser: fpcwasm-1.png

With Standalone Runtime

Free Pascal's source tree contains examples embedding the wasmtime standalone Wasm runtime in Pascal host programs.

See Also

There is an external pet project to create a pascal interpreter, not related to Free Pascal: