Skip to content

Commit 5000176

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

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Diff for: design/mvp/Binary.md

+63
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,59 @@ 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 (field l t)+)) ::= v+:<val(t)>+ => { (l: v,)^(n-1) l[n-1]: v[n-1] } (if n = |l*|)
372+
defval((variant (case l t?)+) ::= i:<core:u32> v:val(t[i]) => l[i](v)
373+
defval((list t)) ::= v:vec(<val(t)>) => [v]
374+
defval((tuple t+)) ::= v+:<val(t)>+ => (v+)
375+
defval((flags l+)) ::= v:<core:u32> => ((l[i] (if and(v, 2^|i|) > 0))^(i:|l*|))
376+
defval((enum l*)) ::= i:<core:u32> => l[i]
377+
defval((option t)) ::= 0x00 => none
378+
| 0x01 v:<val(t)> => (some v)
379+
defval((result)) ::= 0x00 => ok
380+
| 0x01 => error
381+
defval((result t)) ::= 0x00 v:<val(t)> => (ok v)
382+
| 0x01 => error
383+
defval((result (error u))) ::= 0x00 => ok
384+
| 0x01 v:<val(u)> => (error v)
385+
defval((result t (error u))) ::= 0x00 v:<val(t)> => (ok v)
386+
| 0x01 v:<val(u)> => (error v)
387+
```
388+
389+
Notes:
390+
* Reused Core binary rules:
391+
- [`core:name`]
392+
- [`core:s8`]
393+
- [`core:s16`]
394+
- [`core:s32`]
395+
- [`core:s64`]
396+
- [`core:u8`]
397+
- [`core:u16`]
398+
- [`core:u32`]
399+
- [`core:u64`]
400+
- [`core:f32`]
401+
- [`core:f64`]
402+
349403
## Name Section
350404

351405
Like the core wasm [name
@@ -375,7 +429,16 @@ appear once within a `name` section, for example component instances can only be
375429
named once.
376430

377431

432+
[`core:s8`]: https://webassembly.github.io/spec/core/binary/values.html#integers
433+
[`core:u8`]: https://webassembly.github.io/spec/core/binary/values.html#integers
434+
[`core:s16`]: https://webassembly.github.io/spec/core/binary/values.html#integers
435+
[`core:u16`]: https://webassembly.github.io/spec/core/binary/values.html#integers
436+
[`core:s32`]: https://webassembly.github.io/spec/core/binary/values.html#integers
378437
[`core:u32`]: https://webassembly.github.io/spec/core/binary/values.html#integers
438+
[`core:s64`]: https://webassembly.github.io/spec/core/binary/values.html#integers
439+
[`core:u64`]: https://webassembly.github.io/spec/core/binary/values.html#integers
440+
[`core:f32`]: https://webassembly.github.io/spec/core/binary/values.html#floating-point
441+
[`core:f64`]: https://webassembly.github.io/spec/core/binary/values.html#floating-point
379442
[`core:section`]: https://webassembly.github.io/spec/core/binary/modules.html#binary-section
380443
[`core:custom`]: https://webassembly.github.io/spec/core/binary/modules.html#custom-section
381444
[`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)