@@ -5,21 +5,18 @@ 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 ;
89use interpreter:: simd:: exec_next_simd;
910use interpreter:: stack:: CallFrame ;
1011use tinywasm_types:: * ;
1112
12- #[ cfg( feature = "async" ) ]
13- use coro:: SuspendReason ;
14-
1513use super :: num_helpers:: * ;
1614use super :: stack:: { BlockFrame , BlockType , Stack } ;
1715use super :: values:: * ;
1816use crate :: * ;
1917
2018pub ( crate ) enum ReasonToBreak {
2119 Errored ( Error ) ,
22- #[ cfg_attr( not( feature = "async" ) , allow( unused) ) ]
2320 Suspended ( SuspendReason ) ,
2421 Finished ,
2522}
@@ -31,20 +28,18 @@ impl From<ReasonToBreak> for ControlFlow<ReasonToBreak> {
3128}
3229
3330#[ derive( Debug ) ]
34- #[ cfg_attr( not( feature = "async" ) , allow( unused) ) ]
3531pub ( crate ) struct SuspendedHostCoroState {
3632 pub ( crate ) coro_state : Box < dyn HostCoroState > ,
3733 // plug into used in store.get_func to get original function
3834 // can be used for checking returned types
39- #[ allow( dead_code) ] // knowing context is useful for debug and other possible future uses
35+ #[ allow( dead_code) ] // not implemented yet, but knowing context is useful
4036 pub ( crate ) coro_orig_function : u32 ,
4137}
4238
4339#[ derive( Debug ) ]
4440pub ( crate ) struct Executor < ' store , ' stack > {
4541 pub ( crate ) cf : CallFrame ,
4642 pub ( crate ) module : ModuleInstance ,
47- #[ cfg( feature = "async" ) ]
4843 pub ( crate ) suspended_host_coro : Option < SuspendedHostCoroState > ,
4944 pub ( crate ) store : & ' store mut Store ,
5045 pub ( crate ) stack : & ' stack mut Stack ,
@@ -56,14 +51,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
5651 pub ( crate ) fn new ( store : & ' store mut Store , stack : & ' stack mut Stack ) -> Result < Self > {
5752 let current_frame = stack. call_stack . pop ( ) . expect ( "no call frame, this is a bug" ) ;
5853 let current_module = store. get_module_instance_raw ( current_frame. module_addr ( ) ) ;
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- } )
54+ Ok ( Self { cf : current_frame, module : current_module, suspended_host_coro : None , stack, store } )
6755 }
6856
6957 #[ inline( always) ]
@@ -79,7 +67,6 @@ impl<'store, 'stack> Executor<'store, 'stack> {
7967 }
8068 }
8169
82- #[ cfg( feature = "async" ) ]
8370 #[ inline( always) ]
8471 pub ( crate ) fn resume ( & mut self , res_arg : ResumeArgument ) -> Result < ExecOutcome > {
8572 if let Some ( coro_state) = self . suspended_host_coro . as_mut ( ) {
@@ -118,7 +105,6 @@ impl<'store, 'stack> Executor<'store, 'stack> {
118105 /// execution may not be suspended in the middle of execution the funcion:
119106 /// so only do it as the last thing or first thing in the intsruction execution
120107 #[ must_use = "If this returns ControlFlow::Break, the caller should propagate it" ]
121- #[ cfg( feature = "async" ) ]
122108 fn check_should_suspend ( & mut self ) -> ControlFlow < ReasonToBreak > {
123109 if let Some ( flag) = & self . store . suspend_cond . suspend_flag {
124110 if flag. load ( core:: sync:: atomic:: Ordering :: Acquire ) {
@@ -144,11 +130,6 @@ impl<'store, 'stack> Executor<'store, 'stack> {
144130 ControlFlow :: Continue ( ( ) )
145131 }
146132
147- #[ cfg( not( feature = "async" ) ) ]
148- fn check_should_suspend ( & mut self ) -> ControlFlow < ReasonToBreak > {
149- ControlFlow :: Continue ( ( ) )
150- }
151-
152133 #[ inline( always) ]
153134 fn exec_next ( & mut self ) -> ControlFlow < ReasonToBreak > {
154135 use tinywasm_types:: Instruction :: * ;
@@ -433,7 +414,7 @@ impl<'store, 'stack> Executor<'store, 'stack> {
433414 self . module . swap_with ( self . cf . module_addr ( ) , self . store ) ;
434415 ControlFlow :: Continue ( ( ) )
435416 }
436- fn exec_call_host ( & mut self , host_func : Rc < HostFunction > , _func_ref : u32 ) -> ControlFlow < ReasonToBreak > {
417+ fn exec_call_host ( & mut self , host_func : Rc < HostFunction > , func_ref : u32 ) -> ControlFlow < ReasonToBreak > {
437418 let params = self . stack . values . pop_params ( & host_func. ty . params ) ;
438419 let res = host_func. call ( FuncContext { store : self . store , module_addr : self . module . id ( ) } , & params) . to_cf ( ) ?;
439420 match res {
@@ -443,10 +424,9 @@ impl<'store, 'stack> Executor<'store, 'stack> {
443424 self . check_should_suspend ( ) ?; // who knows how long we've spent in host function
444425 ControlFlow :: Continue ( ( ) )
445426 }
446- #[ cfg( feature = "async" ) ]
447427 PotentialCoroCallResult :: Suspended ( suspend_reason, state) => {
448428 self . suspended_host_coro =
449- Some ( SuspendedHostCoroState { coro_state : state, coro_orig_function : _func_ref } ) ;
429+ Some ( SuspendedHostCoroState { coro_state : state, coro_orig_function : func_ref } ) ;
450430 self . cf . incr_instr_ptr ( ) ;
451431 ReasonToBreak :: Suspended ( suspend_reason) . into ( )
452432 }
0 commit comments