From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/programs/structret.zc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/programs/structret.zc (limited to 'tests/programs/structret.zc') diff --git a/tests/programs/structret.zc b/tests/programs/structret.zc new file mode 100644 index 0000000..708c83c --- /dev/null +++ b/tests/programs/structret.zc @@ -0,0 +1,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; +} -- cgit v1.2.3