Clean up a bit of duplication in codegen

This commit is contained in:
Alex Crichton
2018-03-31 09:38:31 -07:00
parent 7880545b3b
commit 9bc2718943

View File

@ -415,36 +415,32 @@ impl ToTokens for ast::ImportFunction {
abi_arguments.push(my_quote! { abi_arguments.push(my_quote! {
#name: <#t as ::wasm_bindgen::convert::WasmBoundary>::Abi #name: <#t as ::wasm_bindgen::convert::WasmBoundary>::Abi
}); });
if i == 0 && is_method { let var = if i == 0 && is_method {
arg_conversions.push(my_quote! { quote! { self }
let #name = <#t as ::wasm_bindgen::convert::WasmBoundary>
::into_abi(self, &mut __stack);
});
} else { } else {
quote! { #name }
};
arg_conversions.push(my_quote! { arg_conversions.push(my_quote! {
let #name = <#t as ::wasm_bindgen::convert::WasmBoundary> let #name = <#t as ::wasm_bindgen::convert::WasmBoundary>
::into_abi(#name, &mut __stack); ::into_abi(#name, &mut __stack);
}); });
} }
}
ast::Type::ByMutRef(_) => panic!("urgh mut"), ast::Type::ByMutRef(_) => panic!("urgh mut"),
ast::Type::ByRef(ref t) => { ast::Type::ByRef(ref t) => {
abi_argument_names.push(name); abi_argument_names.push(name);
abi_arguments.push(my_quote! { #name: u32 }); abi_arguments.push(my_quote! { #name: u32 });
if i == 0 && is_method { let var = if i == 0 && is_method {
arg_conversions.push(my_quote! { quote! { self }
let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary>
::to_abi_ref(self, &mut __stack);
});
} else { } else {
quote! { #name }
};
arg_conversions.push(my_quote! { arg_conversions.push(my_quote! {
let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary> let #name = <#t as ::wasm_bindgen::convert::ToRefWasmBoundary>
::to_abi_ref(#name, &mut __stack); ::to_abi_ref(#var, &mut __stack);
}); });
} }
} }
} }
}
let abi_ret; let abi_ret;
let mut convert_ret; let mut convert_ret;
match self.function.ret { match self.function.ret {