From 14c03b7c26ff06835fca631eed6a3e308946321a Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:16:01 +0000 Subject: feat(lib): add experimental _EXP_STRING backed by std::string Co-Authored-By: Claude Opus 5.5 --- tests/library/exp-string/case.json | 1 + tests/library/exp-string/expected-stderr.txt | 2 ++ tests/library/exp-string/expected.txt | 10 +++++++ tests/library/exp-string/notes.md | 5 ++++ tests/library/exp-string/program.cps | 41 ++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 tests/library/exp-string/case.json create mode 100644 tests/library/exp-string/expected-stderr.txt create mode 100644 tests/library/exp-string/expected.txt create mode 100644 tests/library/exp-string/notes.md create mode 100644 tests/library/exp-string/program.cps (limited to 'tests/library/exp-string') diff --git a/tests/library/exp-string/case.json b/tests/library/exp-string/case.json new file mode 100644 index 0000000..a558ad6 --- /dev/null +++ b/tests/library/exp-string/case.json @@ -0,0 +1 @@ +{"sources":["program.cps","../../../pseudocode-lib/_exp_string.cps"]} diff --git a/tests/library/exp-string/expected-stderr.txt b/tests/library/exp-string/expected-stderr.txt new file mode 100644 index 0000000..6dc689f --- /dev/null +++ b/tests/library/exp-string/expected-stderr.txt @@ -0,0 +1,2 @@ +[Fatal] line 27: unconsumed characters in string conversion +[Fatal] line 32: negative string length diff --git a/tests/library/exp-string/expected.txt b/tests/library/exp-string/expected.txt new file mode 100644 index 0000000..fab16b1 --- /dev/null +++ b/tests/library/exp-string/expected.txt @@ -0,0 +1,10 @@ +helloworld +0 +3 +20500 +20500 +421.250000 +TRUE +conversion caught +length caught +heap diff --git a/tests/library/exp-string/notes.md b/tests/library/exp-string/notes.md new file mode 100644 index 0000000..ca7d489 --- /dev/null +++ b/tests/library/exp-string/notes.md @@ -0,0 +1,5 @@ +# Trace notes + +Review status: pending human review. + +Copies of hello are independent; assigning world to the copy gives helloworld when concatenated. Empty length is zero, and three NUL bytes retain length three. One hundred appended five-byte words grow 20000 bytes to 20500, preserved by BYVAL and RETURN. C++17 formatting gives 42 and 1.250000. Parsing 12.5 compares equal to 12.5. Trailing junk and negative counts emit the explicit library reasons at user lines 27 and 32, then are caught. Discarded numeric and Echo results must release their owned strings at statement end. The explicitly deleted heap object prints heap. This fixture covers compiler/library extensions, including numeric text formatting. diff --git a/tests/library/exp-string/program.cps b/tests/library/exp-string/program.cps new file mode 100644 index 0000000..719d9a4 --- /dev/null +++ b/tests/library/exp-string/program.cps @@ -0,0 +1,41 @@ +INCLUDE "../../../pseudocode-lib/_exp_string.cps" +FUNCTION Echo(S : _EXP_STRING) RETURNS _EXP_STRING + RETURN S +ENDFUNCTION +DECLARE A : _EXP_STRING((C_STRING)"hello") +DECLARE B : _EXP_STRING(A) +B <- (C_STRING)"world" +B <- B +CALL _EXP_STRING_OUTPUT(A & B) +DECLARE Empty : _EXP_STRING +OUTPUT _EXP_STRING_LENGTH(Empty) +DECLARE Nuls : _EXP_STRING(3, (C_CHAR)'\0') +OUTPUT _EXP_STRING_LENGTH(Nuls) +DECLARE Long : _EXP_STRING(20000, (C_CHAR)'x') +DECLARE I : INTEGER +FOR I <- 1 TO 100 + Long <- Long & A +NEXT I +OUTPUT _EXP_STRING_LENGTH(Long) +Long <- Echo(Long) +OUTPUT _EXP_STRING_LENGTH(Long) +CALL _EXP_STRING_OUTPUT(_EXP_STRING_NUM_TO_STR(42) & _EXP_STRING_NUM_TO_STR(1.25)) +DECLARE Number : _EXP_STRING((C_STRING)"12.5") +OUTPUT _EXP_STRING_STR_TO_NUM(Number) = 12.5 +TRY + Number <- (C_STRING)"12x" + OUTPUT _EXP_STRING_STR_TO_NUM(Number) +CATCH + OUTPUT "conversion caught" +ENDTRY +TRY + DECLARE Invalid : _EXP_STRING(-1, (C_CHAR)'x') +CATCH + OUTPUT "length caught" +ENDTRY +CALL _EXP_STRING_NUM_TO_STR(99) +CALL Echo(Long) +DECLARE Heap : _EXP_STRING +Heap <- NEW _EXP_STRING((C_STRING)"heap") +CALL _EXP_STRING_OUTPUT(Heap) +DELETE Heap -- cgit v1.3.1-4-g156e