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 // 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 awaitingBang = label.Contains('!') && !label.EndsWith("!");
bool awaitingParamName = false; bool awaitingParamName = false;
int chevronCount = 0; int chevronDepth = 0;
int parenCount = 0; int parenDepth = 0;
bool hadParen = false;
int lastTopStart = -1; int lastTopStart = -1;
int lastTopEnd = -1; int lastTopEnd = -1;
@ -345,6 +346,7 @@ namespace IDE
return (c.IsLetter) || (c == '_'); return (c.IsLetter) || (c == '_');
} }
CharLoop:
for (int32 i = 0; i < label.Length; i++) for (int32 i = 0; i < label.Length; i++)
{ {
char8 c = label[i]; char8 c = label[i];
@ -447,12 +449,28 @@ namespace IDE
color = SourceEditWidgetContent.sTextColors[(int)SourceElementType.Method]; color = SourceEditWidgetContent.sTextColors[(int)SourceElementType.Method];
}*/ }*/
if (chevronCount == 0) if (chevronDepth == 0)
{ {
lastTopStart = prevStart; lastTopStart = prevStart;
lastTopEnd = i; 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; prevTypeColor = prevStart;
InsertColorChange(label, prevStart, color); InsertColorChange(label, prevStart, color);
i += 5; i += 5;
@ -469,8 +487,8 @@ namespace IDE
if (c == ',') if (c == ',')
awaitingParamName = false; awaitingParamName = false;
if ((c == ')') && (parenCount > 0)) if ((c == ')') && (parenDepth > 0))
parenCount--; parenDepth--;
if ((c != '+') && (c != '.')) if ((c != '+') && (c != '.'))
{ {
@ -488,9 +506,10 @@ namespace IDE
{ {
// Handled // Handled
} }
else if ((c == '(') && ((i == 0) || (chevronCount > 0))) else if ((c == '(') && ((i == 0) || (chevronDepth > 0)))
{ {
parenCount++; hadParen = true;
parenDepth++;
} }
else if ((c == '(') || (c == '+')) else if ((c == '(') || (c == '+'))
{ {
@ -522,7 +541,7 @@ namespace IDE
} }
} }
if ((foundOpenParen) && (!awaitingParamName) && (chevronCount == 0)) if ((foundOpenParen) && (!awaitingParamName) && (chevronDepth == 0))
{ {
if (c == ' ') if (c == ' ')
{ {
@ -554,14 +573,18 @@ namespace IDE
} }
if (c == '<') if (c == '<')
chevronCount++; chevronDepth++;
else if (c == '>') else if (c == '>')
chevronCount--; chevronDepth--;
} }
if ((prevStart != -1) && (codeKind == .Type)) if ((prevStart != -1) &&
((codeKind == .Type) || (!hadParen)))
{ {
InsertColorChange(label, prevStart, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Type]); 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) 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)) if ((mModule->mCompiler->mCeMachine != NULL) && (mModule->mCompiler->mCeMachine->mDebugger != NULL) && (mModule->mCompiler->mCeMachine->mDebugger->mCurDbgState != NULL))
{ {
auto ceDebugger = mModule->mCompiler->mCeMachine->mDebugger; auto ceDebugger = mModule->mCompiler->mCeMachine->mDebugger;
@ -4029,12 +4048,19 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
auto activeFrame = ceDebugger->mCurDbgState->mActiveFrame; auto activeFrame = ceDebugger->mCurDbgState->mActiveFrame;
if (activeFrame->mFunction->mDbgInfo != NULL) if (activeFrame->mFunction->mDbgInfo != NULL)
{ {
int instIdx = activeFrame->GetInstIdx(); int varSkipCountLeft = varSkipCount;
for (auto& dbgVar : activeFrame->mFunction->mDbgInfo->mVariables) 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)) 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)) if ((checkMethodState->mClosureState != NULL) && (checkMethodState->mClosureState->mClosureType != NULL) && (!checkMethodState->mClosureState->mCapturing))
{ {
closureTypeInst = mModule->mCurMethodState->mClosureState->mClosureType; closureTypeInst = mModule->mCurMethodState->mClosureState->mClosureType;
} }
int varSkipCount = 0; int varSkipCountLeft = varSkipCount;
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);
}
BfLocalVarEntry* entry; BfLocalVarEntry* entry;
if (checkMethodState->mLocalVarSet.TryGetWith<StringImpl&>(wantName, &entry)) if (checkMethodState->mLocalVarSet.TryGetWith<StringImpl&>(wantName, &entry))
@ -4098,12 +4107,12 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
auto varDecl = entry->mLocalVar; auto varDecl = entry->mLocalVar;
if (varDecl != NULL) if (varDecl != NULL)
varSkipCount -= varDecl->mNamePrefixCount; varSkipCountLeft -= varDecl->mNamePrefixCount;
while ((varSkipCount > 0) && (varDecl != NULL)) while ((varSkipCountLeft > 0) && (varDecl != NULL))
{ {
varDecl = varDecl->mShadowedLocal; varDecl = varDecl->mShadowedLocal;
varSkipCount--; varSkipCountLeft--;
} }
if ((varDecl != NULL) && (varDecl->mNotCaptured)) if ((varDecl != NULL) && (varDecl->mNotCaptured))
@ -4111,7 +4120,7 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
mModule->Fail("Local variable is not captured", refNode); mModule->Fail("Local variable is not captured", refNode);
} }
if ((varSkipCount == 0) && (varDecl != NULL)) if ((varSkipCountLeft == 0) && (varDecl != NULL))
{ {
if ((closureTypeInst != NULL) && (wantName == "this")) if ((closureTypeInst != NULL) && (wantName == "this"))
break; 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 // Check for the captured locals. It's important we do it here so we get local-first precedence still
if (closureTypeInst != NULL) if (closureTypeInst != NULL)
{ {
int varSkipCount = 0; int varSkipCountLeft = varSkipCount;
StringT<128> wantName;
wantName.Reference(findName);
closureTypeInst->mTypeDef->PopulateMemberSets(); closureTypeInst->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* memberSetEntry = NULL; BfMemberSetEntry* memberSetEntry = NULL;
if (closureTypeInst->mTypeDef->mFieldSet.TryGetWith((StringImpl&)wantName, &memberSetEntry)) if (closureTypeInst->mTypeDef->mFieldSet.TryGetWith((StringImpl&)wantName, &memberSetEntry))
{ {
auto fieldDef = (BfFieldDef*)memberSetEntry->mMemberDef; auto fieldDef = (BfFieldDef*)memberSetEntry->mMemberDef;
while ((varSkipCount > 0) && (fieldDef != NULL)) while ((varSkipCountLeft > 0) && (fieldDef != NULL))
{ {
fieldDef = fieldDef->mNextWithSameName; fieldDef = fieldDef->mNextWithSameName;
varSkipCount--; varSkipCountLeft--;
} }
auto& field = closureTypeInst->mFieldInstances[fieldDef->mIdx]; auto& field = closureTypeInst->mFieldInstances[fieldDef->mIdx];

View file

@ -3075,9 +3075,11 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers
{ {
mHadBuildError = true; 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) if (bfError != NULL)
mCompiler->mPassInstance->MoreInfo(error, refNode); mCompiler->mPassInstance->MoreInfo(error, refNode);
return bfError; return bfError;

View file

@ -2271,7 +2271,24 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
/// ///
{ {
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true); 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) if (fieldInstance != NULL)
mCompiler->mCeMachine->mFieldInstanceSet.Remove(fieldInstance); mCompiler->mCeMachine->mFieldInstanceSet.Remove(fieldInstance);
@ -2717,7 +2734,11 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
/// ///
{ {
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true); 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()) if (result.mType == methodInstance->GetOwner())
prevAttrInstances[methodInstance->GetOwner()] = result.mValue; 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) CeFrame* CeDebugger::GetFrame(int callStackIdx)
{ {
auto ceContext = mCeMachine->mCurContext; auto ceContext = mCeMachine->mCurContext;
if (ceContext == NULL) if (ceContext == NULL)
return NULL; return NULL;
@ -846,6 +846,9 @@ CeFrame* CeDebugger::GetFrame(int callStackIdx)
if (callStackIdx < mDbgCallStack.mSize) if (callStackIdx < mDbgCallStack.mSize)
{ {
int frameIdx = mDbgCallStack[callStackIdx].mFrameIdx;
if (frameIdx < 0)
return NULL;
auto ceFrame = &ceContext->mCallStack[mDbgCallStack[callStackIdx].mFrameIdx]; auto ceFrame = &ceContext->mCallStack[mDbgCallStack[callStackIdx].mFrameIdx];
return ceFrame; return ceFrame;
} }
@ -895,12 +898,12 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread)
auto ceFrame = GetFrame(pendingExpr->mCallStackIdx); auto ceFrame = GetFrame(pendingExpr->mCallStackIdx);
if (ceFrame == NULL) if (ceFrame == NULL)
{ {
return "!failed"; return "!No comptime stack frame selected";
} }
if (pendingExpr->mExprNode == NULL) if (pendingExpr->mExprNode == NULL)
{ {
return "!failed"; return "!No expression";
} }
auto module = mCeMachine->mCeModule; auto module = mCeMachine->mCeModule;
@ -2493,7 +2496,8 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type)
auto dbgTypeInfo = GetDbgTypeInfo(typedVal.mType); 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); dbgTypeInfo = GetDbgTypeInfo(dbgTypeInfo->mType->GetUnderlyingType()->mTypeId);
if (dbgTypeInfo == NULL) if (dbgTypeInfo == NULL)
@ -4191,28 +4195,76 @@ String CeDebugger::GetAutoLocals(int callStackIdx, bool showRegs)
String result; String result;
auto ceFrame = GetFrame(callStackIdx); auto ceFrame = GetFrame(callStackIdx);
if (ceFrame == NULL)
return result;
int scopeIdx = -1; int scopeIdx = -1;
auto ceEntry = ceFrame->mFunction->FindEmitEntry(ceFrame->GetInstIdx()); auto ceEntry = ceFrame->mFunction->FindEmitEntry(ceFrame->GetInstIdx());
if (ceEntry != NULL) if (ceEntry != NULL)
scopeIdx = ceEntry->mScope; scopeIdx = ceEntry->mScope;
if (ceFrame != NULL) int instIdx = ceFrame->GetInstIdx();
if (ceFrame->mFunction->mDbgInfo != NULL)
{ {
int instIdx = ceFrame->GetInstIdx(); auto ceFunction = ceFrame->mFunction;
if (ceFrame->mFunction->mDbgInfo != NULL)
struct CeDbgInfo
{ {
for (auto& dbgVar : ceFrame->mFunction->mDbgInfo->mVariables) int mShadowCount;
{ int mPrevShadowIdx;
if ((dbgVar.mScope == scopeIdx) && (instIdx >= dbgVar.mStartCodePos) && (instIdx < dbgVar.mEndCodePos)) 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; int checkIdx = *idxPtr;
result += "\n"; 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; return result;
} }
@ -4312,6 +4364,12 @@ void CeDebugger::UpdateCallStack(bool slowEarlyOut)
prevInlineIdx = ceScope->mInlinedAt; prevInlineIdx = ceScope->mInlinedAt;
} }
} }
CeDbgStackInfo ceDbgStackInfo;
ceDbgStackInfo.mFrameIdx = -1;
ceDbgStackInfo.mScopeIdx = -1;
ceDbgStackInfo.mInlinedFrom = -1;
mDbgCallStack.Add(ceDbgStackInfo);
} }
int CeDebugger::GetCallStackCount() int CeDebugger::GetCallStackCount()
@ -4435,12 +4493,51 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou
auto& dbgCallstackInfo = mDbgCallStack[stackFrameIdx]; 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 ceFrame = &ceContext->mCallStack[dbgCallstackInfo.mFrameIdx];
auto ceFunction = ceFrame->mFunction; auto ceFunction = ceFrame->mFunction;
if (ceFunction->mFailed) if (ceFunction->mFailed)
*outFlags |= FrameFlags_HadError; *outFlags |= FrameFlags_HadError;
int instIdx = (int)(ceFrame->mInstPtr - &ceFunction->mCode[0] - 2); int instIdx = (int)(ceFrame->mInstPtr - &ceFunction->mCode[0] - 2);
BF_ASSERT(ceFunction->mId != -1); BF_ASSERT(ceFunction->mId != -1);
@ -4448,16 +4545,17 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou
CeEmitEntry* emitEntry = ceFunction->FindEmitEntry(instIdx); CeEmitEntry* emitEntry = ceFunction->FindEmitEntry(instIdx);
*outStackSize = ceContext->mStackSize - ceFrame->mStackAddr;
if (stackFrameIdx < mDbgCallStack.mSize - 1) if (stackFrameIdx < mDbgCallStack.mSize - 1)
{ {
auto& nextStackInfo = mDbgCallStack[stackFrameIdx + 1]; auto& nextStackInfo = mDbgCallStack[stackFrameIdx + 1];
auto prevFrame = &ceContext->mCallStack[nextStackInfo.mFrameIdx]; if (nextStackInfo.mFrameIdx >= 0)
*outStackSize = prevFrame->mStackAddr - ceFrame->mStackAddr; {
} auto prevFrame = &ceContext->mCallStack[nextStackInfo.mFrameIdx];
else *outStackSize = prevFrame->mStackAddr - ceFrame->mStackAddr;
{ }
*outStackSize = ceContext->mStackSize - ceFrame->mStackAddr;
} }
CeDbgScope* ceScope = NULL; CeDbgScope* ceScope = NULL;
if (dbgCallstackInfo.mScopeIdx != -1) if (dbgCallstackInfo.mScopeIdx != -1)

View file

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