allow struct to be defined in a separate mod

This commit is contained in:
vms 2020-07-27 23:03:31 +03:00
parent 689c389cc7
commit 039082a938
7 changed files with 14 additions and 11 deletions

View File

@ -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 _);
}
}

View File

@ -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!(

View File

@ -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 },

View File

@ -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!(

View File

@ -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
}
}

View File

@ -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 _);
}
}
};

View File

@ -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! {