Support NotEqual builtin

This commit is contained in:
Greg Shuflin 2021-11-01 12:40:41 -07:00
parent d9f53abeb2
commit a3f2539993
3 changed files with 10 additions and 1 deletions

View File

@ -33,6 +33,7 @@ pub enum Builtin {
IOGetLine,
Assignment,
Concatenate,
NotEqual,
}
impl Builtin {
@ -65,6 +66,7 @@ impl Builtin {
Concatenate => ty!(StringT -> StringT -> StringT),
Increment => ty!(Nat -> Int),
Negate => ty!(Nat -> Int),
NotEqual => ty!(Nat -> Nat -> Bool),
}
}
}
@ -116,6 +118,7 @@ impl FromStr for Builtin {
"<" => LessThan,
"<=" => LessThanOrEqual,
"==" => Equality,
"!=" => NotEqual,
"=" => Assignment,
"<=>" => Comparison,
"print" => IOPrint,

View File

@ -393,6 +393,12 @@ impl<'a, 'b> Evaluator<'a, 'b> {
(Equality, Lit(Bool(l)), Lit(Bool(r))) => Bool(l == r).into(),
(Equality, Lit(StringLit(ref l)), Lit(StringLit(ref r))) => Bool(l == r).into(),
(NotEqual, Lit(Nat(l)), Lit(Nat(r))) => Bool(l != r).into(),
(NotEqual, Lit(Int(l)), Lit(Int(r))) => Bool(l != r).into(),
(NotEqual, Lit(Float(l)), Lit(Float(r))) => Bool(l != r).into(),
(NotEqual, Lit(Bool(l)), Lit(Bool(r))) => Bool(l != r).into(),
(NotEqual, Lit(StringLit(ref l)), Lit(StringLit(ref r))) => Bool(l != r).into(),
(LessThan, Lit(Nat(l)), Lit(Nat(r))) => Bool(l < r).into(),
(LessThan, Lit(Int(l)), Lit(Int(r))) => Bool(l < r).into(),
(LessThan, Lit(Float(l)), Lit(Float(r))) => Bool(l < r).into(),

View File

@ -419,7 +419,7 @@ fn loops() {
let source = r#"
let mut a = 0
let mut count = 0
while !(a == 5) {
while a != 5 {
a = a + 1
count = count + 100
}