feat(interface-types) Introduce the record type.

This patch updates the `Type` type to be an enum with 2 variants:
`Function` and `Record`, resp. to represent:

1. `(@interface type (func (param i32 i32) (result string)))`
2. `(@interface type (record string i32))`

This patch updates the binary encoder and decoder, along with the WAT
encoder and decoder.
This commit is contained in:
Ivan Enderlin
2020-03-24 16:29:29 +01:00
parent 63f824a240
commit c3c6fcbfdd
5 changed files with 143 additions and 32 deletions

View File

@ -50,18 +50,41 @@ pub enum InterfaceType {
I64,
}
/// Represents a type signature.
///
/// ```wasm,ignore
/// (@interface type (param i32 i32) (result string))
/// ```
/// Represents the kind of type.
#[derive(PartialEq, Debug)]
pub struct Type {
/// Types for the parameters (`(param …)`).
pub inputs: Vec<InterfaceType>,
pub enum TypeKind {
/// A function type.
Function,
/// Types for the results (`(result …)`).
pub outputs: Vec<InterfaceType>,
/// A record type.
Record,
}
/// Represents a type.
#[derive(PartialEq, Debug)]
pub enum Type {
/// A function type, like:
///
/// ```wasm,ignore
/// (@interface type (func (param i32 i32) (result string)))
/// ```
Function {
/// Types for the parameters (`(param …)`).
inputs: Vec<InterfaceType>,
/// Types for the results (`(result …)`).
outputs: Vec<InterfaceType>,
},
/// A record type, like:
///
/// ```wasm,ignore
/// (@interface type (record string i32))
/// ```
Record {
/// Types representing the fields.
fields: Vec<InterfaceType>,
},
}
/// Represents an imported function.