@@ -8,7 +8,7 @@ use value_stack::Stack;
88
99use crate :: core:: reader:: types:: { FuncType , ResultType } ;
1010use crate :: execution:: assert_validated:: UnwrapValidatedExt ;
11- use crate :: execution:: config:: { Config , DefaultConfig } ;
11+ use crate :: execution:: config:: Config ;
1212use crate :: execution:: store:: Store ;
1313use crate :: execution:: value:: Value ;
1414use crate :: interop:: InteropValueList ;
@@ -32,50 +32,46 @@ pub mod value_stack;
3232/// The default module name if a [RuntimeInstance] was created using [RuntimeInstance::new].
3333pub const DEFAULT_MODULE : & str = "__interpreter_default__" ;
3434
35- pub struct RuntimeInstance < ' b , T = ( ) , C = DefaultConfig >
35+ pub struct RuntimeInstance < ' b , C = ( ) >
3636where
37- C : Config + core :: fmt :: Debug ,
37+ C : Config ,
3838{
39- pub config : C ,
40- pub store : Store < ' b , T > ,
39+ pub store : Store < ' b , C > ,
4140}
4241
43- impl < T : Default > Default for RuntimeInstance < ' _ , T , DefaultConfig > {
42+ impl Default for RuntimeInstance < ' _ , ( ) > {
4443 fn default ( ) -> Self {
45- Self :: new ( T :: default ( ) )
44+ Self :: new ( ( ) )
4645 }
4746}
4847
49- impl < ' b , T > RuntimeInstance < ' b , T , DefaultConfig > {
50- pub fn new ( user_data : T ) -> Self {
51- Self :: new_with_config ( user_data, DefaultConfig )
48+ impl < ' b , C : Config > RuntimeInstance < ' b , C > {
49+ pub fn new ( config : C ) -> Self {
50+ RuntimeInstance {
51+ store : Store :: new ( config) ,
52+ }
5253 }
5354
5455 pub fn new_with_default_module (
55- user_data : T ,
56+ config : C ,
5657 validation_info : & ' _ ValidationInfo < ' b > ,
5758 ) -> Result < Self , RuntimeError > {
58- let mut instance = Self :: new_with_config ( user_data , DefaultConfig ) ;
59+ let mut instance = Self :: new ( config ) ;
5960 instance. add_module ( DEFAULT_MODULE , validation_info) ?;
6061 Ok ( instance)
6162 }
6263
6364 pub fn new_named (
64- user_data : T ,
65+ config : C ,
6566 module_name : & str ,
6667 validation_info : & ' _ ValidationInfo < ' b > ,
6768 // store: &mut Store,
6869 ) -> Result < Self , RuntimeError > {
69- let mut instance = Self :: new_with_config ( user_data , DefaultConfig ) ;
70+ let mut instance = Self :: new ( config ) ;
7071 instance. add_module ( module_name, validation_info) ?;
7172 Ok ( instance)
7273 }
73- }
7474
75- impl < ' b , T , C > RuntimeInstance < ' b , T , C >
76- where
77- C : Config + core:: fmt:: Debug ,
78- {
7975 pub fn add_module (
8076 & mut self ,
8177 module_name : & str ,
8480 self . store . add_module ( module_name, validation_info, None )
8581 }
8682
87- pub fn new_with_config ( user_data : T , config : C ) -> Self {
88- RuntimeInstance {
89- config,
90- store : Store :: new ( user_data) ,
91- }
92- }
93-
9483 pub fn get_function_by_name (
9584 & self ,
9685 module_name : & str ,
@@ -196,7 +185,7 @@ where
196185 & mut self ,
197186 module_name : & str ,
198187 name : & str ,
199- host_func : fn ( & mut T , Vec < Value > ) -> Vec < Value > ,
188+ host_func : fn ( & mut C , Vec < Value > ) -> Vec < Value > ,
200189 ) -> Result < FunctionRef , RuntimeError > {
201190 let host_func_ty = FuncType {
202191 params : ResultType {
@@ -214,7 +203,7 @@ where
214203 module_name : & str ,
215204 name : & str ,
216205 host_func_ty : FuncType ,
217- host_func : fn ( & mut T , Vec < Value > ) -> Vec < Value > ,
206+ host_func : fn ( & mut C , Vec < Value > ) -> Vec < Value > ,
218207 ) -> Result < FunctionRef , RuntimeError > {
219208 let func_addr = self . store . alloc_host_func ( host_func_ty, host_func) ;
220209 self . store . registry . register (
@@ -225,11 +214,11 @@ where
225214 Ok ( FunctionRef { func_addr } )
226215 }
227216
228- pub fn user_data ( & self ) -> & T {
217+ pub fn config ( & self ) -> & C {
229218 & self . store . user_data
230219 }
231220
232- pub fn user_data_mut ( & mut self ) -> & mut T {
221+ pub fn config_mut ( & mut self ) -> & mut C {
233222 & mut self . store . user_data
234223 }
235224}
0 commit comments