WebAssembly/Reference types
From Free Pascal wiki
Jump to navigationJump to searchThe 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. For example:
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