From bc5570b708a8ea99f3e50ccdfbbc52e3739bdf0f Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 20 Aug 2020 07:52:17 +0800 Subject: [PATCH] Fixed logical-NOT in constant context. --- src/cc65/expr.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index b91fab8a8..7fb6e455f 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1908,14 +1908,19 @@ void hie10 (ExprDesc* Expr) case TOK_BOOL_NOT: NextToken (); - if (evalexpr (CF_NONE, hie10, Expr) == 0) { + BoolExpr (hie10, Expr); + if (ED_IsConstAbs (Expr)) { /* Constant expression */ Expr->IVal = !Expr->IVal; } else { + /* Not constant, load into the primary */ + LoadExpr (CF_NONE, Expr); g_bneg (TypeOf (Expr->Type)); ED_FinalizeRValLoad (Expr); ED_TestDone (Expr); /* bneg will set cc */ } + /* The result type is always boolean */ + Expr->Type = type_bool; break; case TOK_STAR: @@ -3981,29 +3986,6 @@ void hie0 (ExprDesc *Expr) -int evalexpr (unsigned Flags, void (*Func) (ExprDesc*), ExprDesc* Expr) -/* Will evaluate an expression via the given function. If the result is a -** constant, 0 is returned and the value is put in the Expr struct. If the -** result is not constant, LoadExpr is called to bring the value into the -** primary register and 1 is returned. -*/ -{ - /* Evaluate */ - ExprWithCheck (Func, Expr); - - /* Check for a constant expression */ - if (ED_IsConstAbs (Expr)) { - /* Constant expression */ - return 0; - } else { - /* Not constant, load into the primary */ - LoadExpr (Flags, Expr); - return 1; - } -} - - - void Expression0 (ExprDesc* Expr) /* Evaluate an expression via hie0 and put the result into the primary register */ {