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

Improved attribute encoding for nulls

This commit is contained in:
Brian Fiete 2023-06-24 06:03:46 -04:00
parent 19a2855da9
commit 2ead8e5377
2 changed files with 30 additions and 10 deletions

View file

@ -69,6 +69,9 @@ namespace System.Reflection
var attrDataType = Decode!<TypeCode>(data); var attrDataType = Decode!<TypeCode>(data);
switch (attrDataType) switch (attrDataType)
{ {
case .NullPtr:
args[argIdx] = null;
break;
case .Int8, case .Int8,
.UInt8, .UInt8,
.Char8, .Char8,

View file

@ -5614,19 +5614,22 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType
if (argType->IsObject()) if (argType->IsObject())
{ {
if (argType->IsInstanceOf(mCompiler->mStringTypeDef)) if ((argType->IsInstanceOf(mCompiler->mStringTypeDef)) || (argType == mContext->mBfObjectType))
{ {
int stringId = constant->mInt32; if (constant->mTypeCode == BfTypeCode_StringId)
int* orderedIdPtr;
if (usedStringIdMap.TryAdd(stringId, NULL, &orderedIdPtr))
{ {
*orderedIdPtr = (int)usedStringIdMap.size() - 1; int stringId = constant->mInt32;
} int* orderedIdPtr;
if (usedStringIdMap.TryAdd(stringId, NULL, &orderedIdPtr))
{
*orderedIdPtr = (int)usedStringIdMap.size() - 1;
}
GetStringObjectValue(stringId, true, true); GetStringObjectValue(stringId, true, true);
PUSH_INT8(0xFF); // String PUSH_INT8(0xFF); // String
PUSH_INT32(*orderedIdPtr); PUSH_INT32(*orderedIdPtr);
return; return;
}
} }
} }
@ -5651,6 +5654,19 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType
} }
} }
if (constant->mConstType == BfConstType_BitCastNull)
{
PUSH_INT8(BfTypeCode_NullPtr);
return;
}
if (constant->mConstType == BfConstType_BitCast)
{
auto bitcast = (BfConstantBitCast*)constant;
EncodeAttributeData(typeInstance, argType, BfIRValue(BfIRValueFlags_Const, bitcast->mTarget), data, usedStringIdMap);
return;
}
PUSH_INT8(constant->mTypeCode); PUSH_INT8(constant->mTypeCode);
if ((constant->mTypeCode == BfTypeCode_Int64) || if ((constant->mTypeCode == BfTypeCode_Int64) ||
(constant->mTypeCode == BfTypeCode_UInt64) || (constant->mTypeCode == BfTypeCode_UInt64) ||
@ -5692,6 +5708,7 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType
for (int i = 0; i < argType->mSize; i++) for (int i = 0; i < argType->mSize; i++)
data.Add(0); data.Add(0);
} }
// else if (constant->mConstType == BfConstType_Agg) // else if (constant->mConstType == BfConstType_Agg)
// { // {
// BF_ASSERT(argType->IsComposite()); // BF_ASSERT(argType->IsComposite());