From 9fb445f68827e8cb4b12d85619828e7e4d65a206 Mon Sep 17 00:00:00 2001 From: Ry Date: Sat, 12 Mar 2022 12:15:27 -0800 Subject: [PATCH] fox32+fox32asm: Add proper support for greater than and less than This adds IFGT, IFGTEQ, IFLT, and IFLTEQ, which makes it easier to check for these conditions. --- src/fox32.pest | 12 ++++++++---- src/main.rs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/fox32.pest b/src/fox32.pest index 5157327..6d695dc 100644 --- a/src/fox32.pest +++ b/src/fox32.pest @@ -55,10 +55,14 @@ size = @{ } condition = @{ - "ifz" | - "ifnz" | - "ifc" | - "ifnc" + "ifz" | + "ifnz" | + "ifc" | + "ifnc" | + "ifgteq" | + "ifgt" | + "iflteq" | + "iflt" } instruction = { diff --git a/src/main.rs b/src/main.rs index 1519850..4c71c86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -205,6 +205,10 @@ enum Condition { NotZero, Carry, NotCarry, + GreaterThan, + // GreaterThanEqualTo is equivalent to NotCarry + // LessThan is equivalent to Carry + LessThanEqualTo, } #[derive(PartialEq, Debug, Clone)] @@ -561,6 +565,10 @@ fn parse_condition(pair: &pest::iterators::Pair) -> Condition { "ifnz" => Condition::NotZero, "ifc" => Condition::Carry, "ifnc" => Condition::NotCarry, + "ifgt" => Condition::GreaterThan, + "ifgteq" => Condition::NotCarry, + "iflt" => Condition::Carry, + "iflteq" => Condition::LessThanEqualTo, _ => panic!("Unsupported condition: {}", pair.as_str()), } } @@ -976,6 +984,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 { Condition::NotZero => 0x20, Condition::Carry => 0x30, Condition::NotCarry => 0x40, + Condition::GreaterThan => 0x50, + Condition::LessThanEqualTo => 0x60, } } AstNode::OperationOne {condition, ..} => { @@ -985,6 +995,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 { Condition::NotZero => 0x20, Condition::Carry => 0x30, Condition::NotCarry => 0x40, + Condition::GreaterThan => 0x50, + Condition::LessThanEqualTo => 0x60, } } AstNode::OperationTwo {condition, ..} => { @@ -994,6 +1006,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 { Condition::NotZero => 0x20, Condition::Carry => 0x30, Condition::NotCarry => 0x40, + Condition::GreaterThan => 0x50, + Condition::LessThanEqualTo => 0x60, } } _ => panic!("Attempting to parse a non-instruction AST node as an instruction: {:#?}", node),