From: Brendan Hansen Date: Tue, 12 Jan 2021 20:33:40 +0000 (-0600) Subject: added test case for multiple returns/declarations X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b88d44c18e01c7b596084ffbe52839ded78e8faf;p=onyx.git added test case for multiple returns/declarations --- diff --git a/tests/multiple_returns_robustness b/tests/multiple_returns_robustness new file mode 100644 index 00000000..64ec3eb1 --- /dev/null +++ b/tests/multiple_returns_robustness @@ -0,0 +1,6 @@ +60 +50 +110 +-10 to 200 +0 1 2 +3.0 4.0 5.0 diff --git a/tests/multiple_returns_robustness.onyx b/tests/multiple_returns_robustness.onyx new file mode 100644 index 00000000..cbda0b4e --- /dev/null +++ b/tests/multiple_returns_robustness.onyx @@ -0,0 +1,58 @@ +#load "core/std/js" + +use package core + +foo :: proc () -> (i32, i32) { + return 50, 60; +} + +something :: proc (f: proc () -> ($T, T)) -> T { + a, b := f(); + return a + b; +} + +get_extrema :: proc (arr: [$N] $T) -> (T, T) { + min := arr[0]; + max := arr[0]; + + for e: arr { + if e < min do min = e; + if e > max do max = e; + } + + return min, max; +} + +return_multiple_arrays :: proc () -> ([3] i32, [3] f32) { + iarr := i32.[ 0, 1, 2 ]; + farr := f32.[ 3, 4, 5 ]; + return iarr, farr; +} + +main :: proc (args: [] cstr) { + a, b := foo(); + a, b = b, a; + + c := something(foo); + + println(a); + println(b); + println(c); + + + least, greatest := get_extrema(i32.[ -5, 20, 5, -10, 200, 8 ]); + printf("%i to %i\n", least, greatest); + + iarr, farr := return_multiple_arrays(); + array_print(iarr); + array_print(farr); + + array_print :: proc (arr: [$N] $T) { + for ^e: arr { + print(*e); + print(" "); + } + + print("\n"); + } +}