Operator changes
This commit is contained in:
parent
6e105bac55
commit
547def990e
@ -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),
|
||||
};
|
||||
|
@ -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")),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user