repos / gbc

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

gbc / tests
xplshn  ·  2025-09-10

structs.bx

Bx
 1type struct Point {
 2    x, y int;
 3};
 4
 5type struct Vector {
 6    x int;
 7    y int;
 8//    z float32;
 9};
10
11type struct S {
12    a float32;
13    b float32;
14    c float32;
15    z int;
16};
17
18// Was expecting a failure here due to trying to use positional struct literal return even tho there are more than one kind of type in the struct type
19Vector createVector(x, y int) {
20    //return (Vector{x, y, 0});
21    return (Vector{x, y});
22}
23
24S createS(a, b, c float32, z int) {
25    return (S{a: a, b: b, c: c, z: z});
26}
27
28main() {
29    extrn printf;
30
31    auto p = Point{x: 10, y: 20};
32    printf("p.x: %d\n", p.x);
33    printf("p.y: %d\n", p.y);
34
35    auto p2 = Point{2, 4};
36    printf("p2.x: %d\n", p2.x);
37    printf("p2.y: %d\n", p2.y);
38
39    auto v = Vector{16, 32};
40    printf("v.x: %d\n", v.x);
41    printf("v.y: %d\n", v.y);
42
43    auto v2 = createVector(5, 10);
44    printf("v2.x: %d\n", v2.x);
45    printf("v2.y: %d\n", v2.y);
46
47    auto s = createS(0.1, 0.2, 0.3, 50);
48    printf("s.a: %f\n", s.a);
49    printf("s.b: %f\n", s.b);
50    printf("s.c: %f\n", s.c);
51    printf("s.z: %d\n", s.z);
52
53    return(0);
54}
55