1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Static local methods and variables, fixed erroneous 'this' capture

This commit is contained in:
Brian Fiete 2022-02-11 10:38:57 -05:00
parent 3c74588e10
commit d9725dda7c
6 changed files with 97 additions and 13 deletions

View file

@ -14371,7 +14371,23 @@ int BfModule::GetFieldDataIdx(BfTypeInstance* typeInst, int fieldIdx, const char
return fieldInstance.mDataIdx;
}
BfTypedValue BfModule::GetThis()
void BfModule::MarkUsingThis()
{
auto useMethodState = mCurMethodState;
while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing))
{
useMethodState = useMethodState->mPrevMethodState;
}
if ((useMethodState != NULL) && (!useMethodState->mLocals.IsEmpty()))
{
auto localVar = useMethodState->mLocals[0];
if (localVar->mIsThis)
localVar->mReadFromId = useMethodState->GetRootMethodState()->mCurAccessId++;
}
}
BfTypedValue BfModule::GetThis(bool markUsing)
{
auto useMethodState = mCurMethodState;
while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing))
@ -14465,7 +14481,8 @@ BfTypedValue BfModule::GetThis()
thisValue = thisLocal->mAddr;
else
thisValue = mBfIRBuilder->CreateLoad(thisLocal->mAddr);
useMethodState->mLocals[0]->mReadFromId = useMethodState->GetRootMethodState()->mCurAccessId++;
if (markUsing)
useMethodState->mLocals[0]->mReadFromId = useMethodState->GetRootMethodState()->mCurAccessId++;
if (useMethodState->mClosureState != NULL)
{
@ -21462,6 +21479,8 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth
wantsVisitBody = false;
if (methodInstance->IsOrInUnspecializedVariation())
wantsVisitBody = false;
if ((methodDeclaration != NULL) && (methodDeclaration->mStaticSpecifier != NULL))
wantsVisitBody = false;
if (wantsVisitBody)
{