about summary refs log tree commit diff
path: root/examples/24.pry
blob: f30a7fcf3dc66a63cef20179488a447782c0de6a (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
46
47
48
extern malloc = (i64) => *void;

import "!stdlib.pry";

let test = struct {
	 x: i64,
	 y: *i8,
	 z: *test,
};

let print_struct = (s: *test) => void {
	printf("X: %d\n", (*s).x);
	printf("Y: %s\n", (*s).y);
	if (*s).z != cast(*test, null) {
		print_struct((*s).z);
	};
	return;
};

let main = () => i64 {
	let inst = cast(*test, malloc(sizeof(test)));
	let inst2 = cast(*test, malloc(sizeof(test)));

	print_struct(inst);

	(*inst).x = 4;
	(*inst).y = "hi";
	(*inst).z = inst2;
	
	(*inst2).y = "bye";

	print_struct(inst);

	return 0;
};

/*

Expected stdout:

X: 0
Y: (null)
X: 4
Y: hi

Expected return: 0

*/