mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 17:31:06 +00:00
Merge pull request #1589 from alexcrichton/clamped
Remove the `Clamped` descriptor type
This commit is contained in:
commit
754328bef2
crates/cli-support/src
@ -82,7 +82,6 @@ fn process_closure_arguments(cfg: &mut Context, function: &mut Function) {
|
|||||||
| Descriptor::RefMut(d)
|
| Descriptor::RefMut(d)
|
||||||
| Descriptor::Option(d)
|
| Descriptor::Option(d)
|
||||||
| Descriptor::Slice(d)
|
| Descriptor::Slice(d)
|
||||||
| Descriptor::Clamped(d)
|
|
||||||
| Descriptor::Vector(d) => process_descriptor(cfg, d),
|
| Descriptor::Vector(d) => process_descriptor(cfg, d),
|
||||||
Descriptor::Closure(c) => process_closure(cfg, c),
|
Descriptor::Closure(c) => process_closure(cfg, c),
|
||||||
Descriptor::Function(c) => process_function(cfg, c),
|
Descriptor::Function(c) => process_function(cfg, c),
|
||||||
|
@ -42,6 +42,7 @@ tys! {
|
|||||||
pub enum Descriptor {
|
pub enum Descriptor {
|
||||||
I8,
|
I8,
|
||||||
U8,
|
U8,
|
||||||
|
ClampedU8,
|
||||||
I16,
|
I16,
|
||||||
U16,
|
U16,
|
||||||
I32,
|
I32,
|
||||||
@ -64,7 +65,6 @@ pub enum Descriptor {
|
|||||||
Char,
|
Char,
|
||||||
Option(Box<Descriptor>),
|
Option(Box<Descriptor>),
|
||||||
Unit,
|
Unit,
|
||||||
Clamped(Box<Descriptor>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -105,17 +105,18 @@ pub struct Number {
|
|||||||
|
|
||||||
impl Descriptor {
|
impl Descriptor {
|
||||||
pub fn decode(mut data: &[u32]) -> Descriptor {
|
pub fn decode(mut data: &[u32]) -> Descriptor {
|
||||||
let descriptor = Descriptor::_decode(&mut data);
|
let descriptor = Descriptor::_decode(&mut data, false);
|
||||||
assert!(data.is_empty(), "remaining data {:?}", data);
|
assert!(data.is_empty(), "remaining data {:?}", data);
|
||||||
descriptor
|
descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _decode(data: &mut &[u32]) -> Descriptor {
|
fn _decode(data: &mut &[u32], clamped: bool) -> Descriptor {
|
||||||
match get(data) {
|
match get(data) {
|
||||||
I8 => Descriptor::I8,
|
I8 => Descriptor::I8,
|
||||||
I16 => Descriptor::I16,
|
I16 => Descriptor::I16,
|
||||||
I32 => Descriptor::I32,
|
I32 => Descriptor::I32,
|
||||||
I64 => Descriptor::I64,
|
I64 => Descriptor::I64,
|
||||||
|
U8 if clamped => Descriptor::ClampedU8,
|
||||||
U8 => Descriptor::U8,
|
U8 => Descriptor::U8,
|
||||||
U16 => Descriptor::U16,
|
U16 => Descriptor::U16,
|
||||||
U32 => Descriptor::U32,
|
U32 => Descriptor::U32,
|
||||||
@ -125,11 +126,11 @@ impl Descriptor {
|
|||||||
BOOLEAN => Descriptor::Boolean,
|
BOOLEAN => Descriptor::Boolean,
|
||||||
FUNCTION => Descriptor::Function(Box::new(Function::decode(data))),
|
FUNCTION => Descriptor::Function(Box::new(Function::decode(data))),
|
||||||
CLOSURE => Descriptor::Closure(Box::new(Closure::decode(data))),
|
CLOSURE => Descriptor::Closure(Box::new(Closure::decode(data))),
|
||||||
REF => Descriptor::Ref(Box::new(Descriptor::_decode(data))),
|
REF => Descriptor::Ref(Box::new(Descriptor::_decode(data, clamped))),
|
||||||
REFMUT => Descriptor::RefMut(Box::new(Descriptor::_decode(data))),
|
REFMUT => Descriptor::RefMut(Box::new(Descriptor::_decode(data, clamped))),
|
||||||
SLICE => Descriptor::Slice(Box::new(Descriptor::_decode(data))),
|
SLICE => Descriptor::Slice(Box::new(Descriptor::_decode(data, clamped))),
|
||||||
VECTOR => Descriptor::Vector(Box::new(Descriptor::_decode(data))),
|
VECTOR => Descriptor::Vector(Box::new(Descriptor::_decode(data, clamped))),
|
||||||
OPTIONAL => Descriptor::Option(Box::new(Descriptor::_decode(data))),
|
OPTIONAL => Descriptor::Option(Box::new(Descriptor::_decode(data, clamped))),
|
||||||
STRING => Descriptor::String,
|
STRING => Descriptor::String,
|
||||||
ANYREF => Descriptor::Anyref,
|
ANYREF => Descriptor::Anyref,
|
||||||
ENUM => Descriptor::Enum { hole: get(data) },
|
ENUM => Descriptor::Enum { hole: get(data) },
|
||||||
@ -141,7 +142,7 @@ impl Descriptor {
|
|||||||
}
|
}
|
||||||
CHAR => Descriptor::Char,
|
CHAR => Descriptor::Char,
|
||||||
UNIT => Descriptor::Unit,
|
UNIT => Descriptor::Unit,
|
||||||
CLAMPED => Descriptor::Clamped(Box::new(Descriptor::_decode(data))),
|
CLAMPED => Descriptor::_decode(data, true),
|
||||||
other => panic!("unknown descriptor: {}", other),
|
other => panic!("unknown descriptor: {}", other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,6 +218,7 @@ impl Descriptor {
|
|||||||
let inner = match *self {
|
let inner = match *self {
|
||||||
Descriptor::String => return Some(VectorKind::String),
|
Descriptor::String => return Some(VectorKind::String),
|
||||||
Descriptor::Vector(ref d) => &**d,
|
Descriptor::Vector(ref d) => &**d,
|
||||||
|
Descriptor::Slice(ref d) => &**d,
|
||||||
Descriptor::Ref(ref d) => match **d {
|
Descriptor::Ref(ref d) => match **d {
|
||||||
Descriptor::Slice(ref d) => &**d,
|
Descriptor::Slice(ref d) => &**d,
|
||||||
Descriptor::String => return Some(VectorKind::String),
|
Descriptor::String => return Some(VectorKind::String),
|
||||||
@ -226,10 +228,6 @@ impl Descriptor {
|
|||||||
Descriptor::Slice(ref d) => &**d,
|
Descriptor::Slice(ref d) => &**d,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
},
|
},
|
||||||
Descriptor::Clamped(ref d) => match d.vector_kind()? {
|
|
||||||
VectorKind::U8 => return Some(VectorKind::ClampedU8),
|
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
match *inner {
|
match *inner {
|
||||||
@ -238,6 +236,7 @@ impl Descriptor {
|
|||||||
Descriptor::I32 => Some(VectorKind::I32),
|
Descriptor::I32 => Some(VectorKind::I32),
|
||||||
Descriptor::I64 => Some(VectorKind::I64),
|
Descriptor::I64 => Some(VectorKind::I64),
|
||||||
Descriptor::U8 => Some(VectorKind::U8),
|
Descriptor::U8 => Some(VectorKind::U8),
|
||||||
|
Descriptor::ClampedU8 => Some(VectorKind::ClampedU8),
|
||||||
Descriptor::U16 => Some(VectorKind::U16),
|
Descriptor::U16 => Some(VectorKind::U16),
|
||||||
Descriptor::U32 => Some(VectorKind::U32),
|
Descriptor::U32 => Some(VectorKind::U32),
|
||||||
Descriptor::U64 => Some(VectorKind::U64),
|
Descriptor::U64 => Some(VectorKind::U64),
|
||||||
@ -279,13 +278,6 @@ impl Descriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_clamped_by_ref(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
Descriptor::Clamped(d) => d.is_by_ref(),
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_mut_ref(&self) -> bool {
|
pub fn is_mut_ref(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Descriptor::RefMut(_) => true,
|
Descriptor::RefMut(_) => true,
|
||||||
@ -396,12 +388,12 @@ impl Function {
|
|||||||
fn decode(data: &mut &[u32]) -> Function {
|
fn decode(data: &mut &[u32]) -> Function {
|
||||||
let shim_idx = get(data);
|
let shim_idx = get(data);
|
||||||
let arguments = (0..get(data))
|
let arguments = (0..get(data))
|
||||||
.map(|_| Descriptor::_decode(data))
|
.map(|_| Descriptor::_decode(data, false))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Function {
|
Function {
|
||||||
arguments,
|
arguments,
|
||||||
shim_idx,
|
shim_idx,
|
||||||
ret: Descriptor::_decode(data),
|
ret: Descriptor::_decode(data, false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
i = i,
|
i = i,
|
||||||
val = val,
|
val = val,
|
||||||
));
|
));
|
||||||
if arg.is_by_ref() || arg.is_clamped_by_ref() {
|
if arg.is_by_ref() {
|
||||||
if optional {
|
if optional {
|
||||||
bail!("optional slices aren't currently supported");
|
bail!("optional slices aren't currently supported");
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
if !arg.is_by_ref() && !arg.is_clamped_by_ref() {
|
if !arg.is_by_ref() {
|
||||||
self.prelude(&format!(
|
self.prelude(&format!(
|
||||||
"\
|
"\
|
||||||
{start}
|
{start}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user