repos / gbc

GBC - Go B Compiler
git clone https://github.com/xplshn/gbc.git

gbc / tests
xplshn  ·  2025-09-10

multi_assign.bx

Bx
 1assert_equal(actual, expected, message) {
 2    extrn printf, abort;
 3    printf("%s: ", message);
 4    if (actual != expected) {
 5        printf("FAIL\n");
 6        abort();
 7    } else {
 8        printf("OK\n");
 9    }
10}
11
12main() {
13    extrn assert_equal;
14    
15    auto a, b;
16    a, b = 10, 20;
17    assert_equal(a, 10, "a, b = 10, 20; a == 10");
18    assert_equal(b, 20, "a, b = 10, 20; b == 20");
19    
20    auto x, y, z;
21    x, y, z = 100, 200, 300;
22    assert_equal(x, 100, "x, y, z = 100, 200, 300; x == 100");
23    assert_equal(y, 200, "x, y, z = 100, 200, 300; y == 200");
24    assert_equal(z, 300, "x, y, z = 100, 200, 300; z == 300");
25    
26    auto arr1 3, arr2 3;
27    arr1[0], arr2[0] = 50, 60;
28    assert_equal(arr1[0], 50, "arr1[0], arr2[0] = 50, 60; arr1[0] == 50");
29    assert_equal(arr2[0], 60, "arr1[0], arr2[0] = 50, 60; arr2[0] == 60");
30    
31    auto p, q, mixed 2;
32    p, mixed[1], q = 1000, 2000, 3000;
33    assert_equal(p, 1000, "p, mixed[1], q = 1000, 2000, 3000; p == 1000");
34    assert_equal(mixed[1], 2000, "p, mixed[1], q = 1000, 2000, 3000; mixed[1] == 2000");
35    assert_equal(q, 3000, "p, mixed[1], q = 1000, 2000, 3000; q == 3000");
36    
37    int int_array[3];
38    int other_array[3];
39    
40    int_array[0], other_array[0] = 42, 84;
41    int_array[1], other_array[1] = 123, 246;
42    int_array[2], other_array[2] = 999, 1998;
43    
44    assert_equal(int_array[0], 42, "int_array[0], other_array[0] = 42, 84; int_array[0] == 42");
45    assert_equal(other_array[0], 84, "int_array[0], other_array[0] = 42, 84; other_array[0] == 84");
46    assert_equal(int_array[1], 123, "int_array[1], other_array[1] = 123, 246; int_array[1] == 123");
47    assert_equal(other_array[1], 246, "int_array[1], other_array[1] = 123, 246; other_array[1] == 246");
48    assert_equal(int_array[2], 999, "int_array[2], other_array[2] = 999, 1998; int_array[2] == 999");
49    assert_equal(other_array[2], 1998, "int_array[2], other_array[2] = 999, 1998; other_array[2] == 1998");
50    
51    return(0);
52}