WebAssembly/Reference types

From Lazarus wiki
Revision as of 18:22, 20 June 2023 by Nickysn (talk | contribs) (Initial version of the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The WebAssembly reference types extension adds support for two opaque types - externref and funcref. They are managed by the host and cannot be stored in linear memory. They can be used as function parameters (they can only be passed by value), local variables, function results, and as WebAssembly globals.

Free Pascal support

Support for reference types is partially implemented in the wasm_js_promise_integration branch: [1]

externref

There is a new type in the System unit, called WasmExternRef. It represents the externref WebAssembly type.

funcref

Procedural types can now be declared as WasmFuncRef:

type
  TMyWasmFuncRef = function(a: longint; b: int64): longint; WasmFuncRef;

These types represent the funcref WebAssembly type.

Restrictions

The WebAssembly reference types don't have an in-memory representation. Therefore, the following is not allowed:

  • Taking their address
  • Taking their size, using sizeof() or bitsizeof()
  • Using them as a field in a record, object or class
  • Passing them as var, constref or out parameters

See also