Skip to content

Commit

Permalink
add comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
csgordon committed Jan 27, 2022
1 parent f11da9e commit 81861cc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ pub fn parse_op(i: &[u8]) -> IResult<&[u8], &str> {
tag("/"),
tag("|"),
tag("&"),
tag("^")
tag("^"),
tag("<"),
tag(">"),
tag("==")
))(i).map(|(rest,op)| (rest, from_utf8(op).unwrap()))
}
pub fn parse_register_name(i: &[u8]) -> IResult<&[u8], &str> {
Expand Down Expand Up @@ -809,6 +812,9 @@ fn run_code<'a>(prog: &'a IRProgram<'a>,
"&" => set_var(&mut locs, v, VirtualVal::Data { val: n1&n2 }),
"|" => set_var(&mut locs, v, VirtualVal::Data { val: n1|n2 }),
"^" => set_var(&mut locs, v, VirtualVal::Data { val: n1^n2 }),
"<" => set_var(&mut locs, v, VirtualVal::Data { val: if n1<n2 { 1 } else {0} }),
">" => set_var(&mut locs, v, VirtualVal::Data { val: if n1>n2 {1} else {0} }),
"==" => set_var(&mut locs, v, VirtualVal::Data { val: if n1==n2 {1} else {0}}),
_ => Err(RuntimeError::NYI)
}

Expand Down

0 comments on commit 81861cc

Please sign in to comment.