1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed method binding for mid-compile methodInstance rebuilding

This commit is contained in:
Brian Fiete 2021-02-01 13:55:29 -08:00
parent 370df86ae4
commit ed30e7ad06
2 changed files with 17 additions and 3 deletions

View file

@ -307,6 +307,8 @@ CeFunction::~CeFunction()
for (auto innerFunc : mInnerFunctions) for (auto innerFunc : mInnerFunctions)
delete innerFunc; delete innerFunc;
delete mCeInnerFunctionInfo; delete mCeInnerFunctionInfo;
BfLogSys(mCeMachine->mCompiler->mSystem, "CeFunction::~CeFunction %p\n", this);
} }
void CeFunction::Print() void CeFunction::Print()
@ -1330,6 +1332,7 @@ void CeBuilder::Build()
continue; continue;
CeFunction* innerFunction = new CeFunction(); CeFunction* innerFunction = new CeFunction();
innerFunction->mCeMachine = mCeMachine;
innerFunction->mIsVarReturn = beFunction->mIsVarReturn; innerFunction->mIsVarReturn = beFunction->mIsVarReturn;
innerFunction->mCeInnerFunctionInfo = new CeInnerFunctionInfo(); innerFunction->mCeInnerFunctionInfo = new CeInnerFunctionInfo();
innerFunction->mCeInnerFunctionInfo->mName = beFunction->mName; innerFunction->mCeInnerFunctionInfo->mName = beFunction->mName;
@ -5364,7 +5367,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
auto resultFrameIdx = CE_GETINST(int32); auto resultFrameIdx = CE_GETINST(int32);
int32 callIdx = CE_GETINST(int32); int32 callIdx = CE_GETINST(int32);
auto& callEntry = ceFunction->mCallTable[callIdx]; auto& callEntry = ceFunction->mCallTable[callIdx];
if (callEntry.mBindRevision != mCeMachine->mRevision) if (callEntry.mBindRevision != mCeMachine->mMethodBindRevision)
{ {
callEntry.mFunction = NULL; callEntry.mFunction = NULL;
//mNamedFunctionMap.TryGetValue(callEntry.mFunctionName, &callEntry.mFunction); //mNamedFunctionMap.TryGetValue(callEntry.mFunctionName, &callEntry.mFunction);
@ -5402,7 +5405,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
mCeMachine->PrepareFunction(callEntry.mFunction, NULL); mCeMachine->PrepareFunction(callEntry.mFunction, NULL);
} }
callEntry.mBindRevision = mCeMachine->mRevision; callEntry.mBindRevision = mCeMachine->mMethodBindRevision;
} }
BF_ASSERT(memStart == mMemory.mVals); BF_ASSERT(memStart == mMemory.mVals);
@ -6216,6 +6219,7 @@ CeMachine::CeMachine(BfCompiler* compiler)
mCompiler = compiler; mCompiler = compiler;
mCeModule = NULL; mCeModule = NULL;
mRevision = 0; mRevision = 0;
mMethodBindRevision = 0;
mCurContext = NULL; mCurContext = NULL;
mExecuteId = -1; mExecuteId = -1;
@ -6230,6 +6234,8 @@ CeMachine::CeMachine(BfCompiler* compiler)
mTempParser = NULL; mTempParser = NULL;
mTempReducer = NULL; mTempReducer = NULL;
mTempPassInstance = NULL; mTempPassInstance = NULL;
BfLogSys(mCompiler->mSystem, "CeMachine::CeMachine %p\n", this);
} }
@ -6309,6 +6315,7 @@ void CeMachine::CompileStarted()
{ {
mRevisionExecuteTime = 0; mRevisionExecuteTime = 0;
mRevision++; mRevision++;
mMethodBindRevision++;
if (mCeModule != NULL) if (mCeModule != NULL)
{ {
delete mCeModule; delete mCeModule;
@ -6318,8 +6325,9 @@ void CeMachine::CompileStarted()
void CeMachine::CompileDone() void CeMachine::CompileDone()
{ {
// So things like deleted local methods get recheckeds // So things like deleted local methods get rechecked
mRevision++; mRevision++;
mMethodBindRevision++;
mTypeInfoMap.Clear(); mTypeInfoMap.Clear();
mMethodInstanceSet.Clear(); mMethodInstanceSet.Clear();
} }
@ -6344,6 +6352,8 @@ void CeMachine::RemoveMethod(BfMethodInstance* methodInstance)
{ {
BfLogSys(methodInstance->GetOwner()->mModule->mSystem, "CeMachine::RemoveMethod %p\n", methodInstance); BfLogSys(methodInstance->GetOwner()->mModule->mSystem, "CeMachine::RemoveMethod %p\n", methodInstance);
mMethodBindRevision++;
auto itr = mFunctions.Find(methodInstance); auto itr = mFunctions.Find(methodInstance);
auto ceFunctionInfo = itr->mValue; auto ceFunctionInfo = itr->mValue;
BF_ASSERT(itr != mFunctions.end()); BF_ASSERT(itr != mFunctions.end());
@ -6916,6 +6926,7 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
BF_ASSERT(ceFunctionInfo->mCeFunction == NULL); BF_ASSERT(ceFunctionInfo->mCeFunction == NULL);
ceFunction = new CeFunction(); ceFunction = new CeFunction();
ceFunction->mCeMachine = this;
ceFunction->mIsVarReturn = methodInstance->mReturnType->IsVar(); ceFunction->mIsVarReturn = methodInstance->mReturnType->IsVar();
ceFunction->mCeFunctionInfo = ceFunctionInfo; ceFunction->mCeFunctionInfo = ceFunctionInfo;
ceFunction->mMethodInstance = methodInstance; ceFunction->mMethodInstance = methodInstance;

View file

@ -396,6 +396,7 @@ public:
class CeFunction class CeFunction
{ {
public: public:
CeMachine* mCeMachine;
CeFunctionInfo* mCeFunctionInfo; CeFunctionInfo* mCeFunctionInfo;
CeInnerFunctionInfo* mCeInnerFunctionInfo; CeInnerFunctionInfo* mCeInnerFunctionInfo;
BfMethodInstance* mMethodInstance; BfMethodInstance* mMethodInstance;
@ -421,6 +422,7 @@ public:
public: public:
CeFunction() CeFunction()
{ {
mCeMachine = NULL;
mCeFunctionInfo = NULL; mCeFunctionInfo = NULL;
mCeInnerFunctionInfo = NULL; mCeInnerFunctionInfo = NULL;
mFunctionKind = CeFunctionKind_NotSet; mFunctionKind = CeFunctionKind_NotSet;
@ -765,6 +767,7 @@ public:
BfCompiler* mCompiler; BfCompiler* mCompiler;
BfModule* mCeModule; BfModule* mCeModule;
int mRevision; int mRevision;
int mMethodBindRevision;
int mRevisionExecuteTime; int mRevisionExecuteTime;
int mCurFunctionId; int mCurFunctionId;
int mExecuteId; int mExecuteId;