Store v128 as u128 in wasmtime crate (#689)

As [suggested], this seems like a better and more ergonomic idea than
using `[u8; 16]`!

[suggested]: 3d69e04659 (r36326017)
This commit is contained in:
Alex Crichton
2019-12-17 09:25:09 -06:00
committed by GitHub
parent d1866f0e09
commit dc3f88b297
2 changed files with 4 additions and 4 deletions

View File

@@ -37,7 +37,7 @@ pub enum Val {
FuncRef(HostRef<Func>), FuncRef(HostRef<Func>),
/// A 128-bit number /// A 128-bit number
V128([u8; 16]), V128(u128),
} }
macro_rules! accessors { macro_rules! accessors {
@@ -110,7 +110,7 @@ impl Val {
(F32(f32) f32 unwrap_f32 f32::from_bits(*e)) (F32(f32) f32 unwrap_f32 f32::from_bits(*e))
(F64(f64) f64 unwrap_f64 f64::from_bits(*e)) (F64(f64) f64 unwrap_f64 f64::from_bits(*e))
(FuncRef(&HostRef<Func>) funcref unwrap_funcref e) (FuncRef(&HostRef<Func>) funcref unwrap_funcref e)
(V128(&[u8; 16]) v128 unwrap_v128 e) (V128(u128) v128 unwrap_v128 *e)
} }
/// Attempt to access the underlying value of this `Val`, returning /// Attempt to access the underlying value of this `Val`, returning
@@ -188,7 +188,7 @@ impl From<RuntimeValue> for Val {
RuntimeValue::I64(i) => Val::I64(i), RuntimeValue::I64(i) => Val::I64(i),
RuntimeValue::F32(u) => Val::F32(u), RuntimeValue::F32(u) => Val::F32(u),
RuntimeValue::F64(u) => Val::F64(u), RuntimeValue::F64(u) => Val::F64(u),
RuntimeValue::V128(u) => Val::V128(u), RuntimeValue::V128(u) => Val::V128(u128::from_le_bytes(u)),
} }
} }
} }

View File

@@ -157,7 +157,7 @@ impl ModuleData {
wasmtime::Val::I64(i) => RuntimeValue::I64(i), wasmtime::Val::I64(i) => RuntimeValue::I64(i),
wasmtime::Val::F32(i) => RuntimeValue::F32(i), wasmtime::Val::F32(i) => RuntimeValue::F32(i),
wasmtime::Val::F64(i) => RuntimeValue::F64(i), wasmtime::Val::F64(i) => RuntimeValue::F64(i),
wasmtime::Val::V128(i) => RuntimeValue::V128(i), wasmtime::Val::V128(i) => RuntimeValue::V128(i.to_le_bytes()),
_ => panic!("unsupported value {:?}", v), _ => panic!("unsupported value {:?}", v),
}) })
.collect::<Vec<RuntimeValue>>(), .collect::<Vec<RuntimeValue>>(),