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

Display comptime invocation source on callstack

This commit is contained in:
Brian Fiete 2022-03-17 08:47:34 -07:00
parent fefe1adbd1
commit 2d8221dffe
7 changed files with 281 additions and 90 deletions

View file

@ -327,8 +327,9 @@ namespace IDE
// Check to see if this is just a Mixin name, don't mistake for the bang that separates module name
bool awaitingBang = label.Contains('!') && !label.EndsWith("!");
bool awaitingParamName = false;
int chevronCount = 0;
int parenCount = 0;
int chevronDepth = 0;
int parenDepth = 0;
bool hadParen = false;
int lastTopStart = -1;
int lastTopEnd = -1;
@ -345,6 +346,7 @@ namespace IDE
return (c.IsLetter) || (c == '_');
}
CharLoop:
for (int32 i = 0; i < label.Length; i++)
{
char8 c = label[i];
@ -447,12 +449,28 @@ namespace IDE
color = SourceEditWidgetContent.sTextColors[(int)SourceElementType.Method];
}*/
if (chevronCount == 0)
if (chevronDepth == 0)
{
lastTopStart = prevStart;
lastTopEnd = i;
}
if ((prevStart == 0) && (c == ' '))
{
for (int32 checkI = i + 1; checkI < label.Length; checkI++)
{
char8 checkC = label[checkI];
if (checkC == ':')
{
prevStart = -1;
i = checkI;
continue CharLoop;
}
if ((!checkC.IsLetter) && (!checkC.IsWhiteSpace))
break;
}
}
prevTypeColor = prevStart;
InsertColorChange(label, prevStart, color);
i += 5;
@ -469,8 +487,8 @@ namespace IDE
if (c == ',')
awaitingParamName = false;
if ((c == ')') && (parenCount > 0))
parenCount--;
if ((c == ')') && (parenDepth > 0))
parenDepth--;
if ((c != '+') && (c != '.'))
{
@ -488,9 +506,10 @@ namespace IDE
{
// Handled
}
else if ((c == '(') && ((i == 0) || (chevronCount > 0)))
else if ((c == '(') && ((i == 0) || (chevronDepth > 0)))
{
parenCount++;
hadParen = true;
parenDepth++;
}
else if ((c == '(') || (c == '+'))
{
@ -522,7 +541,7 @@ namespace IDE
}
}
if ((foundOpenParen) && (!awaitingParamName) && (chevronCount == 0))
if ((foundOpenParen) && (!awaitingParamName) && (chevronDepth == 0))
{
if (c == ' ')
{
@ -554,14 +573,18 @@ namespace IDE
}
if (c == '<')
chevronCount++;
chevronDepth++;
else if (c == '>')
chevronCount--;
chevronDepth--;
}
if ((prevStart != -1) && (codeKind == .Type))
if ((prevStart != -1) &&
((codeKind == .Type) || (!hadParen)))
{
InsertColorChange(label, prevStart, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Type]);
if (codeKind == .Callstack)
label.Append('\x02');
}
}
}

View file

