From 4a87e4d97b6d7beb5e74b0493baeae522a87a062 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 8 Feb 2025 11:04:19 +0100 Subject: [PATCH] Fix no inline for overloaded operators --- oscar64/Constexpr.cpp | 3 +++ oscar64/Declaration.cpp | 13 +++++++++++++ oscar64/GlobalAnalyzer.cpp | 4 ++++ oscar64/InterCode.cpp | 2 +- oscar64/InterCodeGenerator.cpp | 15 +++++++++++++++ oscar64/Parser.cpp | 28 ++++++++++++++++++++++------ 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/oscar64/Constexpr.cpp b/oscar64/Constexpr.cpp index 3431872..f6da20b 100644 --- a/oscar64/Constexpr.cpp +++ b/oscar64/Constexpr.cpp @@ -1023,6 +1023,9 @@ ConstexprInterpreter::Value ConstexprInterpreter::EvalUnary(Expression* exp, con break; case TK_MUL: return vl.GetPtr(); + case TK_SIZEOF: + v.PutInt(vl.mDecType->mSize); + break; default: mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible operator", TokenNames[exp->mToken]); } diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 418bc77..2ce6db7 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -649,6 +649,19 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio return this; } + else if (mType == EX_PREFIX && mToken == TK_SIZEOF) + { + if (mLeft->mDecType->mFlags & DTF_DEFINED) + { + Expression* ex = new Expression(mLocation, EX_CONSTANT); + Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER); + dec->mBase = TheSignedIntTypeDeclaration; + dec->mInteger = mLeft->mDecType->mSize; + ex->mDecValue = dec; + ex->mDecType = dec->mBase; + return ex; + } + } else if (mType == EX_PREFIX && mLeft->mType == EX_CONSTANT) { diff --git a/oscar64/GlobalAnalyzer.cpp b/oscar64/GlobalAnalyzer.cpp index 7dd8ed2..cd086ed 100644 --- a/oscar64/GlobalAnalyzer.cpp +++ b/oscar64/GlobalAnalyzer.cpp @@ -899,6 +899,10 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo { return TheUnsignedCharTypeDeclaration; } + else if (exp->mToken == TK_SIZEOF) + { + return TheUnsignedIntTypeDeclaration; + } else { procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index ae0b11e..cef7f0e 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -23226,7 +23226,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "equipment_navigate"); + CheckFunc = !strcmp(mIdent->mString, "reuref::(cast)"); CheckCase = false; mEntryBlock = mBlocks[0]; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index f774ef4..e94cda5 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -3439,6 +3439,18 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(exp->mLocation, ERRR_CANNOT_FIND_BANK_OF_EXPRESSION, "Cannot find bank of expressiohn"); } break; + case TK_SIZEOF: + { + ins->mCode = IC_CONSTANT; + ins->mNumOperands = 0; + ins->mConst.mType = IT_INT16; + ins->mConst.mIntConst = exp->mLeft->mDecType->mSize; + ins->mDst.mType = IT_INT16; + ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType); + block->Append(ins); + return ExValue(TheUnsignedIntTypeDeclaration, ins->mDst.mTemp, vl.mReference - 1); + } + case TK_NEW: { ins->mCode = IC_MALLOC; @@ -5628,6 +5640,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* return ExValue(TheVoidTypeDeclaration); } + case EX_TYPE: + return ExValue(exp->mDecType); + default: mErrors->Error(exp->mLocation, EERR_UNIMPLEMENTED, "Unimplemented expression"); return ExValue(TheVoidTypeDeclaration); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 407d350..43640a5 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -4786,6 +4786,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE); ctdec->mFlags |= storageFlags & (DTF_REQUEST_INLINE | DTF_CONSTEXPR | DTF_VIRTUAL); + cdec->mFlags |= storageFlags & (DTF_PREVENT_INLINE); cdec->mSection = mCodeSection; cdec->mBase->mFlags |= typeFlags; @@ -4836,6 +4837,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE); ctdec->mFlags |= storageFlags & (DTF_REQUEST_INLINE | DTF_CONSTEXPR | DTF_VIRTUAL); + cdec->mFlags |= storageFlags & (DTF_PREVENT_INLINE); cdec->mSection = mCodeSection; cdec->mBase->mFlags |= typeFlags; @@ -4880,7 +4882,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex cdec->mBase = ctdec; cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE); - cdec->mFlags |= storageFlags & (DTF_INLINE | DTF_CONSTEXPR); + cdec->mFlags |= storageFlags & (DTF_INLINE | DTF_CONSTEXPR | DTF_PREVENT_INLINE); cdec->mSection = mCodeSection; cdec->mBase->mFlags |= typeFlags; @@ -6785,6 +6787,10 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid) dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER); dec->mBase = TheSignedIntTypeDeclaration; + exp = new Expression(mScanner->mLocation, EX_CONSTANT); + exp->mDecValue = dec; + exp->mDecType = dec->mBase; + if (ConsumeTokenIf(TK_ELLIPSIS)) { rexp = ParseParenthesisExpression(); @@ -6805,14 +6811,24 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid) else { rexp = ParseParenthesisExpression(); + Declaration* btype; if (rexp->mDecType->IsReference()) - dec->mInteger = rexp->mDecType->mBase->mSize; + btype = rexp->mDecType->mBase; else - dec->mInteger = rexp->mDecType->mSize; + btype = rexp->mDecType; + + if (btype->mFlags & DTF_DEFINED) + dec->mInteger = btype->mSize; + else + { + exp->mType = EX_PREFIX; + exp->mToken = TK_SIZEOF; + exp->mLeft = new Expression(mScanner->mLocation, EX_TYPE); + exp->mLeft->mDecType = btype; + exp->mLeft->mDecValue = nullptr; + } } - exp = new Expression(mScanner->mLocation, EX_CONSTANT); - exp->mDecValue = dec; - exp->mDecType = dec->mBase; + break; case TK_OPEN_PARENTHESIS: