diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-21 06:00:55 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-21 06:00:55 +0000 |
| commit | bfe020bfa91640e7a6f1a516dc752fa754249088 (patch) | |
| tree | fd82055133f45fdeaacddd4e62b210f4b63e0c03 /tests/i | |
| parent | c56877035d6600b463a9cbf0e339f7548c0b46fd (diff) | |
feat(codegen): support explicit template arguments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i')
| -rw-r--r-- | tests/i/template-explicit-args/case.json | 1 | ||||
| -rw-r--r-- | tests/i/template-explicit-args/expected.txt | 9 | ||||
| -rw-r--r-- | tests/i/template-explicit-args/notes.md | 5 | ||||
| -rw-r--r-- | tests/i/template-explicit-args/program.cps | 47 |
4 files changed, 62 insertions, 0 deletions
diff --git a/tests/i/template-explicit-args/case.json b/tests/i/template-explicit-args/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/template-explicit-args/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/template-explicit-args/expected.txt b/tests/i/template-explicit-args/expected.txt new file mode 100644 index 0000000..1c46cb5 --- /dev/null +++ b/tests/i/template-explicit-args/expected.txt @@ -0,0 +1,9 @@ +2.000000 +3 +tail +0.000000 +2.500000 +9 +200 +100 +chain diff --git a/tests/i/template-explicit-args/notes.md b/tests/i/template-explicit-args/notes.md new file mode 100644 index 0000000..b487fdd --- /dev/null +++ b/tests/i/template-explicit-args/notes.md @@ -0,0 +1,5 @@ +# template-explicit-args + +Human review: pending. Expected output was independently traced by AI, not captured from cpsc. + +Basis: TEMPLATE is a project extension. Max explicitly selects REAL and INTEGER, producing 2.000000 and 3. Second binds its first type explicitly and deduces STRING for its second, returning tail. Zero's otherwise undeducible return type is explicitly REAL, producing 0.000000. CALL and bare Print statements produce 2.500000 and 9. Pick uses the ordinary exact overload without explicit arguments (200) and the template with them (100). Echo preserves the STRING chain through a result method, and discarded STRING results exercise statement cleanup without output. 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") |
