From 8f32b87b185e2068ae9cab04899c0546b18cc43a Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 13 Apr 2022 16:29:36 +0200 Subject: [PATCH] Fix call of function pointers in array --- autotest/autotest.bat | 3 +++ autotest/funcarraycall.c | 30 ++++++++++++++++++++++++++++++ oscar64/GlobalAnalyzer.cpp | 2 ++ oscar64/InterCodeGenerator.cpp | 2 +- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 ++++---- oscar64setup/oscar64setup.vdproj | 6 +++--- 7 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 autotest/funcarraycall.c diff --git a/autotest/autotest.bat b/autotest/autotest.bat index b9792a5..92c743e 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -108,6 +108,9 @@ rem @echo off @call :test funcvartest.c @if %errorlevel% neq 0 goto :error +@call :test funcarraycall.c +@if %errorlevel% neq 0 goto :error + @call :test structassigntest.c @if %errorlevel% neq 0 goto :error diff --git a/autotest/funcarraycall.c b/autotest/funcarraycall.c new file mode 100644 index 0000000..4ea69f2 --- /dev/null +++ b/autotest/funcarraycall.c @@ -0,0 +1,30 @@ + +int (*funcs[10])(int); + +#assign x 0 +#repeat +int f##x(int i) +{ + return i + x; +} +#assign x x + 1 +#until x == 10 + +int test(int k) +{ + for(char i=0; i<10; i++) + k = funcs[i](k); + return k; +} + +int main(void) +{ +#assign x 0 +#repeat + funcs[x] = f##x; +#assign x x + 1 +#until x == 10 + + int k = test(-45); + return k; +} diff --git a/oscar64/GlobalAnalyzer.cpp b/oscar64/GlobalAnalyzer.cpp index d153aa8..0714be1 100644 --- a/oscar64/GlobalAnalyzer.cpp +++ b/oscar64/GlobalAnalyzer.cpp @@ -361,6 +361,8 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec) return Analyze(exp->mLeft, procDec); case EX_INDEX: ldec = Analyze(exp->mLeft, procDec); + if (ldec->mType == DT_VARIABLE || ldec->mType == DT_ARGUMENT) + ldec = ldec->mBase; rdec = Analyze(exp->mRight, procDec); return ldec->mBase; case EX_QUALIFY: diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 230c1a7..afea71e 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -2336,7 +2336,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* atotal = 2; } - if (exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION) + if (exp->mLeft->mDecValue && exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION) proc->AddCalledFunction(proc->mModule->mProcedures[exp->mLeft->mDecValue->mVarIndex]); else proc->CallsFunctionPointer(); diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 37a13e6..21941bd 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -73,7 +73,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.5.115"); + strcpy(strProductVersion, "1.5.116"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 3bbfdcb..af03da6 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,5,115,0 - PRODUCTVERSION 1,5,115,0 + FILEVERSION 1,5,116,0 + PRODUCTVERSION 1,5,116,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.5.115.0" + VALUE "FileVersion", "1.5.116.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.5.115.0" + VALUE "ProductVersion", "1.5.116.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index 1a4e51e..e4fbc50 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -4023,15 +4023,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{FA319FAF-1EB3-4F52-9FEA-2BC0B4CB5CAC}" - "PackageCode" = "8:{ACF87401-D180-424C-B9D4-E855CBF66BB1}" + "ProductCode" = "8:{0ED76161-EB93-44B9-8ED5-B52DAE35B818}" + "PackageCode" = "8:{B9A27BFE-6C41-4995-B0B1-AA37F7D48E99}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.5.115" + "ProductVersion" = "8:1.5.116" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"