aboutsummaryrefslogtreecommitdiff
path: root/tests/i/class-raii
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 08:34:42 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 08:34:42 +0000
commitabd56ef20bc8061bbecec29edd1301d324c2cb34 (patch)
tree8da9a14372a60d4df8bf58693c62c187765e7240 /tests/i/class-raii
parent59e3c50bcd58130e81e1f57b21d6e57b4d4aba6d (diff)
feat(classes): destroy stack objects at scope exit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/i/class-raii')
-rw-r--r--tests/i/class-raii/case.json1
-rw-r--r--tests/i/class-raii/expected.txt12
-rw-r--r--tests/i/class-raii/notes.md5
-rw-r--r--tests/i/class-raii/program.cps49
4 files changed, 67 insertions, 0 deletions
diff --git a/tests/i/class-raii/case.json b/tests/i/class-raii/case.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/i/class-raii/case.json
@@ -0,0 +1 @@
+{}
diff --git a/tests/i/class-raii/expected.txt b/tests/i/class-raii/expected.txt
new file mode 100644
index 0000000..532f9db
--- /dev/null
+++ b/tests/i/class-raii/expected.txt
@@ -0,0 +1,12 @@
+destroy:31
+destroy:32
+destroy:20
+destroy:21
+destroy:50
+destroy:42
+destroy:41
+destroy:33
+destroy:2
+destroy:1
+main end
+destroy:100
diff --git a/tests/i/class-raii/notes.md b/tests/i/class-raii/notes.md
new file mode 100644
index 0000000..336e5cb
--- /dev/null
+++ b/tests/i/class-raii/notes.md
@@ -0,0 +1,5 @@
+# Stack lifetimes
+
+Human review: pending. Expected output was independently traced by AI.
+
+Loop re-declarations destroy 31 and 32 before reinitialization. Copy destroys local 20 then its shallow parameter copy 21. Early RETURN destroys record field 50, array elements 42 and 41, loop local 33, original rebound storage 2 and first local 1. Heap object 99 stays alive. Never is not constructed. Main destroys 100 after its final output.
diff --git a/tests/i/class-raii/program.cps b/tests/i/class-raii/program.cps
new file mode 100644
index 0000000..ff350f9
--- /dev/null
+++ b/tests/i/class-raii/program.cps
@@ -0,0 +1,49 @@
+CLASS Traced
+ Id : INTEGER
+ PROCEDURE NEW()
+ Id <- 0
+ ENDPROCEDURE
+ PROCEDURE DELETE()
+ OUTPUT "destroy:", Id
+ ENDPROCEDURE
+ENDCLASS
+TYPE Wrapped
+ DECLARE Item : Traced
+ENDTYPE
+PROCEDURE Copy(Value : Traced)
+ DECLARE Local : Traced
+ Local.Id <- 20
+ Value.Id <- 21
+ENDPROCEDURE
+PROCEDURE Work()
+ DECLARE First : Traced
+ First.Id <- 1
+ DECLARE Rebound : Traced
+ Rebound.Id <- 2
+ Rebound <- NEW Traced()
+ Rebound.Id <- 99
+ DECLARE I : INTEGER
+ FOR I <- 1 TO 3
+ DECLARE Again : Traced
+ Again.Id <- 3
+ Again.Id <- I + 30
+ NEXT I
+ DECLARE Arr : ARRAY[1:2] OF Plain
+ Arr[1].Item.Id <- 41
+ Arr[2].Item.Id <- 42
+ DECLARE Rec : Wrapped
+ Rec.Item.Id <- 50
+ CALL Copy(First)
+ IF TRUE THEN
+ RETURN
+ ENDIF
+ DECLARE Never : Traced
+ Never.Id <- 77
+ENDPROCEDURE
+CLASS Plain
+ Item : Traced
+ENDCLASS
+DECLARE Global : Traced
+ Global.Id <- 100
+CALL Work()
+OUTPUT "main end"