From 939276669f85e392a82d9de4949a30579e1b3e53 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 21 Aug 2025 09:54:45 -0700 Subject: [PATCH] Tests for scopes and issue #479 / PR #1358 --- test/asm/listing/300-scopes-basic.s | 16 ++++++++++++ test/asm/listing/301-nested-scopes.s | 7 ++++++ test/asm/listing/302-scope-redefined.s | 7 ++++++ .../303-change-addressing-mode-error.s | 7 ++++++ .../listing/304-fix-addressing-mode-error.s | 7 ++++++ .../listing/305-explicit-scope-reference.s | 6 +++++ .../listing/306-scope-use-before-definition.s | 10 ++++++++ test/asm/listing/307-scope-chains.s | 18 ++++++++++++++ test/asm/listing/308-global-scope-anchoring.s | 18 ++++++++++++++ .../309-namespace-path-vs-addressing-mode.s | 16 ++++++++++++ .../asm/listing/310-create-in-current-scope.s | 15 ++++++++++++ test/asm/listing/311-close-new-scopes-error.s | 9 +++++++ .../303-change-addressing-mode-error.err | 0 .../control/311-close-new-scopes-error.err | 0 test/asm/listing/ref/300-scopes-basic.bin-ref | Bin 0 -> 10 bytes .../asm/listing/ref/300-scopes-basic.list-ref | 21 ++++++++++++++++ .../asm/listing/ref/301-nested-scopes.bin-ref | 1 + .../listing/ref/301-nested-scopes.list-ref | 12 +++++++++ .../listing/ref/302-scope-redefined.bin-ref | Bin 0 -> 3 bytes .../listing/ref/302-scope-redefined.list-ref | 12 +++++++++ .../ref/302-scope-redefined.list-ref-bak | 12 +++++++++ .../303-change-addressing-mode-error.err2-ref | 1 + .../ref/304-fix-addressing-mode-error.bin-ref | 1 + .../304-fix-addressing-mode-error.list-ref | 12 +++++++++ .../ref/305-explicit-scope-reference.bin-ref | 1 + .../ref/305-explicit-scope-reference.list-ref | 11 +++++++++ .../306-scope-use-before-definition.bin-ref | 1 + .../306-scope-use-before-definition.list-ref | 15 ++++++++++++ test/asm/listing/ref/307-scope-chains.bin-ref | 1 + .../asm/listing/ref/307-scope-chains.list-ref | 23 ++++++++++++++++++ .../ref/308-global-scope-anchoring.bin-ref | 1 + .../ref/308-global-scope-anchoring.list-ref | 23 ++++++++++++++++++ ...-namespace-path-vs-addressing-mode.bin-ref | Bin 0 -> 7 bytes ...namespace-path-vs-addressing-mode.list-ref | 21 ++++++++++++++++ .../ref/310-create-in-current-scope.bin-ref | Bin 0 -> 10 bytes .../ref/310-create-in-current-scope.list-ref | 20 +++++++++++++++ .../ref/311-close-new-scopes-error.err2-ref | 1 + 37 files changed, 326 insertions(+) create mode 100644 test/asm/listing/300-scopes-basic.s create mode 100644 test/asm/listing/301-nested-scopes.s create mode 100644 test/asm/listing/302-scope-redefined.s create mode 100644 test/asm/listing/303-change-addressing-mode-error.s create mode 100644 test/asm/listing/304-fix-addressing-mode-error.s create mode 100644 test/asm/listing/305-explicit-scope-reference.s create mode 100644 test/asm/listing/306-scope-use-before-definition.s create mode 100644 test/asm/listing/307-scope-chains.s create mode 100644 test/asm/listing/308-global-scope-anchoring.s create mode 100644 test/asm/listing/309-namespace-path-vs-addressing-mode.s create mode 100644 test/asm/listing/310-create-in-current-scope.s create mode 100644 test/asm/listing/311-close-new-scopes-error.s create mode 100644 test/asm/listing/control/303-change-addressing-mode-error.err create mode 100644 test/asm/listing/control/311-close-new-scopes-error.err create mode 100644 test/asm/listing/ref/300-scopes-basic.bin-ref create mode 100644 test/asm/listing/ref/300-scopes-basic.list-ref create mode 100644 test/asm/listing/ref/301-nested-scopes.bin-ref create mode 100644 test/asm/listing/ref/301-nested-scopes.list-ref create mode 100644 test/asm/listing/ref/302-scope-redefined.bin-ref create mode 100644 test/asm/listing/ref/302-scope-redefined.list-ref create mode 100644 test/asm/listing/ref/302-scope-redefined.list-ref-bak create mode 100644 test/asm/listing/ref/303-change-addressing-mode-error.err2-ref create mode 100644 test/asm/listing/ref/304-fix-addressing-mode-error.bin-ref create mode 100644 test/asm/listing/ref/304-fix-addressing-mode-error.list-ref create mode 100644 test/asm/listing/ref/305-explicit-scope-reference.bin-ref create mode 100644 test/asm/listing/ref/305-explicit-scope-reference.list-ref create mode 100644 test/asm/listing/ref/306-scope-use-before-definition.bin-ref create mode 100644 test/asm/listing/ref/306-scope-use-before-definition.list-ref create mode 100644 test/asm/listing/ref/307-scope-chains.bin-ref create mode 100644 test/asm/listing/ref/307-scope-chains.list-ref create mode 100644 test/asm/listing/ref/308-global-scope-anchoring.bin-ref create mode 100644 test/asm/listing/ref/308-global-scope-anchoring.list-ref create mode 100644 test/asm/listing/ref/309-namespace-path-vs-addressing-mode.bin-ref create mode 100644 test/asm/listing/ref/309-namespace-path-vs-addressing-mode.list-ref create mode 100644 test/asm/listing/ref/310-create-in-current-scope.bin-ref create mode 100644 test/asm/listing/ref/310-create-in-current-scope.list-ref create mode 100644 test/asm/listing/ref/311-close-new-scopes-error.err2-ref diff --git a/test/asm/listing/300-scopes-basic.s b/test/asm/listing/300-scopes-basic.s new file mode 100644 index 000000000..4d97ba431 --- /dev/null +++ b/test/asm/listing/300-scopes-basic.s @@ -0,0 +1,16 @@ + + .org $800 + + symbol1 := * ; ::symbol1 + .addr symbol1 ; ::symbol1 + + +.scope scope1 + symbol1 := * ; ::scope1::symbol1 + + .addr symbol1 ; ::scope1::symbol1 + .addr ::symbol1 ; ::symbol1 +.endscope + + .addr symbol1 ; ::symbol1 + .addr scope1::symbol1 ; ::scope1::symbol diff --git a/test/asm/listing/301-nested-scopes.s b/test/asm/listing/301-nested-scopes.s new file mode 100644 index 000000000..ef70c03ef --- /dev/null +++ b/test/asm/listing/301-nested-scopes.s @@ -0,0 +1,7 @@ + .scope outer + foo = 2 + .scope inner + lda #foo + foo = 3 + .endscope + .endscope diff --git a/test/asm/listing/302-scope-redefined.s b/test/asm/listing/302-scope-redefined.s new file mode 100644 index 000000000..cc2463caf --- /dev/null +++ b/test/asm/listing/302-scope-redefined.s @@ -0,0 +1,7 @@ + .scope outer + foo = $1234 + .scope inner + lda foo,x + foo = $12 + .endscope + .endscope diff --git a/test/asm/listing/303-change-addressing-mode-error.s b/test/asm/listing/303-change-addressing-mode-error.s new file mode 100644 index 000000000..a005581e3 --- /dev/null +++ b/test/asm/listing/303-change-addressing-mode-error.s @@ -0,0 +1,7 @@ + .scope outer + foo = $12 + .scope inner + lda foo,x + foo = $1234 + .endscope + .endscope diff --git a/test/asm/listing/304-fix-addressing-mode-error.s b/test/asm/listing/304-fix-addressing-mode-error.s new file mode 100644 index 000000000..3dda1d8ee --- /dev/null +++ b/test/asm/listing/304-fix-addressing-mode-error.s @@ -0,0 +1,7 @@ + .scope outer + foo = $12 + .scope inner + lda a:foo,x + foo = $1234 + .endscope + .endscope diff --git a/test/asm/listing/305-explicit-scope-reference.s b/test/asm/listing/305-explicit-scope-reference.s new file mode 100644 index 000000000..b3423ab25 --- /dev/null +++ b/test/asm/listing/305-explicit-scope-reference.s @@ -0,0 +1,6 @@ + bar = 3 + + .scope foo + bar = 2 + lda #::bar ; Access the global bar (which is 3) + .endscope diff --git a/test/asm/listing/306-scope-use-before-definition.s b/test/asm/listing/306-scope-use-before-definition.s new file mode 100644 index 000000000..8a0f37f24 --- /dev/null +++ b/test/asm/listing/306-scope-use-before-definition.s @@ -0,0 +1,10 @@ + .scope foo + bar = 3 + .endscope + + .scope outer + lda #foo::bar ; Will load 3, not 2! + .scope foo + bar = 2 + .endscope + .endscope diff --git a/test/asm/listing/307-scope-chains.s b/test/asm/listing/307-scope-chains.s new file mode 100644 index 000000000..860589244 --- /dev/null +++ b/test/asm/listing/307-scope-chains.s @@ -0,0 +1,18 @@ + .scope foo + .scope outer + .scope inner + bar = 1 + .endscope + .endscope + .scope another + .scope nested + lda #outer::inner::bar ; 1 + .endscope + .endscope + .endscope + + .scope outer + .scope inner + bar = 2 + .endscope + .endscope diff --git a/test/asm/listing/308-global-scope-anchoring.s b/test/asm/listing/308-global-scope-anchoring.s new file mode 100644 index 000000000..65df8b1fc --- /dev/null +++ b/test/asm/listing/308-global-scope-anchoring.s @@ -0,0 +1,18 @@ + .scope foo + .scope outer + .scope inner + bar = 1 + .endscope + .endscope + .scope another + .scope nested + lda #::outer::inner::bar ; 2 + .endscope + .endscope + .endscope + + .scope outer + .scope inner + bar = 2 + .endscope + .endscope diff --git a/test/asm/listing/309-namespace-path-vs-addressing-mode.s b/test/asm/listing/309-namespace-path-vs-addressing-mode.s new file mode 100644 index 000000000..fae9b9bd4 --- /dev/null +++ b/test/asm/listing/309-namespace-path-vs-addressing-mode.s @@ -0,0 +1,16 @@ +.org $2000 + +.proc s1 + + symbol := $1 + + stx s1::s2::symbol + stx s2_symbol + +.scope s2 +symbol: .byte 0 +.endscope + +s2_symbol := s2::symbol + +.endproc diff --git a/test/asm/listing/310-create-in-current-scope.s b/test/asm/listing/310-create-in-current-scope.s new file mode 100644 index 000000000..422756f9c --- /dev/null +++ b/test/asm/listing/310-create-in-current-scope.s @@ -0,0 +1,15 @@ +.scope main +.proc foo + + ;; should all be the same + lda params__bar + lda params::bar + lda foo::params::bar + +.proc params +bar: .byte 0 +.endproc + params__bar := params::bar + +.endproc +.endscope diff --git a/test/asm/listing/311-close-new-scopes-error.s b/test/asm/listing/311-close-new-scopes-error.s new file mode 100644 index 000000000..72346b25a --- /dev/null +++ b/test/asm/listing/311-close-new-scopes-error.s @@ -0,0 +1,9 @@ +.scope foo +start: + jmp bar::start +.endscope + +.scope bar +start: + rts +.endscope diff --git a/test/asm/listing/control/303-change-addressing-mode-error.err b/test/asm/listing/control/303-change-addressing-mode-error.err new file mode 100644 index 000000000..e69de29bb diff --git a/test/asm/listing/control/311-close-new-scopes-error.err b/test/asm/listing/control/311-close-new-scopes-error.err new file mode 100644 index 000000000..e69de29bb diff --git a/test/asm/listing/ref/300-scopes-basic.bin-ref b/test/asm/listing/ref/300-scopes-basic.bin-ref new file mode 100644 index 0000000000000000000000000000000000000000..a5f97a8a829a062c08bbbb0e7e8126888d312c12 GIT binary patch literal 10 PcmZSJVB%l^LM9FX0OkNK literal 0 HcmV?d00001 diff --git a/test/asm/listing/ref/300-scopes-basic.list-ref b/test/asm/listing/ref/300-scopes-basic.list-ref new file mode 100644 index 000000000..bf7649c96 --- /dev/null +++ b/test/asm/listing/ref/300-scopes-basic.list-ref @@ -0,0 +1,21 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 300-scopes-basic.s +Current file: 300-scopes-basic.s + +000000r 1 +000000r 1 .org $800 +000800 1 +000800 1 symbol1 := * ; ::symbol1 +000800 1 00 08 .addr symbol1 ; ::symbol1 +000802 1 +000802 1 +000802 1 .scope scope1 +000802 1 symbol1 := * ; ::scope1::symbol1 +000802 1 +000802 1 02 08 .addr symbol1 ; ::scope1::symbol1 +000804 1 00 08 .addr ::symbol1 ; ::symbol1 +000806 1 .endscope +000806 1 +000806 1 00 08 .addr symbol1 ; ::symbol1 +000808 1 02 08 .addr scope1::symbol1 ; ::scope1::symbol +000808 1 diff --git a/test/asm/listing/ref/301-nested-scopes.bin-ref b/test/asm/listing/ref/301-nested-scopes.bin-ref new file mode 100644 index 000000000..0b3310a2e --- /dev/null +++ b/test/asm/listing/ref/301-nested-scopes.bin-ref @@ -0,0 +1 @@ +© \ No newline at end of file diff --git a/test/asm/listing/ref/301-nested-scopes.list-ref b/test/asm/listing/ref/301-nested-scopes.list-ref new file mode 100644 index 000000000..64d2f6500 --- /dev/null +++ b/test/asm/listing/ref/301-nested-scopes.list-ref @@ -0,0 +1,12 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 301-nested-scopes.s +Current file: 301-nested-scopes.s + +000000r 1 .scope outer +000000r 1 foo = 2 +000000r 1 .scope inner +000000r 1 A9 03 lda #foo +000002r 1 foo = 3 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 diff --git a/test/asm/listing/ref/302-scope-redefined.bin-ref b/test/asm/listing/ref/302-scope-redefined.bin-ref new file mode 100644 index 0000000000000000000000000000000000000000..4a028eccadbd46b4264500e0fbefec840c191aef GIT binary patch literal 3 Kcmdlh!~g&SUI5Sl literal 0 HcmV?d00001 diff --git a/test/asm/listing/ref/302-scope-redefined.list-ref b/test/asm/listing/ref/302-scope-redefined.list-ref new file mode 100644 index 000000000..624fac152 --- /dev/null +++ b/test/asm/listing/ref/302-scope-redefined.list-ref @@ -0,0 +1,12 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 302-scope-redefined.s +Current file: 302-scope-redefined.s + +000000r 1 .scope outer +000000r 1 foo = $1234 +000000r 1 .scope inner +000000r 1 BD 12 00 lda foo,x +000003r 1 foo = $12 +000003r 1 .endscope +000003r 1 .endscope +000003r 1 diff --git a/test/asm/listing/ref/302-scope-redefined.list-ref-bak b/test/asm/listing/ref/302-scope-redefined.list-ref-bak new file mode 100644 index 000000000..468c08409 --- /dev/null +++ b/test/asm/listing/ref/302-scope-redefined.list-ref-bak @@ -0,0 +1,12 @@ +ca65 V2.19 - Git 7f1dd09bc +Main file : 302-scope-redefined.s +Current file: 302-scope-redefined.s + +000000r 1 .scope outer +000000r 1 foo = $1234 +000000r 1 .scope inner +000000r 1 BD 12 00 lda foo,x +000003r 1 foo = $12 +000003r 1 .endscope +000003r 1 .endscope +000003r 1 diff --git a/test/asm/listing/ref/303-change-addressing-mode-error.err2-ref b/test/asm/listing/ref/303-change-addressing-mode-error.err2-ref new file mode 100644 index 000000000..fbbbe831b --- /dev/null +++ b/test/asm/listing/ref/303-change-addressing-mode-error.err2-ref @@ -0,0 +1 @@ +303-change-addressing-mode-error.s:4: Error: Range error (4660 not in [0..255]) diff --git a/test/asm/listing/ref/304-fix-addressing-mode-error.bin-ref b/test/asm/listing/ref/304-fix-addressing-mode-error.bin-ref new file mode 100644 index 000000000..57089a9e1 --- /dev/null +++ b/test/asm/listing/ref/304-fix-addressing-mode-error.bin-ref @@ -0,0 +1 @@ +½4 \ No newline at end of file diff --git a/test/asm/listing/ref/304-fix-addressing-mode-error.list-ref b/test/asm/listing/ref/304-fix-addressing-mode-error.list-ref new file mode 100644 index 000000000..2d208331f --- /dev/null +++ b/test/asm/listing/ref/304-fix-addressing-mode-error.list-ref @@ -0,0 +1,12 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 304-fix-addressing-mode-error.s +Current file: 304-fix-addressing-mode-error.s + +000000r 1 .scope outer +000000r 1 foo = $12 +000000r 1 .scope inner +000000r 1 BD 34 12 lda a:foo,x +000003r 1 foo = $1234 +000003r 1 .endscope +000003r 1 .endscope +000003r 1 diff --git a/test/asm/listing/ref/305-explicit-scope-reference.bin-ref b/test/asm/listing/ref/305-explicit-scope-reference.bin-ref new file mode 100644 index 000000000..0b3310a2e --- /dev/null +++ b/test/asm/listing/ref/305-explicit-scope-reference.bin-ref @@ -0,0 +1 @@ +© \ No newline at end of file diff --git a/test/asm/listing/ref/305-explicit-scope-reference.list-ref b/test/asm/listing/ref/305-explicit-scope-reference.list-ref new file mode 100644 index 000000000..14953529c --- /dev/null +++ b/test/asm/listing/ref/305-explicit-scope-reference.list-ref @@ -0,0 +1,11 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 305-explicit-scope-reference.s +Current file: 305-explicit-scope-reference.s + +000000r 1 bar = 3 +000000r 1 +000000r 1 .scope foo +000000r 1 bar = 2 +000000r 1 A9 03 lda #::bar ; Access the global bar (which is 3) +000002r 1 .endscope +000002r 1 diff --git a/test/asm/listing/ref/306-scope-use-before-definition.bin-ref b/test/asm/listing/ref/306-scope-use-before-definition.bin-ref new file mode 100644 index 000000000..0b3310a2e --- /dev/null +++ b/test/asm/listing/ref/306-scope-use-before-definition.bin-ref @@ -0,0 +1 @@ +© \ No newline at end of file diff --git a/test/asm/listing/ref/306-scope-use-before-definition.list-ref b/test/asm/listing/ref/306-scope-use-before-definition.list-ref new file mode 100644 index 000000000..9bdb31659 --- /dev/null +++ b/test/asm/listing/ref/306-scope-use-before-definition.list-ref @@ -0,0 +1,15 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 306-scope-use-before-definition.s +Current file: 306-scope-use-before-definition.s + +000000r 1 .scope foo +000000r 1 bar = 3 +000000r 1 .endscope +000000r 1 +000000r 1 .scope outer +000000r 1 A9 03 lda #foo::bar ; Will load 3, not 2! +000002r 1 .scope foo +000002r 1 bar = 2 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 diff --git a/test/asm/listing/ref/307-scope-chains.bin-ref b/test/asm/listing/ref/307-scope-chains.bin-ref new file mode 100644 index 000000000..7cd3c6693 --- /dev/null +++ b/test/asm/listing/ref/307-scope-chains.bin-ref @@ -0,0 +1 @@ +© \ No newline at end of file diff --git a/test/asm/listing/ref/307-scope-chains.list-ref b/test/asm/listing/ref/307-scope-chains.list-ref new file mode 100644 index 000000000..2904384b0 --- /dev/null +++ b/test/asm/listing/ref/307-scope-chains.list-ref @@ -0,0 +1,23 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 307-scope-chains.s +Current file: 307-scope-chains.s + +000000r 1 .scope foo +000000r 1 .scope outer +000000r 1 .scope inner +000000r 1 bar = 1 +000000r 1 .endscope +000000r 1 .endscope +000000r 1 .scope another +000000r 1 .scope nested +000000r 1 A9 01 lda #outer::inner::bar ; 1 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 .endscope +000002r 1 +000002r 1 .scope outer +000002r 1 .scope inner +000002r 1 bar = 2 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 diff --git a/test/asm/listing/ref/308-global-scope-anchoring.bin-ref b/test/asm/listing/ref/308-global-scope-anchoring.bin-ref new file mode 100644 index 000000000..f0eb53ecc --- /dev/null +++ b/test/asm/listing/ref/308-global-scope-anchoring.bin-ref @@ -0,0 +1 @@ +© \ No newline at end of file diff --git a/test/asm/listing/ref/308-global-scope-anchoring.list-ref b/test/asm/listing/ref/308-global-scope-anchoring.list-ref new file mode 100644 index 000000000..7983d6894 --- /dev/null +++ b/test/asm/listing/ref/308-global-scope-anchoring.list-ref @@ -0,0 +1,23 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 308-global-scope-anchoring.s +Current file: 308-global-scope-anchoring.s + +000000r 1 .scope foo +000000r 1 .scope outer +000000r 1 .scope inner +000000r 1 bar = 1 +000000r 1 .endscope +000000r 1 .endscope +000000r 1 .scope another +000000r 1 .scope nested +000000r 1 A9 02 lda #::outer::inner::bar ; 2 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 .endscope +000002r 1 +000002r 1 .scope outer +000002r 1 .scope inner +000002r 1 bar = 2 +000002r 1 .endscope +000002r 1 .endscope +000002r 1 diff --git a/test/asm/listing/ref/309-namespace-path-vs-addressing-mode.bin-ref b/test/asm/listing/ref/309-namespace-path-vs-addressing-mode.bin-ref new file mode 100644 index 0000000000000000000000000000000000000000..e712b68e4b1c30a32ff54bb9d34afba982d6b802 GIT binary patch literal 7 OcmeBUQ|Mz;U;qFIHvwq? literal 0 HcmV?d00001 diff --git a/test/asm/listing/ref/309-namespace-path-vs-addressing-mode.list-ref b/test/asm/listing/ref/309-namespace-path-vs-addressing-mode.list-ref new file mode 100644 index 000000000..0bbc19268 --- /dev/null +++ b/test/asm/listing/ref/309-namespace-path-vs-addressing-mode.list-ref @@ -0,0 +1,21 @@ +ca65 Vx.xx - Git XXXXXXXXX +Main file : 309-namespace-path-vs-addressing-mode.s +Current file: 309-namespace-path-vs-addressing-mode.s + +000000r 1 .org $2000 +002000 1 +002000 1 .proc s1 +002000 1 +002000 1 symbol := $1 +002000 1 +002000 1 8E 06 20 stx s1::s2::symbol +002003 1 8E 06 20 stx s2_symbol +002006 1 +002006 1 .scope s2 +002006 1 00 symbol: .byte 0 +002007 1 .endscope +002007 1 +002007 1 s2_symbol := s2::symbol +002007 1 +002007 1 .endproc +002007 1 diff --git a/test/asm/listing/ref/310-create-in-current-scope.bin-ref b/test/asm/listing/ref/310-create-in-current-scope.bin-ref new file mode 100644 index 0000000000000000000000000000000000000000..4a483cae1d4ee1acab1ca4c9c05a67243f378148 GIT binary patch literal 10 NcmZ3>DX