aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-21 06:04:52 +0000
committer_ov4 <ov4@ov4.org>2026-10-21 06:04:52 +0000
commit25ae363250e479701ed532c55c255e043c8240da (patch)
tree296977f6d6b1ba8ebfb5029fa0c7ea4235cbc9a5 /tests
parentbfe020bfa91640e7a6f1a516dc752fa754249088 (diff)
feat(codegen): add variadic function templates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/i/template-variadic/case.json1
-rw-r--r--tests/i/template-variadic/expected.txt12
-rw-r--r--tests/i/template-variadic/notes.md9
-rw-r--r--tests/i/template-variadic/program.cps37
-rw-r--r--tests/iii/template-variadic-errors/case.json11
-rw-r--r--tests/iii/template-variadic-errors/program.cps39
6 files changed, 109 insertions, 0 deletions
diff --git a/tests/i/template-variadic/case.json b/tests/i/template-variadic/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/template-variadic/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/template-variadic/expected.txt b/tests/i/template-variadic/expected.txt
new file mode 100644
index 0000000..a3177f6
--- /dev/null
+++ b/tests/i/template-variadic/expected.txt
@@ -0,0 +1,12 @@
+1
+2.500000
+c
+str
+1
+2.500000
+7
+3.500000
+30
+10
+20
+10
diff --git a/tests/i/template-variadic/notes.md b/tests/i/template-variadic/notes.md
new file mode 100644
index 0000000..7771cfa
--- /dev/null
+++ b/tests/i/template-variadic/notes.md
@@ -0,0 +1,9 @@
+# Variadic function templates
+
+Human review: pending.
+
+TEMPLATE and parameter packs are compiler extensions. PrintAll outputs each head before recursively forwarding the remaining arguments. Its ordinary parameterless overload terminates the recursion and produces no output. The first call therefore prints INTEGER 1, REAL 2.500000, CHAR c and STRING str in order; the direct empty call prints nothing. Explicit INTEGER binds the first type of the next call, which prints 1 and 2.500000.
+
+Forward explicitly binds the first pack entry to INTEGER, deduces its REAL tail and forwards both the type pack and value pack, producing 7 and 3.500000. Its empty instantiation forwards empty packs to the parameterless base case and produces no output.
+
+Pick returns 30 for the exact ordinary INTEGER overload, 10 for the fixed template on REAL, and 20 for the variadic two-argument template. Explicit INTEGER selects the fixed template and returns 10. REAL formatting follows the project's six-decimal output convention.
diff --git a/tests/i/template-variadic/program.cps b/tests/i/template-variadic/program.cps
new file mode 100644
index 0000000..3127c89
--- /dev/null
+++ b/tests/i/template-variadic/program.cps
@@ -0,0 +1,37 @@
+OVERLOAD PROCEDURE PrintAll()
+ENDPROCEDURE
+
+TEMPLATE <T, Rest...>
+OVERLOAD PROCEDURE PrintAll(First : T, Others : Rest...)
+ OUTPUT First
+ CALL PrintAll(Others...)
+ENDPROCEDURE
+
+TEMPLATE <Types...>
+PROCEDURE Forward(Values : Types...)
+ CALL PrintAll<Types...>(Values...)
+ENDPROCEDURE
+
+TEMPLATE <T>
+OVERLOAD FUNCTION Pick(Value : T) RETURNS INTEGER
+ RETURN 10
+ENDFUNCTION
+
+TEMPLATE <T, Rest...>
+OVERLOAD FUNCTION Pick(First : T, Others : Rest...) RETURNS INTEGER
+ RETURN 20
+ENDFUNCTION
+
+OVERLOAD FUNCTION Pick(Value : INTEGER) RETURNS INTEGER
+ RETURN 30
+ENDFUNCTION
+
+CALL PrintAll(1, 2.5, 'c', "str")
+CALL PrintAll()
+CALL PrintAll<INTEGER>(1, 2.5)
+CALL Forward<INTEGER>(7, 3.5)
+CALL Forward()
+OUTPUT Pick(1)
+OUTPUT Pick(1.0)
+OUTPUT Pick(1, 2)
+OUTPUT Pick<INTEGER>(1)
diff --git a/tests/iii/template-variadic-errors/case.json b/tests/iii/template-variadic-errors/case.json
new file mode 100644
index 0000000..ac4093a
--- /dev/null
+++ b/tests/iii/template-variadic-errors/case.json
@@ -0,0 +1,11 @@
+{
+ "errors": [
+ {"reason": "No matching overload for MissingBase", "line": 3},
+ {"reason": "A parameter pack expansion is only allowed in an argument list", "line": 8},
+ {"reason": "A parameter pack expansion is only allowed in an argument list", "line": 14},
+ {"reason": "A parameter pack expansion is only allowed in an argument list", "line": 19},
+ {"reason": "No matching overload for Exact", "line": 37},
+ {"reason": "No matching overload for Exact", "line": 38},
+ {"reason": "Ambiguous call to Tied", "line": 39}
+ ]
+}
diff --git a/tests/iii/template-variadic-errors/program.cps b/tests/iii/template-variadic-errors/program.cps
new file mode 100644
index 0000000..df2ebc1
--- /dev/null
+++ b/tests/iii/template-variadic-errors/program.cps
@@ -0,0 +1,39 @@
+TEMPLATE <T, Rest...>
+PROCEDURE MissingBase(First : T, Others : Rest...)
+ CALL MissingBase(Others...)
+ENDPROCEDURE
+
+TEMPLATE <Types...>
+PROCEDURE BadOutput(Values : Types...)
+ OUTPUT Values...
+ENDPROCEDURE
+
+TEMPLATE <Types...>
+PROCEDURE BadIndex(Values : Types...)
+ DECLARE Items : ARRAY[1:2] OF INTEGER
+ OUTPUT Items[Values...]
+ENDPROCEDURE
+
+TEMPLATE <Types...>
+PROCEDURE BadOperand(Values : Types...)
+ OUTPUT 1 + Values...
+ENDPROCEDURE
+
+TEMPLATE <T, Rest...>
+PROCEDURE Exact(First : T, Others : Rest...)
+ENDPROCEDURE
+
+TEMPLATE <A...>
+OVERLOAD PROCEDURE Tied(Values : A...)
+ENDPROCEDURE
+TEMPLATE <B...>
+OVERLOAD PROCEDURE Tied(Values : B...)
+ENDPROCEDURE
+
+CALL MissingBase(1)
+CALL BadOutput(1)
+CALL BadIndex(1)
+CALL BadOperand(1)
+CALL Exact<INTEGER, REAL>(1, 2)
+CALL Exact<INTEGER, REAL, CHAR>(1, 2.5)
+CALL Tied(1)