Browse Source

updates

pull/5/head
Jason Williams 6 years ago
parent
commit
d5bb1de17d
  1. 12
      src/lib/exec.rs
  2. 32
      src/lib/js/value.rs

12
src/lib/exec.rs

@ -255,16 +255,16 @@ impl Executor for Interpreter {
let v_a = *v_r_a;
let v_b = *v_r_b;
Ok(Gc::new(match *op {
OpAdd => v_a + *v_b,
OpSub => v_a - *v_b,
OpMul => v_a * *v_b,
OpDiv => v_a / *v_b,
OpMod => v_a % *v_b,
OpAdd => v_a + v_b,
OpSub => v_a - v_b,
OpMul => v_a * v_b,
OpDiv => v_a / v_b,
OpMod => v_a % v_b,
}))
}
ExprDef::UnaryOpExpr(ref op, ref a) => {
let v_r_a = try!(self.run(a));
let v_a = v_r_a.borrow();
let v_a = *v_r_a;
Ok(match *op {
UnaryMinus => to_value(-v_a.to_num()),
UnaryPlus => to_value(v_a.to_num()),

32
src/lib/js/value.rs

@ -368,59 +368,69 @@ impl Add for ValueData {
fn add(self, other: ValueData) -> ValueData {
return match (self, other) {
(ValueData::String(s), other) | (other, ValueData::String(s)) => {
ValueData::String(s.clone().append(other.to_string()))
ValueData::String(s.clone() + &other.to_string())
}
(_, _) => ValueData::Number(self.to_num() + other.to_num()),
};
}
}
impl Sub for ValueData {
fn sub(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn sub(self, other: ValueData) -> ValueData {
ValueData::Number(self.to_num() - other.to_num())
}
}
impl Mul for ValueData {
fn mul(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn mul(self, other: ValueData) -> ValueData {
ValueData::Number(self.to_num() * other.to_num())
}
}
impl Div for ValueData {
fn div(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn div(self, other: ValueData) -> ValueData {
ValueData::Number(self.to_num() / other.to_num())
}
}
impl Rem for ValueData {
fn rem(&self, other: ValueData) -> ValueData {
type Output = ValueData;
fn rem(self, other: ValueData) -> ValueData {
ValueData::Number(self.to_num() % other.to_num())
}
}
impl BitAnd for ValueData {
fn bitand(&self, other: ValueData) -> ValueData {
type Output = ValueData;
fn bitand(self, other: ValueData) -> ValueData {
ValueData::Integer(self.to_int() & other.to_int())
}
}
impl BitOr for ValueData {
fn bitor(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn bitor(self, other: ValueData) -> ValueData {
ValueData::Integer(self.to_int() | other.to_int())
}
}
impl BitXor for ValueData {
fn bitxor(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn bitxor(self, other: ValueData) -> ValueData {
ValueData::Integer(self.to_int() ^ other.to_int())
}
}
impl Shl for ValueData {
fn shl(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn shl(self, other: ValueData) -> ValueData {
ValueData::Integer(self.to_int() << other.to_int())
}
}
impl Shr for ValueData {
fn shr(&self, other: &ValueData) -> ValueData {
type Output = ValueData;
fn shr(self, other: ValueData) -> ValueData {
ValueData::Integer(self.to_int() >> other.to_int())
}
}
impl Not for ValueData {
fn not(&self) -> ValueData {
type Output = ValueData;
fn not(self) -> ValueData {
ValueData::Boolean(!self.is_true())
}
}

Loading…
Cancel
Save