56 lines
1.1 KiB
Plaintext
56 lines
1.1 KiB
Plaintext
// Test: compound assignment operators on global variables
|
|
// Ensures += -= *= /= %= &= |= ^= <<= >>= all do load-modify-store
|
|
|
|
#import "modules/std.sx";
|
|
|
|
g_add : s64 = 10;
|
|
g_sub : s64 = 10;
|
|
g_mul : s64 = 10;
|
|
g_div : s64 = 100;
|
|
g_mod : s64 = 10;
|
|
g_and : s64 = 0xff;
|
|
g_or : s64 = 0x0f;
|
|
g_xor : s64 = 0xff;
|
|
g_shl : s64 = 1;
|
|
g_shr : s64 = 256;
|
|
|
|
main :: () -> void {
|
|
// += repeated: should accumulate, not reset
|
|
g_add += 1;
|
|
g_add += 1;
|
|
g_add += 1;
|
|
print("add: {}\n", g_add); // 13
|
|
|
|
g_sub -= 3;
|
|
g_sub -= 2;
|
|
print("sub: {}\n", g_sub); // 5
|
|
|
|
g_mul *= 2;
|
|
g_mul *= 3;
|
|
print("mul: {}\n", g_mul); // 60
|
|
|
|
g_div /= 5;
|
|
g_div /= 4;
|
|
print("div: {}\n", g_div); // 5
|
|
|
|
g_mod %= 3;
|
|
print("mod: {}\n", g_mod); // 1
|
|
|
|
g_and &= 0x0f;
|
|
print("and: {}\n", g_and); // 15
|
|
|
|
g_or |= 0xf0;
|
|
print("or: {}\n", g_or); // 255
|
|
|
|
g_xor ^= 0x0f;
|
|
print("xor: {}\n", g_xor); // 240
|
|
|
|
g_shl <<= 4;
|
|
g_shl <<= 2;
|
|
print("shl: {}\n", g_shl); // 64
|
|
|
|
g_shr >>= 3;
|
|
g_shr >>= 2;
|
|
print("shr: {}\n", g_shr); // 8
|
|
}
|