1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 18:48:01 +02:00

Merged comptime reflection info into normal reflection data types

This commit is contained in:
Brian Fiete 2022-02-12 08:05:47 -05:00
parent b0c6dd7e43
commit e7f0b21cf6
20 changed files with 432 additions and 453 deletions

View file

@ -429,8 +429,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
mIPrintableTypeDef = NULL;
mIHashableTypeDef = NULL;
mIComptimeTypeApply = NULL;
mIComptimeMethodApply = NULL;
mComptimeFieldInfoTypeDef = NULL;
mIComptimeMethodApply = NULL;
mIOnTypeInitTypeDef = NULL;
mIOnTypeDoneTypeDef = NULL;
mIOnFieldInitTypeDef = NULL;
@ -457,6 +456,8 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
mReflectSpecializedGenericType = NULL;
mReflectTypeInstanceTypeDef = NULL;
mReflectUnspecializedGenericType = NULL;
mReflectFieldInfoTypeDef = NULL;
mReflectMethodInfoTypeDef = NULL;
mSizedArrayTypeDef = NULL;
mStaticInitAfterAttributeTypeDef = NULL;
mStaticInitPriorityAttributeTypeDef = NULL;
@ -6832,8 +6833,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
mIPrintableTypeDef = _GetRequiredType("System.IPrintable");
mIHashableTypeDef = _GetRequiredType("System.IHashable");
mIComptimeTypeApply = _GetRequiredType("System.IComptimeTypeApply");
mIComptimeMethodApply = _GetRequiredType("System.IComptimeMethodApply");
mComptimeFieldInfoTypeDef = _GetRequiredType("System.Reflection.ComptimeFieldInfo");
mIComptimeMethodApply = _GetRequiredType("System.IComptimeMethodApply");
mIOnTypeInitTypeDef = _GetRequiredType("System.IOnTypeInit");
mIOnTypeDoneTypeDef = _GetRequiredType("System.IOnTypeDone");
mIOnFieldInitTypeDef = _GetRequiredType("System.IOnFieldInit");
@ -6861,6 +6861,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
mReflectSpecializedGenericType = _GetRequiredType("System.Reflection.SpecializedGenericType");
mReflectTypeInstanceTypeDef = _GetRequiredType("System.Reflection.TypeInstance");
mReflectUnspecializedGenericType = _GetRequiredType("System.Reflection.UnspecializedGenericType");
mReflectFieldInfoTypeDef = _GetRequiredType("System.Reflection.FieldInfo");
mReflectMethodInfoTypeDef = _GetRequiredType("System.Reflection.MethodInfo");
mSizedArrayTypeDef = _GetRequiredType("System.SizedArray", 2);
mStaticInitAfterAttributeTypeDef = _GetRequiredType("System.StaticInitAfterAttribute");
mStaticInitPriorityAttributeTypeDef = _GetRequiredType("System.StaticInitPriorityAttribute");

View file

@ -389,8 +389,7 @@ public:
BfTypeDef* mIPrintableTypeDef;
BfTypeDef* mIHashableTypeDef;
BfTypeDef* mIComptimeTypeApply;
BfTypeDef* mIComptimeMethodApply;
BfTypeDef* mComptimeFieldInfoTypeDef;
BfTypeDef* mIComptimeMethodApply;
BfTypeDef* mIOnTypeInitTypeDef;
BfTypeDef* mIOnTypeDoneTypeDef;
BfTypeDef* mIOnFieldInitTypeDef;
@ -416,6 +415,8 @@ public:
BfTypeDef* mReflectSpecializedGenericType;
BfTypeDef* mReflectTypeInstanceTypeDef;
BfTypeDef* mReflectUnspecializedGenericType;
BfTypeDef* mReflectFieldInfoTypeDef;
BfTypeDef* mReflectMethodInfoTypeDef;
BfTypeDef* mSizedArrayTypeDef;
BfTypeDef* mAttributeTypeDef;

View file