@ -4022,6 +4022,25 @@ BfTypedValue BfExprEvaluator::LoadLocal(BfLocalVariable* varDecl, bool allowRef)
BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringImpl& findName, bool ignoreInitialError, bool* hadError)
{
int varSkipCount = 0;
StringT<128> wantName;
wantName.Reference(findName);
if (findName.StartsWith('@'))
{
wantName = findName;
while (wantName.StartsWith("@"))
{
if (wantName != "@return")
varSkipCount++;
wantName.Remove(0);
}
}
if (wantName.IsEmpty())
{
mModule->Fail("Shadowed variable name expected after '@'", refNode);
}
if ((mModule->mCompiler->mCeMachine != NULL) && (mModule->mCompiler->mCeMachine->mDebugger != NULL) && (mModule->mCompiler->mCeMachine->mDebugger->mCurDbgState != NULL))
{
auto ceDebugger = mModule->mCompiler->mCeMachine->mDebugger;
@ -4029,12 +4048,19 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
auto activeFrame = ceDebugger->mCurDbgState->mActiveFrame;
if (activeFrame->mFunction->mDbgInfo != NULL)
{
int instIdx = activeFrame->GetInstIdx();
for (auto& dbgVar : activeFrame->mFunction->mDbgInfo->mVariables)
int varSkipCountLeft = varSkipCount;
int instIdx = activeFrame->GetInstIdx();
for (int i = activeFrame->mFunction->mDbgInfo->mVariables.mSize - 1; i >= 0; i--)
{
if (dbgVar.mName == findName)
auto& dbgVar = activeFrame->mFunction->mDbgInfo->mVariables[i];
if (dbgVar.mName == wantName)
{
if ((dbgVar.mValue.mKind == CeOperandKind_AllocaAddr) || (dbgVar.mValue.mKind == CeOperandKind_FrameOfs))
if (varSkipCountLeft > 0)
{
varSkipCountLeft--;
}
else if ((dbgVar.mValue.mKind == CeOperandKind_AllocaAddr) || (dbgVar.mValue.mKind == CeOperandKind_FrameOfs))
{
if ((instIdx >= dbgVar.mStartCodePos) && (instIdx < dbgVar.mEndCodePos))
{
@ -4071,26 +4097,9 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
if ((checkMethodState->mClosureState != NULL) && (checkMethodState->mClosureState->mClosureType != NULL) && (!checkMethodState->mClosureState->mCapturing))
{
closureTypeInst = mModule->mCurMethodState->mClosureState->mClosureType;
}
}
int varSkipCount = 0;
StringT<128> wantName;
wantName.Reference(findName);
if (findName.StartsWith('@'))
{
wantName = findName;
while (wantName.StartsWith("@"))
{
if (wantName != "@return")
varSkipCount++;
wantName.Remove(0);
}
}
if (wantName.IsEmpty())
{
mModule->Fail("Shadowed variable name expected after '@'", refNode);
}
int varSkipCountLeft = varSkipCount;
BfLocalVarEntry* entry;
if (checkMethodState->mLocalVarSet.TryGetWith<StringImpl&>(wantName, &entry))
@ -4098,12 +4107,12 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
auto varDecl = entry->mLocalVar;
if (varDecl != NULL)
varSkipCount -= varDecl->mNamePrefixCount;
varSkipCountLeft -= varDecl->mNamePrefixCount;
while ((varSkipCount > 0) && (varDecl != NULL))
while ((varSkipCountLeft > 0) && (varDecl != NULL))
{
varDecl = varDecl->mShadowedLocal;
varSkipCount--;
varSkipCountLeft--;
}
if ((varDecl != NULL) && (varDecl->mNotCaptured))
@ -4111,7 +4120,7 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
mModule->Fail("Local variable is not captured", refNode);
}
if ((varSkipCount == 0) && (varDecl != NULL))
if ((varSkipCountLeft == 0) && (varDecl != NULL))
{
if ((closureTypeInst != NULL) && (wantName == "this"))
break;
@ -4153,20 +4162,18 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
// Check for the captured locals. It's important we do it here so we get local-first precedence still
if (closureTypeInst != NULL)
{
int varSkipCount = 0;
StringT<128> wantName;
wantName.Reference(findName);
{
int varSkipCountLeft = varSkipCount;
closureTypeInst->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* memberSetEntry = NULL;
if (closureTypeInst->mTypeDef->mFieldSet.TryGetWith((StringImpl&)wantName, &memberSetEntry))
{
auto fieldDef = (BfFieldDef*)memberSetEntry->mMemberDef;
while ((varSkipCount > 0) && (fieldDef != NULL))
while ((varSkipCountLeft > 0) && (fieldDef != NULL))
{
fieldDef = fieldDef->mNextWithSameName;
varSkipCount--;
varSkipCountLeft--;
}
auto& field = closureTypeInst->mFieldInstances[fieldDef->mIdx];

View file

@ -3075,9 +3075,11 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers
{
mHadBuildError = true;
if ((mCompiler->mCeMachine->mCurContext != NULL) && (mCompiler->mCeMachine->mCurContext->mCurTargetSrc != NULL))
if ((mCompiler->mCeMachine->mCurContext != NULL) && (mCompiler->mCeMachine->mCurContext->mCurCallSource != NULL) &&
(mCompiler->mCeMachine->mCurContext->mCurCallSource->mRefNode != NULL))
{
BfError* bfError = mCompiler->mPassInstance->Fail("Comptime method generation had errors", mCompiler->mCeMachine->mCurContext->mCurTargetSrc);
BfError* bfError = mCompiler->mPassInstance->Fail("Comptime method generation had errors",
mCompiler->mCeMachine->mCurContext->mCurCallSource->mRefNode);
if (bfError != NULL)
mCompiler->mPassInstance->MoreInfo(error, refNode);
return bfError;

View file

@ -2271,7 +2271,24 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
///
{
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true);
result = ceContext->Call(customAttribute.mRef, this, methodInstance, args, CeEvalFlags_ForceReturnThis, NULL);
CeCallSource callSource;
callSource.mRefNode = customAttribute.mRef;
if (isFieldApply)
{
callSource.mKind = CeCallSource::Kind_FieldInit;
callSource.mFieldInstance = fieldInstance;
}
else if (ceEmitContext != NULL)
{
callSource.mKind = CeCallSource::Kind_TypeInit;
}
else
{
callSource.mKind = CeCallSource::Kind_TypeDone;
}
result = ceContext->Call(callSource, this, methodInstance, args, CeEvalFlags_ForceReturnThis, NULL);
}
if (fieldInstance != NULL)
mCompiler->mCeMachine->mFieldInstanceSet.Remove(fieldInstance);
@ -2717,7 +2734,11 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
///
{
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true);
result = ceContext->Call(customAttribute.mRef, this, applyMethodInstance, args, CeEvalFlags_ForceReturnThis, NULL);
CeCallSource callSource;
callSource.mRefNode = customAttribute.mRef;
callSource.mKind = CeCallSource::Kind_MethodInit;
result = ceContext->Call(callSource, this, applyMethodInstance, args, CeEvalFlags_ForceReturnThis, NULL);
}
if (result.mType == methodInstance->GetOwner())
prevAttrInstances[methodInstance->GetOwner()] = result.mValue;

View file

@ -836,7 +836,7 @@ void CeDebugger::SetNextStatement(bool inAssembly, const StringImpl& fileName, i
}
CeFrame* CeDebugger::GetFrame(int callStackIdx)
{
{
auto ceContext = mCeMachine->mCurContext;
if (ceContext == NULL)
return NULL;
@ -846,6 +846,9 @@ CeFrame* CeDebugger::GetFrame(int callStackIdx)
if (callStackIdx < mDbgCallStack.mSize)
{
int frameIdx = mDbgCallStack[callStackIdx].mFrameIdx;
if (frameIdx < 0)
return NULL;
auto ceFrame = &ceContext->mCallStack[mDbgCallStack[callStackIdx].mFrameIdx];
return ceFrame;
}
@ -895,12 +898,12 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread)
auto ceFrame = GetFrame(pendingExpr->mCallStackIdx);
if (ceFrame == NULL)
{
return "!failed";
return "!No comptime stack frame selected";
}
if (pendingExpr->mExprNode == NULL)
{
return "!failed";
return "!No expression";
}
auto module = mCeMachine->mCeModule;
@ -2493,7 +2496,8 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type)
auto dbgTypeInfo = GetDbgTypeInfo(typedVal.mType);
if ((dbgTypeInfo != NULL) && (dbgTypeInfo->mType->IsPointer()))
if ((dbgTypeInfo != NULL) &&
((dbgTypeInfo->mType->IsPointer()) || ((dbgTypeInfo->mType->IsRef()))))
dbgTypeInfo = GetDbgTypeInfo(dbgTypeInfo->mType->GetUnderlyingType()->mTypeId);
if (dbgTypeInfo == NULL)
@ -4191,28 +4195,76 @@ String CeDebugger::GetAutoLocals(int callStackIdx, bool showRegs)
String result;
auto ceFrame = GetFrame(callStackIdx);
auto ceFrame = GetFrame(callStackIdx);
if (ceFrame == NULL)
return result;
int scopeIdx = -1;
auto ceEntry = ceFrame->mFunction->FindEmitEntry(ceFrame->GetInstIdx());
if (ceEntry != NULL)
scopeIdx = ceEntry->mScope;
if (ceFrame != NULL)
int instIdx = ceFrame->GetInstIdx();
if (ceFrame->mFunction->mDbgInfo != NULL)
{
int instIdx = ceFrame->GetInstIdx();
if (ceFrame->mFunction->mDbgInfo != NULL)
auto ceFunction = ceFrame->mFunction;
struct CeDbgInfo
{
for (auto& dbgVar : ceFrame->mFunction->mDbgInfo->mVariables)
{
if ((dbgVar.mScope == scopeIdx) && (instIdx >= dbgVar.mStartCodePos) && (instIdx < dbgVar.mEndCodePos))
int mShadowCount;
int mPrevShadowIdx;
bool mIncluded;
CeDbgInfo()
{
mShadowCount = 0;
mPrevShadowIdx = -1;
mIncluded = true;
}
};
Array<CeDbgInfo> dbgInfo;
Dictionary<String, int> nameIndices;
dbgInfo.Resize(ceFunction->mDbgInfo->mVariables.mSize);
for (int i = 0; i < ceFunction->mDbgInfo->mVariables.mSize; i++)
{
auto& dbgVar = ceFunction->mDbgInfo->mVariables[i];
if ((dbgVar.mScope == scopeIdx) && (instIdx >= dbgVar.mStartCodePos) && (instIdx < dbgVar.mEndCodePos))
{
int* idxPtr = NULL;
if (!nameIndices.TryAdd(dbgVar.mName, NULL, &idxPtr))
{
result += dbgVar.mName;
result += "\n";
int checkIdx = *idxPtr;
dbgInfo[i].mPrevShadowIdx = checkIdx;
while (checkIdx != -1)
{
dbgInfo[checkIdx].mShadowCount++;
checkIdx = dbgInfo[checkIdx].mPrevShadowIdx;
}
}
*idxPtr = i;
}
else
{
dbgInfo[i].mIncluded = false;
}
}
for (int i = 0; i < ceFunction->mDbgInfo->mVariables.mSize; i++)
{
auto& dbgVar = ceFunction->mDbgInfo->mVariables[i];
if (dbgInfo[i].mIncluded)
{
for (int shadowIdx = 0; shadowIdx < dbgInfo[i].mShadowCount; shadowIdx++)
result += "@";
result += dbgVar.mName;
result += "\n";
}
}
}
}
return result;
}
@ -4312,6 +4364,12 @@ void CeDebugger::UpdateCallStack(bool slowEarlyOut)
prevInlineIdx = ceScope->mInlinedAt;
}
}
CeDbgStackInfo ceDbgStackInfo;
ceDbgStackInfo.mFrameIdx = -1;
ceDbgStackInfo.mScopeIdx = -1;
ceDbgStackInfo.mInlinedFrom = -1;
mDbgCallStack.Add(ceDbgStackInfo);
}
int CeDebugger::GetCallStackCount()
@ -4435,12 +4493,51 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou
auto& dbgCallstackInfo = mDbgCallStack[stackFrameIdx];
if (dbgCallstackInfo.mFrameIdx == -1)
{
if (ceContext->mCurCallSource != NULL)
{
int line = -1;
int lineChar = -1;
auto parserData = ceContext->mCurCallSource->mRefNode->GetParserData();
if (parserData != NULL)
{
parserData->GetLineCharAtIdx(ceContext->mCurCallSource->mRefNode->GetSrcStart(), line, lineChar);
*outLine = line;
*outColumn = lineChar;
*outFile = parserData->mFileName;
}
}
// Entry marker
String result = "const eval";
if (ceContext->mCurCallSource->mKind == CeCallSource::Kind_FieldInit)
{
return String("field init of : ") + ceContext->mCurModule->TypeToString(ceContext->mCurCallSource->mFieldInstance->mOwner) + "." +
ceContext->mCurCallSource->mFieldInstance->GetFieldDef()->mName;
}
else if (ceContext->mCurCallSource->mKind == CeCallSource::Kind_MethodInit)
{
return ("method init of : ") + ceContext->mCurModule->MethodToString(ceContext->mCallerMethodInstance);
}
else if (ceContext->mCurCallSource->mKind == CeCallSource::Kind_TypeInit)
result = "type init";
else if (ceContext->mCurCallSource->mKind == CeCallSource::Kind_TypeDone)
result = "type done";
if (ceContext->mCallerMethodInstance != NULL)
result += String(" in : ") + ceContext->mCurModule->MethodToString(ceContext->mCallerMethodInstance);
else if (ceContext->mCallerTypeInstance != NULL)
result += String(" in : ") + ceContext->mCurModule->TypeToString(ceContext->mCallerTypeInstance);
return result;
}
auto ceFrame = &ceContext->mCallStack[dbgCallstackInfo.mFrameIdx];
auto ceFunction = ceFrame->mFunction;
if (ceFunction->mFailed)
*outFlags |= FrameFlags_HadError;
int instIdx = (int)(ceFrame->mInstPtr - &ceFunction->mCode[0] - 2);
BF_ASSERT(ceFunction->mId != -1);
@ -4448,16 +4545,17 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou
CeEmitEntry* emitEntry = ceFunction->FindEmitEntry(instIdx);
*outStackSize = ceContext->mStackSize - ceFrame->mStackAddr;
if (stackFrameIdx < mDbgCallStack.mSize - 1)
{
auto& nextStackInfo = mDbgCallStack[stackFrameIdx + 1];
auto prevFrame = &ceContext->mCallStack[nextStackInfo.mFrameIdx];
*outStackSize = prevFrame->mStackAddr - ceFrame->mStackAddr;
}
else
{
*outStackSize = ceContext->mStackSize - ceFrame->mStackAddr;
if (nextStackInfo.mFrameIdx >= 0)
{
auto prevFrame = &ceContext->mCallStack[nextStackInfo.mFrameIdx];
*outStackSize = prevFrame->mStackAddr - ceFrame->mStackAddr;
}
}
CeDbgScope* ceScope = NULL;
if (dbgCallstackInfo.mScopeIdx != -1)

View file

@ -421,8 +421,10 @@ CeEmitEntry* CeFunction::FindEmitEntry(int instIdx, int* entryIdx)
return emitEntry;
}
// This is for "safe" retrieval from within CeDebugger
int CeFunction::SafeGetId()
{
#ifdef BF_PLATFORM_WINDOWS
__try
{
return mId;
@ -432,6 +434,9 @@ int CeFunction::SafeGetId()
}
return 0;
#else
return mId;
#endif
}
//////////////////////////////////////////////////////////////////////////
@ -3301,7 +3306,7 @@ CeContext::CeContext()
mExecuteId = -1;
mStackSize = -1;
mCurTargetSrc = NULL;
mCurCallSource = NULL;
mHeap = new ContiguousHeap();
mCurFrame = NULL;
mCurModule = NULL;
@ -3310,7 +3315,7 @@ CeContext::CeContext()
mCallerTypeInstance = NULL;
mCallerActiveTypeDef = NULL;
mCurExpectingType = NULL;
mCurEmitContext = NULL;
mCurEmitContext = NULL;
}
CeContext::~CeContext()
@ -3325,7 +3330,7 @@ BfError* CeContext::Fail(const StringImpl& error)
return NULL;
if (mCurEmitContext != NULL)
mCurEmitContext->mFailed = true;
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurTargetSrc, (mCurEvalFlags & CeEvalFlags_PersistantError) != 0);
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurCallSource->mRefNode, (mCurEvalFlags & CeEvalFlags_PersistantError) != 0);
if (bfError == NULL)
return NULL;
@ -3340,7 +3345,7 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str)
{
if (mCurEmitContext != NULL)
mCurEmitContext->mFailed = true;
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurTargetSrc,
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurCallSource->mRefNode,
(mCurEvalFlags & CeEvalFlags_PersistantError) != 0,
((mCurEvalFlags & CeEvalFlags_DeferIfNotOnlyError) != 0) && !mCurModule->mHadBuildError);
if (bfError == NULL)
@ -3911,7 +3916,7 @@ bool CeContext::GetCustomAttribute(BfModule* module, BfIRConstHolder* constHolde
return false;
auto ceContext = mCeMachine->AllocContext();
BfIRValue foreignValue = ceContext->CreateAttribute(mCurTargetSrc, module, constHolder, customAttr);
BfIRValue foreignValue = ceContext->CreateAttribute(mCurCallSource->mRefNode, module, constHolder, customAttr);
auto foreignConstant = module->mBfIRBuilder->GetConstant(foreignValue);
if (foreignConstant->mConstType == BfConstType_AggCE)
{
@ -4679,7 +4684,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI
paramIdx++;
}
BfTypedValue retValue = Call(targetSrc, module, ctorMethodInstance, ctorArgs, CeEvalFlags_None, NULL);
BfTypedValue retValue = Call(CeCallSource(targetSrc), module, ctorMethodInstance, ctorArgs, CeEvalFlags_None, NULL);
if (!retValue)
return ceAttrVal;
@ -4728,7 +4733,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI
}
BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType)
BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType)
{
// DISABLED
//return BfTypedValue();
@ -4738,7 +4743,7 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
SetAndRestoreValue<CeContext*> curPrevContext(mPrevContext, mCeMachine->mCurContext);
SetAndRestoreValue<CeContext*> prevContext(mCeMachine->mCurContext, this);
SetAndRestoreValue<CeEvalFlags> prevEvalFlags(mCurEvalFlags, flags);
SetAndRestoreValue<BfAstNode*> prevTargetSrc(mCurTargetSrc, targetSrc);
SetAndRestoreValue<CeCallSource*> prevCallSource(mCurCallSource, &callSource);
SetAndRestoreValue<BfModule*> prevModule(mCurModule, module);
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInstance);
SetAndRestoreValue<BfMethodInstance*> prevCallerMethodInstance(mCallerMethodInstance, module->mCurMethodInstance);
@ -5378,7 +5383,7 @@ class CeAsyncOperation
public:
CeInternalData* mInternalData;
int mRefCount;
void* mData;
uint8* mData;
int mDataSize;
int mReadSize;
BfpFileResult mResult;
@ -6029,7 +6034,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
return false;
}
mCurModule->CEMixin(mCurTargetSrc, emitStr);
mCurModule->CEMixin(mCurCallSource->mRefNode, emitStr);
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Sleep)
{
@ -6162,7 +6167,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
char* strPtr = (char*)(memStart + strAddr);
char** endPtr = NULL;
if (endAddr != NULL)
if (endAddr != 0)
endPtr = (char**)(memStart + endAddr);
result = strtod(strPtr, endPtr);
if (endAddr != 0)
@ -6728,11 +6733,11 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
}
};
if (outStdInAddr != NULL)
if (outStdInAddr != 0)
_SetHandle(outStdInAddr, outStdIn);
if (outStdOutAddr != NULL)
if (outStdOutAddr != 0)
_SetHandle(outStdOutAddr, outStdOut);
if (outStdErrAddr != NULL)
if (outStdErrAddr != 0)
_SetHandle(outStdErrAddr, outStdErr);
}
else if (checkFunction->mFunctionKind == CeFunctionKind_BfpSpawn_Kill)
@ -8455,6 +8460,7 @@ CeMachine::CeMachine(BfCompiler* compiler)
mRevision = 0;
mMethodBindRevision = 0;
mCurContext = NULL;
mCurCallSource = NULL;
mExecuteId = -1;
mCurFunctionId = 0;
@ -9560,10 +9566,10 @@ void CeMachine::ReleaseContext(CeContext* ceContext)
ceContext->mInternalDataMap.Clear();
}
BfTypedValue CeMachine::Call(BfAstNode* targetSrc, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType)
BfTypedValue CeMachine::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType)
{
auto ceContext = AllocContext();
auto result = ceContext->Call(targetSrc, module, methodInstance, args, flags, expectingType);
auto result = ceContext->Call(callSource, module, methodInstance, args, flags, expectingType);
ReleaseContext(ceContext);
return result;
}

