diff --git a/autotest/autotest.bat b/autotest/autotest.bat index d327391..512bab6 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -15,6 +15,9 @@ if %errorlevel% neq 0 goto :error call :test recursiontest.c if %errorlevel% neq 0 goto :error +call :test fastcalltest.c +if %errorlevel% neq 0 goto :error + call :test strcmptest.c if %errorlevel% neq 0 goto :error diff --git a/autotest/fastcalltest.c b/autotest/fastcalltest.c new file mode 100644 index 0000000..28b91cc --- /dev/null +++ b/autotest/fastcalltest.c @@ -0,0 +1,28 @@ +#include +#include + +int p1(int a, int b) +{ + return a + b; +} + +int p2(int a, int b) +{ + return a * b; +} + +int c1(int x) +{ + return x; +} + +int c2(int x) +{ + return c1(x); +} + +int main(void) +{ + return p1(5, p2(c2(2), c2(4))) - 13; +} + diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 57c3b64..481c936 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -2161,6 +2161,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else proc->CallsFunctionPointer(); + GrowingArray defins(nullptr); + Declaration* pdec = ftype->mParams; Expression* pex = exp->mRight; while (pex) @@ -2280,7 +2282,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else wins->mSrc[1].mOperandSize = 2; - block->Append(wins); + if (ftype->mFlags & DTF_FASTCALL) + defins.Push(wins); + else + block->Append(wins); atotal += wins->mSrc[1].mOperandSize; } @@ -2292,6 +2297,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (pdec) mErrors->Error(exp->mLocation, EERR_WRONG_PARAMETER, "Not enough arguments for function call"); + for (int i = 0; i < defins.Size(); i++) + block->Append(defins[i]); + InterInstruction * cins = new InterInstruction(); if (exp->mLeft->mDecValue && exp->mLeft->mDecValue->mFlags & DTF_NATIVE) cins->mCode = IC_CALL_NATIVE;