mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 23:30:18 +00:00
ranaming
This commit is contained in:
parent
7b8d72e84c
commit
55cfb1e844
@ -20,18 +20,18 @@ use serde::Serialize;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct AstFuncArgument {
|
||||
pub struct AstFnArgument {
|
||||
pub name: String,
|
||||
pub ty: ParsedType,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct AstFunctionSignature {
|
||||
pub struct AstFnSignature {
|
||||
// Option is needed only for skipping serialization/deserialization of syn::ItemFn
|
||||
#[serde(skip)]
|
||||
pub visibility: Option<syn::Visibility>,
|
||||
pub name: String,
|
||||
pub arguments: Vec<AstFuncArgument>,
|
||||
pub arguments: Vec<AstFnArgument>,
|
||||
// fce supports only one return value now,
|
||||
// waiting for adding multi-value support in Wasmer.
|
||||
pub output_type: Option<ParsedType>,
|
||||
@ -58,7 +58,7 @@ pub struct AstRecordItem {
|
||||
pub struct AstExternFnItem {
|
||||
pub link_name: Option<String>,
|
||||
// only imports are possible here
|
||||
pub signature: AstFunctionSignature,
|
||||
pub signature: AstFnSignature,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
@ -74,8 +74,8 @@ pub struct AstExternModItem {
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct AstFunctionItem {
|
||||
pub signature: AstFunctionSignature,
|
||||
pub struct AstFnItem {
|
||||
pub signature: AstFnSignature,
|
||||
|
||||
// Option is needed only for skipping serialization/deserialization of syn::ItemFn
|
||||
#[serde(skip)]
|
||||
@ -85,7 +85,7 @@ pub struct AstFunctionItem {
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "ast_type")]
|
||||
pub enum FCEAst {
|
||||
Function(AstFunctionItem),
|
||||
Function(AstFnItem),
|
||||
ExternMod(AstExternModItem),
|
||||
Record(AstRecordItem),
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ use super::ParseMacroInput;
|
||||
use crate::fce_ast_types;
|
||||
use crate::ParsedType;
|
||||
use crate::fce_ast_types::FCEAst;
|
||||
use crate::fce_ast_types::AstFunctionItem;
|
||||
use crate::fce_ast_types::AstFuncArgument;
|
||||
use crate::fce_ast_types::AstFnItem;
|
||||
use crate::fce_ast_types::AstFnArgument;
|
||||
use crate::syn_error;
|
||||
|
||||
use syn::Result;
|
||||
@ -36,7 +36,7 @@ impl ParseMacroInput for syn::ItemFn {
|
||||
.zip(self.sig.inputs.iter().map(|arg| arg.span()));
|
||||
check_parsed_functions(parsed_args)?;
|
||||
|
||||
let ast_fn = FCEAst::Function(AstFunctionItem {
|
||||
let ast_fn = FCEAst::Function(AstFnItem {
|
||||
signature,
|
||||
original: Some(self),
|
||||
});
|
||||
@ -47,7 +47,7 @@ impl ParseMacroInput for syn::ItemFn {
|
||||
pub(super) fn try_to_ast_signature(
|
||||
signature: syn::Signature,
|
||||
visibility: syn::Visibility,
|
||||
) -> Result<fce_ast_types::AstFunctionSignature> {
|
||||
) -> Result<fce_ast_types::AstFnSignature> {
|
||||
use quote::ToTokens;
|
||||
|
||||
check_function(&signature)?;
|
||||
@ -76,7 +76,7 @@ pub(super) fn try_to_ast_signature(
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
let ty = ParsedType::from_type(pat.ty.as_ref())?;
|
||||
let ast_arg = AstFuncArgument { name, ty };
|
||||
let ast_arg = AstFnArgument { name, ty };
|
||||
|
||||
Ok(ast_arg)
|
||||
})
|
||||
@ -84,7 +84,7 @@ pub(super) fn try_to_ast_signature(
|
||||
|
||||
let output_type = ParsedType::from_return_type(&output)?;
|
||||
|
||||
let ast_function_item = fce_ast_types::AstFunctionSignature {
|
||||
let ast_function_item = fce_ast_types::AstFnSignature {
|
||||
visibility: Some(visibility),
|
||||
name: signature.ident.to_string(),
|
||||
arguments,
|
||||
@ -127,7 +127,7 @@ fn check_function(signature: &syn::Signature) -> Result<()> {
|
||||
}
|
||||
|
||||
fn check_parsed_functions<'a>(
|
||||
args: impl ExactSizeIterator<Item = (&'a AstFuncArgument, proc_macro2::Span)>,
|
||||
args: impl ExactSizeIterator<Item = (&'a AstFnArgument, proc_macro2::Span)>,
|
||||
) -> Result<()> {
|
||||
for (arg, span) in args {
|
||||
if contains_inner_ref(&arg.ty) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
use super::ParsedType;
|
||||
use crate::fce_ast_types::AstFuncArgument;
|
||||
use crate::fce_ast_types::AstFnArgument;
|
||||
use crate::wasm_type::RustType;
|
||||
|
||||
/// This trait could be used to generate raw args needed to construct a export function.
|
||||
@ -23,7 +23,7 @@ pub(crate) trait FnArgGlueCodeGenerator {
|
||||
fn generate_arguments(&self) -> Vec<RustType>;
|
||||
}
|
||||
|
||||
impl FnArgGlueCodeGenerator for AstFuncArgument {
|
||||
impl FnArgGlueCodeGenerator for AstFnArgument {
|
||||
fn generate_arguments(&self) -> Vec<RustType> {
|
||||
match self.ty {
|
||||
ParsedType::Boolean(_) => vec![RustType::I32],
|
||||
|
@ -18,7 +18,7 @@ use super::ParsedType;
|
||||
use super::passing_style_of;
|
||||
use super::PassingStyle;
|
||||
use crate::new_ident;
|
||||
use crate::fce_ast_types::AstFuncArgument;
|
||||
use crate::fce_ast_types::AstFnArgument;
|
||||
|
||||
use quote::quote;
|
||||
|
||||
@ -32,7 +32,7 @@ pub(crate) struct FnEpilogDescriptor {
|
||||
|
||||
/// Contains all ingredients needed for epilog creation.
|
||||
pub(crate) struct FnEpilogIngredients<'i> {
|
||||
pub(crate) args: &'i [AstFuncArgument],
|
||||
pub(crate) args: &'i [AstFnArgument],
|
||||
pub(crate) converted_args: &'i [syn::Ident],
|
||||
pub(crate) return_type: &'i Option<ParsedType>,
|
||||
}
|
||||
@ -157,7 +157,7 @@ fn generate_mem_forgets(ingredients: &FnEpilogIngredients<'_>) -> proc_macro2::T
|
||||
}
|
||||
|
||||
fn mem_forget_by_args(
|
||||
args: &[AstFuncArgument],
|
||||
args: &[AstFnArgument],
|
||||
converted_args: &[syn::Ident],
|
||||
) -> proc_macro2::TokenStream {
|
||||
debug_assert!(args.len() == converted_args.len());
|
||||
|
@ -19,7 +19,7 @@ use super::FnArgGlueCodeGenerator;
|
||||
use super::passing_style_of;
|
||||
use crate::new_ident;
|
||||
use crate::wasm_type::RustType;
|
||||
use crate::fce_ast_types::AstFuncArgument;
|
||||
use crate::fce_ast_types::AstFnArgument;
|
||||
use crate::parsed_type::PassingStyle;
|
||||
|
||||
use quote::quote;
|
||||
@ -48,7 +48,7 @@ pub(crate) trait FnPrologGlueCodeGenerator {
|
||||
fn generate_prolog(&self) -> FnPrologDescriptor;
|
||||
}
|
||||
|
||||
impl FnPrologGlueCodeGenerator for Vec<AstFuncArgument> {
|
||||
impl FnPrologGlueCodeGenerator for Vec<AstFnArgument> {
|
||||
fn generate_prolog(&self) -> FnPrologDescriptor {
|
||||
let mut raw_arg_names = Vec::with_capacity(self.len());
|
||||
let mut raw_arg_types = Vec::with_capacity(self.len());
|
||||
|
@ -18,7 +18,7 @@ use super::ParsedType;
|
||||
use crate::wasm_type::RustType;
|
||||
use crate::new_ident;
|
||||
use crate::parsed_type::PassingStyle;
|
||||
use crate::fce_ast_types::AstFuncArgument;
|
||||
use crate::fce_ast_types::AstFnArgument;
|
||||
|
||||
pub(crate) struct WrapperDescriptor {
|
||||
pub(crate) arg_names: Vec<syn::Ident>,
|
||||
@ -59,7 +59,7 @@ pub(crate) trait ForeignModPrologGlueCodeGenerator {
|
||||
fn generate_extern_prolog(&self) -> ExternDescriptor;
|
||||
}
|
||||
|
||||
impl ForeignModPrologGlueCodeGenerator for Vec<AstFuncArgument> {
|
||||
impl ForeignModPrologGlueCodeGenerator for Vec<AstFnArgument> {
|
||||
fn generate_wrapper_prolog(&self) -> WrapperDescriptor {
|
||||
use crate::parsed_type::foreign_mod_arg::ForeignModArgGlueCodeGenerator;
|
||||
use quote::ToTokens;
|
||||
|
@ -25,7 +25,7 @@ use crate::new_ident;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
|
||||
impl quote::ToTokens for fce_ast_types::AstFunctionItem {
|
||||
impl quote::ToTokens for fce_ast_types::AstFnItem {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
crate::prepare_global_data!(
|
||||
Function,
|
||||
|
Loading…
Reference in New Issue
Block a user