@@ -39,102 +39,58 @@ pub(crate) struct EngineInner {
3939 // pub(crate) allocator: Box<dyn Allocator + Send + Sync>,
4040}
4141
42- // pub(crate) trait Allocator {}
43- // pub(crate) struct DefaultAllocator;
44- // impl Allocator for DefaultAllocator {}
45-
4642/// Default initial size for the 32-bit value stack (i32, f32 values).
47- pub const DEFAULT_VALUE_STACK_32_INIT_SIZE : usize = 32 * 1024 ; // 32KB
43+ pub const DEFAULT_VALUE_STACK_32_SIZE : usize = 64 * 1024 ; // 64k slots
4844
4945/// Default initial size for the 64-bit value stack (i64, f64 values).
50- pub const DEFAULT_VALUE_STACK_64_INIT_SIZE : usize = 16 * 1024 ; // 16KB
46+ pub const DEFAULT_VALUE_STACK_64_SIZE : usize = 32 * 1024 ; // 32k slots
5147
5248/// Default initial size for the 128-bit value stack (v128 values).
53- pub const DEFAULT_VALUE_STACK_128_INIT_SIZE : usize = 8 * 1024 ; // 8KB
49+ pub const DEFAULT_VALUE_STACK_128_SIZE : usize = 4 * 1024 ; // 4k slots
5450
5551/// Default initial size for the reference value stack (funcref, externref values).
56- pub const DEFAULT_VALUE_STACK_REF_INIT_SIZE : usize = 1024 ; // 1KB
52+ pub const DEFAULT_VALUE_STACK_REF_SIZE : usize = 4 * 1024 ; // 4k slots
5753
58- /// Default initial size for the block stack.
59- pub const DEFAULT_BLOCK_STACK_INIT_SIZE : usize = 128 ;
54+ /// Default initial size for the block stack (control frames) .
55+ pub const DEFAULT_BLOCK_STACK_SIZE : usize = 1024 ; // 1024 frames
6056
61- /// Default initial size for the call stack.
62- pub const DEFAULT_CALL_STACK_INIT_SIZE : usize = 128 ;
57+ /// Default initial size for the call stack (function frames) .
58+ pub const DEFAULT_CALL_STACK_SIZE : usize = 1024 ; // 1024 frames
6359
6460/// Configuration for the WebAssembly interpreter
6561#[ derive( Debug , Clone ) ]
6662#[ non_exhaustive]
6763pub struct Config {
6864 /// Initial size of the 32-bit value stack (i32, f32 values).
69- pub stack_32_init_size : usize ,
65+ pub stack_32_size : usize ,
7066 /// Initial size of the 64-bit value stack (i64, f64 values).
71- pub stack_64_init_size : usize ,
67+ pub stack_64_size : usize ,
7268 /// Initial size of the 128-bit value stack (v128 values).
73- pub stack_128_init_size : usize ,
69+ pub stack_128_size : usize ,
7470 /// Initial size of the reference value stack (funcref, externref values).
75- pub stack_ref_init_size : usize ,
76- /// Optional maximum sizes for the stacks. If set, the interpreter will enforce these limits and return an error if they are exceeded.
77- pub stack_32_max_size : Option < usize > ,
78- /// Optional maximum sizes for the stacks. If set, the interpreter will enforce these limits and return an error if they are exceeded.
79- pub stack_64_max_size : Option < usize > ,
80- /// Optional maximum sizes for the stacks. If set, the interpreter will enforce these limits and return an error if they are exceeded.
81- pub stack_128_max_size : Option < usize > ,
82- /// Optional maximum sizes for the stacks. If set, the interpreter will enforce these limits and return an error if they are exceeded.
83- pub stack_ref_max_size : Option < usize > ,
84-
71+ pub stack_ref_size : usize ,
8572 /// Initial size of the call stack.
86- pub call_stack_init_size : usize ,
87- /// The maximum size of the call stack. If set, the interpreter will enforce this limit and return an error if it is exceeded.
88- pub call_stack_max_size : Option < usize > ,
89-
73+ pub call_stack_size : usize ,
9074 /// Initial size of the control stack (block stack).
91- pub block_stack_init_size : usize ,
92- /// Optional maximum size for the control stack (block stack). If set, the interpreter will enforce this limit and return an error if it is exceeded.
93- pub block_stack_max_size : Option < usize > ,
75+ pub block_stack_size : usize ,
9476}
9577
9678impl Config {
9779 /// Create a new stack configuration with default settings.
9880 pub fn new ( ) -> Self {
9981 Self :: default ( )
10082 }
101-
102- /// Set the same maximum size for all stacks. If set, the interpreter will enforce this limit and return an error if it is exceeded.
103- pub fn with_max_stack_size ( mut self , max_size : usize ) -> Self {
104- self . stack_32_max_size = Some ( max_size) ;
105- self . stack_64_max_size = Some ( max_size) ;
106- self . stack_128_max_size = Some ( max_size) ;
107- self . stack_ref_max_size = Some ( max_size) ;
108- self . block_stack_max_size = Some ( max_size) ;
109- self
110- }
111-
112- /// Set the same initial size for all stacks.
113- pub fn with_initial_stack_size ( mut self , init_size : usize ) -> Self {
114- self . stack_32_init_size = init_size;
115- self . stack_64_init_size = init_size;
116- self . stack_128_init_size = init_size;
117- self . stack_ref_init_size = init_size;
118- self . block_stack_init_size = init_size;
119- self
120- }
12183}
12284
12385impl Default for Config {
12486 fn default ( ) -> Self {
12587 Self {
126- stack_32_init_size : DEFAULT_VALUE_STACK_32_INIT_SIZE ,
127- stack_64_init_size : DEFAULT_VALUE_STACK_64_INIT_SIZE ,
128- stack_128_init_size : DEFAULT_VALUE_STACK_128_INIT_SIZE ,
129- stack_ref_init_size : DEFAULT_VALUE_STACK_REF_INIT_SIZE ,
130- block_stack_init_size : DEFAULT_BLOCK_STACK_INIT_SIZE ,
131- call_stack_init_size : DEFAULT_CALL_STACK_INIT_SIZE ,
132- call_stack_max_size : None ,
133- stack_32_max_size : None ,
134- stack_64_max_size : None ,
135- stack_128_max_size : None ,
136- stack_ref_max_size : None ,
137- block_stack_max_size : None ,
88+ stack_32_size : DEFAULT_VALUE_STACK_32_SIZE ,
89+ stack_64_size : DEFAULT_VALUE_STACK_64_SIZE ,
90+ stack_128_size : DEFAULT_VALUE_STACK_128_SIZE ,
91+ stack_ref_size : DEFAULT_VALUE_STACK_REF_SIZE ,
92+ call_stack_size : DEFAULT_CALL_STACK_SIZE ,
93+ block_stack_size : DEFAULT_BLOCK_STACK_SIZE ,
13894 }
13995 }
14096}
0 commit comments