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:
parent
37576d389c
commit
bb87ca7b52
2 changed files with 45 additions and 5 deletions
|
@ -18295,14 +18295,28 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal
|
||||||
result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType);
|
result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((methodMatcher.mBestMethodInstance) && (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic) &&
|
if ((methodMatcher.mBestMethodInstance) &&
|
||||||
((findOp == BfUnaryOp_Increment) || (findOp == BfUnaryOp_Decrement)))
|
((findOp == BfUnaryOp_Increment) || (findOp == BfUnaryOp_Decrement)))
|
||||||
{
|
{
|
||||||
if (args[0].mTypedValue.IsAddr())
|
if (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic)
|
||||||
mModule->mBfIRBuilder->CreateStore(result.mValue, args[0].mTypedValue.mValue);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
mModule->AssertErrorState();
|
if (args[0].mTypedValue.IsAddr())
|
||||||
|
mModule->mBfIRBuilder->CreateStore(result.mValue, args[0].mTypedValue.mValue);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mModule->AssertErrorState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!result.mType->IsValuelessType())
|
||||||
|
{
|
||||||
|
if (targetVal.IsAddr())
|
||||||
|
{
|
||||||
|
result = mModule->LoadValue(result);
|
||||||
|
mModule->mBfIRBuilder->CreateStore(result.mValue, targetVal.mValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,13 @@ namespace Tests
|
||||||
res.mA = lhs.mA - rhs.mA;
|
res.mA = lhs.mA - rhs.mA;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StructA operator++(StructA val)
|
||||||
|
{
|
||||||
|
StructA newVal;
|
||||||
|
newVal.mA = val.mA + 1;
|
||||||
|
return newVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StructB
|
struct StructB
|
||||||
|
@ -35,6 +42,11 @@ namespace Tests
|
||||||
result.mA = sa.mA + sb.mB + 1000;
|
result.mA = sa.mA + sb.mB + 1000;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void operator++() mut
|
||||||
|
{
|
||||||
|
mB++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StructC
|
struct StructC
|
||||||
|
@ -220,6 +232,20 @@ namespace Tests
|
||||||
StructA sa4 = Op(sa0, sb0);
|
StructA sa4 = Op(sa0, sb0);
|
||||||
Test.Assert(sa4.mA == 1012);
|
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);
|
float val = Op((int32)100, (int16)23);
|
||||||
Test.Assert(val == 123);
|
Test.Assert(val == 123);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue