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
|
|
|
|
2019-09-28 00:55:35 +02:00
|
|
|
#[derive(PartialEq, Clone, Debug)]
|
2019-09-12 22:44:20 +02:00
|
|
|
pub enum InterfaceType {
|
|
|
|
Int,
|
|
|
|
Float,
|
|
|
|
Any,
|
|
|
|
String,
|
|
|
|
Seq,
|
|
|
|
I32,
|
|
|
|
I64,
|
|
|
|
F32,
|
|
|
|
F64,
|
|
|
|
AnyRef,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
2019-09-13 14:26:49 +02:00
|
|
|
pub(crate) enum AdapterKind {
|
2019-09-12 22:44:20 +02:00
|
|
|
Import,
|
|
|
|
Export,
|
|
|
|
HelperFunction,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Export<'input> {
|
|
|
|
pub name: &'input str,
|
|
|
|
pub input_types: Vec<InterfaceType>,
|
|
|
|
pub output_types: Vec<InterfaceType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Type<'input> {
|
|
|
|
pub name: &'input str,
|
|
|
|
pub fields: Vec<&'input str>,
|
|
|
|
pub types: Vec<InterfaceType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct ImportedFunction<'input> {
|
|
|
|
pub namespace: &'input str,
|
|
|
|
pub name: &'input str,
|
|
|
|
pub input_types: Vec<InterfaceType>,
|
|
|
|
pub output_types: Vec<InterfaceType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum Adapter<'input> {
|
|
|
|
Import {
|
|
|
|
namespace: &'input str,
|
|
|
|
name: &'input str,
|
|
|
|
input_types: Vec<InterfaceType>,
|
|
|
|
output_types: Vec<InterfaceType>,
|
|
|
|
instructions: Vec<Instruction<'input>>,
|
|
|
|
},
|
|
|
|
Export {
|
|
|
|
name: &'input str,
|
|
|
|
input_types: Vec<InterfaceType>,
|
|
|
|
output_types: Vec<InterfaceType>,
|
|
|
|
instructions: Vec<Instruction<'input>>,
|
|
|
|
},
|
|
|
|
HelperFunction {
|
|
|
|
name: &'input str,
|
|
|
|
input_types: Vec<InterfaceType>,
|
|
|
|
output_types: Vec<InterfaceType>,
|
|
|
|
instructions: Vec<Instruction<'input>>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Forward<'input> {
|
|
|
|
pub name: &'input str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Interfaces<'input> {
|
|
|
|
pub exports: Vec<Export<'input>>,
|
|
|
|
pub types: Vec<Type<'input>>,
|
|
|
|
pub imported_functions: Vec<ImportedFunction<'input>>,
|
|
|
|
pub adapters: Vec<Adapter<'input>>,
|
|
|
|
pub forwards: Vec<Forward<'input>>,
|
|
|
|
}
|