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

Fixes for increment/decrement operators

This commit is contained in:
Brian Fiete 2020-11-05 08:51:20 -08:00
parent 37576d389c
commit bb87ca7b52
2 changed files with 45 additions and 5 deletions

View file

@ -18295,8 +18295,10 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal
result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType);
}
if ((methodMatcher.mBestMethodInstance) && (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic) &&
if ((methodMatcher.mBestMethodInstance) &&
((findOp == BfUnaryOp_Increment) || (findOp == BfUnaryOp_Decrement)))
{
if (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic)
{
if (args[0].mTypedValue.IsAddr())
mModule->mBfIRBuilder->CreateStore(result.mValue, args[0].mTypedValue.mValue);
@ -18305,6 +18307,18 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal
mModule->AssertErrorState();
}
}
else
{
if (!result.mType->IsValuelessType())
{
if (targetVal.IsAddr())
{
result = mModule->LoadValue(result);
mModule->mBfIRBuilder->CreateStore(result.mValue, targetVal.mValue);
}
}
}
}
if (postOpVal)
result = postOpVal;

View file

@ -23,6 +23,13 @@ namespace Tests
res.mA = lhs.mA - rhs.mA;
return res;
}
public static StructA operator++(StructA val)
{
StructA newVal;
newVal.mA = val.mA + 1;
return newVal;
}
}
struct StructB
@ -35,6 +42,11 @@ namespace Tests
result.mA = sa.mA + sb.mB + 1000;
return result;
}
public void operator++() mut
{
mB++;
}
}
struct StructC
@ -220,6 +232,20 @@ namespace Tests
StructA sa4 = Op(sa0, sb0);
Test.Assert(sa4.mA == 1012);
StructA sa6 = sa0++;
Test.Assert(sa0.mA == 2);
Test.Assert(sa6.mA == 1);
sa6 = ++sa0;
Test.Assert(sa0.mA == 3);
Test.Assert(sa6.mA == 3);
StructB sb6 = sb0++;
Test.Assert(sb0.mB == 12);
Test.Assert(sb6.mB == 11);
sb6 = ++sb0;
Test.Assert(sb0.mB == 13);
Test.Assert(sb6.mB == 13);
float val = Op((int32)100, (int16)23);
Test.Assert(val == 123);