From 180da3de4aef0fb210d36acbaeb00f6f84a28da6 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 4 Nov 2021 08:29:54 +0100 Subject: [PATCH] Fix array[] parameters in functions --- oscar64/InterCodeGenerator.cpp | 4 ++++ oscar64/Parser.cpp | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 7e45e8f..9f15efd 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1634,12 +1634,16 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = Dereference(proc, block, vl); if (!vl.mType->IsNumericType()) mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric type"); + else if (vl.mType->mType == DT_TYPE_INTEGER && vl.mType->mSize < 2) + vl = CoerceType(proc, block, vl, TheSignedIntTypeDeclaration); ins->mOperator = IA_NEG; break; case TK_BINARY_NOT: vl = Dereference(proc, block, vl); if (!(vl.mType->mType == DT_TYPE_POINTER || vl.mType->IsNumericType())) mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric or pointer type"); + else if (vl.mType->mType == DT_TYPE_INTEGER && vl.mType->mSize < 2) + vl = CoerceType(proc, block, vl, TheUnsignedIntTypeDeclaration); ins->mOperator = IA_NOT; break; case TK_MUL: diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 343c21a..ccc9f8e 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -431,16 +431,23 @@ Declaration* Parser::ParsePostfixDeclaration(void) } else { - if (!(adec->mBase->mFlags & DTF_DEFINED)) + if (!(adec->mBase->mFlags & DTF_DEFINED) && adec->mBase->mType != DT_TYPE_ARRAY) mErrors->Error(adec->mLocation, EERR_UNDEFINED_OBJECT, "Type of argument not defined"); adec->mType = DT_ARGUMENT; adec->mVarIndex = vi; adec->mOffset = 0; if (adec->mBase->mType == DT_TYPE_ARRAY) - adec->mSize = 2; - else - adec->mSize = adec->mBase->mSize; + { + Declaration * ndec = new Declaration(adec->mBase->mLocation, DT_TYPE_POINTER); + ndec->mBase = adec->mBase->mBase; + ndec->mSize = 2; + ndec->mFlags |= DTF_DEFINED; + adec->mBase = ndec; + } + + adec->mSize = adec->mBase->mSize; + vi += adec->mSize; if (pdec) pdec->mNext = adec;