mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
housekeeping
This commit is contained in:
parent
a448f03ed4
commit
4b6f6d9111
@ -21,8 +21,16 @@ use super::log;
|
||||
/// The allocated memory region is intended to be use as a Vec.
|
||||
#[no_mangle]
|
||||
pub unsafe fn allocate(elem_count: usize, elem_ty: usize) -> usize {
|
||||
let allocated_mem = allocate_impl(elem_count, elem_ty);
|
||||
if elem_count == 0 {
|
||||
// otherwise 1 would be returned thanks to the internals of Vec in Rust
|
||||
return 0;
|
||||
}
|
||||
|
||||
let allocated_mem = allocate_impl(elem_count, elem_ty);
|
||||
println!(
|
||||
"sdk.allocate: {} {} -> {}\n",
|
||||
elem_count, elem_ty, allocated_mem
|
||||
);
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!(
|
||||
"sdk.allocate: {} {} -> {}\n",
|
||||
|
@ -22,7 +22,7 @@ mod foreign_mod_epilog;
|
||||
mod foreign_mod_prolog;
|
||||
mod traits;
|
||||
mod utils;
|
||||
mod vector_utils;
|
||||
mod vector_ser_der;
|
||||
|
||||
pub(crate) use fn_arg::*;
|
||||
pub(crate) use fn_epilog::*;
|
||||
@ -30,7 +30,7 @@ pub(crate) use fn_prolog::*;
|
||||
pub(crate) use foreign_mod_prolog::*;
|
||||
pub(crate) use foreign_mod_epilog::*;
|
||||
pub(crate) use utils::*;
|
||||
pub(crate) use vector_utils::*;
|
||||
pub(crate) use vector_ser_der::*;
|
||||
|
||||
use serde::Serialize;
|
||||
use serde::Deserialize;
|
||||
|
@ -116,14 +116,11 @@ fn generate_epilog(ty: &Option<ParsedType>) -> proc_macro2::TokenStream {
|
||||
fluence::internal::set_result_size(result.len() as _);
|
||||
}
|
||||
}
|
||||
Some(ParsedType::Vector(ty, passing_style)) => {
|
||||
Some(ParsedType::Vector(ty, _)) => {
|
||||
let generated_serializer_name = "__fce_generated_vec_serializer";
|
||||
let generated_serializer_ident = new_ident!(generated_serializer_name);
|
||||
let vector_serializer = super::vector_utils::generate_vector_serializer(
|
||||
ty,
|
||||
*passing_style,
|
||||
generated_serializer_name,
|
||||
);
|
||||
let vector_serializer =
|
||||
super::vector_ser_der::generate_vector_ser(ty, generated_serializer_name);
|
||||
|
||||
quote! {
|
||||
#vector_serializer
|
||||
|
@ -135,7 +135,7 @@ fn generate_type_lifting_prolog(
|
||||
let generated_der_ident = new_ident!(generated_der_name);
|
||||
|
||||
let vector_deserializer =
|
||||
super::vector_utils::generate_vector_deserializer(ty, &generated_der_name);
|
||||
super::vector_ser_der::generate_vector_der(ty, &generated_der_name);
|
||||
|
||||
quote! {
|
||||
#vector_deserializer
|
||||
|
@ -60,7 +60,7 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
|
||||
let generated_der_name = "__fce_generated_vec_deserializer";
|
||||
let generated_der_ident = new_ident!(generated_der_name);
|
||||
let vector_deserializer =
|
||||
super::vector_utils::generate_vector_deserializer(ty, generated_der_name);
|
||||
super::vector_ser_der::generate_vector_der(ty, generated_der_name);
|
||||
|
||||
quote! {
|
||||
#vector_deserializer
|
||||
|
@ -80,8 +80,8 @@ impl ForeignModPrologGlueCodeGenerator for Vec<AstFnArgument> {
|
||||
arg_transforms.extend(quote::quote! { let mut #arg_ident = std::mem::ManuallyDrop::new(#arg_ident); });
|
||||
arg_drops.extend(quote::quote! { std::mem::ManuallyDrop::drop(&mut #arg_ident); });
|
||||
},
|
||||
ParsedType::Vector(ty, passing_style) => {
|
||||
let vec_arg_transforms = vector_arg_transforms(ty, *passing_style, &arg_name);
|
||||
ParsedType::Vector(ty, _) => {
|
||||
let vec_arg_transforms = vector_arg_transforms(ty, &arg_name);
|
||||
arg_transforms.extend(vec_arg_transforms);
|
||||
}
|
||||
_ => {}
|
||||
@ -127,18 +127,13 @@ impl ForeignModPrologGlueCodeGenerator for Vec<AstFnArgument> {
|
||||
}
|
||||
}
|
||||
|
||||
fn vector_arg_transforms(
|
||||
ty: &ParsedType,
|
||||
passing_style: PassingStyle,
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
fn vector_arg_transforms(ty: &ParsedType, arg_name: &str) -> proc_macro2::TokenStream {
|
||||
let generated_ser_name = format!("__fce_generated_vec_serializer_{}", arg_name);
|
||||
let generated_ser_name = crate::utils::prepare_ident(generated_ser_name);
|
||||
let generated_ser_ident = new_ident!(generated_ser_name);
|
||||
let arg_ident = new_ident!(arg_name);
|
||||
|
||||
let vector_serializer =
|
||||
super::vector_utils::generate_vector_serializer(ty, passing_style, &generated_ser_name);
|
||||
let vector_serializer = super::vector_ser_der::generate_vector_ser(ty, &generated_ser_name);
|
||||
|
||||
let arg_transform = quote::quote! {
|
||||
#vector_serializer
|
||||
|
88
crates/wit/src/parsed_type/vector_ser_der.rs
Normal file
88
crates/wit/src/parsed_type/vector_ser_der.rs
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mod der;
|
||||
mod ser;
|
||||
|
||||
use ser::*;
|
||||
use der::*;
|
||||
use super::ParsedType;
|
||||
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn generate_vector_ser(
|
||||
value_ty: &ParsedType,
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let values_ser = match value_ty {
|
||||
ParsedType::Boolean(_)
|
||||
| ParsedType::I8(_)
|
||||
| ParsedType::U8(_)
|
||||
| ParsedType::I16(_)
|
||||
| ParsedType::U16(_)
|
||||
| ParsedType::I32(_)
|
||||
| ParsedType::U32(_)
|
||||
| ParsedType::I64(_)
|
||||
| ParsedType::U64(_)
|
||||
| ParsedType::F32(_)
|
||||
| ParsedType::F64(_) => {
|
||||
quote! {
|
||||
(arg.as_ptr() as _, arg.len() as _)
|
||||
}
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => string_ser(),
|
||||
ParsedType::Vector(ty, _) => vector_ser(arg_name, ty),
|
||||
ParsedType::Record(..) => record_ser(),
|
||||
};
|
||||
|
||||
let arg = crate::new_ident!(arg_name);
|
||||
|
||||
quote! {
|
||||
unsafe fn #arg(arg: &Vec<#value_ty>) -> (u32, u32) {
|
||||
#values_ser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn generate_vector_der(
|
||||
value_ty: &ParsedType,
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let arg = crate::new_ident!(arg_name);
|
||||
|
||||
let values_deserializer = match value_ty {
|
||||
ParsedType::Boolean(_) => {
|
||||
quote! {
|
||||
let arg: Vec<u8> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
arg.into_iter().map(|v| v != 0).collect::<Vec<bool>>()
|
||||
}
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => string_der(),
|
||||
ParsedType::Vector(ty, _) => vector_der(arg_name, ty),
|
||||
ParsedType::Record(record_name, _) => record_der(record_name),
|
||||
_ => {
|
||||
quote! {
|
||||
Vec::from_raw_parts(offset as _, size as _, size as _)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
unsafe fn #arg(offset: u32, size: u32) -> Vec<#value_ty> {
|
||||
#values_deserializer
|
||||
}
|
||||
}
|
||||
}
|
78
crates/wit/src/parsed_type/vector_ser_der/der.rs
Normal file
78
crates/wit/src/parsed_type/vector_ser_der/der.rs
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::ParsedType;
|
||||
|
||||
use quote::quote;
|
||||
|
||||
pub(super) fn string_der() -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut arg = arg.into_iter();
|
||||
let mut result = Vec::with_capacity(arg.len() / 2);
|
||||
|
||||
while let Some(offset) = arg.next() {
|
||||
let size = arg.next().unwrap();
|
||||
let value = String::from_raw_parts(offset as _, size as _, size as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn vector_der(arg_name: &str, ty: &ParsedType) -> proc_macro2::TokenStream {
|
||||
let deserializer_name = format!("{}_{}", arg_name, ty);
|
||||
let deserializer_name = crate::utils::prepare_ident(deserializer_name);
|
||||
let deserializer_ident = crate::new_ident!(deserializer_name);
|
||||
|
||||
let inner_vector_deserializer = super::generate_vector_der(&*ty, &deserializer_name);
|
||||
|
||||
quote! {
|
||||
#inner_vector_deserializer
|
||||
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
let size = arg.next().unwrap();
|
||||
|
||||
let value = #deserializer_ident(offset as _, size as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn record_der(record_name: &str) -> proc_macro2::TokenStream {
|
||||
let record_name_ident = crate::new_ident!(record_name);
|
||||
|
||||
quote! {
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
for offset in arg {
|
||||
let value = #record_name_ident::__fce_generated_deserialize(offset as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
77
crates/wit/src/parsed_type/vector_ser_der/ser.rs
Normal file
77
crates/wit/src/parsed_type/vector_ser_der/ser.rs
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use super::ParsedType;
|
||||
|
||||
use quote::quote;
|
||||
|
||||
pub(super) fn string_ser() -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
let mut result: Vec<u32> = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(value.as_ptr() as _);
|
||||
result.push(value.len() as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn vector_ser(arg_name: &str, ty: &ParsedType) -> proc_macro2::TokenStream {
|
||||
let ser_name = format!("{}_{}", arg_name, ty);
|
||||
let ser_name = crate::utils::prepare_ident(ser_name);
|
||||
let ser_ident = crate::new_ident!(ser_name);
|
||||
|
||||
let inner_vector_ser = super::generate_vector_ser(ty, &ser_name);
|
||||
|
||||
quote! {
|
||||
#inner_vector_ser
|
||||
|
||||
let mut result: Vec<u32> = Vec::with_capacity(2 * arg.len());
|
||||
for value in arg {
|
||||
let (ptr, size) = #ser_ident(&value);
|
||||
result.push(ptr as _);
|
||||
result.push(size as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn record_ser() -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
let mut result: Vec<u32> = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(value.__fce_generated_serialize() as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use super::ParsedType;
|
||||
use super::PassingStyle;
|
||||
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn generate_vector_serializer(
|
||||
value_ty: &ParsedType,
|
||||
_vec_passing_style: PassingStyle,
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let values_serializer = match value_ty {
|
||||
ParsedType::Boolean(_)
|
||||
| ParsedType::I8(_)
|
||||
| ParsedType::U8(_)
|
||||
| ParsedType::I16(_)
|
||||
| ParsedType::U16(_)
|
||||
| ParsedType::I32(_)
|
||||
| ParsedType::U32(_)
|
||||
| ParsedType::I64(_)
|
||||
| ParsedType::U64(_)
|
||||
| ParsedType::F32(_)
|
||||
| ParsedType::F64(_) => {
|
||||
quote! {
|
||||
(arg.as_ptr() as _, arg.len() as _)
|
||||
}
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => {
|
||||
quote! {
|
||||
let mut result: Vec<u32> = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(value.as_ptr() as _);
|
||||
result.push(value.len() as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
||||
ParsedType::Vector(ty, passing_style) => {
|
||||
let ser_name = format!("{}_{}", arg_name, ty);
|
||||
let ser_name = crate::utils::prepare_ident(ser_name);
|
||||
let ser_ident = crate::new_ident!(ser_name);
|
||||
|
||||
let inner_vector_ser = generate_vector_serializer(&*ty, *passing_style, &ser_name);
|
||||
|
||||
quote! {
|
||||
#inner_vector_ser
|
||||
|
||||
let mut result: Vec<u32> = Vec::with_capacity(2 * arg.len());
|
||||
for value in arg {
|
||||
let (ptr, size) = #ser_ident(&value);
|
||||
result.push(ptr as _);
|
||||
result.push(size as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
||||
|
||||
ParsedType::Record(..) => {
|
||||
quote! {
|
||||
let mut result: Vec<u32> = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(value.__fce_generated_serialize() as _);
|
||||
}
|
||||
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let arg = crate::new_ident!(arg_name);
|
||||
|
||||
quote! {
|
||||
unsafe fn #arg(arg: &Vec<#value_ty>) -> (u32, u32) {
|
||||
#values_serializer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn generate_vector_deserializer(
|
||||
value_ty: &ParsedType,
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let arg = crate::new_ident!(arg_name);
|
||||
|
||||
let values_deserializer = match value_ty {
|
||||
ParsedType::Boolean(_) => {
|
||||
quote! {
|
||||
let arg: Vec<u8> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
arg.into_iter().map(|v| v == 1).collect::<Vec<bool>>()
|
||||
}
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => {
|
||||
quote! {
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut arg = arg.into_iter();
|
||||
let mut result = Vec::with_capacity(arg.len() / 2);
|
||||
|
||||
while let Some(offset) = arg.next() {
|
||||
let size = arg.next().unwrap();
|
||||
let value = String::from_raw_parts(offset as _, size as _, size as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
ParsedType::Vector(ty, _) => {
|
||||
let deserializer_name = format!("{}_{}", arg_name, ty);
|
||||
let deserializer_name = crate::utils::prepare_ident(deserializer_name);
|
||||
let deserializer_ident = crate::new_ident!(deserializer_name);
|
||||
|
||||
let inner_vector_deserializer = generate_vector_deserializer(&*ty, &deserializer_name);
|
||||
|
||||
quote! {
|
||||
#inner_vector_deserializer
|
||||
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
let size = arg.next().unwrap();
|
||||
|
||||
let value = #deserializer_ident(offset as _, size as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
ParsedType::Record(record_name, _) => {
|
||||
let record_name_ident = crate::new_ident!(record_name);
|
||||
|
||||
quote! {
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
for offset in arg {
|
||||
let value = #record_name_ident::__fce_generated_deserialize(offset as _);
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
quote! {
|
||||
Vec::from_raw_parts(offset as _, size as _, size as _)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
unsafe fn #arg(offset: u32, size: u32) -> Vec<#value_ty> {
|
||||
#values_deserializer
|
||||
}
|
||||
}
|
||||
}
|
@ -96,14 +96,14 @@ impl FieldValuesBuilder {
|
||||
fn bool_der(&mut self, field: &syn::Ident) -> TokenStream {
|
||||
let value_id = self.value_id;
|
||||
let result = quote! { let #field = raw_record[#value_id] != 0; };
|
||||
self.value_id += 1;
|
||||
self.value_id += std::mem::size_of::<u8>();
|
||||
result
|
||||
}
|
||||
|
||||
fn i8_der(&mut self, field: &syn::Ident) -> TokenStream {
|
||||
let value_id = self.value_id;
|
||||
let result = quote! { let #field = raw_record[#value_id] as i8; };
|
||||
self.value_id += 1;
|
||||
self.value_id += std::mem::size_of::<i8>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 2;
|
||||
self.value_id += std::mem::size_of::<i16>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 4;
|
||||
self.value_id += std::mem::size_of::<i32>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -147,14 +147,14 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 8;
|
||||
self.value_id += std::mem::size_of::<i64>();
|
||||
result
|
||||
}
|
||||
|
||||
fn u8_der(&mut self, field: &syn::Ident) -> TokenStream {
|
||||
let value_id = self.value_id;
|
||||
let result = quote! { let #field = raw_record[#value_id] as u8; };
|
||||
self.value_id += 1;
|
||||
self.value_id += std::mem::size_of::<u8>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 2;
|
||||
self.value_id += std::mem::size_of::<u16>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 4;
|
||||
self.value_id += std::mem::size_of::<u32>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 8;
|
||||
self.value_id += std::mem::size_of::<u64>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 4;
|
||||
self.value_id += std::mem::size_of::<f32>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ impl FieldValuesBuilder {
|
||||
]);
|
||||
};
|
||||
|
||||
self.value_id += 8;
|
||||
self.value_id += std::mem::size_of::<f64>();
|
||||
result
|
||||
}
|
||||
|
||||
@ -267,8 +267,7 @@ impl FieldValuesBuilder {
|
||||
let generated_der_name = crate::utils::prepare_ident(generated_der_name);
|
||||
let generated_der_ident = new_ident!(generated_der_name);
|
||||
|
||||
let vector_deserializer =
|
||||
crate::parsed_type::generate_vector_deserializer(ty, &generated_der_name);
|
||||
let vector_deserializer = crate::parsed_type::generate_vector_der(ty, &generated_der_name);
|
||||
|
||||
let value_id = self.value_id;
|
||||
|
||||
@ -312,7 +311,7 @@ impl FieldValuesBuilder {
|
||||
let #field = #record_ident::__fce_generated_deserialize(offset as _);
|
||||
};
|
||||
|
||||
self.value_id += 4;
|
||||
self.value_id += std::mem::size_of::<u32>();
|
||||
|
||||
result
|
||||
}
|
||||
|
@ -50,24 +50,21 @@ impl RecordSerGlueCodeGenerator for AstRecordItem {
|
||||
raw_record.extend(&(#field_ident.len() as u32).to_le_bytes());
|
||||
}
|
||||
}
|
||||
ParsedType::Vector(ty, passing_style) => {
|
||||
let generated_serializer_name = format!(
|
||||
ParsedType::Vector(ty, _) => {
|
||||
let generated_ser_name = format!(
|
||||
"__fce_generated_vec_serializer_{}_{}",
|
||||
field.name.as_ref().unwrap(),
|
||||
id
|
||||
);
|
||||
|
||||
let generated_serializer_ident = new_ident!(generated_serializer_name);
|
||||
let vector_serializer = crate::parsed_type::generate_vector_serializer(
|
||||
ty,
|
||||
*passing_style,
|
||||
&generated_serializer_name,
|
||||
);
|
||||
let generated_ser_ident = new_ident!(generated_ser_name);
|
||||
let vector_ser =
|
||||
crate::parsed_type::generate_vector_ser(ty, &generated_ser_name);
|
||||
let serialized_field_ident = new_ident!(format!("serialized_arg_{}", id));
|
||||
|
||||
quote::quote! {
|
||||
#vector_serializer
|
||||
let #serialized_field_ident = unsafe { #generated_serializer_ident(&#field_ident) };
|
||||
#vector_ser
|
||||
let #serialized_field_ident = unsafe { #generated_ser_ident(&#field_ident) };
|
||||
|
||||
raw_record.extend(&#serialized_field_ident.0.to_le_bytes());
|
||||
raw_record.extend(&#serialized_field_ident.1.to_le_bytes());
|
||||
|
@ -83,7 +83,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -94,7 +94,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -105,7 +105,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u3
|
||||
result.push(value.len() as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -62,7 +62,7 @@ pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u3
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -74,7 +74,7 @@ pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u3
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -85,7 +85,7 @@ pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u3
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl CallParameters {
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -110,7 +110,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
@ -121,7 +121,7 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
result.push(size as _);
|
||||
}
|
||||
let result_ptr = result.as_ptr();
|
||||
let result_len = result.len();
|
||||
let result_len = result.len() / 2;
|
||||
fluence::internal::add_object_to_release(Box::new(result));
|
||||
(result_ptr as _, result_len as _)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user