aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/structret.zc
blob: 708c83cffc2787e4b206a1f4f0d7e8c5a3eb31b0 (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
// structs returned from native functions: the stub makes the result (a new object,
// owned by the caller) and the native call fills it in. the helper library is built
// by test.sh (build/sbv.so).
fn put_f(x) { asm { x @ #1220 } return 0; }
struct Pair { int a; int b; }
struct Vec { float x; float y; }
struct Trio { int a; int b; int c; }
struct Mixed { int a; float x; }
struct Vec3 { float x; float y; float z; }
extern struct Pair mkpair(long a, long b);
extern struct Vec mkvec(double x, double y);
extern struct Trio mktrio(long a, long b, long c);
extern struct Mixed mkmixed(long a, double x);
extern struct Vec3 mkv3(double x);
int main() {
	Pair* p; Vec* v; Trio* t; Mixed* m; Vec3* w;
	cload(b"build/sbv.so");
	p = mkpair(3, 4); put_n(p.a); put_c(32); put_n(p.b); put_c(32);
	v = mkvec(2.5, 3.0); put_f(v.x); put_c(32); put_f(v.y); put_c(32);
	t = mktrio(7, 8, 9); put_n(t.a + t.b + t.c); put_c(32);
	m = mkmixed(7, 0.5); put_n(m.a); put_c(32); put_f(m.x); put_c(32);
	w = mkv3(1.5); put_f(w.z); put_c(10);
	return 0;
}