Simplify value instantiation
This commit is contained in:
parent
460f363c91
commit
fbd23e05b6
@ -154,8 +154,10 @@ impl Stacked {
|
|||||||
self.stack.push(value);
|
self.stack.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_constant(&mut self, value: Value) {
|
fn push_constant<T: Into<Value>>(&mut self, value: T) {
|
||||||
self.stack.push(Expression::Value(value));
|
let value = Expression::Value(value.into());
|
||||||
|
|
||||||
|
self.stack.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_recall(&mut self, num: u32) {
|
fn push_recall(&mut self, num: u32) {
|
||||||
@ -217,13 +219,13 @@ impl Stacked {
|
|||||||
fn from_equal_zero(&mut self, inst: &Instruction) -> bool {
|
fn from_equal_zero(&mut self, inst: &Instruction) -> bool {
|
||||||
match inst {
|
match inst {
|
||||||
Instruction::I32Eqz => {
|
Instruction::I32Eqz => {
|
||||||
self.push_constant(Value::I32(0));
|
self.push_constant(0_i32);
|
||||||
self.push_cmp_op(CmpOp::Eq_I32);
|
self.push_cmp_op(CmpOp::Eq_I32);
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Instruction::I64Eqz => {
|
Instruction::I64Eqz => {
|
||||||
self.push_constant(Value::I64(0));
|
self.push_constant(0_i64);
|
||||||
self.push_cmp_op(CmpOp::Eq_I64);
|
self.push_cmp_op(CmpOp::Eq_I64);
|
||||||
|
|
||||||
true
|
true
|
||||||
@ -578,10 +580,10 @@ impl<'a> Builder<'a> {
|
|||||||
|
|
||||||
self.data.gen_leak_pending(&mut stat);
|
self.data.gen_leak_pending(&mut stat);
|
||||||
}
|
}
|
||||||
Inst::I32Const(v) => self.data.push_constant(Value::I32(*v)),
|
Inst::I32Const(v) => self.data.push_constant(*v),
|
||||||
Inst::I64Const(v) => self.data.push_constant(Value::I64(*v)),
|
Inst::I64Const(v) => self.data.push_constant(*v),
|
||||||
Inst::F32Const(v) => self.data.push_constant(Value::F32(f32::from_bits(*v))),
|
Inst::F32Const(v) => self.data.push_constant(*v),
|
||||||
Inst::F64Const(v) => self.data.push_constant(Value::F64(f64::from_bits(*v))),
|
Inst::F64Const(v) => self.data.push_constant(*v),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,6 +605,30 @@ pub enum Value {
|
|||||||
F64(f64),
|
F64(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<i32> for Value {
|
||||||
|
fn from(value: i32) -> Self {
|
||||||
|
Self::I32(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<i64> for Value {
|
||||||
|
fn from(value: i64) -> Self {
|
||||||
|
Self::I64(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u32> for Value {
|
||||||
|
fn from(value: u32) -> Self {
|
||||||
|
Self::F32(f32::from_bits(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u64> for Value {
|
||||||
|
fn from(value: u64) -> Self {
|
||||||
|
Self::F64(f64::from_bits(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AnyUnOp {
|
pub struct AnyUnOp {
|
||||||
pub op: UnOp,
|
pub op: UnOp,
|
||||||
pub rhs: Box<Expression>,
|
pub rhs: Box<Expression>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user