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