Skip to content

Commit 87b1e0c

Browse files
rossbergLuke Wagner
authored and
Luke Wagner
committed
Extensible encoding of function signatures (#640)
* Prettify section names * Restructure encoding of function signatures * Revert "[Binary 11] Update the version number to 0xB." * Leave index space for growing the number of base types * Comments addressed * clarify how export/import names convert to JS strings (#569) (#573) * When embedded in the web, clarify how export/import names convert to JS strings (#569) * Fixes suggested by @jf * Address more feedback Added a link to http://monsur.hossa.in/2012/07/20/utf-8-in-javascript.html. Simplified the decoding algorithm thanks to Luke's feedback. * Access to proprietary APIs apart from HTML5 (#656) * comments
1 parent 67c25af commit 87b1e0c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

BinaryEncoding.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ A four-byte little endian unsigned integer.
3535
### varint32
3636
A [Signed LEB128](https://en.wikipedia.org/wiki/LEB128#Signed_LEB128) variable-length integer, limited to int32 values.
3737

38+
### varuint1
39+
A [LEB128](https://en.wikipedia.org/wiki/LEB128) variable-length integer, limited to the values 0 or 1. `varuint1` values may contain leading zeros. (This type is mainly used for compatibility with potential future extensions.)
40+
3841
### varuint32
3942
A [LEB128](https://en.wikipedia.org/wiki/LEB128) variable-length integer, limited to uint32 values. `varuint32` values may contain leading zeros.
4043

@@ -117,15 +120,19 @@ The type section declares all function signatures that will be used in the modul
117120

118121
| Field | Type | Description |
119122
| ----- | ----- | ----- |
120-
| count | `varuint32` | count of signature entries to follow |
123+
| count | `varuint32` | count of type entries to follow |
121124
| entries | `type_entry*` | repeated type entries as described below |
122125

123126
#### Type entry
124127
| Field | Type | Description |
125128
| ----- | ----- | ----- |
129+
| form | `uint8` | `0x40`, indicating a function type |
126130
| param_count | `varuint32` | the number of parameters to the function |
127-
| return_type | `value_type?` | the return type of the function, with `0` indicating no return type |
128131
| param_types | `value_type*` | the parameter types of the function |
132+
| return_count | `varuint1` | the number of results from the function |
133+
| return_type | `value_type?` | the result type of the function (if return_count is 1) |
134+
135+
(Note: In the future, this section may contain other forms of type entries as well, which can be distinguished by the `form` field.)
129136

130137
### Import section
131138

@@ -216,7 +223,7 @@ The start section declares the [start function](Modules.md#module-start-function
216223

217224
ID: `code`
218225

219-
The code section assigns a body to every function in the module.
226+
The code section contains a body for every function in the module.
220227
The count of function declared in the [function section](#function-section)
221228
and function bodies defined in this section must be the same and the `i`th
222229
declaration corresponds to the `i`th function body.
@@ -230,7 +237,7 @@ declaration corresponds to the `i`th function body.
230237

231238
ID: `data`
232239

233-
The data section declares the initialized data that should be loaded
240+
The data section declares the initialized data that is loaded
234241
into the linear memory.
235242

236243
| Field | Type | Description |

0 commit comments

Comments
 (0)