Operator changes

This commit is contained in:
greg 2018-02-26 02:11:56 -08:00
parent b3fff100d2
commit a564ffa1ce
2 changed files with 8 additions and 2 deletions

View File

@ -63,7 +63,8 @@ lazy_static! {
"+" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 10),
"-" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 10),
"*" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"/" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"/" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Float))))), (), 20),
"//" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"%" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"++" => (Func(bx!(Const(StringT)), bx!(Func(bx!(Const(StringT)), bx!(Const(StringT))))), (), 30),
};

View File

@ -183,7 +183,12 @@ impl<'a> State<'a> {
("++", Str(s1), Str(s2)) => Str(format!("{}{}", s1, s2)),
("-", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l - r),
("*", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l * r),
("/", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l / r),
("/", UnsignedInt(l), UnsignedInt(r)) => Float((l as f64)/ (r as f64)),
("//", UnsignedInt(l), UnsignedInt(r)) => if r == 0 {
return Err(format!("Runtime error: divide by zero"));
} else {
UnsignedInt(l / r)
},
("%", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l % r),
_ => return Err(format!("Runtime error: not yet implemented")),
})