Skip to content

Commit 3cd3dc8

Browse files

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
@@ -358,40 +358,46 @@ Notes:
358358
(See [Value Definitions](Explainer.md#value-definitions) in the explainer.)
359359

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

397403
Notes:
@@ -408,7 +414,9 @@ Notes:
408414
- [`core:uN`]
409415
- [`core:f32`]
410416
- [`core:f64`]
417+
* `|` operator is used to denote bitwise OR operation, which performs OR on every bit of two numbers in their binary form
411418
* `&` operator is used to denote bitwise AND operation, which performs AND on every bit of two numbers in their binary form
419+
* `<<` operator is used to denote a bitwise left shift operation, which appends `0` at LSB position
412420
* `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]
413421
* `||B||` is the length of the byte sequence generated from the production `B` in a derivation as defined in [Core convention auxilary notation]
414422

0 commit comments

Comments
 (0)