Fix call of function pointers in array

This commit is contained in:
drmortalwombat 2022-04-13 16:29:36 +02:00
parent 417574b4bb
commit 8f32b87b18
7 changed files with 44 additions and 9 deletions

View File

@ -108,6 +108,9 @@ rem @echo off
@call :test funcvartest.c @call :test funcvartest.c
@if %errorlevel% neq 0 goto :error @if %errorlevel% neq 0 goto :error
@call :test funcarraycall.c
@if %errorlevel% neq 0 goto :error
@call :test structassigntest.c @call :test structassigntest.c
@if %errorlevel% neq 0 goto :error @if %errorlevel% neq 0 goto :error

30
autotest/funcarraycall.c Normal file
View File

@ -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;
}

View File

@ -361,6 +361,8 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec)
return Analyze(exp->mLeft, procDec); return Analyze(exp->mLeft, procDec);
case EX_INDEX: case EX_INDEX:
ldec = Analyze(exp->mLeft, procDec); ldec = Analyze(exp->mLeft, procDec);
if (ldec->mType == DT_VARIABLE || ldec->mType == DT_ARGUMENT)
ldec = ldec->mBase;
rdec = Analyze(exp->mRight, procDec); rdec = Analyze(exp->mRight, procDec);
return ldec->mBase; return ldec->mBase;
case EX_QUALIFY: case EX_QUALIFY:

View File

@ -2336,7 +2336,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
atotal = 2; 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]); proc->AddCalledFunction(proc->mModule->mProcedures[exp->mLeft->mDecValue->mVarIndex]);
else else
proc->CallsFunctionPointer(); proc->CallsFunctionPointer();

View File

@ -73,7 +73,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.5.115"); strcpy(strProductVersion, "1.5.116");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,5,115,0 FILEVERSION 1,5,116,0
PRODUCTVERSION 1,5,115,0 PRODUCTVERSION 1,5,116,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "oscar64" VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler" VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.5.115.0" VALUE "FileVersion", "1.5.116.0"
VALUE "InternalName", "oscar64.exe" VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe" VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64" VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.5.115.0" VALUE "ProductVersion", "1.5.116.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -4023,15 +4023,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{FA319FAF-1EB3-4F52-9FEA-2BC0B4CB5CAC}" "ProductCode" = "8:{0ED76161-EB93-44B9-8ED5-B52DAE35B818}"
"PackageCode" = "8:{ACF87401-D180-424C-B9D4-E855CBF66BB1}" "PackageCode" = "8:{B9A27BFE-6C41-4995-B0B1-AA37F7D48E99}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0" "AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.5.115" "ProductVersion" = "8:1.5.116"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"