From 3d7d1d7cf8685f0d9230cd89d06017869da1c6d8 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 27 Oct 2026 14:00:16 +0000 Subject: feat(library)!: replace #LIB with __LIB source regions Track library mode by original source line, including deferred template bodies and automatic object cleanup. Update call lines from ordinary code and migrate the embedded standard library to PP_DEFINE __LIB. Co-Authored-By: Claude Opus 5.5 --- tests/i/library-lines/library.cps | 2 +- tests/i/library-regions/case.json | 6 ++++ tests/i/library-regions/expected-stderr.txt | 6 ++++ tests/i/library-regions/expected.txt | 6 ++++ tests/i/library-regions/notes.md | 5 +++ tests/i/library-regions/program.cps | 12 ++++++++ tests/i/library-regions/regions.cps | 47 +++++++++++++++++++++++++++++ tests/iii/legacy-lib/case.json | 1 + tests/iii/legacy-lib/program.cps | 2 ++ 9 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/i/library-regions/case.json create mode 100644 tests/i/library-regions/expected-stderr.txt create mode 100644 tests/i/library-regions/expected.txt create mode 100644 tests/i/library-regions/notes.md create mode 100644 tests/i/library-regions/program.cps create mode 100644 tests/i/library-regions/regions.cps create mode 100644 tests/iii/legacy-lib/case.json create mode 100644 tests/iii/legacy-lib/program.cps (limited to 'tests') diff --git a/tests/i/library-lines/library.cps b/tests/i/library-lines/library.cps index a35a2e9..d54f948 100644 --- a/tests/i/library-lines/library.cps +++ b/tests/i/library-lines/library.cps @@ -1,4 +1,4 @@ -#LIB +PP_DEFINE __LIB PROCEDURE Check() CALL Inner() ENDPROCEDURE diff --git a/tests/i/library-regions/case.json b/tests/i/library-regions/case.json new file mode 100644 index 0000000..9f95525 --- /dev/null +++ b/tests/i/library-regions/case.json @@ -0,0 +1,6 @@ +{ + "sources": [ + "program.cps", + "regions.cps" + ] +} diff --git a/tests/i/library-regions/expected-stderr.txt b/tests/i/library-regions/expected-stderr.txt new file mode 100644 index 0000000..89aee0f --- /dev/null +++ b/tests/i/library-regions/expected-stderr.txt @@ -0,0 +1,6 @@ +[Fatal] line 2: Division by zero +[Fatal] line 10: Division by zero +[Fatal] line 15: Division by zero +[Fatal] line 23: Division by zero +[Fatal] line 4: Division by zero +[Fatal] line 9: Division by zero diff --git a/tests/i/library-regions/expected.txt b/tests/i/library-regions/expected.txt new file mode 100644 index 0000000..b414108 --- /dev/null +++ b/tests/i/library-regions/expected.txt @@ -0,0 +1,6 @@ +1 +2 +3 +4 +5 +6 diff --git a/tests/i/library-regions/notes.md b/tests/i/library-regions/notes.md new file mode 100644 index 0000000..dbe4faf --- /dev/null +++ b/tests/i/library-regions/notes.md @@ -0,0 +1,5 @@ +# Trace notes + +Review status: pending human review. + +Mixed has an ordinary header but enables __LIB inside its body. Its first division uses the caller's line 2. After UNDEF, its own division uses regions.cps line 10 and a nested library call uses line 15. A disabled DEFINE does not enable __LIB, so the next division uses line 23. The library template retains its definition's mode during deferred emission and reports its caller's line 4. DeleteOnExit destroys its local object on return; the automatic library destructor retains the ordinary caller's line 9. Every error is caught and prints the next integer from 1 through 6. These are compiler extensions. diff --git a/tests/i/library-regions/program.cps b/tests/i/library-regions/program.cps new file mode 100644 index 0000000..315dbe6 --- /dev/null +++ b/tests/i/library-regions/program.cps @@ -0,0 +1,12 @@ +INCLUDE "regions.cps" +CALL Mixed() +TRY + CALL TemplateError() +CATCH + OUTPUT 5 +ENDTRY +TRY + CALL DeleteOnExit() +CATCH + OUTPUT 6 +ENDTRY diff --git a/tests/i/library-regions/regions.cps b/tests/i/library-regions/regions.cps new file mode 100644 index 0000000..310014a --- /dev/null +++ b/tests/i/library-regions/regions.cps @@ -0,0 +1,47 @@ +PROCEDURE Mixed() +PP_DEFINE __LIB +TRY + OUTPUT 1 DIV 0 +CATCH + OUTPUT 1 +ENDTRY +PP_UNDEF __LIB +TRY + OUTPUT 1 DIV 0 +CATCH + OUTPUT 2 +ENDTRY +TRY + CALL LibraryError() +CATCH + OUTPUT 3 +ENDTRY +PP_IFDEF Never +PP_DEFINE __LIB +PP_ENDIF +TRY + OUTPUT 1 DIV 0 +CATCH + OUTPUT 4 +ENDTRY +ENDPROCEDURE +PP_DEFINE __LIB +PROCEDURE LibraryError() + CALL NestedError() +ENDPROCEDURE +PROCEDURE NestedError() + OUTPUT 1 DIV 0 +ENDPROCEDURE +TEMPLATE +PROCEDURE TemplateError() + OUTPUT 1 DIV 0 +ENDPROCEDURE +CLASS DeleteError + PROCEDURE DELETE() + OUTPUT 1 DIV 0 + ENDPROCEDURE +ENDCLASS +PROCEDURE DeleteOnExit() + DECLARE X : DeleteError +ENDPROCEDURE +PP_UNDEF __LIB diff --git a/tests/iii/legacy-lib/case.json b/tests/iii/legacy-lib/case.json new file mode 100644 index 0000000..d593f34 --- /dev/null +++ b/tests/iii/legacy-lib/case.json @@ -0,0 +1 @@ +{"errors":[{"reason":"Unknown compiler directive","line":1}]} diff --git a/tests/iii/legacy-lib/program.cps b/tests/iii/legacy-lib/program.cps new file mode 100644 index 0000000..8abe9d9 --- /dev/null +++ b/tests/iii/legacy-lib/program.cps @@ -0,0 +1,2 @@ +#LIB +OUTPUT 1 -- cgit v1.3.1-4-g156e