From c56877035d6600b463a9cbf0e339f7548c0b46fd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 05:54:26 +0000 Subject: feat(codegen): instantiate function templates by deduction Co-Authored-By: Claude Opus 5.5 --- tests/i/template-functions/program.cps | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/i/template-functions/program.cps (limited to 'tests/i/template-functions/program.cps') diff --git a/tests/i/template-functions/program.cps b/tests/i/template-functions/program.cps new file mode 100644 index 0000000..40cceac --- /dev/null +++ b/tests/i/template-functions/program.cps @@ -0,0 +1,46 @@ +TEMPLATE +FUNCTION Max(A : T, B : T) RETURNS T + IF A > B THEN + RETURN A + ENDIF + RETURN B +ENDFUNCTION + +TEMPLATE +FUNCTION First(Values : ARRAY OF T) RETURNS T + RETURN Values[1] +ENDFUNCTION + +TEMPLATE +PROCEDURE Swap(BYREF Left : T, Right : T) + DECLARE Temp : T + Temp <- Left + Left <- Right + Right <- Temp +ENDPROCEDURE + +TEMPLATE +OVERLOAD FUNCTION Pick(Value : T) RETURNS INTEGER + RETURN 100 +ENDFUNCTION +OVERLOAD FUNCTION Pick(Value : INTEGER) RETURNS INTEGER + RETURN 200 +ENDFUNCTION + +OUTPUT Max(3, 7) +OUTPUT Max(1.5, 2.5) +OUTPUT Max("apple", "pear") +OUTPUT Max(Max(1, 2), 3) +DECLARE Values : ARRAY[1:2] OF INTEGER +Values[1] <- 42 +Values[2] <- 99 +OUTPUT First(Values) +DECLARE Left : INTEGER +DECLARE Right : INTEGER +Left <- 4 +Right <- 9 +CALL Swap(Left, Right) +OUTPUT Left +OUTPUT Right +OUTPUT Pick(1) +OUTPUT Pick(1.5) -- cgit v1.3.1-4-g156e