(&mut self, func: &Function)
| 695 | } |
| 696 | |
| 697 | fn export(&mut self, func: &Function) { |
| 698 | // Determine if is async |
| 699 | let async_ = self |
| 700 | .world_gen |
| 701 | .opts |
| 702 | .async_ |
| 703 | .is_async(self.resolve, self.interface, func, false); |
| 704 | if async_ { |
| 705 | self.world_gen.async_support.mark_async(); |
| 706 | } |
| 707 | |
| 708 | // Generate declarations for user implementations. |
| 709 | { |
| 710 | let mbt_sig = self.world_gen.pkg_resolver.mbt_sig(self.name, func, false); |
| 711 | let func_sig = self.sig_string(&mbt_sig, async_); |
| 712 | |
| 713 | print_docs(&mut self.src, &func.docs); |
| 714 | uwrite!( |
| 715 | self.src, |
| 716 | r#" |
| 717 | declare {func_sig} |
| 718 | "# |
| 719 | ); |
| 720 | } |
| 721 | |
| 722 | // Generate the caller function |
| 723 | let variant = if async_ { |
| 724 | AbiVariant::GuestExportAsync |
| 725 | } else { |
| 726 | AbiVariant::GuestExport |
| 727 | }; |
| 728 | |
| 729 | let sig = self.resolve.wasm_signature(variant, func); |
| 730 | |
| 731 | let mut bindgen = FunctionBindgen::new( |
| 732 | self, |
| 733 | (0..sig.params.len()).map(|i| format!("p{i}")).collect(), |
| 734 | ); |
| 735 | |
| 736 | abi::call( |
| 737 | bindgen.interface_gen.resolve, |
| 738 | variant, |
| 739 | LiftLower::LiftArgsLowerResults, |
| 740 | func, |
| 741 | &mut bindgen, |
| 742 | async_, |
| 743 | ); |
| 744 | |
| 745 | // TODO: adapt async cleanup |
| 746 | assert!(!bindgen.needs_cleanup_list); |
| 747 | |
| 748 | // Async functions deferred task return |
| 749 | let deferred_task_return = bindgen.deferred_task_return.clone(); |
| 750 | |
| 751 | let src = bindgen.src; |
| 752 | |
| 753 | let result_type = match &sig.results[..] { |
| 754 | [] => "Unit", |
no test coverage detected