Tests for scopes and issue #479 / PR #1358

This commit is contained in:
Joshua Bell
2025-08-21 09:54:45 -07:00
parent 2454ab831c
commit 939276669f
37 changed files with 326 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,7 @@
.scope outer
foo = 2
.scope inner
lda #foo
foo = 3
.endscope
.endscope

View File

@@ -0,0 +1,7 @@
.scope outer
foo = $1234
.scope inner
lda foo,x
foo = $12
.endscope
.endscope

View File

@@ -0,0 +1,7 @@
.scope outer
foo = $12
.scope inner
lda foo,x
foo = $1234
.endscope
.endscope

View File

@@ -0,0 +1,7 @@
.scope outer
foo = $12
.scope inner
lda a:foo,x
foo = $1234
.endscope
.endscope

View File

@@ -0,0 +1,6 @@
bar = 3
.scope foo
bar = 2
lda #::bar ; Access the global bar (which is 3)
.endscope

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,9 @@
.scope foo
start:
jmp bar::start
.endscope
.scope bar
start:
rts
.endscope

Binary file not shown.

View File

@@ -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

View File

@@ -0,0 +1 @@
<EFBFBD>

View File

@@ -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

Binary file not shown.

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1 @@
303-change-addressing-mode-error.s:4: Error: Range error (4660 not in [0..255])

View File

@@ -0,0 +1 @@
<EFBFBD>4

View File

@@ -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

View File

@@ -0,0 +1 @@
<EFBFBD>

View File

@@ -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

View File

@@ -0,0 +1 @@
<EFBFBD>

View File

@@ -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

View File

@@ -0,0 +1 @@
<EFBFBD>

View File

@@ -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

View File

@@ -0,0 +1 @@
<EFBFBD>

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,20 @@
ca65 Vx.xx - Git XXXXXXXXX
Main file : 310-create-in-current-scope.s
Current file: 310-create-in-current-scope.s
000000r 1 .scope main
000000r 1 .proc foo
000000r 1
000000r 1 ;; should all be the same
000000r 1 AD rr rr lda params__bar
000003r 1 AD rr rr lda params::bar
000006r 1 AD rr rr lda foo::params::bar
000009r 1
000009r 1 .proc params
000009r 1 00 bar: .byte 0
00000Ar 1 .endproc
00000Ar 1 params__bar := params::bar
00000Ar 1
00000Ar 1 .endproc
00000Ar 1 .endscope
00000Ar 1

View File

@@ -0,0 +1 @@
311-close-new-scopes-error.s:3: Error: Symbol 'start' is undefined