diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index a3930925..d9a9bda8 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -792,7 +792,10 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef else if (typeRefName == "Inline") methodDef->mAlwaysInline = true; else if (typeRefName == "AllowAppend") + { methodDef->mHasAppend = true; + methodDef->mIsNoSplat = true; + } else if (typeRefName == "Checked") methodDef->mCheckedKind = BfCheckedKind_Checked; else if (typeRefName == "Unchecked") @@ -1866,6 +1869,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) methodDef->mProtection = BfProtection_Public; methodDef->mMethodType = BfMethodType_CtorCalcAppend; methodDef->mIsMutating = method->mIsMutating; + methodDef->mIsNoSplat = true; methodDef->mMethodDeclaration = method->mMethodDeclaration; methodDef->mReturnTypeRef = mSystem->mDirectIntTypeRef; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index e39df23d..a413c78d 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -411,6 +411,8 @@ public: void EmitAppendAlign(int align, int sizeMultiple = 0) { + BF_ASSERT(align > 0); + if (mIsFirstConstPass) mModule->mCurMethodInstance->mAppendAllocAlign = BF_MAX((int)mModule->mCurMethodInstance->mAppendAllocAlign, align); @@ -426,6 +428,8 @@ public: mCurAppendAlign = sizeMultiple % align; } + BF_ASSERT(mCurAppendAlign > 0); + if (mConstAccum) { auto constant = mModule->mBfIRBuilder->GetConstant(mConstAccum.mValue); @@ -614,6 +618,8 @@ public: } } + mModule->PopulateType(resultType); + if (isRawArrayAlloc) { curAlign = resultType->mAlign; @@ -13129,10 +13135,6 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance) } methodInstance->mIdHash = (int64)hashCtx.Finish64(); - if (methodInstance->mIdHash == 0x3400000029LL) - { - NOP; - } } BfIRValue BfModule::GetInterfaceSlotNum(BfTypeInstance* ifaceType) @@ -14730,7 +14732,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr return BfTypedValue(); // Do we need to iterate in order to resolve mAppendAllocAlign? - bool isFirstRun = methodInst->mAppendAllocAlign < 0; + bool isFirstRun = methodInst->mEndingAppendAllocAlign < 0; bool wasAllConst = true; int argIdx = 0; @@ -15079,10 +15081,15 @@ void BfModule::CreateStaticCtor() { continue; } - GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true); - + GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true); } } + + auto _CheckInitBlock = [&](BfAstNode* node) + { + }; + + EmitInitBlocks(_CheckInitBlock); } else { @@ -15565,11 +15572,6 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis)) paramIdx = -1; - if (methodInstance->mMethodDef->mName == "Invoke@GetFFIType$wPb") - { - NOP; - } - int argCount = methodInstance->GetIRFunctionParamCount(this); while (argIdx < argCount) @@ -15753,6 +15755,37 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func } } +void BfModule::EmitInitBlocks(const std::function& initBlockCallback) +{ + auto methodDef = mCurMethodInstance->mMethodDef; + + mCurTypeInstance->mTypeDef->PopulateMemberSets(); + BfMemberSetEntry* entry = NULL; + BfMethodDef* initMethodDef = NULL; + mCurTypeInstance->mTypeDef->mMethodSet.TryGetWith(String("__BfInit"), &entry); + if (entry != NULL) + initMethodDef = (BfMethodDef*)entry->mMemberDef; + + SizedArray initBodies; + + for (; initMethodDef != NULL; initMethodDef = initMethodDef->mNextWithSameName) + { + if (initMethodDef->mDeclaringType != methodDef->mDeclaringType) + continue; + if (initMethodDef->mMethodType != BfMethodType_Init) + continue; + if (initMethodDef->mIsStatic != methodDef->mIsStatic) + continue; + initBodies.Insert(0, initMethodDef->mBody); + } + + for (auto body : initBodies) + { + initBlockCallback(body); + VisitEmbeddedStatement(body); + } +} + void BfModule::EmitCtorBody(bool& skipBody) { auto methodInstance = mCurMethodInstance; @@ -16012,29 +16045,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } } - mCurTypeInstance->mTypeDef->PopulateMemberSets(); - BfMemberSetEntry* entry = NULL; - BfMethodDef* initMethodDef = NULL; - mCurTypeInstance->mTypeDef->mMethodSet.TryGetWith(String("__BfInit"), &entry); - if (entry != NULL) - initMethodDef = (BfMethodDef*)entry->mMemberDef; - - SizedArray initBodies; - - for (; initMethodDef != NULL; initMethodDef = initMethodDef->mNextWithSameName) - { - if (initMethodDef->mDeclaringType != methodDef->mDeclaringType) - continue; - if (initMethodDef->mMethodType != BfMethodType_Init) - continue; - initBodies.Insert(0, initMethodDef->mBody); - } - - for (auto body : initBodies) - { - _CheckInitBlock(body); - VisitEmbeddedStatement(body); - } + EmitInitBlocks(_CheckInitBlock); if (hadInlineInitBlock) { diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 54d7fff7..e208afbd 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1820,6 +1820,7 @@ public: void CreateDllImportMethod(); BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance); void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); + void EmitInitBlocks(const std::function& initBlockCallback); void EmitCtorBody(bool& skipBody); void EmitDtorBody(); void EmitEnumToStringBody();