diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
| commit | 345e3d419eafb0e234aecb4a33f37efe2afbbf53 (patch) | |
| tree | 9330322103f26f15c6df91cbbd62bf5a1f6e72da /tests | |
| parent | 927e3fc0384c941f9ad313a28768660c3cdb1777 (diff) | |
feat(classes): add copy constructors and statement-scoped temporaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i/class-copy/case.json | 1 | ||||
| -rw-r--r-- | tests/i/class-copy/expected.txt | 23 | ||||
| -rw-r--r-- | tests/i/class-copy/program.cps | 65 | ||||
| -rw-r--r-- | tests/iii/class-copy-byval/case.json | 1 | ||||
| -rw-r--r-- | tests/iii/class-copy-byval/program.cps | 5 |
5 files changed, 95 insertions, 0 deletions
diff --git a/tests/i/class-copy/case.json b/tests/i/class-copy/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/class-copy/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/class-copy/expected.txt b/tests/i/class-copy/expected.txt new file mode 100644 index 0000000..86e18a1 --- /dev/null +++ b/tests/i/class-copy/expected.txt @@ -0,0 +1,23 @@ +pass:1 +destroy:11 +destroy:2 +pass:2 +destroy:12 +destroy:3 +destroy:3 +destroy:8 +destroy:8 +destroy:4 +4 +destroy:4 +destroy:6 +destroy:6 +caught:3 +destroy:9 +destroy:9 +argument caught:3 +counts:9:3 +destroy:8 +destroy:1 +destroy:1 +remaining:0 diff --git a/tests/i/class-copy/program.cps b/tests/i/class-copy/program.cps new file mode 100644 index 0000000..373e4c5 --- /dev/null +++ b/tests/i/class-copy/program.cps @@ -0,0 +1,65 @@ +GLOBAL + DECLARE Live : INTEGER + DECLARE Copies : INTEGER +ENDGLOBAL +CLASS Traced + Value : INTEGER + OVERLOAD PROCEDURE NEW() + Live <- Live + 1 + ENDPROCEDURE + OVERLOAD PROCEDURE NEW(BYREF Other : Traced) + Value <- Other.Value + Live <- Live + 1 + Copies <- Copies + 1 + ENDPROCEDURE + PROCEDURE DELETE() + OUTPUT "destroy:", Value + Live <- Live - 1 + ENDPROCEDURE + FUNCTION Read() RETURNS INTEGER + RETURN Value + ENDFUNCTION + FUNCTION Explode() RETURNS INTEGER + THROW + ENDFUNCTION +ENDCLASS +FUNCTION Make(N : INTEGER) RETURNS Traced + DECLARE Local : Traced + Local.Value <- N + RETURN Local +ENDFUNCTION +FUNCTION Forward(N : INTEGER) RETURNS Traced + RETURN Make(N) +ENDFUNCTION +PROCEDURE Pass(Item : Traced) + OUTPUT "pass:", Item.Value + Item.Value <- Item.Value + 10 +ENDPROCEDURE +FUNCTION Fail() RETURNS INTEGER + THROW +ENDFUNCTION +PROCEDURE Accept(Item : Traced, Ignored : INTEGER) +ENDPROCEDURE +PROCEDURE Work() + DECLARE A : Traced + A.Value <- 1 + CALL Pass(A) + CALL Pass(Forward(2)) + CALL Make(3) + DECLARE B : Traced(A) + DECLARE C : Traced(Make(8)) + OUTPUT Make(4).Read() + TRY + OUTPUT Make(6).Explode() + CATCH + OUTPUT "caught:", Live + ENDTRY + TRY + CALL Accept(Make(9), Fail()) + CATCH + OUTPUT "argument caught:", Live + ENDTRY + OUTPUT "counts:", Copies, ":", Live +ENDPROCEDURE +CALL Work() +OUTPUT "remaining:", Live diff --git a/tests/iii/class-copy-byval/case.json b/tests/iii/class-copy-byval/case.json new file mode 100644 index 0000000..719703e --- /dev/null +++ b/tests/iii/class-copy-byval/case.json @@ -0,0 +1 @@ +{"errors":[{"reason":"copy constructor must take BYREF","line":2}]} diff --git a/tests/iii/class-copy-byval/program.cps b/tests/iii/class-copy-byval/program.cps new file mode 100644 index 0000000..145c6f7 --- /dev/null +++ b/tests/iii/class-copy-byval/program.cps @@ -0,0 +1,5 @@ +CLASS Bad + OVERLOAD PROCEDURE NEW(Other : Bad) + ENDPROCEDURE +ENDCLASS +OUTPUT 0 |
