Skip to content

Commit c253d12

Browse files
rvolosatovslukewagner
authored andcommitted
1 parent a60a21e commit c253d12

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

design/mvp/Binary.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -355,40 +355,46 @@ Notes:
355355
(See [Value Definitions](Explainer.md#value-definitions) in the explainer.)
356356

357357
```ebnf
358-
value ::= t:<valtype> len:<uN> v:<val(t)> => (value t v) (where len = ||v||)
359-
val(bool) ::= 0x00 => false
360-
| 0x01 => true
361-
val(u8) ::= v:<core:byte> => (u8 v)
362-
val(s8) ::= v:<core:byte> => (s8 v) if v < 128 else (v - 256)
363-
val(s16) ::= v:<core:s16> => (s16 v)
364-
val(u16) ::= v:<core:u16> => (u16 v)
365-
val(s32) ::= v:<core:s32> => (s32 v)
366-
val(u32) ::= v:<core:u32> => (u32 v)
367-
val(s64) ::= v:<core:s64> => (s64 v)
368-
val(u64) ::= v:<core:u64> => (u64 v)
369-
val(f32) ::= v:<core:f32> => (f32 v) (if !isnan(v))
370-
| 0x00 0x00 0xC0 0x7F => (f32 nan)
371-
val(f64) ::= v:<core:f64> => (f64 v) (if !isnan(v))
372-
| 0x00 0x00 0x00 0x00 0x00 0x00 0xF8 0x7F => (f64 nan)
373-
val(char) ::= v:<core:u32> => v (if v < 0xD800 or 0xE000 <= v <= 0x10FFFF)
374-
val(string) ::= v:<core:name> => v
375-
val(i:<typeidx>) ::= v:<val(type-index-space[i])> => v
376-
val((record (field l t)+)) ::= v+:<val(t)>+ => (record v+)
377-
val((variant (case l t?)+) ::= i:<core:u32> v?:<val(t[i])>? => (variant l[i] v?)
378-
val((list t)) ::= v:vec(<val(t)>) => (list v)
379-
val((tuple t+)) ::= v+:<val(t)>+ => (tuple v+)
380-
val((flags l+)) ::= (v:<core:byte>)^N => (flags (l[i] for i in 0..N-1 if v & 2^i > 0)) (where N = ceil(|l+| / 8))
381-
val((enum l+)) ::= i:<core:u32> => (enum l[i])
382-
val((option t)) ::= 0x00 => none
383-
| 0x01 v:<val(t)> => (some v)
384-
val((result)) ::= 0x00 => ok
385-
| 0x01 => error
386-
val((result t)) ::= 0x00 v:<val(t)> => (ok v)
387-
| 0x01 => error
388-
val((result (error u))) ::= 0x00 => ok
389-
| 0x01 v:<val(u)> => (error v)
390-
val((result t (error u))) ::= 0x00 v:<val(t)> => (ok v)
391-
| 0x01 v:<val(u)> => (error v)
358+
value ::= t:<valtype> len:<uN> v:<val(t)> => (value t v) (where len = ||v||)
359+
val(bool) ::= 0x00 => false
360+
| 0x01 => true
361+
val(u8) ::= v:<core:byte> => (u8 v)
362+
val(s8) ::= v:<core:byte> => (s8 v) if v < 128 else (v - 256)
363+
val(s16) ::= v:<core:s16> => (s16 v)
364+
val(u16) ::= v:<core:u16> => (u16 v)
365+
val(s32) ::= v:<core:s32> => (s32 v)
366+
val(u32) ::= v:<core:u32> => (u32 v)
367+
val(s64) ::= v:<core:s64> => (s64 v)
368+
val(u64) ::= v:<core:u64> => (u64 v)
369+
val(f32) ::= v:<core:f32> => (f32 v) (if !isnan(v))
370+
| 0x00 0x00 0xC0 0x7F => (f32 nan)
371+
val(f64) ::= v:<core:f64> => (f64 v) (if !isnan(v))
372+
| 0x00 0x00 0x00 0x00 0x00 0x00 0xF8 0x7F => (f64 nan)
373+
val(char) ::= v:<core:u32> => v (if v < 0xD800 or 0xE000 <= v <= 0x10FFFF)
374+
val(string) ::= v:<core:name> => v
375+
val(i:<typeidx>) ::= v:<val(type-index-space[i])> => v
376+
val((record (field l t)+)) ::= v+:<val(t)>+ => (record v+)
377+
val((variant (case l t?)+) ::= a:<core:byte> v?:<val(t[i])>? => (variant l[a] v?) (if |l| <= 255)
378+
| a:<core:byte> b:<core:byte> v?:<val(t[i])>? => (variant l[a | b << 8] v?) (if |l| <= 65535)
379+
| a:<core:byte> b:<core:byte> c:<core:byte> v?:<val(t[i])>? => (variant l[a | b << 8 | c << 16] v?) (if |l| <= 16777215)
380+
| a:<core:byte> b:<core:byte> c:<core:byte> d:<core:byte> v?:<val(t[i])>? => (variant l[a | b << 8 | c << 16 | d << 24] v?) (if |l| > 16777215)
381+
val((list t)) ::= v:vec(<val(t)>) => (list v)
382+
val((tuple t+)) ::= v+:<val(t)>+ => (tuple v+)
383+
val((flags l+)) ::= (v:<core:byte>)^N => (flags (l[i] for i in 0..N-1 if v & 2^i > 0)) (where N = ceil(|l+| / 8))
384+
val((enum l+)) ::= a:<core:byte> => (enum l[a]) (if |l| <= 255)
385+
| a:<core:byte> b:<core:byte> => (enum l[a | b << 8]) (if |l| <= 65535)
386+
| a:<core:byte> b:<core:byte> c:<core:byte> => (enum l[a | b << 8 | c << 16]) (if |l| <= 16777215)
387+
| a:<core:byte> b:<core:byte> c:<core:byte> d:<core:byte> => (enum l[a | b << 8 | c << 16 | d << 24]) (if |l| > 16777215)
388+
val((option t)) ::= 0x00 => none
389+
| 0x01 v:<val(t)> => (some v)
390+
val((result)) ::= 0x00 => ok
391+
| 0x01 => error
392+
val((result t)) ::= 0x00 v:<val(t)> => (ok v)
393+
| 0x01 => error
394+
val((result (error u))) ::= 0x00 => ok
395+
| 0x01 v:<val(u)> => (error v)
396+
val((result t (error u))) ::= 0x00 v:<val(t)> => (ok v)
397+
| 0x01 v:<val(u)> => (error v)
392398
```
393399

394400
Notes:
@@ -405,7 +411,9 @@ Notes:
405411
- [`core:uN`]
406412
- [`core:f32`]
407413
- [`core:f64`]
414+
* `|` operator is used to denote bitwise OR operation, which performs OR on every bit of two numbers in their binary form
408415
* `&` operator is used to denote bitwise AND operation, which performs AND on every bit of two numbers in their binary form
416+
* `<<` operator is used to denote a bitwise left shift operation, which appends `0` at LSB position
409417
* `isnan` is a function, which takes a floating point number as a parameter and returns `true` iff it represents a NaN as defined in [IEEE 754 standard]
410418
* `||B||` is the length of the byte sequence generated from the production `B` in a derivation as defined in [Core convention auxilary notation]
411419

0 commit comments

Comments
 (0)