@@ -768,7 +768,7 @@ pub mod vtable{ordinal} {{
768768 }
769769
770770 fn lower_to_memory ( & mut self , address : & str , value : & str , ty : & Type , module : & str ) -> String {
771- let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true ) ;
771+ let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true , false ) ;
772772 abi:: lower_to_memory ( f. r#gen . resolve , & mut f, address. into ( ) , value. into ( ) , ty) ;
773773 format ! ( "unsafe {{ {} }}" , String :: from( f. src) )
774774 }
@@ -780,7 +780,7 @@ pub mod vtable{ordinal} {{
780780 indirect : bool ,
781781 module : & str ,
782782 ) -> String {
783- let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true ) ;
783+ let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true , false ) ;
784784 abi:: deallocate_lists_in_types ( f. r#gen . resolve , types, operands, indirect, & mut f) ;
785785 format ! ( "unsafe {{ {} }}" , String :: from( f. src) )
786786 }
@@ -792,13 +792,13 @@ pub mod vtable{ordinal} {{
792792 indirect : bool ,
793793 module : & str ,
794794 ) -> String {
795- let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true ) ;
795+ let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true , false ) ;
796796 abi:: deallocate_lists_and_own_in_types ( f. r#gen . resolve , types, operands, indirect, & mut f) ;
797797 format ! ( "unsafe {{ {} }}" , String :: from( f. src) )
798798 }
799799
800800 fn lift_from_memory ( & mut self , address : & str , ty : & Type , module : & str ) -> String {
801- let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true ) ;
801+ let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true , false ) ;
802802 let result = abi:: lift_from_memory ( f. r#gen . resolve , & mut f, address. into ( ) , ty) ;
803803 format ! ( "unsafe {{ {}\n {result} }}" , String :: from( f. src) )
804804 }
@@ -809,7 +809,13 @@ pub mod vtable{ordinal} {{
809809 func : & Function ,
810810 params : Vec < String > ,
811811 ) {
812- let mut f = FunctionBindgen :: new ( self , params, module, false ) ;
812+ let mut f = FunctionBindgen :: new (
813+ self ,
814+ params,
815+ module,
816+ false ,
817+ self . r#gen . should_return_self ( func) ,
818+ ) ;
813819 abi:: call (
814820 f. r#gen . resolve ,
815821 AbiVariant :: GuestImport ,
@@ -1032,7 +1038,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
10321038 }
10331039 lowers. push ( "ParamsLower(_ptr,)" . to_string ( ) ) ;
10341040 } else {
1035- let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true ) ;
1041+ let mut f = FunctionBindgen :: new ( self , Vec :: new ( ) , module, true , false ) ;
10361042 let mut results = Vec :: new ( ) ;
10371043 for ( i, Param { ty, .. } ) in func. params . iter ( ) . enumerate ( ) {
10381044 let name = format ! ( "_lower{i}" ) ;
@@ -1078,8 +1084,13 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
10781084 }
10791085 uwriteln ! (
10801086 self . src,
1081- "_MySubtask {{ _unused: core::marker::PhantomData }}.call(({})).await" ,
1082- params. join( " " )
1087+ "_MySubtask {{ _unused: core::marker::PhantomData }}.call(({})).await{}" ,
1088+ params. join( " " ) ,
1089+ if self . r#gen. should_return_self( func) {
1090+ ";\n self"
1091+ } else {
1092+ ""
1093+ }
10831094 ) ;
10841095 }
10851096
@@ -1121,7 +1132,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
11211132 ) ;
11221133 }
11231134
1124- let mut f = FunctionBindgen :: new ( self , params, self . wasm_import_module , false ) ;
1135+ let mut f = FunctionBindgen :: new ( self , params, self . wasm_import_module , false , false ) ;
11251136 let variant = if async_ {
11261137 AbiVariant :: GuestExportAsync
11271138 } else {
@@ -1191,7 +1202,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
11911202 let params = self . print_post_return_sig ( func) ;
11921203 self . src . push_str ( "{ unsafe {\n " ) ;
11931204
1194- let mut f = FunctionBindgen :: new ( self , params, self . wasm_import_module , false ) ;
1205+ let mut f = FunctionBindgen :: new ( self , params, self . wasm_import_module , false , false ) ;
11951206 abi:: post_return ( f. r#gen . resolve , func, & mut f) ;
11961207 let FunctionBindgen {
11971208 needs_cleanup_list,
@@ -1451,7 +1462,11 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
14511462 }
14521463 }
14531464 } else {
1454- self . print_result_type ( & func. result ) ;
1465+ if self . r#gen . should_return_self ( func) {
1466+ self . push_str ( "&Self" ) ;
1467+ } else {
1468+ self . print_result_type ( & func. result ) ;
1469+ }
14551470 }
14561471 params
14571472 }
0 commit comments