@@ -38,7 +38,7 @@ pub(crate) fn convert_module_element(element: wasmparser::Element<'_>) -> Result
38
38
. collect :: < Result < Vec < _ > > > ( ) ?
39
39
. into_boxed_slice ( ) ;
40
40
41
- Ok ( tinywasm_types:: Element { kind, items, ty : convert_reftype ( & ty) , range : element. range } )
41
+ Ok ( tinywasm_types:: Element { kind, items, ty : convert_reftype ( ty) , range : element. range } )
42
42
}
43
43
}
44
44
}
@@ -76,23 +76,23 @@ pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Im
76
76
kind : match import. ty {
77
77
wasmparser:: TypeRef :: Func ( ty) => ImportKind :: Function ( ty) ,
78
78
wasmparser:: TypeRef :: Table ( ty) => ImportKind :: Table ( TableType {
79
- element_type : convert_reftype ( & ty. element_type ) ,
79
+ element_type : convert_reftype ( ty. element_type ) ,
80
80
size_initial : ty. initial . try_into ( ) . map_err ( |_| {
81
81
crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size initial is too large: {}" , ty. initial) )
82
82
} ) ?,
83
83
size_max : match ty. maximum {
84
84
Some ( max) => Some ( max. try_into ( ) . map_err ( |_| {
85
- crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {}" , max ) )
85
+ crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {max}" ) )
86
86
} ) ?) ,
87
87
None => None ,
88
88
} ,
89
89
} ) ,
90
- wasmparser:: TypeRef :: Memory ( ty) => ImportKind :: Memory ( convert_module_memory ( ty) ? ) ,
90
+ wasmparser:: TypeRef :: Memory ( ty) => ImportKind :: Memory ( convert_module_memory ( ty) ) ,
91
91
wasmparser:: TypeRef :: Global ( ty) => {
92
92
ImportKind :: Global ( GlobalType { mutable : ty. mutable , ty : convert_valtype ( & ty. content_type ) } )
93
93
}
94
94
wasmparser:: TypeRef :: Tag ( ty) => {
95
- return Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported import kind: {:?}" , ty ) ) )
95
+ return Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported import kind: {ty :?}" ) ) )
96
96
}
97
97
} ,
98
98
} )
@@ -101,18 +101,15 @@ pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Im
101
101
pub ( crate ) fn convert_module_memories < T : IntoIterator < Item = wasmparser:: Result < wasmparser:: MemoryType > > > (
102
102
memory_types : T ,
103
103
) -> Result < Vec < MemoryType > > {
104
- memory_types. into_iter ( ) . map ( |memory| convert_module_memory ( memory?) ) . collect :: < Result < Vec < _ > > > ( )
104
+ memory_types. into_iter ( ) . map ( |memory| Ok ( convert_module_memory ( memory?) ) ) . collect :: < Result < Vec < _ > > > ( )
105
105
}
106
106
107
- pub ( crate ) fn convert_module_memory ( memory : wasmparser:: MemoryType ) -> Result < MemoryType > {
108
- Ok ( MemoryType {
109
- arch : match memory. memory64 {
110
- true => MemoryArch :: I64 ,
111
- false => MemoryArch :: I32 ,
112
- } ,
107
+ pub ( crate ) fn convert_module_memory ( memory : wasmparser:: MemoryType ) -> MemoryType {
108
+ MemoryType {
109
+ arch : if memory. memory64 { MemoryArch :: I64 } else { MemoryArch :: I32 } ,
113
110
page_count_initial : memory. initial ,
114
111
page_count_max : memory. maximum ,
115
- } )
112
+ }
116
113
}
117
114
118
115
pub ( crate ) fn convert_module_tables < ' a , T : IntoIterator < Item = wasmparser:: Result < wasmparser:: Table < ' a > > > > (
@@ -129,12 +126,12 @@ pub(crate) fn convert_module_table(table: wasmparser::Table<'_>) -> Result<Table
129
126
let size_max = match table. ty . maximum {
130
127
Some ( max) => Some (
131
128
max. try_into ( )
132
- . map_err ( |_| crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {}" , max ) ) ) ?,
129
+ . map_err ( |_| crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {max}" ) ) ) ?,
133
130
) ,
134
131
None => None ,
135
132
} ;
136
133
137
- Ok ( TableType { element_type : convert_reftype ( & table. ty . element_type ) , size_initial, size_max } )
134
+ Ok ( TableType { element_type : convert_reftype ( table. ty . element_type ) , size_initial, size_max } )
138
135
}
139
136
140
137
pub ( crate ) fn convert_module_globals (
@@ -185,11 +182,11 @@ pub(crate) fn convert_module_code(
185
182
186
183
for i in 0 ..validator. len_locals ( ) {
187
184
match validator. get_local_type ( i) {
188
- Some ( wasmparser:: ValType :: I32 ) | Some ( wasmparser:: ValType :: F32 ) => {
185
+ Some ( wasmparser:: ValType :: I32 | wasmparser:: ValType :: F32 ) => {
189
186
local_addr_map. push ( local_counts. c32 ) ;
190
187
local_counts. c32 += 1 ;
191
188
}
192
- Some ( wasmparser:: ValType :: I64 ) | Some ( wasmparser:: ValType :: F64 ) => {
189
+ Some ( wasmparser:: ValType :: I64 | wasmparser:: ValType :: F64 ) => {
193
190
local_addr_map. push ( local_counts. c64 ) ;
194
191
local_counts. c64 += 1 ;
195
192
}
@@ -225,7 +222,7 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result<FuncType>
225
222
Ok ( FuncType { params, results } )
226
223
}
227
224
228
- pub ( crate ) fn convert_reftype ( reftype : & wasmparser:: RefType ) -> ValType {
225
+ pub ( crate ) fn convert_reftype ( reftype : wasmparser:: RefType ) -> ValType {
229
226
match reftype {
230
227
_ if reftype. is_func_ref ( ) => ValType :: RefFunc ,
231
228
_ if reftype. is_extern_ref ( ) => ValType :: RefExtern ,
@@ -240,7 +237,7 @@ pub(crate) fn convert_valtype(valtype: &wasmparser::ValType) -> ValType {
240
237
wasmparser:: ValType :: F32 => ValType :: F32 ,
241
238
wasmparser:: ValType :: F64 => ValType :: F64 ,
242
239
wasmparser:: ValType :: V128 => ValType :: V128 ,
243
- wasmparser:: ValType :: Ref ( r) => convert_reftype ( r) ,
240
+ wasmparser:: ValType :: Ref ( r) => convert_reftype ( * r) ,
244
241
}
245
242
}
246
243
@@ -260,7 +257,7 @@ pub(crate) fn process_const_operators(ops: OperatorsReader<'_>) -> Result<ConstI
260
257
wasmparser:: Operator :: F32Const { value } => Ok ( ConstInstruction :: F32Const ( f32:: from_bits ( value. bits ( ) ) ) ) ,
261
258
wasmparser:: Operator :: F64Const { value } => Ok ( ConstInstruction :: F64Const ( f64:: from_bits ( value. bits ( ) ) ) ) ,
262
259
wasmparser:: Operator :: GlobalGet { global_index } => Ok ( ConstInstruction :: GlobalGet ( * global_index) ) ,
263
- op => Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported const instruction: {:?}" , op ) ) ) ,
260
+ op => Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported const instruction: {op :?}" ) ) ) ,
264
261
}
265
262
}
266
263
0 commit comments