add support of complex types to a foreign items

This commit is contained in:
vms 2020-07-26 14:19:16 +03:00
parent 057be9a9b7
commit 7e1197b49b
4 changed files with 17 additions and 6 deletions

View File

@ -28,7 +28,7 @@ impl ForeignModArgGlueCodeGenerator for ParsedType {
let arg = crate::new_ident!(format!("arg_{}", arg_start_id));
match self {
ParsedType::Utf8String | ParsedType::ByteVector => {
ParsedType::Utf8String | ParsedType::ByteVector | ParsedType::Record(_) => {
quote! { #arg.as_ptr() as _, #arg.len() as _ }
}
_ => quote! { arg },

View File

@ -58,7 +58,18 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
fluence::internal::get_result_size() as _
)
},
Some(ParsedType::Record(_)) => unimplemented!(),
Some(ParsedType::Record(record_name)) => {
let record_deserializer = crate::new_ident!(
crate::token_stream_generator::GENERATED_RECORD_DESERIALIZER_PREFIX.to_string()
+ record_name
);
quote! {
#record_deserializer(
fluence::internal::get_result_ptr() as _,
fluence::internal::get_result_size() as _,
);
}
}
_ => panic!(
"perhaps new type's been added to ParsedType, and this match became incomplete"
),

View File

@ -120,11 +120,11 @@ impl RecordDeserializerGlueCodeGenerator for fce_ast_types::AstRecordItem {
let ptr_id = value_id;
let size_id = value_id + 1;
value_id += 1;
let deserializer_name =
let record_deserializer =
new_ident!(GENERATED_RECORD_DESERIALIZER_PREFIX.to_string() + record_name);
quote! {
let #field = #deserializer_name(raw_record[#ptr_id] as _, raw_record[#size_id] as _);
let #field = #record_deserializer(raw_record[#ptr_id] as _, raw_record[#size_id] as _);
}
}
};

View File

@ -50,10 +50,10 @@ impl RecordSerializerGlueCodeGenerator for fce_ast_types::AstRecordItem {
}
}
ParsedType::Record(record_name) => {
let serializer_name =
let record_serializer =
new_ident!(GENERATED_RECORD_SERIALIZER_PREFIX.to_string() + &record_name);
quote! {
raw_record.push(#serializer_name(#field_ident) as _);
raw_record.push(#record_serializer(#field_ident) as _);
}
}
_ => quote! {