Skip to content

Commit e848d3a

Browse files
committed
formalize component value definitions
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 145752a commit e848d3a

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Diff for: design/mvp/Binary.md

+61
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ section ::= section_0(<core:custom>) => ϵ
3636
| s: section_9(<start>) => [s]
3737
| i*:section_10(vec(<import>)) => i*
3838
| e*:section_11(vec(<export>)) => e*
39+
| v*:section_12(vec(<value>)) => v*
3940
```
4041
Notes:
4142
* Reused Core binary rules: [`core:section`], [`core:custom`], [`core:module`]
@@ -346,6 +347,57 @@ Notes:
346347
* `<integrity-metadata>` is as defined by the
347348
[SRI](https://www.w3.org/TR/SRI/#dfn-integrity-metadata) spec.
348349

350+
## Value Definitions
351+
352+
(See [Value Definitions](Explainer.md#value-definitions) in the explainer.)
353+
354+
```ebnf
355+
value ::= t:<valtype> v:<val(t)> => (value t v)
356+
val(bool) ::= 0x00 => false
357+
| 0x01 => true
358+
val(u8) ::= v:<core:u8> => v
359+
val(s8) ::= v:<core:s8> => v
360+
val(s16) ::= v:<core:s16> => v
361+
val(u16) ::= v:<core:u16> => v
362+
val(s32) ::= v:<core:s32> => v
363+
val(u32) ::= v:<core:u32> => v
364+
val(s64) ::= v:<core:s64> => v
365+
val(u64) ::= v:<core:u64> => v
366+
val(f32) ::= v:<core:f32> => v
367+
val(f64) ::= v:<core:f64> => v
368+
val(char) ::= v:<core:u32> => v
369+
val(string) ::= v:<core:name> => v
370+
val(i:<typeidx>) ::= v:<defval(t)> => v (if (type t) = type-index-space[i])
371+
defval((record lt+)) ::= (v:<fieldval(f:lt)>)^n => v^n (if |lt*| > 0 and n = |lt*|)
372+
defval((variant case*)) ::= i:<core:u32> v:caseval(c) => i v (if i < |case*| and c = case[i])
373+
defval((list t)) ::= vec(<val(t)>)
374+
defval((tuple t+)) ::= (v:<val(e:t)>)^n => v^n (if |t*| > 0 and n = |t*|)
375+
defval((flags l+)) ::= v:<core:u32> => v (if |l*| > 0 and v < 2^|l*|)
376+
defval((enum l*)) ::= i:<core:u32> => i v (if i < |l*|)
377+
defval((option t)) ::= 0x00 => none
378+
| 0x01 v:<val(t)> => (some v)
379+
defval((result t? (error u)?)) ::= 0x00 => ok
380+
| 0x00 v:<val(t)> => (ok v)
381+
| 0x01 => error
382+
| 0x01 v:<val(u)> => (error v)
383+
fieldval((field l t)) ::= v:<val(t)> => v
384+
caseval((case l t?)) ::= v?:<val(t)>? => v?
385+
```
386+
387+
Notes:
388+
* Reused Core binary rules:
389+
- [`core:name`]
390+
- [`core:s8`]
391+
- [`core:s16`]
392+
- [`core:s32`]
393+
- [`core:s64`]
394+
- [`core:u8`]
395+
- [`core:u16`]
396+
- [`core:u32`]
397+
- [`core:u64`]
398+
- [`core:f32`]
399+
- [`core:f64`]
400+
349401
## Name Section
350402

351403
Like the core wasm [name
@@ -375,7 +427,16 @@ appear once within a `name` section, for example component instances can only be
375427
named once.
376428

377429

430+
[`core:s8`]: https://webassembly.github.io/spec/core/binary/values.html#integers
431+
[`core:u8`]: https://webassembly.github.io/spec/core/binary/values.html#integers
432+
[`core:s16`]: https://webassembly.github.io/spec/core/binary/values.html#integers
433+
[`core:u16`]: https://webassembly.github.io/spec/core/binary/values.html#integers
434+
[`core:s32`]: https://webassembly.github.io/spec/core/binary/values.html#integers
378435
[`core:u32`]: https://webassembly.github.io/spec/core/binary/values.html#integers
436+
[`core:s64`]: https://webassembly.github.io/spec/core/binary/values.html#integers
437+
[`core:u64`]: https://webassembly.github.io/spec/core/binary/values.html#integers
438+
[`core:f32`]: https://webassembly.github.io/spec/core/binary/values.html#floating-point
439+
[`core:f64`]: https://webassembly.github.io/spec/core/binary/values.html#floating-point
379440
[`core:section`]: https://webassembly.github.io/spec/core/binary/modules.html#binary-section
380441
[`core:custom`]: https://webassembly.github.io/spec/core/binary/modules.html#custom-section
381442
[`core:module`]: https://webassembly.github.io/spec/core/binary/modules.html#binary-module

Diff for: design/mvp/Explainer.md

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ JavaScript runtimes. For a more user-focussed explanation, take a look at the
2525
* [Canonical built-ins](#canonical-built-ins)
2626
* [Start definitions](#-start-definitions)
2727
* [Import and export definitions](#import-and-export-definitions)
28+
* [Value definitions](#value-definitions)
2829
* [Component invariants](#component-invariants)
2930
* [JavaScript embedding](#JavaScript-embedding)
3031
* [JS API](#JS-API)
@@ -87,6 +88,7 @@ definition ::= core-prefix(<core:module>)
8788
| <start> 🪺
8889
| <import>
8990
| <export>
91+
| <value>
9092
9193
where core-prefix(X) parses '(' 'core' Y ')' when X parses '(' Y ')'
9294
```
@@ -1633,7 +1635,12 @@ the standard [avoidance problem] that appears in module systems with abstract
16331635
types. In particular, it ensures that a client of a component is able to
16341636
externally define a type compatible with the exports of the component.
16351637

1638+
### 🪙 Value Definitions
16361639

1640+
Components may define values in the value index
1641+
```ebnf
1642+
value ::= t:<valtype> v:<val(t)> => (value t v)
1643+
```
16371644
## Component Invariants
16381645

16391646
As a consequence of the shared-nothing design described above, all calls into

0 commit comments

Comments
 (0)