about summary refs log tree commit diff
path: root/examples/22.src
blob: cc367bf726cee1fa9afcbd6369bb758421f0060e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extern malloc = (i64) => *void;

import "!stdlib.src";

/* declare new struct type */
let test = struct {
	 x: i64,
	 y: *i8,
	 z: bool
};

let main = () => i64 {
	/* instanciate new struct. instanciating fields isn't supported here */
	let inst = test{};

	inst.x = 2;
	inst.z = true;
	inst.y = malloc(1);
	(*(inst.y)) = 5;

	let x = 0;

	printf("Inst x: %d\n", inst.x);
	printf("Inst y: %d\n", *(inst.y));

	if inst.z {
		x = 1;
	};

	printf("Test: %d\n", x);

	return 0;
};

/*

Expected stdout:

Inst x: 2
Inst y: 5
Test: 1

Expected return: 0

*/