diff options
Diffstat (limited to 'tests/i/template-explicit-args/program.cps')
| -rw-r--r-- | tests/i/template-explicit-args/program.cps | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/i/template-explicit-args/program.cps b/tests/i/template-explicit-args/program.cps new file mode 100644 index 0000000..123bda6 --- /dev/null +++ b/tests/i/template-explicit-args/program.cps @@ -0,0 +1,47 @@ +TEMPLATE <T> +FUNCTION Max(A : T, B : T) RETURNS T + IF A > B THEN + RETURN A + ENDIF + RETURN B +ENDFUNCTION + +TEMPLATE <A, B> +FUNCTION Second(First : A, Last : B) RETURNS B + RETURN Last +ENDFUNCTION + +TEMPLATE <T> +FUNCTION Zero() RETURNS T + RETURN (T)0 +ENDFUNCTION + +TEMPLATE <T> +PROCEDURE Print(Value : T) + OUTPUT Value +ENDPROCEDURE + +TEMPLATE <T> +FUNCTION Echo(Value : T) RETURNS T + RETURN Value +ENDFUNCTION + +TEMPLATE <T> +OVERLOAD FUNCTION Pick(Value : T) RETURNS INTEGER + RETURN 100 +ENDFUNCTION +OVERLOAD FUNCTION Pick(Value : INTEGER) RETURNS INTEGER + RETURN 200 +ENDFUNCTION + +OUTPUT Max<REAL>(1.5, 2.0) +OUTPUT Max<INTEGER>(Max<INTEGER>(1, 2), 3) +OUTPUT Second<INTEGER>(7, "tail") +OUTPUT Zero<REAL>() +CALL Print<REAL>(2.5) +Print<INTEGER>(9) +OUTPUT Pick(7) +OUTPUT Pick<INTEGER>(7) +OUTPUT (STRING)Echo<STRING>("chain").C_STR() +CALL Echo<STRING>("discarded") +Echo<STRING>("also discarded") |
