mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 06:01:33 +00:00
Fix support for floating point numbers
This commit is contained in:
@ -154,8 +154,8 @@ impl LocalBacking {
|
||||
to.data = match from.init {
|
||||
Initializer::Const(Value::I32(x)) => x as u64,
|
||||
Initializer::Const(Value::I64(x)) => x as u64,
|
||||
Initializer::Const(Value::F32(x)) => x as u64,
|
||||
Initializer::Const(Value::F64(x)) => x,
|
||||
Initializer::Const(Value::F32(x)) => x.to_bits() as u64,
|
||||
Initializer::Const(Value::F64(x)) => x.to_bits(),
|
||||
Initializer::GetGlobal(index) => (imports.globals[index.index()].global).data,
|
||||
};
|
||||
}
|
||||
@ -309,8 +309,8 @@ impl ImportBacking {
|
||||
data: match val {
|
||||
Value::I32(n) => *n as u64,
|
||||
Value::I64(n) => *n as u64,
|
||||
Value::F32(n) => *n as u64,
|
||||
Value::F64(n) => *n,
|
||||
Value::F32(n) => (*n).to_bits() as u64,
|
||||
Value::F64(n) => (*n).to_bits(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -18,16 +18,16 @@ pub enum Type {
|
||||
F64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Value {
|
||||
/// The `i32` type.
|
||||
I32(i32),
|
||||
/// The `i64` type.
|
||||
I64(i64),
|
||||
/// The `f32` type.
|
||||
F32(u32),
|
||||
F32(f32),
|
||||
/// The `f64` type.
|
||||
F64(u64),
|
||||
F64(f64),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@ -55,13 +55,13 @@ impl From<i64> for Value {
|
||||
|
||||
impl From<f32> for Value {
|
||||
fn from(f: f32) -> Self {
|
||||
Value::F32(f as _)
|
||||
Value::F32(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for Value {
|
||||
fn from(f: f64) -> Self {
|
||||
Value::F64(f as _)
|
||||
Value::F64(f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ pub struct Table {
|
||||
/// A global value initializer.
|
||||
/// Overtime, this will be able to represent more and more
|
||||
/// complex expressions.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Initializer {
|
||||
/// Corresponds to a `const.*` instruction.
|
||||
Const(Value),
|
||||
|
Reference in New Issue
Block a user