1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Comptime updates, start of metaprogramming support

This commit is contained in:
Brian Fiete 2021-01-08 16:21:03 -08:00
parent be1c099f19
commit 3bbf2d8313
43 changed files with 1562 additions and 885 deletions

View file

@ -634,6 +634,12 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f
auto typeOf = (BfTypeOf_Const*)fromConst;
return CreateTypeOf(typeOf->mType);
}
else if (fromConst->mConstType == BfConstType_TypeOf_WithData)
{
auto typeOf = (BfTypeOf_WithData_Const*)fromConst;
auto dataConstant = fromHolder->GetConstant(typeOf->mTypeData);
return CreateTypeOf(typeOf->mType, CreateConst(dataConstant, fromHolder));
}
else if (fromConst->mConstType == BfConstType_AggZero)
{
auto aggZero = (BfConstant*)fromConst;
@ -783,7 +789,20 @@ BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type)
{
BfTypeOf_Const* typeOf = mTempAlloc.Alloc<BfTypeOf_Const>();
typeOf->mConstType = BfConstType_TypeOf;
typeOf->mType = type;
auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(typeOf));
#ifdef CHECK_CONSTHOLDER
irValue.mHolder = this;
#endif
return irValue;
}
BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type, BfIRValue typeData)
{
BfTypeOf_WithData_Const* typeOf = mTempAlloc.Alloc<BfTypeOf_WithData_Const>();
typeOf->mConstType = BfConstType_TypeOf_WithData;
typeOf->mType = type;
typeOf->mTypeData = typeData;
auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(typeOf));
#ifdef CHECK_CONSTHOLDER
irValue.mHolder = this;
@ -1949,11 +1968,18 @@ void BfIRBuilder::Write(const BfIRValue& irValue)
{
Write(constant->mInt64);
}
break;
case (int)BfConstType_TypeOf:
{
auto typeofConst = (BfTypeOf_Const*)constant;
Write(MapType(typeofConst->mType, BfIRPopulateType_Identity));
}
break;
case (int)BfConstType_Undef:
{
auto undefConst = (BfConstantUndef*)constant;
Write(undefConst->mType);
case (int)BfConstType_TypeOf_WithData:
{
auto typeofConst = (BfTypeOf_WithData_Const*)constant;
Write(MapType(typeofConst->mType, BfIRPopulateType_Identity));
Write(typeofConst->mTypeData);
}
break;
default:
@ -4476,6 +4502,12 @@ BfIRValue BfIRBuilder::CreateGlobalStringPtr(const StringImpl& str)
return retVal;
}
void BfIRBuilder::SetReflectTypeData(BfIRType type, BfIRValue globalVar)
{
BfIRValue retVal = WriteCmd(BfIRCmd_SetReflectTypeData, type, globalVar);
NEW_CMD_INSERTED_IRVALUE;
}
BfIRBlock BfIRBuilder::CreateBlock(const StringImpl& name, bool addNow)
{
if (addNow)