@@ -5,18 +5,21 @@ use super::no_std_floats::NoStdFloatExt;
55use alloc:: boxed:: Box ;
66use alloc:: { format, rc:: Rc , string:: ToString } ;
77use core:: ops:: ControlFlow ;
8- use coro:: SuspendReason ;
98use interpreter:: simd:: exec_next_simd;
109use interpreter:: stack:: CallFrame ;
1110use tinywasm_types:: * ;
1211
12+ #[ cfg( feature = "async" ) ]
13+ use coro:: SuspendReason ;
14+
1315use super :: num_helpers:: * ;
1416use super :: stack:: { BlockFrame , BlockType , Stack } ;
1517use super :: values:: * ;
1618use crate :: * ;
1719
1820pub ( crate ) enum ReasonToBreak {
1921 Errored ( Error ) ,
22+ #[ cfg_attr( not( feature = "async" ) , allow( unused) ) ]
2023 Suspended ( SuspendReason ) ,
2124 Finished ,
2225}
@@ -28,18 +31,20 @@ impl From<ReasonToBreak> for ControlFlow<ReasonToBreak> {
2831}
2932
3033#[ derive( Debug ) ]
34+ #[ cfg_attr( not( feature = "async" ) , allow( unused) ) ]
3135pub ( crate ) struct SuspendedHostCoroState {
3236 pub ( crate ) coro_state : Box < dyn HostCoroState > ,
3337 // plug into used in store.get_func to get original function
3438 // can be used for checking returned types
35- #[ allow( dead_code) ] // not implemented yet, but knowing context is useful
39+ #[ allow( dead_code) ] // knowing context is useful for debug and other possible future uses
3640 pub ( crate ) coro_orig_function : u32 ,
3741}
3842
3943#[ derive( Debug ) ]
4044pub ( crate ) struct Executor < ' store , ' stack > {
4145 pub ( crate ) cf : CallFrame ,
4246 pub ( crate ) module : ModuleInstance ,
47+ #[ cfg( feature = "async" ) ]
4348 pub ( crate ) suspended_host_coro : Option < SuspendedHostCoroState > ,
4449 pub ( crate ) store : & ' store mut Store ,
4550 pub ( crate ) stack : & ' stack mut Stack ,
@@ -51,7 +56,14 @@ impl<'store, 'stack> Executor<'store, 'stack> {
5156 pub ( crate ) fn new ( store : & ' store mut Store , stack : & ' stack mut Stack ) -> Result < Self > {
5257 let current_frame = stack. call_stack . pop ( ) . expect ( "no call frame, this is a bug" ) ;
5358 let current_module = store. get_module_instance_raw ( current_frame. module_addr ( ) ) ;
54- Ok ( Self { cf : current_frame, module : current_module, suspended_host_coro : None , stack, store } )
59+ Ok ( Self {
60+ cf : current_frame,
61+ module : current_module,
62+ #[ cfg( feature = "async" ) ]
63+ suspended_host_coro : None ,
64+ stack,
65+ store,
66+ } )
5567 }
5668
5769 #[ inline( always) ]
@@ -67,6 +79,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
6779 }
6880 }
6981
82+ #[ cfg( feature = "async" ) ]
7083 #[ inline( always) ]
7184 pub ( crate ) fn resume ( & mut self , res_arg : ResumeArgument ) -> Result < ExecOutcome > {
7285 if let Some ( coro_state) = self . suspended_host_coro . as_mut ( ) {
@@ -105,6 +118,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
105118 /// execution may not be suspended in the middle of execution the funcion:
106119 /// so only do it as the last thing or first thing in the intsruction execution
107120 #[ must_use = "If this returns ControlFlow::Break, the caller should propagate it" ]
121+ #[ cfg( feature = "async" ) ]
108122 fn check_should_suspend ( & mut self ) -> ControlFlow < ReasonToBreak > {
109123 if let Some ( flag) = & self . store . suspend_cond . suspend_flag {
110124 if flag. load ( core:: sync:: atomic:: Ordering :: Acquire ) {
@@ -130,6 +144,11 @@ impl<'store, 'stack> Executor<'store, 'stack> {
130144 ControlFlow :: Continue ( ( ) )
131145 }
132146
147+ #[ cfg( not( feature = "async" ) ) ]
148+ fn check_should_suspend ( & mut self ) -> ControlFlow < ReasonToBreak > {
149+ ControlFlow :: Continue ( ( ) )
150+ }
151+
133152 #[ inline( always) ]
134153 fn exec_next ( & mut self ) -> ControlFlow < ReasonToBreak > {
135154 use tinywasm_types:: Instruction :: * ;
@@ -414,7 +433,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
414433 self . module . swap_with ( self . cf . module_addr ( ) , self . store ) ;
415434 ControlFlow :: Continue ( ( ) )
416435 }
417- fn exec_call_host ( & mut self , host_func : Rc < HostFunction > , func_ref : u32 ) -> ControlFlow < ReasonToBreak > {
436+ fn exec_call_host ( & mut self , host_func : Rc < HostFunction > , _func_ref : u32 ) -> ControlFlow < ReasonToBreak > {
418437 let params = self . stack . values . pop_params ( & host_func. ty . params ) ;
419438 let res = host_func. call ( FuncContext { store : self . store , module_addr : self . module . id ( ) } , & params) . to_cf ( ) ?;
420439 match res {
@@ -424,9 +443,10 @@ impl<'store, 'stack> Executor<'store, 'stack> {
424443 self . check_should_suspend ( ) ?; // who knows how long we've spent in host function
425444 ControlFlow :: Continue ( ( ) )
426445 }
446+ #[ cfg( feature = "async" ) ]
427447 PotentialCoroCallResult :: Suspended ( suspend_reason, state) => {
428448 self . suspended_host_coro =
429- Some ( SuspendedHostCoroState { coro_state : state, coro_orig_function : func_ref } ) ;
449+ Some ( SuspendedHostCoroState { coro_state : state, coro_orig_function : _func_ref } ) ;
430450 self . cf . incr_instr_ptr ( ) ;
431451 ReasonToBreak :: Suspended ( suspend_reason) . into ( )
432452 }
0 commit comments