aboutsummaryrefslogtreecommitdiff
path: root/BinaryEncoding.md
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-10-11 08:02:10 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2025-03-10 00:03:41 +0100
commite8f0f3cd54c4142a0463659d12f1667bc35e7ace (patch)
treee74ca8efeacbafc85a9e8680cea1ece43c99e9e2 /BinaryEncoding.md
parent08e06cccaf9fe14558e1f3deec81b3d14175cd4b (diff)
downloadnanowasm-design-e8f0f3cd54c4142a0463659d12f1667bc35e7ace.tar.gz
Add NanoWasm extensions
This commit introduces third-party extensions to the MVP, branded as "NanoWasm", that aim to reduce memory consumption and computational time for resource-constrained environments, at the expense of increased module file size.
Diffstat (limited to 'BinaryEncoding.md')
-rw-r--r--BinaryEncoding.md85
1 files changed, 85 insertions, 0 deletions
diff --git a/BinaryEncoding.md b/BinaryEncoding.md
index 2677b35..91f1094 100644
--- a/BinaryEncoding.md
+++ b/BinaryEncoding.md
@@ -532,6 +532,91 @@ where a `local_name` is encoded as:
| index | `varuint32` | the index of the function whose locals are being named |
| local_map | `name_map` | assignment of names to local indices |
+### NanoWasm type offset section
+
+Custom section `name` field: `"nw_to"`
+
+The NanoWasm type offset section is a
+[custom section](#high-level-structure). It is therefore encoded with id `0`
+followed by the name string `"nw_to"`. It is meant as a
+[NanoWasm](#NanoWasm.md) extension to the MVP that allows NanoWasm-compatible
+interpreters to quickly retrieve the offset of a type inside the
+[type section](#type-section), without having to keep this information
+in-memory.
+
+| Field | Type | Description |
+| ----- | ---- | ----------- |
+| offset | uint32* | Type offset inside the [type section](#type-section), encoded as little-endian
+
+### NanoWasm function type index section
+
+Custom section `name` field: `"nw_fti"`
+
+The NanoWasm function type index section is a
+[custom section](#high-level-structure). It is therefore encoded with id `0`
+followed by the name string `"nw_ft"`. It is meant as a
+[NanoWasm](#NanoWasm.md) extension to the MVP that allows NanoWasm-compatible
+interpreters to quickly retrieve the type index of a function, without having
+to read the [function section](#function-section) or keep this information
+in-memory.
+
+| Field | Type | Description |
+| ----- | ---- | ----------- |
+| offset | uint32* | Type index, as expressed by the [function section](#function-section), encoded as little-endian
+
+### NanoWasm function body offset section
+
+Custom section `name` field: `"nw_fbo"`
+
+The Nanowasm function body offset section is a
+[custom section](#high-level-structure). It is therefore encoded with id `0`
+followed by the name string `"nw_fbo"`. It is meant as a
+[NanoWasm](#NanoWasm.md) extension to the MVP that allows NanoWasm-compatible
+interpreters to quickly retrieve the offset of a function body inside the
+[code section](#code-section), without having to keep this information
+in-memory.
+
+The Nanowasm function body offset section contains an array of fixed-width
+offsets. This allows interpreters to inspect the offset a given
+[function index](Modules.md#function-index-space) with constant-time access.
+
+Similarly to function bodies in the code section, imported functions are not
+listed on this section.
+
+| Field | Type | Description |
+| ----- | ---- | ----------- |
+| offset | uint32* | Function body offset inside the [code section](#code-section), encoded as little-endian
+
+### NanoWasm label offset section
+
+Custom section `name` field: `"nw_lo"`
+
+The Nanowasm label offset section is a [custom section](#high-level-structure).
+It is therefore encoded with id `0` followed by the name string `"nw_lo"`.
+It is meant as a [NanoWasm](#NanoWasm.md) extension to the MVP that allows NanoWasm-compatible interpreters to quickly
+retrieve the offset for a given label relative to a function body, without
+having to keep this information in-memory.
+
+The Nanowasm label offset section starts with an array of fixed-width
+offsets to an array of `label_offset` entries. This allows interpreters to
+inspect the offset for a given label when a
+[control flow operator](#Control-flow-operators) is interpreted, without
+having to read the rest of the body function beforehand.
+
+Similarly to function bodies in the code section, imported functions are not
+listed on this section.
+
+| Field | Type | Description |
+| ----- | ---- | ----------- |
+| offset | uint32* | offset to the `label_offset` entry, encoded as little-endian
+
+Where each non-imported function defines a `label_offset` entry as follows:
+
+| Field | Type | Description |
+| ----- | ---- | ----------- |
+| count | varuint32 | number of label offsets
+| offset | uint32* | offset to the label index relative to the function body start, encoded as little-endian
+
# Function Bodies
Function bodies consist of a sequence of local variable declarations followed by