35 lines
528 B
Plaintext
35 lines
528 B
Plaintext
|
|
type Pair = struct {
|
|
a: i32,
|
|
b: i32,
|
|
};
|
|
|
|
fn main() i32 {
|
|
/* struct field access */
|
|
var p: Pair;
|
|
p.a = 1;
|
|
p.b = 2;
|
|
if p.a != 1 { ret 1; }
|
|
if p.b != 2 { ret 2; }
|
|
|
|
/* inline type definition */
|
|
type Triple = struct {
|
|
x: i32,
|
|
y: i32,
|
|
z: i32,
|
|
};
|
|
var t: Triple;
|
|
t.x = 10;
|
|
t.y = 20;
|
|
t.z = 30;
|
|
if t.x + t.y + t.z != 60 { ret 3; }
|
|
|
|
/* type reuse */
|
|
var p2: Pair;
|
|
p2.a = 5;
|
|
p2.b = 6;
|
|
if p2.a + p2.b != 11 { ret 4; }
|
|
|
|
ret 0;
|
|
}
|