aboutsummaryrefslogtreecommitdiff
path: root/tests/i/template-functions/program.cps
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-21 05:54:26 +0000
committer_ov4 <ov4@ov4.org>2026-10-21 05:54:26 +0000
commitc56877035d6600b463a9cbf0e339f7548c0b46fd (patch)
tree5b2af13b7f8f097d8de5436a729b39e85427b9f0 /tests/i/template-functions/program.cps
parentdd5bbae055fd34ce2e12ef63f8a261c6b15dc83e (diff)
feat(codegen): instantiate function templates by deduction
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i/template-functions/program.cps')
-rw-r--r--tests/i/template-functions/program.cps46
1 files changed, 46 insertions, 0 deletions
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 <T>
+FUNCTION Max(A : T, B : T) RETURNS T
+ IF A > B THEN
+ RETURN A
+ ENDIF
+ RETURN B
+ENDFUNCTION
+
+TEMPLATE <T>
+FUNCTION First(Values : ARRAY OF T) RETURNS T
+ RETURN Values[1]
+ENDFUNCTION
+
+TEMPLATE <T>
+PROCEDURE Swap(BYREF Left : T, Right : T)
+ DECLARE Temp : T
+ Temp <- Left
+ Left <- Right
+ Right <- Temp
+ENDPROCEDURE
+
+TEMPLATE <T>
+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)