replaced hand-written with generated

This commit is contained in:
NikVolf 2016-03-29 22:15:45 +03:00
parent bd377e1f28
commit 34f6c1f2f1
2 changed files with 31 additions and 33 deletions

View File

@ -112,7 +112,7 @@ fn push_invoke_signature_aster(
(None, vec![], vec![]) (None, vec![], vec![])
}; };
let return_type_name = match signature.decl.output { let (return_type_name, return_type_ty) = match signature.decl.output {
FunctionRetTy::Ty(ref ty) => { FunctionRetTy::Ty(ref ty) => {
let name_str = format!("{}_output", implement.ident.name.as_str()); let name_str = format!("{}_output", implement.ident.name.as_str());
let tree = builder.item() let tree = builder.item()
@ -121,9 +121,9 @@ fn push_invoke_signature_aster(
.struct_(name_str.as_str()) .struct_(name_str.as_str())
.field(format!("payload")).ty().build(ty.clone()); .field(format!("payload")).ty().build(ty.clone());
push(Annotatable::Item(tree.build())); push(Annotatable::Item(tree.build()));
Some(name_str.to_owned()) (Some(name_str.to_owned()), Some(ty.clone()))
} }
_ => None _ => (None, None)
}; };
Dispatch { Dispatch {
@ -132,6 +132,7 @@ fn push_invoke_signature_aster(
input_arg_names: input_arg_names, input_arg_names: input_arg_names,
input_arg_tys: input_arg_tys, input_arg_tys: input_arg_tys,
return_type_name: return_type_name, return_type_name: return_type_name,
return_type_ty: return_type_ty,
} }
} }
@ -141,6 +142,7 @@ struct Dispatch {
input_arg_names: Vec<String>, input_arg_names: Vec<String>,
input_arg_tys: Vec<P<Ty>>, input_arg_tys: Vec<P<Ty>>,
return_type_name: Option<String>, return_type_name: Option<String>,
return_type_ty: Option<P<Ty>>,
} }
fn implement_dispatch_arm_invoke( fn implement_dispatch_arm_invoke(
@ -337,16 +339,30 @@ fn implement_proxy_method_body(
vec![] vec![]
}; };
let output_type_id = builder.id(dispatch.return_type_name.clone().unwrap().as_str()); let wait_result_stmt = quote_stmt!(cx, while !socket.ready().load(::std::sync::atomic::Ordering::Relaxed) { });
let invariant_serialization = quote_expr!(cx, { if let Some(ref return_ty) = dispatch.return_type_ty {
while !socket.ready().load(::std::sync::atomic::Ordering::Relaxed) { } let return_expr = quote_expr!(cx,
::bincode::serde::deserialize_from::<_, $output_type_id>(&mut socket, ::bincode::SizeLimit::Infinite).unwrap() ::bincode::serde::deserialize_from::<_, $return_ty>(&mut socket, ::bincode::SizeLimit::Infinite).unwrap()
}); );
quote_expr!(cx, {
$request
$wait_result_stmt
$return_expr
})
}
else {
quote_expr!(cx, {
$request
$wait_result_stmt
})
}
//let output_type_id = builder.id(dispatch.return_type_name.clone().unwrap().as_str());
// let invariant_serialization = quote_expr!(cx, {
//
//
// });
quote_expr!(cx, {
$request
$invariant_serialization
})
} }
fn implement_proxy_method( fn implement_proxy_method(
@ -376,7 +392,7 @@ fn implement_proxy_method(
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::BinOp(::syntax::parse::token::And))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::BinOp(::syntax::parse::token::And)));
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Ident(ext_cx.ident_of("self"), ::syntax::parse::token::Plain))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Ident(ext_cx.ident_of("self"), ::syntax::parse::token::Plain)));
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Comma)); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::Comma));
for arg_idx in 0..dispatch.input_arg_names.len() { for arg_idx in 0..dispatch.input_arg_names.len() {
let arg_name = dispatch.input_arg_names[arg_idx].as_str(); let arg_name = dispatch.input_arg_names[arg_idx].as_str();
let arg_ty = dispatch.input_arg_tys[arg_idx].clone(); let arg_ty = dispatch.input_arg_tys[arg_idx].clone();
@ -388,10 +404,9 @@ fn implement_proxy_method(
} }
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::CloseDelim(::syntax::parse::token::Paren))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::CloseDelim(::syntax::parse::token::Paren)));
if let Some(ref return_name) = dispatch.return_type_name { if let Some(ref return_ty) = dispatch.return_type_ty {
let return_ident = builder.id(return_name);
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::RArrow)); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::RArrow));
tt.extend(::quasi::ToTokens::to_tokens(&return_ident, ext_cx).into_iter()); tt.extend(::quasi::ToTokens::to_tokens(return_ty, ext_cx).into_iter());
} }
tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::OpenDelim(::syntax::parse::token::Brace))); tt.push(::syntax::ast::TokenTree::Token(_sp, ::syntax::parse::token::OpenDelim(::syntax::parse::token::Brace)));

View File

@ -37,23 +37,6 @@ impl Service {
} }
impl<S: ::ipc::IpcSocket> ServiceProxy<S> { impl<S: ::ipc::IpcSocket> ServiceProxy<S> {
pub fn commit(&self, f: u32) -> u32 {
#[derive(Serialize)]
struct Request<'a> {
f: &'a u32,
}
let payload = Request{ f: &f, };
let mut socket_ref = self.socket.borrow_mut();
let mut socket = socket_ref.deref_mut();
let serialized_payload = ::bincode::serde::serialize(&payload, ::bincode::SizeLimit::Infinite).unwrap();
::ipc::invoke(0, &Some(serialized_payload), &mut socket);
while !socket.ready().load(::std::sync::atomic::Ordering::Relaxed) { }
::bincode::serde::deserialize_from::<_, u32>(&mut socket, ::bincode::SizeLimit::Infinite).unwrap()
}
pub fn new(socket: S) -> ServiceProxy<S> { pub fn new(socket: S) -> ServiceProxy<S> {
ServiceProxy { ServiceProxy {
socket: ::std::cell::RefCell::new(socket), socket: ::std::cell::RefCell::new(socket),