fluence_sdk_wit/parsed_type/
fn_arg.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use super::ParsedType;
18use crate::ast_types::AstFnArgument;
19use crate::wasm_type::RustType;
20
21/// This trait could be used to generate raw args needed to construct a export function.
22pub(crate) trait FnArgGlueCodeGenerator {
23    fn generate_arguments(&self) -> Vec<RustType>;
24}
25
26impl FnArgGlueCodeGenerator for AstFnArgument {
27    fn generate_arguments(&self) -> Vec<RustType> {
28        match self.ty {
29            ParsedType::Boolean(_) => vec![RustType::I32],
30            ParsedType::I8(_) => vec![RustType::I8],
31            ParsedType::I16(_) => vec![RustType::I16],
32            ParsedType::I32(_) => vec![RustType::I32],
33            ParsedType::I64(_) => vec![RustType::I64],
34            ParsedType::U8(_) => vec![RustType::U8],
35            ParsedType::U16(_) => vec![RustType::U16],
36            ParsedType::U32(_) => vec![RustType::U32],
37            ParsedType::U64(_) => vec![RustType::U64],
38            ParsedType::Record(..) => vec![RustType::U32],
39            ParsedType::F32(_) => vec![RustType::F32],
40            ParsedType::F64(_) => vec![RustType::F64],
41            ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) | ParsedType::Vector(..) => {
42                vec![RustType::U32, RustType::U32]
43            }
44        }
45    }
46}