2020-02-10 15:27:04 +01:00
|
|
|
//! Represents the WIT language as a tree. This is the central
|
|
|
|
//! representation of the language.
|
|
|
|
|
2019-09-26 14:14:46 +02:00
|
|
|
use crate::interpreter::Instruction;
|
2019-09-13 14:50:17 +02:00
|
|
|
use std::str;
|
2019-09-12 22:44:20 +02:00
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// Represents the types supported by WIT.
|
2020-03-10 15:41:49 +01:00
|
|
|
#[derive(PartialEq, Debug, Clone)]
|
2019-09-12 22:44:20 +02:00
|
|
|
pub enum InterfaceType {
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 8-bits signed integer.
|
|
|
|
S8,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 16-bits signed integer.
|
|
|
|
S16,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 32-bits signed integer.
|
|
|
|
S32,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 64-bits signed integer.
|
|
|
|
S64,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 8-bits unsigned integer.
|
|
|
|
U8,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 16-bits unsigned integer.
|
|
|
|
U16,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
/// A 32-bits unsigned integer.
|
|
|
|
U32,
|
|
|
|
|
|
|
|
/// A 64-bits unsigned integer.
|
|
|
|
U64,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// A 32-bits float.
|
2019-09-12 22:44:20 +02:00
|
|
|
F32,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// A 64-bits float.
|
2019-09-12 22:44:20 +02:00
|
|
|
F64,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-26 15:34:04 +01:00
|
|
|
/// A string.
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
String,
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// An `any` reference.
|
feat(interface-types) Update interface types.
According to the last working notes, new interface types are s8, s16,
s32, s64, u8, u16, u32, u64, f32, f64, string, anyref, i32, and i64.
Their binary reprensentations are changing too, from 0x00 to 0x0d.
2020-02-24 15:37:03 +01:00
|
|
|
Anyref,
|
|
|
|
|
|
|
|
/// A 32-bits integer (as defined in WebAssembly core).
|
|
|
|
I32,
|
|
|
|
|
|
|
|
/// A 64-bits integer (as defiend in WebAssembly core).
|
|
|
|
I64,
|
2019-09-12 22:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:29:29 +01:00
|
|
|
/// Represents the kind of type.
|
2020-02-24 16:23:31 +01:00
|
|
|
#[derive(PartialEq, Debug)]
|
2020-03-24 16:29:29 +01:00
|
|
|
pub enum TypeKind {
|
|
|
|
/// A function type.
|
|
|
|
Function,
|
2020-02-24 16:23:31 +01:00
|
|
|
|
2020-03-24 16:29:29 +01:00
|
|
|
/// 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>,
|
|
|
|
},
|
2020-02-24 16:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// Represents an imported function.
|
2019-09-12 22:44:20 +02:00
|
|
|
#[derive(PartialEq, Debug)]
|
2020-02-10 15:41:41 +01:00
|
|
|
pub struct Import<'input> {
|
|
|
|
/// The function namespace.
|
|
|
|
pub namespace: &'input str,
|
|
|
|
|
|
|
|
/// The function name.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub name: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// The type signature.
|
|
|
|
pub signature_type: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Represents an exported function signature.
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Export<'input> {
|
|
|
|
/// The export name.
|
|
|
|
pub name: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// The WIT function type being exported.
|
|
|
|
pub function_type: u32,
|
2019-09-12 22:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// Represents an adapter.
|
|
|
|
#[derive(PartialEq, Debug)]
|
2020-03-10 10:37:09 +01:00
|
|
|
pub struct Adapter {
|
2020-02-24 18:12:01 +01:00
|
|
|
/// The adapter function type.
|
|
|
|
pub function_type: u32,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// The instructions.
|
2020-03-10 10:37:09 +01:00
|
|
|
pub instructions: Vec<Instruction>,
|
2020-02-24 18:12:01 +01:00
|
|
|
}
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-26 15:32:14 +01:00
|
|
|
/// Represents an implementation.
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Implementation {
|
|
|
|
/// The core function type.
|
|
|
|
pub core_function_type: u32,
|
|
|
|
|
|
|
|
/// The adapter function type.
|
|
|
|
pub adapter_function_type: u32,
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// Represents the kind of interface.
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub(crate) enum InterfaceKind {
|
|
|
|
/// A type.
|
|
|
|
Type,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// An imported function.
|
|
|
|
Import,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// An adapter.
|
|
|
|
Adapter,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// An exported function.
|
|
|
|
Export,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
2020-02-24 18:12:01 +01:00
|
|
|
/// An implementation.
|
|
|
|
Implementation,
|
2019-09-12 22:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// Represents a set of interfaces, i.e. it entirely describes a WIT
|
|
|
|
/// definition.
|
2020-02-20 12:15:23 +01:00
|
|
|
#[derive(PartialEq, Default, Debug)]
|
2019-09-12 22:44:20 +02:00
|
|
|
pub struct Interfaces<'input> {
|
2020-02-24 16:23:31 +01:00
|
|
|
/// All the types.
|
|
|
|
pub types: Vec<Type>,
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// All the imported functions.
|
|
|
|
pub imports: Vec<Import<'input>>,
|
|
|
|
|
2020-02-10 15:44:28 +01:00
|
|
|
/// All the adapters.
|
2020-03-10 10:37:09 +01:00
|
|
|
pub adapters: Vec<Adapter>,
|
2020-02-24 18:12:01 +01:00
|
|
|
|
|
|
|
/// All the exported functions.
|
|
|
|
pub exports: Vec<Export<'input>>,
|
|
|
|
|
|
|
|
/// All the implementations.
|
|
|
|
pub implementations: Vec<Implementation>,
|
2019-09-12 22:44:20 +02:00
|
|
|
}
|