@ -1567,24 +1567,37 @@ BfIRValue BfModule::CreateStringCharPtr(const StringImpl& str, int stringId, boo
return mBfIRBuilder->CreateInBoundsGEP(gv, 0, 0);
}
void BfModule::FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams)
void BfModule::FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams, bool fillInPadding)
{
if (!typeInst->mTypeDef->mIsCombinedPartial)
if ((!typeInst->mTypeDef->mIsCombinedPartial) && (!fillInPadding))
return;
int prevDataIdx = -1;
int usedDataIdx = 0;
if (typeInst->mBaseType != NULL)
usedDataIdx++;
int valueParamIdx = 0;
if (typeInst->mBaseType != NULL)
{
usedDataIdx++;
valueParamIdx++;
prevDataIdx++;
}
int startingParamsSize = (int)valueParams.mSize;
for (int fieldIdx = 0; fieldIdx < (int)typeInst->mFieldInstances.size(); fieldIdx++)
{
auto fieldInstance = &typeInst->mFieldInstances[fieldIdx];
if (fieldInstance->mDataIdx < 0)
continue;
BF_ASSERT(fieldInstance->mDataIdx > prevDataIdx);
if (fillInPadding)
{
for (int i = prevDataIdx + 1; i < fieldInstance->mDataIdx; i++)
valueParams.Insert(valueParamIdx++, mBfIRBuilder->CreateConstArrayZero(0));
}
valueParamIdx++;
prevDataIdx = fieldInstance->mDataIdx;
usedDataIdx++;
@ -5355,6 +5368,123 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType
}
}
BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx)
{
bool isComptime = mBfIRBuilder->mIgnoreWrites;
BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
auto typeInstance = fieldInstance->mOwner;
BfType* intType = GetPrimitiveType(BfTypeCode_Int32);
BfType* intPtrType = GetPrimitiveType(BfTypeCode_IntPtr);
BfType* shortType = GetPrimitiveType(BfTypeCode_Int16);
BfType* typeIdType = intType;
BfTypeInstance* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef)->ToTypeInstance();
BfIRValue emptyValueType = mBfIRBuilder->mIgnoreWrites ?
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType->mBaseType), SizedArray<BfIRValue, 1>()) :
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->mBaseType), SizedArray<BfIRValue, 1>());
BfIRValue fieldNameConst = GetStringObjectValue(fieldDef->mName, !mIsComptimeModule);
bool is32Bit = mCompiler->mSystem->mPtrSize == 4;
int typeId = 0;
auto fieldType = fieldInstance->GetResolvedType();
if (fieldType->IsGenericParam())
{
//TODO:
}
else
typeId = fieldType->mTypeId;
BfFieldFlags fieldFlags = (BfFieldFlags)0;
if (fieldDef->mProtection == BfProtection_Protected)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Protected);
if (fieldDef->mProtection == BfProtection_Public)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Public);
if (fieldDef->mIsStatic)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Static);
if (fieldDef->mIsConst)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Const);
if (fieldDef->IsEnumCaseEntry())
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_EnumCase);
BfIRValue constValue;
BfIRValue constValue2;
if (fieldInstance->GetFieldDef()->mIsConst)
{
if (fieldInstance->mConstIdx != -1)
{
auto constant = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64);
if (is32Bit)
constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64 >> 32);
}
}
else if (fieldInstance->GetFieldDef()->mIsStatic)
{
BfTypedValue refVal;
if (!mIsComptimeModule) // This can create circular reference issues for a `Self` static
refVal = ReferenceStaticField(fieldInstance);
if (refVal.mValue.IsConst())
{
auto constant = mBfIRBuilder->GetConstant(refVal.mValue);
if (constant->mConstType == BfConstType_GlobalVar)
{
auto globalVar = (BfGlobalVar*)constant;
if (globalVar->mName[0] == '#')
refVal = BfTypedValue();
}
}
if ((refVal.IsAddr()) && (!isComptime))
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
}
if (!constValue)
constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, fieldInstance->mDataOffset);
BfIRValue result;
if (is32Bit)
{
if (!constValue2)
constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0);
SizedArray<BfIRValue, 8> fieldVals =
{
emptyValueType,
fieldNameConst, // mName
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mData
constValue2, // mDataHi
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
FixConstValueParams(reflectFieldDataType, fieldVals, isComptime);
result = isComptime ?
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
}
else
{
SizedArray<BfIRValue, 8> fieldVals =
{
emptyValueType,
fieldNameConst, // mName
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mData
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
FixConstValueParams(reflectFieldDataType, fieldVals, isComptime);
result = isComptime ?
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
}
return result;
}
BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStringIdMap, bool forceReflectFields, bool needsTypeData, bool needsTypeNames, bool needsVData)
{
if ((IsHotCompile()) && (!type->mDirty))
@ -6562,102 +6692,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
break;
BfFieldInstance* fieldInstance = &typeInstance->mFieldInstances[fieldIdx];
BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
BfIRValue fieldNameConst = GetStringObjectValue(fieldDef->mName, !mIsComptimeModule);
int typeId = 0;
auto fieldType = fieldInstance->GetResolvedType();
if (fieldType->IsGenericParam())
{
//TODO:
}
else
typeId = fieldType->mTypeId;
BfFieldFlags fieldFlags = (BfFieldFlags)0;
if (fieldDef->mProtection == BfProtection_Protected)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Protected);
if (fieldDef->mProtection == BfProtection_Public)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Public);
if (fieldDef->mIsStatic)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Static);
if (fieldDef->mIsConst)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Const);
if (fieldDef->IsEnumCaseEntry())
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_EnumCase);
int customAttrIdx = _HandleCustomAttrs(fieldInstance->mCustomAttributes);
BfIRValue constValue;
BfIRValue constValue2;
if (fieldInstance->GetFieldDef()->mIsConst)
{
if (fieldInstance->mConstIdx != -1)
{
auto constant = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64);
if (is32Bit)
constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64 >> 32);
}
}
else if (fieldInstance->GetFieldDef()->mIsStatic)
{
BfTypedValue refVal;
if (!mIsComptimeModule) // This can create circular reference issues for a `Self` static
refVal = ReferenceStaticField(fieldInstance);
if (refVal.mValue.IsConst())
{
auto constant = mBfIRBuilder->GetConstant(refVal.mValue);
if (constant->mConstType == BfConstType_GlobalVar)
{
auto globalVar = (BfGlobalVar*)constant;
if (globalVar->mName[0] == '#')
refVal = BfTypedValue();
}
}
if (refVal.IsAddr())
{
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
}
}
if (!constValue)
constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, fieldInstance->mDataOffset);
if (is32Bit)
{
if (!constValue2)
constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0);
SizedArray<BfIRValue, 8> fieldVals =
{
emptyValueType,
fieldNameConst, // mName
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mData
constValue2, // mDataHi
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
auto fieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals);
fieldTypes.push_back(fieldData);
}
else
{
SizedArray<BfIRValue, 8> fieldVals =
{
emptyValueType,
fieldNameConst, // mName
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mData
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
auto fieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals);
fieldTypes.push_back(fieldData);
}
fieldTypes.push_back(CreateFieldData(fieldInstance, _HandleCustomAttrs(fieldInstance->mCustomAttributes)));
}
auto reflectFieldDataIRType = mBfIRBuilder->MapType(reflectFieldDataType);
@ -20844,7 +20879,13 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
if (bodyBlock->mCloseBrace != NULL)
{
BfAstNode* target = bodyBlock->mCloseBrace;
Fail("Method must return value", target);
if (!mCompiler->mHasRequiredTypes)
{
AddFailType(mCurTypeInstance);
mHadBuildError = true;
}
else
Fail("Method must return value", target);
}
else
{

View file

@ -1562,7 +1562,7 @@ public:
BfIRValue GetDefaultValue(BfType* type);
BfTypedValue GetFakeTypedValue(BfType* type);
BfTypedValue GetDefaultTypedValue(BfType* type, bool allowRef = false, BfDefaultValueKind defaultValueKind = BfDefaultValueKind_Const);
void FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams);
void FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams, bool fillInPadding = false);
BfIRValue CreateStringObjectValue(const StringImpl& str, int stringId, bool define);
BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define);
int GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
@ -1978,6 +1978,7 @@ public:
BfIRValue CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTypeInstance* implTypeInst, int startVirtIdx);
BfIRValue CreateTypeDataRef(BfType* type);
void EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType, BfIRValue arg, SizedArrayImpl<uint8>& data, Dictionary<int, int>& usedStringIdMap);
BfIRValue CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx);
BfIRValue CreateTypeData(BfType* type, Dictionary<int, int>& usedStringIdMap, bool forceReflectFields, bool needsTypeData, bool needsTypeNames, bool needsVData);
BfIRValue FixClassVData(BfIRValue value);

