From 17bbba7327f3dddbe555c44df964c6ce0f587f53 Mon Sep 17 00:00:00 2001
From: acqn <acqn163@outlook.com>
Date: Thu, 20 Aug 2020 07:52:03 +0800
Subject: [PATCH] Added integer boolean type string. No longer set the
 "expression tested" flag with constant results in comparison.

---
 src/cc65/datatype.c |  1 +
 src/cc65/datatype.h |  1 +
 src/cc65/expr.c     | 10 +++++-----
 src/cc65/exprdesc.c | 14 ++++++++++++++
 src/cc65/exprdesc.h |  3 +++
 5 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c
index ad008cfd3..f4f978a3c 100644
--- a/src/cc65/datatype.c
+++ b/src/cc65/datatype.c
@@ -66,6 +66,7 @@ Type type_int[]         = { TYPE(T_INT),    TYPE(T_END) };
 Type type_uint[]        = { TYPE(T_UINT),   TYPE(T_END) };
 Type type_long[]        = { TYPE(T_LONG),   TYPE(T_END) };
 Type type_ulong[]       = { TYPE(T_ULONG),  TYPE(T_END) };
+Type type_bool[]        = { TYPE(T_INT),    TYPE(T_END) };
 Type type_void[]        = { TYPE(T_VOID),   TYPE(T_END) };
 Type type_size_t[]      = { TYPE(T_SIZE_T), TYPE(T_END) };
 Type type_float[]       = { TYPE(T_FLOAT),  TYPE(T_END) };
diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h
index 8e9ee4c33..5c3e71da5 100644
--- a/src/cc65/datatype.h
+++ b/src/cc65/datatype.h
@@ -196,6 +196,7 @@ extern Type type_int[];
 extern Type type_uint[];
 extern Type type_long[];
 extern Type type_ulong[];
+extern Type type_bool[];
 extern Type type_void[];
 extern Type type_size_t[];
 extern Type type_float[];
diff --git a/src/cc65/expr.c b/src/cc65/expr.c
index 12a0c0b57..3d4a5eb1b 100644
--- a/src/cc65/expr.c
+++ b/src/cc65/expr.c
@@ -2595,13 +2595,13 @@ static void hie_compare (const GenDesc* Ops,    /* List of generators */
 
             /* The result is an rvalue in the primary */
             ED_FinalizeRValLoad (Expr);
+
+            /* Condition codes are set */
+            ED_TestDone (Expr);
         }
 
-        /* Result type is always int */
-        Expr->Type = type_int;
-
-Done:   /* Condition codes are set */
-        ED_TestDone (Expr);
+        /* Result type is always boolean */
+Done:   Expr->Type = type_bool;
     }
 }
 
diff --git a/src/cc65/exprdesc.c b/src/cc65/exprdesc.c
index 5ff848fb7..d0ee2789a 100644
--- a/src/cc65/exprdesc.c
+++ b/src/cc65/exprdesc.c
@@ -229,6 +229,20 @@ ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value)
 
 
 
+ExprDesc* ED_MakeConstBool (ExprDesc* Expr, long Value)
+/* Replace Expr with a constant boolean expression with the given value */
+{
+    Expr->Sym   = 0;
+    Expr->Type  = type_bool;
+    Expr->Flags = E_LOC_NONE | E_RTYPE_RVAL | (Expr->Flags & E_HAVE_MARKS);
+    Expr->Name  = 0;
+    Expr->IVal  = Value;
+    Expr->FVal  = FP_D_Make (0.0);
+    return Expr;
+}
+
+
+
 ExprDesc* ED_FinalizeRValLoad (ExprDesc* Expr)
 /* Finalize the result of LoadExpr to be an rvalue in the primary register */
 {
diff --git a/src/cc65/exprdesc.h b/src/cc65/exprdesc.h
index 1541c2e4e..0a0f970a6 100644
--- a/src/cc65/exprdesc.h
+++ b/src/cc65/exprdesc.h
@@ -411,6 +411,9 @@ ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, Type* Type);
 ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value);
 /* Replace Expr with an constant integer with the given value */
 
+ExprDesc* ED_MakeConstBool (ExprDesc* Expr, long Value);
+/* Replace Expr with a constant boolean expression with the given value */
+
 ExprDesc* ED_FinalizeRValLoad (ExprDesc* Expr);
 /* Finalize the result of LoadExpr to be an rvalue in the primary register */