wasmer_interface_types_fl/
ast.rs1use crate::{interpreter::Instruction, IRecordType, IType};
5
6use serde::Deserialize;
7use serde::Serialize;
8use std::str;
9use std::sync::Arc;
10
11#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
13pub enum TypeKind {
14 Function,
16
17 Record,
19}
20
21#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
23pub struct FunctionArg {
24 pub name: String,
26
27 pub ty: IType,
29}
30
31#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
33pub enum Type {
34 Function {
40 arguments: Arc<Vec<FunctionArg>>,
42
43 output_types: Arc<Vec<IType>>,
45 },
46
47 Record(Arc<IRecordType>),
53}
54
55#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)]
57pub struct Import<'input> {
58 pub namespace: &'input str,
60
61 pub name: &'input str,
63
64 pub function_type: u32,
66}
67
68#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)]
70pub struct Export<'input> {
71 pub name: &'input str,
73
74 pub function_type: u32,
76}
77
78#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
80pub struct Adapter {
81 pub function_type: u32,
83
84 pub instructions: Vec<Instruction>,
86}
87
88#[derive(PartialEq, Eq, Debug, Default, Clone, Hash, Serialize, Deserialize)]
90pub struct Implementation {
91 pub core_function_type: u32,
93
94 pub adapter_function_type: u32,
96}
97
98#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
100pub enum InterfaceKind {
101 Version,
103
104 Type,
106
107 Import,
109
110 Adapter,
112
113 Export,
115
116 Implementation,
118}
119
120#[derive(PartialEq, Eq, Debug, Clone, Hash)]
123pub struct Interfaces<'input> {
124 pub version: semver::Version,
126
127 pub types: Vec<Type>,
129
130 pub imports: Vec<Import<'input>>,
132
133 pub adapters: Vec<Adapter>,
135
136 pub exports: Vec<Export<'input>>,
138
139 pub implementations: Vec<Implementation>,
141}
142
143impl Interfaces<'_> {
144 pub fn new() -> Self {
146 use std::str::FromStr;
147
148 let version = semver::Version::from_str(env!("CARGO_PKG_VERSION")).unwrap();
150
151 Self {
152 version,
153 types: Vec::new(),
154 imports: Vec::new(),
155 adapters: Vec::new(),
156 exports: Vec::new(),
157 implementations: Vec::new(),
158 }
159 }
160
161 pub fn from_version(version: semver::Version) -> Self {
163 Self {
164 version,
165 types: Vec::new(),
166 imports: Vec::new(),
167 adapters: Vec::new(),
168 exports: Vec::new(),
169 implementations: Vec::new(),
170 }
171 }
172}
173
174impl Default for Interfaces<'_> {
175 fn default() -> Self {
176 Self::new()
177 }
178}