From 5a1ff689260b1010a0b0707ac12b0a625c0a04fe Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 30 Mar 2022 14:58:41 +0200 Subject: [PATCH] Fix binary and/or with boolean values, now raising a warning --- oscar64/Errors.h | 1 + oscar64/InterCodeGenerator.cpp | 8 ++++++++ oscar64/NativeCodeGenerator.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/oscar64/Errors.h b/oscar64/Errors.h index 8d0dcbc..2e0cd7b 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -21,6 +21,7 @@ enum ErrorID EWARN_INDEX_OUT_OF_BOUNDS, EWARN_SYNTAX, EWARN_NOT_INTERRUPT_SAFE, + EWARN_BOOL_SHORTCUT, EERR_GENERIC = 3000, EERR_FILE_NOT_FOUND, diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index be0a728..d143a08 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1542,6 +1542,14 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* dtype = TheUnsignedIntTypeDeclaration; } + // Convert bool to char on binary operation + if (dtype->mType == DT_TYPE_BOOL) + { + if (exp->mToken == TK_BINARY_AND || exp->mToken == TK_BINARY_OR) + mErrors->Error(exp->mLocation, EWARN_BOOL_SHORTCUT, "Binary and/or operator used for boolean values, use logical operator ('&&' '||')."); + dtype = TheUnsignedCharTypeDeclaration; + } + vl = CoerceType(proc, block, vl, dtype); vr = CoerceType(proc, block, vr, dtype); diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index b69cdef..e391b46 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -19085,7 +19085,7 @@ void NativeCodeBasicBlock::BuildPlacement(GrowingArray& p { if (!mPlaced) { - assert(mBranch != ASMIT_JMP || mIns.Size() > 0); + assert(mBranch != ASMIT_JMP || mIns.Size() > 0 || mTrueJump == this); mPlaced = true; mPlace = placement.Size();