diff --git a/crates/wit/src/lib.rs b/crates/wit/src/lib.rs index 3d098d4..96189c8 100644 --- a/crates/wit/src/lib.rs +++ b/crates/wit/src/lib.rs @@ -43,3 +43,4 @@ pub use parsed_type::ParsedType; pub use token_stream_generator::GENERATED_FUNC_PREFIX; pub use token_stream_generator::GENERATED_SECTION_PREFIX; pub use token_stream_generator::GENERATED_GLOBAL_PREFIX; +pub use wasm_type::WasmType; diff --git a/crates/wit/src/parse_macro_input/item_record.rs b/crates/wit/src/parse_macro_input/item_record.rs index 05f022d..d88d9b2 100644 --- a/crates/wit/src/parse_macro_input/item_record.rs +++ b/crates/wit/src/parse_macro_input/item_record.rs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + use super::ParseMacroInput; use crate::{fce_ast_types, AstRecordField}; use crate::fce_ast_types::FCEAst; diff --git a/crates/wit/src/parsed_type.rs b/crates/wit/src/parsed_type.rs index 88d0257..b36feae 100644 --- a/crates/wit/src/parsed_type.rs +++ b/crates/wit/src/parsed_type.rs @@ -21,6 +21,8 @@ mod foreign_mod_arg; mod foreign_mod_epilog; mod foreign_mod_prolog; +use crate::wasm_type::WasmType; + pub(crate) use fn_arg::*; pub(crate) use fn_epilog::*; pub(crate) use fn_prolog::*; @@ -208,4 +210,22 @@ impl ParsedType { ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => true, } } + + pub fn to_raw_types(&self) -> Vec { + match self { + ParsedType::Boolean + | ParsedType::I8 + | ParsedType::I16 + | ParsedType::I32 + | ParsedType::U8 + | ParsedType::U16 + | ParsedType::U32 => vec![WasmType::I32], + ParsedType::I64 | ParsedType::U64 => vec![WasmType::I64], + ParsedType::F32 => vec![WasmType::F32], + ParsedType::F64 => vec![WasmType::F64], + ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => { + vec![WasmType::I32, WasmType::I32] + } + } + } } diff --git a/crates/wit/src/parsed_type/fn_arg.rs b/crates/wit/src/parsed_type/fn_arg.rs index 12b759c..4105438 100644 --- a/crates/wit/src/parsed_type/fn_arg.rs +++ b/crates/wit/src/parsed_type/fn_arg.rs @@ -1,3 +1,19 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + use super::ParsedType; use crate::wasm_type::WasmType; @@ -8,21 +24,6 @@ pub(crate) trait FnArgGlueCodeGenerator { impl FnArgGlueCodeGenerator for ParsedType { fn generate_arguments(&self) -> Vec { - // TODO: investigate possible issues in conversion between signed and unsigned types - match self { - ParsedType::Boolean - | ParsedType::I8 - | ParsedType::I16 - | ParsedType::I32 - | ParsedType::U8 - | ParsedType::U16 - | ParsedType::U32 => vec![WasmType::I32], - ParsedType::I64 | ParsedType::U64 => vec![WasmType::I64], - ParsedType::F32 => vec![WasmType::F32], - ParsedType::F64 => vec![WasmType::F64], - ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => { - vec![WasmType::I32, WasmType::I32] - } - } + self.to_raw_types() } } diff --git a/crates/wit/src/wasm_type.rs b/crates/wit/src/wasm_type.rs index 9d7e1fc..652070c 100644 --- a/crates/wit/src/wasm_type.rs +++ b/crates/wit/src/wasm_type.rs @@ -1,7 +1,7 @@ use proc_macro2::TokenStream; /// Raw Wasm types according to the spec except i128. -pub(crate) enum WasmType { +pub enum WasmType { I32, I64, F32,