mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
allow struct to be defined in a separate mod
This commit is contained in:
parent
689c389cc7
commit
039082a938
@ -98,10 +98,10 @@ fn generate_epilog(ty: &Option<ParsedType>) -> proc_macro2::TokenStream {
|
||||
return result as _;
|
||||
},
|
||||
Some(ParsedType::Record(record_name)) => {
|
||||
let serializer =
|
||||
let record_serializer =
|
||||
crate::new_ident!(GENERATED_RECORD_SERIALIZER_PREFIX.to_string() + record_name);
|
||||
quote! {
|
||||
let result_ptr = #serializer(result);
|
||||
let result_ptr = crate::#record_serializer(result);
|
||||
fluence::internal::set_result_ptr(result_ptr as _);
|
||||
}
|
||||
}
|
||||
|
@ -106,11 +106,11 @@ fn generate_type_prolog(
|
||||
let #generated_arg_id = Vec::from_raw_parts(#ptr as _, #size as _, #size as _);
|
||||
},
|
||||
ParsedType::Record(record_name) => {
|
||||
let deserializer = crate::new_ident!(
|
||||
let record_deserializer = crate::new_ident!(
|
||||
GENERATED_RECORD_DESERIALIZER_PREFIX.to_string() + record_name
|
||||
);
|
||||
quote! {
|
||||
let #generated_arg_id = #deserializer(#ptr);
|
||||
let #generated_arg_id = crate::#record_deserializer(#ptr);
|
||||
}
|
||||
}
|
||||
_ => panic!(
|
||||
|
@ -32,12 +32,12 @@ impl ForeignModArgGlueCodeGenerator for ParsedType {
|
||||
quote! { #arg.as_ptr() as _, #arg.len() as _ }
|
||||
}
|
||||
ParsedType::Record(record_name) => {
|
||||
let serializer = crate::new_ident!(
|
||||
let record_serializer = crate::new_ident!(
|
||||
crate::token_stream_generator::GENERATED_RECORD_SERIALIZER_PREFIX.to_string()
|
||||
+ record_name
|
||||
);
|
||||
quote! {
|
||||
#serializer(#arg)
|
||||
crate::#record_serializer(#arg)
|
||||
}
|
||||
}
|
||||
_ => quote! { arg },
|
||||
|
@ -64,7 +64,7 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
|
||||
+ record_name
|
||||
);
|
||||
quote! {
|
||||
#record_deserializer(fluence::internal::get_result_ptr() as _)
|
||||
crate::#record_deserializer(fluence::internal::get_result_ptr() as _)
|
||||
}
|
||||
}
|
||||
_ => panic!(
|
||||
|
@ -76,7 +76,7 @@ fn generate_serializer_fn(record: &fce_ast_types::AstRecordItem) -> proc_macro2:
|
||||
} = record.generate_serializer(&record.name);
|
||||
|
||||
quote::quote! {
|
||||
pub(crate) fn #serializer_fn_name(record: #record_type) -> i32 {
|
||||
pub(in crate) fn #serializer_fn_name(record: #record_type) -> i32 {
|
||||
let mut raw_record = Vec::new();
|
||||
|
||||
#serializer
|
||||
@ -103,11 +103,13 @@ fn generate_deserializer_fn(record: &fce_ast_types::AstRecordItem) -> proc_macro
|
||||
crate::utils::get_record_size(record.fields.iter().map(|ast_field| &ast_field.ty));
|
||||
|
||||
quote::quote! {
|
||||
unsafe fn #deserializer_fn_name(offset: i32) -> #return_type {
|
||||
pub(in crate) unsafe fn #deserializer_fn_name(offset: i32) -> #return_type {
|
||||
let raw_record: Vec<u64> = Vec::from_raw_parts(offset as _, #record_size, #record_size);
|
||||
|
||||
#deserializer
|
||||
|
||||
std::mem::forget(raw_record);
|
||||
|
||||
#type_constructor
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ impl RecordDeserializerGlueCodeGenerator for fce_ast_types::AstRecordItem {
|
||||
new_ident!(GENERATED_RECORD_DESERIALIZER_PREFIX.to_string() + record_name);
|
||||
|
||||
quote! {
|
||||
let #field = #record_deserializer(raw_record[#ptr_id] as _);
|
||||
let #field = crate::#record_deserializer(raw_record[#ptr_id] as _);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -47,13 +47,14 @@ impl RecordSerializerGlueCodeGenerator for fce_ast_types::AstRecordItem {
|
||||
quote! {
|
||||
raw_record.push(#field_ident.as_ptr() as _);
|
||||
raw_record.push(#field_ident.len() as _);
|
||||
std::mem::forget(#field_ident);
|
||||
}
|
||||
}
|
||||
ParsedType::Record(record_name) => {
|
||||
let record_serializer =
|
||||
new_ident!(GENERATED_RECORD_SERIALIZER_PREFIX.to_string() + &record_name);
|
||||
quote! {
|
||||
raw_record.push(#record_serializer(#field_ident) as _);
|
||||
raw_record.push(crate::#record_serializer(#field_ident) as _);
|
||||
}
|
||||
}
|
||||
_ => quote! {
|
||||
|
Loading…
Reference in New Issue
Block a user