aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/structret.zc
blob: 5e9965346fe6d554ee7cceca4081216ea4c6dd4b (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
namespace;
include rt;

// 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;
	rt.cload(b"build/sbv.so");
	p = mkpair(3, 4); rt.put_n(p.a); rt.put_c(32); rt.put_n(p.b); rt.put_c(32);
	v = mkvec(2.5, 3.0); put_f(v.x); rt.put_c(32); put_f(v.y); rt.put_c(32);
	t = mktrio(7, 8, 9); rt.put_n(t.a + t.b + t.c); rt.put_c(32);
	m = mkmixed(7, 0.5); rt.put_n(m.a); rt.put_c(32); put_f(m.x); rt.put_c(32);
	w = mkv3(1.5); put_f(w.z); rt.put_c(10);
	return 0;
}