@@ -35,6 +35,7 @@ use hyperlight_component_util::hl::{
3535 emit_hl_unmarshal_result,
3636} ;
3737use hyperlight_component_util:: { resource, rtypes} ;
38+ use proc_macro:: Ident ;
3839use proc_macro2:: TokenStream ;
3940use quote:: { format_ident, quote} ;
4041use syn:: ext:: IdentExt ;
@@ -154,7 +155,6 @@ fn emit_export_extern_decl<'a, 'b, 'c>(
154155 . iter ( )
155156 . map ( |p| rtypes:: emit_value ( s, & p. ty ) )
156157 . collect :: < Vec < _ > > ( ) ;
157- let rwt = rtypes:: emit_func_result ( s, & ft. result ) ;
158158 let ( pds, pus) = ft. params . iter ( ) . enumerate ( )
159159 . map ( |( i, p) | {
160160 let id = kebab_to_var ( p. name . name ) ;
@@ -166,7 +166,7 @@ fn emit_export_extern_decl<'a, 'b, 'c>(
166166 let get_instance = path. iter ( ) . map ( |export| quote ! {
167167 let instance_idx = Some ( instance. get_export( & mut * store, instance_idx. as_ref( ) , #export) . unwrap( ) ) ;
168168 } ) . collect :: < Vec < _ > > ( ) ;
169- let ret = format_ident ! ( "ret" ) ;
169+ let ( function_call , ret) = emit_wasm_function_call ( s , & ft . result , pwts , pus ) ;
170170 let marshal_result = emit_hl_marshal_result ( s, ret. clone ( ) , & ft. result ) ;
171171 quote ! {
172172 fn #n( fc: & :: hyperlight_common:: flatbuffer_wrappers:: function_call:: FunctionCall ) -> :: hyperlight_guest:: error:: Result <:: alloc:: vec:: Vec <u8 >> {
@@ -176,8 +176,7 @@ fn emit_export_extern_decl<'a, 'b, 'c>(
176176 let instance_idx = None ;
177177 #( #get_instance; ) *
178178 let func_idx = instance. get_export( & mut * store, instance_idx. as_ref( ) , #nlit) . unwrap( ) ;
179- let #ret = instance. get_typed_func:: <( #( #pwts, ) * ) , ( #rwt, ) >( & mut * store, func_idx) ?
180- . call( & mut * store, ( #( #pus, ) * ) ) ?. 0 ;
179+ #function_call
181180 :: core:: result:: Result :: Ok ( :: hyperlight_common:: flatbuffer_wrappers:: util:: get_flatbuffer_result:: <& [ u8 ] >( & #marshal_result) )
182181 }
183182 :: hyperlight_guest_bin:: guest_function:: register:: register_function(
@@ -206,6 +205,34 @@ fn emit_export_extern_decl<'a, 'b, 'c>(
206205 }
207206}
208207
208+ fn emit_wasm_function_call (
209+ s : & mut State ,
210+ result : & etypes:: Result ,
211+ pwts : Vec < TokenStream > ,
212+ pus : Vec < TokenStream > ,
213+ ) -> ( TokenStream , proc_macro2:: Ident ) {
214+ let ret = format_ident ! ( "ret" ) ;
215+
216+ // if the result is empty we don't want a return result with `get_typed_func`
217+ let rwt = match result {
218+ etypes:: Result :: Named ( rs) if rs. is_empty ( ) => {
219+ quote ! {
220+ instance. get_typed_func:: <( #( #pwts, ) * ) , ( ) >( & mut * store, func_idx) ?
221+ . call( & mut * store, ( #( #pus, ) * ) ) ?;
222+ }
223+ }
224+ _ => {
225+ let r = rtypes:: emit_func_result ( s, result) ;
226+ quote ! {
227+ let #ret = instance. get_typed_func:: <( #( #pwts, ) * ) , ( ( #r, ) ) >( & mut * store, func_idx) ?
228+ . call( & mut * store, ( #( #pus, ) * ) ) ?. 0 ;
229+ }
230+ }
231+ } ;
232+
233+ ( rwt, ret)
234+ }
235+
209236// Emit code to register each export of the given instance with the
210237// wasmtime linker, calling through Hyperlight.
211238//
0 commit comments