diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/programs/structret.zc | |
a
Diffstat (limited to 'tests/programs/structret.zc')
| -rw-r--r-- | tests/programs/structret.zc | 24 |
1 files changed, 24 insertions, 0 deletions
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; +} |