View file

@ -2197,30 +2197,16 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
args.Add(attrVal);
if (isFieldApply)
{
auto fieldDef = fieldInstance->GetFieldDef();
BfFieldFlags fieldFlags = (BfFieldFlags)0;
if (fieldDef->mProtection == BfProtection_Protected)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Protected);
if (fieldDef->mProtection == BfProtection_Public)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Public);
if (fieldDef->mIsStatic)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Static);
if (fieldDef->mIsConst)
fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Const);
auto fieldInfoType = ResolveTypeDef(mCompiler->mComptimeFieldInfoTypeDef);
auto fieldInfoType = ResolveTypeDef(mCompiler->mReflectFieldInfoTypeDef);
if (fieldInfoType != NULL)
{
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true);
SizedArray<BfIRValue, 9> fieldData =
{
mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(fieldInfoType, BfIRPopulateType_Identity)),
GetConstValue((uint64)(intptr)fieldInstance, GetPrimitiveType(BfTypeCode_Int64)), // mNativeFieldInstance
GetConstValue(typeInstance->mTypeId, GetPrimitiveType(BfTypeCode_Int32)), // mOwner
GetConstValue((fieldInstance->mResolvedType != NULL) ? fieldInstance->mResolvedType->mTypeId : 0, GetPrimitiveType(BfTypeCode_Int32)), // mTypeId
GetConstValue(fieldDef->mIdx, GetPrimitiveType(BfTypeCode_Int32)), // mFieldIdx
GetConstValue((int)fieldFlags, GetPrimitiveType(BfTypeCode_Int16)), // mFieldFlags
};
mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(fieldInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)),
mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance
CreateFieldData(fieldInstance, fieldInstance->GetFieldDef()->mIdx)
};
FixConstValueParams(fieldInfoType->ToTypeInstance(), fieldData);
auto fieldDataAgg = mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(fieldInfoType, BfIRPopulateType_Identity), fieldData);
args.Add(fieldDataAgg);
@ -2612,7 +2598,19 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
SizedArray<BfIRValue, 1> args;
if (!attrType->IsValuelessType())
args.Add(attrVal);
args.Add(mBfIRBuilder->CreateConst(BfTypeCode_UInt64, (uint64)(intptr)methodInstance));
auto methodInfoType = ResolveTypeDef(mCompiler->mReflectMethodInfoTypeDef);
SizedArray<BfIRValue, 9> methodData =
{
mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(methodInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)),
mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance
GetConstValue((int64)methodInstance, GetPrimitiveType(BfTypeCode_Int64)), // mNativeMethodInstance
};
FixConstValueParams(methodInfoType->ToTypeInstance(), methodData);
auto fieldDataAgg = mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(methodInfoType, BfIRPopulateType_Identity), methodData);
args.Add(fieldDataAgg);
if (applyMethodInstance->GetParamCount() > 1)
{
if (irValue)
@ -2628,16 +2626,8 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance)
}
mCompiler->mCEMachine->mMethodInstanceSet.Add(methodInstance);
//TESTING
// mCompiler->mCEMachine->ReleaseContext(ceContext);
// ceContext = mCompiler->mCEMachine->AllocContext();
// ceContext->mMemory.mSize = ceContext->mMemory.mAllocSize;
auto activeTypeDef = typeInstance->mTypeDef;
//auto result = ceContext->Call(customAttribute.mRef, this, applyMethodInstance, args, CeEvalFlags_None, NULL);
BfTypedValue result;
///
{

View file

@ -3517,6 +3517,18 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
if (constant->mConstType == BfConstType_Agg)
{
if (type->IsPointer())
{
auto elementType = type->GetUnderlyingType();
auto toPtr = CeMalloc(elementType->mSize);
addr_ce toAddr = (addr_ce)(toPtr - mMemory.mVals);
if (mCeMachine->mCeModule->mSystem->mPtrSize == 4)
CE_GETC(int32) = (int32)toAddr;
else
CE_GETC(int64) = (int64)toAddr;
return WriteConstant(module, toAddr, constant, elementType, isParams);
}
auto aggConstant = (BfConstantAgg*)constant;
if (type->IsSizedArray())
{
@ -3671,6 +3683,14 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
return WriteConstant(module, addr, constTarget, type);
}
if (constant->mConstType == BfConstType_PtrToInt)
{
auto ptrToIntConst = (BfConstantPtrToInt*)constant;
auto constTarget = module->mBfIRBuilder->GetConstantById(ptrToIntConst->mTarget);
return WriteConstant(module, addr, constTarget, type);
}
if (constant->mConstType == BfConstType_BitCastNull)
{
BF_ASSERT(type->IsPointer() || type->IsObjectOrInterface());
@ -3764,7 +3784,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
if (checkConstant->mConstType == BfConstType_AggCE)
return WriteConstant(module, addr, checkConstant, type, isParams);
}
}
}
return false;
}
@ -5048,11 +5068,10 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
}
if ((methodIdx < 0) || (methodIdx >= typeInfo->mMethodInstances.mSize))
{
_Fail("Method out of bounds");
return false;
*(int64*)(stackPtr + 0) = 0;
}
*(int64*)(stackPtr + 0) = (int64)(intptr)typeInfo->mMethodInstances[methodIdx];
else
*(int64*)(stackPtr + 0) = (int64)(intptr)typeInfo->mMethodInstances[methodIdx];
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Method_ToString)
{
@ -5087,8 +5106,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
// int32 mReturnType
// int32 mParamCount
// int16 mFlags
// int32 mMethodIdx
int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+4+2);
int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+4+2+4);
auto methodInstance = mCeMachine->GetMethodInstance(methodHandle);
if (methodInstance == NULL)
@ -5099,7 +5119,8 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
*(int32*)(stackPtr + 0) = methodInstance->mReturnType->mTypeId;
*(int32*)(stackPtr + 4) = methodInstance->GetParamCount();
*(int16*)(stackPtr + 4+4) = methodInstance->GetMethodFlags();
*(int16*)(stackPtr + 4+4) = methodInstance->GetMethodFlags();
*(int32*)(stackPtr + 4+4+2) = methodInstance->mMethodDef->mIdx;
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetParamInfo)
{
@ -5129,20 +5150,6 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
*(int16*)(stackPtr + 4) = 0; // Flags
CeSetAddrVal(stackPtr + 4+2, stringAddr, ptrSize);
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Field_GetName)
{
int64 fieldHandle = *(int64*)((uint8*)stackPtr + ptrSize);
auto fieldInstance = mCeMachine->GetFieldInstance(fieldHandle);
if (fieldInstance == NULL)
{
_Fail("Invalid field instance");
return false;
}
CeSetAddrVal(stackPtr + 0, GetString(fieldInstance->GetFieldDef()->mName), ptrSize);
_FixVariables();
}
else if (checkFunction->mFunctionKind == CeFunctionKind_EmitTypeBody)
{
int32 typeId = *(int32*)((uint8*)stackPtr);
@ -7997,10 +8004,6 @@ void CeMachine::CheckFunctionKind(CeFunction* ceFunction)
{
ceFunction->mFunctionKind = CeFunctionKind_Method_GetParamInfo;
}
else if (methodDef->mName == "Comptime_Field_GetName")
{
ceFunction->mFunctionKind = CeFunctionKind_Field_GetName;
}
}
else if (owner->IsInstanceOf(mCeModule->mCompiler->mCompilerTypeDef))
{

View file

@ -332,7 +332,6 @@ enum CeFunctionKind
CeFunctionKind_Method_GetName,
CeFunctionKind_Method_GetInfo,
CeFunctionKind_Method_GetParamInfo,
CeFunctionKind_Field_GetName,
CeFunctionKind_EmitTypeBody,
CeFunctionKind_EmitAddInterface,