From 39661855c0816ac248be437704c76f58359cb5f0 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 06:52:23 +0000 Subject: feat(classes): construct declared objects and nested fields and arrays Co-Authored-By: Claude Opus 5.5 --- tests/i/class-constructors/case.json | 1 + tests/i/class-constructors/expected.txt | 17 +++++++++++++ tests/i/class-constructors/notes.md | 5 ++++ tests/i/class-constructors/program.cps | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 tests/i/class-constructors/case.json create mode 100644 tests/i/class-constructors/expected.txt create mode 100644 tests/i/class-constructors/notes.md create mode 100644 tests/i/class-constructors/program.cps (limited to 'tests/i/class-constructors') diff --git a/tests/i/class-constructors/case.json b/tests/i/class-constructors/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/i/class-constructors/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/i/class-constructors/expected.txt b/tests/i/class-constructors/expected.txt new file mode 100644 index 0000000..cb57e7c --- /dev/null +++ b/tests/i/class-constructors/expected.txt @@ -0,0 +1,17 @@ +leaf:0 +leaf:0 +name +0 +leaf:0 +leaf:0 +leaf:0 +leaf:0 +3,3 +leaf:0 +leaf:0 +pair:6 +3,3 +leaf:0 +3 +leaf:0 +3 diff --git a/tests/i/class-constructors/notes.md b/tests/i/class-constructors/notes.md new file mode 100644 index 0000000..0145a0a --- /dev/null +++ b/tests/i/class-constructors/notes.md @@ -0,0 +1,5 @@ +# Class constructors + +Human review: pending. Expected output was independently traced by AI. + +The project extends guide section 10.2 with automatic stack, field and array construction. Leaf observes its zeroed Value before setting it to 3. A and B each construct once; Named stores name; Plain has no constructor and stays zero. Four array elements each construct once. Wrapped constructs Pair's two Leaf fields in order before Pair observes their sum of 6. Each execution of the loop declaration zeroes and constructs Local again, so both iterations print leaf:0 then 3 despite storing 99 in the previous iteration. diff --git a/tests/i/class-constructors/program.cps b/tests/i/class-constructors/program.cps new file mode 100644 index 0000000..2b85b4d --- /dev/null +++ b/tests/i/class-constructors/program.cps @@ -0,0 +1,42 @@ +CLASS Leaf + Value : INTEGER + PROCEDURE New() + OUTPUT "leaf:", Value + Value <- 3 + ENDPROCEDURE +ENDCLASS +CLASS Pair + First : Leaf + Second : Leaf + PROCEDURE NEW() + OUTPUT "pair:", First.Value + Second.Value + ENDPROCEDURE +ENDCLASS +TYPE Wrapped + DECLARE Item : Pair +ENDTYPE +CLASS Named + Text : STRING + PROCEDURE NEW(Name : STRING) + Text <- Name + ENDPROCEDURE +ENDCLASS +CLASS Plain + Value : INTEGER +ENDCLASS +DECLARE A : Leaf +DECLARE B : Leaf() +DECLARE N : Named("name") +OUTPUT N.Text +DECLARE P : Plain() +OUTPUT P.Value +DECLARE Items : ARRAY[-1:0, 2:3] OF Leaf +OUTPUT Items[-1,2].Value, ",", Items[0,3].Value +DECLARE W : Wrapped +OUTPUT W.Item.First.Value, ",", W.Item.Second.Value +DECLARE Index : INTEGER +FOR Index <- 1 TO 2 + DECLARE Local : Leaf + OUTPUT Local.Value + Local.Value <- 99 +NEXT Index -- cgit v1.3.1-4-g156e