View file

@ -991,6 +991,39 @@ public:
}
};
class CeCallSource
{
public:
enum Kind
{
Kind_Unknown,
Kind_TypeInit,
Kind_TypeDone,
Kind_FieldInit,
Kind_MethodInit
};
public:
Kind mKind;
BfAstNode* mRefNode;
BfFieldInstance* mFieldInstance;
public:
CeCallSource(BfAstNode* refNode)
{
mKind = Kind_Unknown;
mRefNode = refNode;
mFieldInstance = NULL;
}
CeCallSource()
{
mKind = Kind_Unknown;
mRefNode = NULL;
mFieldInstance = NULL;
}
};
class CeContext
{
public:
@ -1018,7 +1051,7 @@ public:
BfTypeDef* mCallerActiveTypeDef;
BfMethodInstance* mCurMethodInstance;
BfType* mCurExpectingType;
BfAstNode* mCurTargetSrc;
CeCallSource* mCurCallSource;
BfModule* mCurModule;
CeFrame* mCurFrame;
CeEmitContext* mCurEmitContext;
@ -1058,7 +1091,7 @@ public:
BfIRValue CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfIRConstHolder* constHolder, BfCustomAttribute* customAttribute, addr_ce ceAttrAddr = 0);
bool Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* startFramePtr, BfType*& returnType);
BfTypedValue Call(BfAstNode* targetSrc, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType);
BfTypedValue Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType);
};
struct CeTypeInfo
@ -1119,6 +1152,7 @@ public:
CeContext* mCurContext;
CeEmitContext* mCurEmitContext;
CeCallSource* mCurCallSource;
CeBuilder* mCurBuilder;
CeFunction* mPreparingFunction;
@ -1172,7 +1206,7 @@ public:
CeContext* AllocContext();
void ReleaseContext(CeContext* context);
BfTypedValue Call(BfAstNode* targetSrc, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType);
BfTypedValue Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray<BfIRValue>& args, CeEvalFlags flags, BfType* expectingType);
};
NS_BF_END