42
42
pub enum Descriptor {
43
43
I8 ,
44
44
U8 ,
45
+ ClampedU8 ,
45
46
I16 ,
46
47
U16 ,
47
48
I32 ,
@@ -64,7 +65,6 @@ pub enum Descriptor {
64
65
Char ,
65
66
Option ( Box < Descriptor > ) ,
66
67
Unit ,
67
- Clamped ( Box < Descriptor > ) ,
68
68
}
69
69
70
70
#[ derive( Debug , Clone ) ]
@@ -105,17 +105,18 @@ pub struct Number {
105
105
106
106
impl Descriptor {
107
107
pub fn decode ( mut data : & [ u32 ] ) -> Descriptor {
108
- let descriptor = Descriptor :: _decode ( & mut data) ;
108
+ let descriptor = Descriptor :: _decode ( & mut data, false ) ;
109
109
assert ! ( data. is_empty( ) , "remaining data {:?}" , data) ;
110
110
descriptor
111
111
}
112
112
113
- fn _decode ( data : & mut & [ u32 ] ) -> Descriptor {
113
+ fn _decode ( data : & mut & [ u32 ] , clamped : bool ) -> Descriptor {
114
114
match get ( data) {
115
115
I8 => Descriptor :: I8 ,
116
116
I16 => Descriptor :: I16 ,
117
117
I32 => Descriptor :: I32 ,
118
118
I64 => Descriptor :: I64 ,
119
+ U8 if clamped => Descriptor :: ClampedU8 ,
119
120
U8 => Descriptor :: U8 ,
120
121
U16 => Descriptor :: U16 ,
121
122
U32 => Descriptor :: U32 ,
@@ -125,11 +126,11 @@ impl Descriptor {
125
126
BOOLEAN => Descriptor :: Boolean ,
126
127
FUNCTION => Descriptor :: Function ( Box :: new ( Function :: decode ( data) ) ) ,
127
128
CLOSURE => Descriptor :: Closure ( Box :: new ( Closure :: decode ( data) ) ) ,
128
- REF => Descriptor :: Ref ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
129
- REFMUT => Descriptor :: RefMut ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
130
- SLICE => Descriptor :: Slice ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
131
- VECTOR => Descriptor :: Vector ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
132
- OPTIONAL => Descriptor :: Option ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
129
+ REF => Descriptor :: Ref ( Box :: new ( Descriptor :: _decode ( data, clamped ) ) ) ,
130
+ REFMUT => Descriptor :: RefMut ( Box :: new ( Descriptor :: _decode ( data, clamped ) ) ) ,
131
+ SLICE => Descriptor :: Slice ( Box :: new ( Descriptor :: _decode ( data, clamped ) ) ) ,
132
+ VECTOR => Descriptor :: Vector ( Box :: new ( Descriptor :: _decode ( data, clamped ) ) ) ,
133
+ OPTIONAL => Descriptor :: Option ( Box :: new ( Descriptor :: _decode ( data, clamped ) ) ) ,
133
134
STRING => Descriptor :: String ,
134
135
ANYREF => Descriptor :: Anyref ,
135
136
ENUM => Descriptor :: Enum { hole : get ( data) } ,
@@ -141,7 +142,7 @@ impl Descriptor {
141
142
}
142
143
CHAR => Descriptor :: Char ,
143
144
UNIT => Descriptor :: Unit ,
144
- CLAMPED => Descriptor :: Clamped ( Box :: new ( Descriptor :: _decode ( data) ) ) ,
145
+ CLAMPED => Descriptor :: _decode ( data, true ) ,
145
146
other => panic ! ( "unknown descriptor: {}" , other) ,
146
147
}
147
148
}
@@ -217,6 +218,7 @@ impl Descriptor {
217
218
let inner = match * self {
218
219
Descriptor :: String => return Some ( VectorKind :: String ) ,
219
220
Descriptor :: Vector ( ref d) => & * * d,
221
+ Descriptor :: Slice ( ref d) => & * * d,
220
222
Descriptor :: Ref ( ref d) => match * * d {
221
223
Descriptor :: Slice ( ref d) => & * * d,
222
224
Descriptor :: String => return Some ( VectorKind :: String ) ,
@@ -226,10 +228,6 @@ impl Descriptor {
226
228
Descriptor :: Slice ( ref d) => & * * d,
227
229
_ => return None ,
228
230
} ,
229
- Descriptor :: Clamped ( ref d) => match d. vector_kind ( ) ? {
230
- VectorKind :: U8 => return Some ( VectorKind :: ClampedU8 ) ,
231
- _ => return None ,
232
- } ,
233
231
_ => return None ,
234
232
} ;
235
233
match * inner {
@@ -238,6 +236,7 @@ impl Descriptor {
238
236
Descriptor :: I32 => Some ( VectorKind :: I32 ) ,
239
237
Descriptor :: I64 => Some ( VectorKind :: I64 ) ,
240
238
Descriptor :: U8 => Some ( VectorKind :: U8 ) ,
239
+ Descriptor :: ClampedU8 => Some ( VectorKind :: ClampedU8 ) ,
241
240
Descriptor :: U16 => Some ( VectorKind :: U16 ) ,
242
241
Descriptor :: U32 => Some ( VectorKind :: U32 ) ,
243
242
Descriptor :: U64 => Some ( VectorKind :: U64 ) ,
@@ -279,13 +278,6 @@ impl Descriptor {
279
278
}
280
279
}
281
280
282
- pub fn is_clamped_by_ref ( & self ) -> bool {
283
- match self {
284
- Descriptor :: Clamped ( d) => d. is_by_ref ( ) ,
285
- _ => false ,
286
- }
287
- }
288
-
289
281
pub fn is_mut_ref ( & self ) -> bool {
290
282
match * self {
291
283
Descriptor :: RefMut ( _) => true ,
@@ -396,12 +388,12 @@ impl Function {
396
388
fn decode ( data : & mut & [ u32 ] ) -> Function {
397
389
let shim_idx = get ( data) ;
398
390
let arguments = ( 0 ..get ( data) )
399
- . map ( |_| Descriptor :: _decode ( data) )
391
+ . map ( |_| Descriptor :: _decode ( data, false ) )
400
392
. collect :: < Vec < _ > > ( ) ;
401
393
Function {
402
394
arguments,
403
395
shim_idx,
404
- ret : Descriptor :: _decode ( data) ,
396
+ ret : Descriptor :: _decode ( data, false ) ,
405
397
}
406
398
}
407
399
}
0 commit comments