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-02-21 12:23:58 +01:00
|
|
|
#[derive(PartialEq, Debug)]
|
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
|
|
|
|
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 stirng.
|
|
|
|
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-02-10 15:41:41 +01:00
|
|
|
/// Represents the kind of adapter.
|
2019-09-12 22:44:20 +02:00
|
|
|
#[derive(PartialEq, Debug)]
|
2019-09-13 14:26:49 +02:00
|
|
|
pub(crate) enum AdapterKind {
|
2020-02-10 15:41:41 +01:00
|
|
|
/// An adapter defined for an imported function of a WebAssembly instance.
|
2019-09-12 22:44:20 +02:00
|
|
|
Import,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// An adapter defined for an exported function of a WebAssembly instance.
|
2019-09-12 22:44:20 +02:00
|
|
|
Export,
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:23:31 +01:00
|
|
|
/// Represents a type signature.
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Type {
|
|
|
|
/// Types for the parameters.
|
|
|
|
pub inputs: Vec<InterfaceType>,
|
|
|
|
|
|
|
|
/// Types for the results.
|
|
|
|
pub outputs: Vec<InterfaceType>,
|
|
|
|
}
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// Represents an exported function signature.
|
2019-09-12 22:44:20 +02:00
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Export<'input> {
|
2020-02-10 15:41:41 +01:00
|
|
|
/// The function name.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub name: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function input types.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub input_types: Vec<InterfaceType>,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function output types.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub output_types: Vec<InterfaceType>,
|
|
|
|
}
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// Represents an imported function signature.
|
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
|
|
|
|
|
|
|
/// The function input types.
|
|
|
|
pub input_types: Vec<InterfaceType>,
|
|
|
|
|
|
|
|
/// The function output types.
|
|
|
|
pub output_types: Vec<InterfaceType>,
|
2019-09-12 22:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:41:41 +01:00
|
|
|
/// Represents an adapter.
|
2019-09-12 22:44:20 +02:00
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum Adapter<'input> {
|
2020-02-10 15:41:41 +01:00
|
|
|
/// An adapter for an imported function.
|
2019-09-12 22:44:20 +02:00
|
|
|
Import {
|
2020-02-10 15:41:41 +01:00
|
|
|
/// The function namespace.
|
2019-09-12 22:44:20 +02:00
|
|
|
namespace: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function name.
|
2019-09-12 22:44:20 +02:00
|
|
|
name: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function input types.
|
2019-09-12 22:44:20 +02:00
|
|
|
input_types: Vec<InterfaceType>,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function output types.
|
2019-09-12 22:44:20 +02:00
|
|
|
output_types: Vec<InterfaceType>,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The instructions of the adapter.
|
2019-09-12 22:44:20 +02:00
|
|
|
instructions: Vec<Instruction<'input>>,
|
|
|
|
},
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// An adapter for an exported function.
|
2019-09-12 22:44:20 +02:00
|
|
|
Export {
|
2020-02-10 15:41:41 +01:00
|
|
|
/// The function name.
|
2019-09-12 22:44:20 +02:00
|
|
|
name: &'input str,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function input types.
|
2019-09-12 22:44:20 +02:00
|
|
|
input_types: Vec<InterfaceType>,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The function output types.
|
2019-09-12 22:44:20 +02:00
|
|
|
output_types: Vec<InterfaceType>,
|
2020-02-10 15:41:41 +01:00
|
|
|
|
|
|
|
/// The instructions of the adapter.
|
2019-09-12 22:44:20 +02:00
|
|
|
instructions: Vec<Instruction<'input>>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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:44:28 +01:00
|
|
|
/// All the exported functions.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub exports: Vec<Export<'input>>,
|
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.
|
2019-09-12 22:44:20 +02:00
|
|
|
pub adapters: Vec<Adapter<'input>>,
|
|
|
|
}
|