1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Added support for const string generic args

This commit is contained in:
Brian Fiete 2022-02-04 14:26:50 -05:00
parent 361be9dc92
commit a87ccd299d
5 changed files with 63 additions and 5 deletions

View file

@ -1639,14 +1639,13 @@ BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId,
mBfIRBuilder->PopulateType(stringTypeInst);
auto stringValLiteral = mBfIRBuilder->CreateGlobalVariable(
mBfIRBuilder->MapTypeInst(stringTypeInst),
mBfIRBuilder->MapTypeInst(stringTypeInst, BfIRPopulateType_Full),
true,
BfIRLinkageType_External,
define ? stringValData : BfIRValue(),
stringObjName);
auto stringVal = mBfIRBuilder->CreateBitCast(stringValLiteral, mBfIRBuilder->MapType(stringTypeInst, BfIRPopulateType_Full));
return stringVal;
return stringValLiteral;
}
int BfModule::GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder)
@ -7666,6 +7665,9 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar
if (constraintType->IsPrimitiveType())
typeCode = ((BfPrimitiveType*)constraintType)->mTypeDef->mTypeCode;
if (constraintType->IsInstanceOf(mCompiler->mStringTypeDef))
isValidTypeCode = true;
switch (typeCode)
{
case BfTypeCode_StringId:
@ -12070,6 +12072,8 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
primType = (BfPrimitiveType*)value.mType;
else if (value.mType->IsTypedPrimitive())
primType = value.mType->GetUnderlyingType();
else if (value.mType->IsInstanceOf(mCompiler->mStringTypeDef))
primType = value.mType;
if (primType)
{
@ -12083,6 +12087,17 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
return variant;
}
if (constant->mConstType == BfConstType_GlobalVar)
{
int stringIdx = GetStringPoolIdx(value.mValue, mBfIRBuilder);
if (stringIdx != -1)
{
variant.mTypeCode = BfTypeCode_StringId;
variant.mInt64 = stringIdx;
return variant;
}
}
switch (constant->mTypeCode)
{
case BfTypeCode_Boolean:
@ -12102,6 +12117,7 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
case BfTypeCode_Char8:
case BfTypeCode_Char16:
case BfTypeCode_Char32:
case BfTypeCode_StringId:
variant.mTypeCode = constant->mTypeCode;
variant.mInt64 = constant->mInt64;
break;