1
- #![ allow( dead_code) ] // TODO: remove this
2
-
3
1
use core:: {
4
2
cell:: RefCell ,
5
3
sync:: atomic:: { AtomicUsize , Ordering } ,
6
4
} ;
7
5
8
6
use alloc:: { format, rc:: Rc , string:: ToString , vec, vec:: Vec } ;
9
- use tinywasm_types:: {
10
- Addr , Data , DataAddr , ElemAddr , Element , ElementKind , FuncAddr , Global , GlobalType , MemAddr , MemoryArch ,
11
- MemoryType , ModuleInstanceAddr , TableAddr , TableType , WasmFunction ,
12
- } ;
7
+ use tinywasm_types:: * ;
13
8
14
9
use crate :: {
15
10
runtime:: { self , DefaultRuntime } ,
@@ -49,7 +44,7 @@ impl Store {
49
44
Self :: default ( )
50
45
}
51
46
52
- pub ( crate ) fn get_module_instance ( & self , addr : ModuleInstanceAddr ) -> Option < & ModuleInstance > {
47
+ pub ( crate ) fn _get_module_instance ( & self , addr : ModuleInstanceAddr ) -> Option < & ModuleInstance > {
53
48
self . module_instances . get ( addr as usize )
54
49
}
55
50
@@ -118,7 +113,7 @@ impl Store {
118
113
let func_count = self . data . funcs . len ( ) ;
119
114
let mut func_addrs = Vec :: with_capacity ( func_count) ;
120
115
for ( i, func) in funcs. into_iter ( ) . enumerate ( ) {
121
- self . data . funcs . push ( Rc :: new ( FunctionInstance { func : Function :: Wasm ( func) , owner : idx } ) ) ;
116
+ self . data . funcs . push ( Rc :: new ( FunctionInstance { func : Function :: Wasm ( func) , _owner : idx } ) ) ;
122
117
func_addrs. push ( ( i + func_count) as FuncAddr ) ;
123
118
}
124
119
Ok ( func_addrs)
@@ -155,9 +150,13 @@ impl Store {
155
150
pub ( crate ) fn init_globals ( & mut self , globals : Vec < Global > , idx : ModuleInstanceAddr ) -> Result < Vec < Addr > > {
156
151
let global_count = self . data . globals . len ( ) ;
157
152
let mut global_addrs = Vec :: with_capacity ( global_count) ;
158
- // then add the module globals
159
153
for ( i, global) in globals. iter ( ) . enumerate ( ) {
160
- global_addrs. push ( self . add_global ( global. ty , self . eval_const ( & global. init ) ?, idx) ?. into ( ) ) ;
154
+ self . data . globals . push ( Rc :: new ( RefCell :: new ( GlobalInstance :: new (
155
+ global. ty ,
156
+ self . eval_const ( & global. init ) ?,
157
+ idx,
158
+ ) ) ) ) ;
159
+ global_addrs. push ( ( i + global_count) as Addr ) ;
161
160
}
162
161
163
162
Ok ( global_addrs)
@@ -287,27 +286,8 @@ impl Store {
287
286
Ok ( self . data . mems . len ( ) as MemAddr - 1 )
288
287
}
289
288
290
- pub ( crate ) fn add_elem ( & mut self , elem : Element , idx : ModuleInstanceAddr ) -> Result < ElemAddr > {
291
- let init = elem
292
- . items
293
- . iter ( )
294
- . map ( |item| {
295
- item. addr ( )
296
- . ok_or_else ( || Error :: UnsupportedFeature ( format ! ( "const expression other than ref: {:?}" , item) ) )
297
- } )
298
- . collect :: < Result < Vec < _ > > > ( ) ?;
299
-
300
- self . data . elems . push ( ElemInstance :: new ( elem. kind , idx, Some ( init) ) ) ;
301
- Ok ( self . data . elems . len ( ) as ElemAddr - 1 )
302
- }
303
-
304
- pub ( crate ) fn add_data ( & mut self , data : Data , idx : ModuleInstanceAddr ) -> Result < DataAddr > {
305
- self . data . datas . push ( DataInstance :: new ( data. data . to_vec ( ) , idx) ) ;
306
- Ok ( self . data . datas . len ( ) as DataAddr - 1 )
307
- }
308
-
309
289
pub ( crate ) fn add_func ( & mut self , func : Function , idx : ModuleInstanceAddr ) -> Result < FuncAddr > {
310
- self . data . funcs . push ( Rc :: new ( FunctionInstance { func, owner : idx } ) ) ;
290
+ self . data . funcs . push ( Rc :: new ( FunctionInstance { func, _owner : idx } ) ) ;
311
291
Ok ( self . data . funcs . len ( ) as FuncAddr - 1 )
312
292
}
313
293
@@ -362,10 +342,6 @@ impl Store {
362
342
self . data . tables . get ( addr) . ok_or_else ( || Error :: Other ( format ! ( "table {} not found" , addr) ) )
363
343
}
364
344
365
- pub ( crate ) fn get_elem ( & self , addr : usize ) -> Result < & ElemInstance > {
366
- self . data . elems . get ( addr) . ok_or_else ( || Error :: Other ( format ! ( "element {} not found" , addr) ) )
367
- }
368
-
369
345
/// Get the global at the actual index in the store
370
346
pub ( crate ) fn get_global_val ( & self , addr : usize ) -> Result < RawWasmValue > {
371
347
self . data
@@ -390,7 +366,7 @@ impl Store {
390
366
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#function-instances>
391
367
pub struct FunctionInstance {
392
368
pub ( crate ) func : Function ,
393
- pub ( crate ) owner : ModuleInstanceAddr , // index into store.module_instances, none for host functions
369
+ pub ( crate ) _owner : ModuleInstanceAddr , // index into store.module_instances, none for host functions
394
370
}
395
371
396
372
// TODO: check if this actually helps
@@ -415,14 +391,14 @@ impl FunctionInstance {
415
391
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#table-instances>
416
392
#[ derive( Debug ) ]
417
393
pub ( crate ) struct TableInstance {
418
- pub ( crate ) kind : TableType ,
419
394
pub ( crate ) elements : Vec < Addr > ,
420
- pub ( crate ) owner : ModuleInstanceAddr , // index into store.module_instances
395
+ pub ( crate ) _kind : TableType ,
396
+ pub ( crate ) _owner : ModuleInstanceAddr , // index into store.module_instances
421
397
}
422
398
423
399
impl TableInstance {
424
400
pub ( crate ) fn new ( kind : TableType , owner : ModuleInstanceAddr ) -> Self {
425
- Self { elements : vec ! [ 0 ; kind. size_initial as usize ] , kind, owner }
401
+ Self { elements : vec ! [ 0 ; kind. size_initial as usize ] , _kind : kind, _owner : owner }
426
402
}
427
403
428
404
pub ( crate ) fn get ( & self , addr : usize ) -> Result < Addr > {
@@ -468,7 +444,7 @@ pub(crate) struct MemoryInstance {
468
444
pub ( crate ) kind : MemoryType ,
469
445
pub ( crate ) data : Vec < u8 > ,
470
446
pub ( crate ) page_count : usize ,
471
- pub ( crate ) owner : ModuleInstanceAddr , // index into store.module_instances
447
+ pub ( crate ) _owner : ModuleInstanceAddr , // index into store.module_instances
472
448
}
473
449
474
450
impl MemoryInstance {
@@ -480,7 +456,7 @@ impl MemoryInstance {
480
456
kind,
481
457
data : vec ! [ 0 ; PAGE_SIZE * kind. page_count_initial as usize ] ,
482
458
page_count : kind. page_count_initial as usize ,
483
- owner,
459
+ _owner : owner,
484
460
}
485
461
}
486
462
@@ -556,14 +532,14 @@ impl MemoryInstance {
556
532
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#global-instances>
557
533
#[ derive( Debug ) ]
558
534
pub ( crate ) struct GlobalInstance {
559
- pub ( crate ) ty : GlobalType ,
560
535
pub ( crate ) value : RawWasmValue ,
561
- owner : ModuleInstanceAddr , // index into store.module_instances
536
+ pub ( crate ) _ty : GlobalType ,
537
+ pub ( crate ) _owner : ModuleInstanceAddr , // index into store.module_instances
562
538
}
563
539
564
540
impl GlobalInstance {
565
541
pub ( crate ) fn new ( ty : GlobalType , value : RawWasmValue , owner : ModuleInstanceAddr ) -> Self {
566
- Self { ty, value, owner }
542
+ Self { _ty : ty, value, _owner : owner }
567
543
}
568
544
}
569
545
@@ -572,14 +548,14 @@ impl GlobalInstance {
572
548
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#element-instances>
573
549
#[ derive( Debug ) ]
574
550
pub ( crate ) struct ElemInstance {
575
- kind : ElementKind ,
576
- items : Option < Vec < u32 > > , // none is the element was dropped
577
- owner : ModuleInstanceAddr , // index into store.module_instances
551
+ _kind : ElementKind ,
552
+ _items : Option < Vec < u32 > > , // none is the element was dropped
553
+ _owner : ModuleInstanceAddr , // index into store.module_instances
578
554
}
579
555
580
556
impl ElemInstance {
581
557
pub ( crate ) fn new ( kind : ElementKind , owner : ModuleInstanceAddr , items : Option < Vec < u32 > > ) -> Self {
582
- Self { kind, owner, items }
558
+ Self { _kind : kind, _owner : owner, _items : items }
583
559
}
584
560
}
585
561
@@ -588,12 +564,12 @@ impl ElemInstance {
588
564
/// See <https://webassembly.github.io/spec/core/exec/runtime.html#data-instances>
589
565
#[ derive( Debug ) ]
590
566
pub ( crate ) struct DataInstance {
591
- pub ( crate ) data : Vec < u8 > ,
592
- owner : ModuleInstanceAddr , // index into store.module_instances
567
+ pub ( crate ) _data : Vec < u8 > ,
568
+ pub ( crate ) _owner : ModuleInstanceAddr , // index into store.module_instances
593
569
}
594
570
595
571
impl DataInstance {
596
572
pub ( crate ) fn new ( data : Vec < u8 > , owner : ModuleInstanceAddr ) -> Self {
597
- Self { data, owner }
573
+ Self { _data : data, _owner : owner }
598
574
}
599
575
}
0 commit comments