mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-26 14:49:15 +00:00
Improve test coverage. One failing test.
This commit is contained in:
parent
3ff96a0353
commit
5a49382ad4
@ -19,7 +19,8 @@ routine.
|
|||||||
= NamedLocation Nothing "score": UpdatedWith A
|
= NamedLocation Nothing "score": UpdatedWith A
|
||||||
|
|
||||||
A routine cannot expect registers which a called routine does not
|
A routine cannot expect registers which a called routine does not
|
||||||
preserve, to be preserved.
|
preserve, to be preserved. We say the called routine "poisons" those
|
||||||
|
registers.
|
||||||
|
|
||||||
| assign byte border_colour 4000
|
| assign byte border_colour 4000
|
||||||
| reserve byte score
|
| reserve byte score
|
||||||
@ -35,7 +36,8 @@ preserve, to be preserved.
|
|||||||
| }
|
| }
|
||||||
? routine 'main' does not preserve 'A'
|
? routine 'main' does not preserve 'A'
|
||||||
|
|
||||||
But if it does it can.
|
But if a called routine does preserve those registers, the caller can
|
||||||
|
continue to use them after calling the routine.
|
||||||
|
|
||||||
| assign byte border_colour 4000
|
| assign byte border_colour 4000
|
||||||
| reserve byte score
|
| reserve byte score
|
||||||
@ -60,7 +62,8 @@ But if it does it can.
|
|||||||
= X: UpdatedWith (Immediate 1)
|
= X: UpdatedWith (Immediate 1)
|
||||||
= NamedLocation Nothing "score": UpdatedWith X
|
= NamedLocation Nothing "score": UpdatedWith X
|
||||||
|
|
||||||
We can't expect to stay named variables to stay unmodified either.
|
Not only registers, but also named variables, can be poisoned by a called
|
||||||
|
routine.
|
||||||
|
|
||||||
| reserve byte score
|
| reserve byte score
|
||||||
| routine update_score
|
| routine update_score
|
||||||
@ -74,8 +77,9 @@ We can't expect to stay named variables to stay unmodified either.
|
|||||||
| }
|
| }
|
||||||
? routine 'main' does not preserve 'NamedLocation Nothing "score"'
|
? routine 'main' does not preserve 'NamedLocation Nothing "score"'
|
||||||
|
|
||||||
What the solution to the above is to notate `update_score` as intentionally
|
Of course, the difference between poisoning and intentionally modifying a
|
||||||
modifying score, as an "output" of the routine.
|
storage location is a matter of intent. The solution to the above is to
|
||||||
|
explicitly notate `update_score` as an "output" of the routine.
|
||||||
|
|
||||||
| assign byte border_colour 4000
|
| assign byte border_colour 4000
|
||||||
| reserve byte score
|
| reserve byte score
|
||||||
@ -236,11 +240,9 @@ Poisoning a high byte or low byte of a word poisons the whole word.
|
|||||||
| }
|
| }
|
||||||
? routine 'main' does not preserve 'NamedLocation Nothing "score"'
|
? routine 'main' does not preserve 'NamedLocation Nothing "score"'
|
||||||
|
|
||||||
| assign vector cinv 788
|
Some more tests...
|
||||||
| reserve vector save_cinv
|
|
||||||
|
|
|
||||||
| assign word position $fb
|
| assign word position $fb
|
||||||
|
|
|
||||||
| reserve byte value
|
| reserve byte value
|
||||||
|
|
|
|
||||||
| routine reset_position {
|
| routine reset_position {
|
||||||
@ -250,7 +252,7 @@ Poisoning a high byte or low byte of a word poisons the whole word.
|
|||||||
| sta >position
|
| sta >position
|
||||||
| }
|
| }
|
||||||
|
|
|
|
||||||
| routine our_cinv {
|
| routine main {
|
||||||
| inc value
|
| inc value
|
||||||
| lda value
|
| lda value
|
||||||
| ldy #0
|
| ldy #0
|
||||||
@ -259,27 +261,9 @@ Poisoning a high byte or low byte of a word poisons the whole word.
|
|||||||
| jsr reset_position
|
| jsr reset_position
|
||||||
| } else {
|
| } else {
|
||||||
| }
|
| }
|
||||||
| jmp (save_cinv)
|
|
||||||
| }
|
|
||||||
|
|
|
||||||
| routine main {
|
|
||||||
| jsr reset_position
|
|
||||||
| sei {
|
|
||||||
| copy cinv save_cinv
|
|
||||||
| copy routine our_cinv to cinv
|
|
||||||
| }
|
|
||||||
| clc
|
|
||||||
| repeat bcc { }
|
|
||||||
| }
|
| }
|
||||||
= main ([])
|
= main ([])
|
||||||
= A: PoisonedWith (Immediate 4)
|
= A: PoisonedWith (Immediate 4)
|
||||||
= FlagC: UpdatedWith (Immediate 0)
|
|
||||||
= NamedLocation Nothing "cinv": UpdatedWith (Immediate 7)
|
|
||||||
= NamedLocation Nothing "position": PoisonedWith A
|
|
||||||
= NamedLocation Nothing "save_cinv": UpdatedWith (NamedLocation Nothing "cinv")
|
|
||||||
=
|
|
||||||
= our_cinv ([])
|
|
||||||
= A: PoisonedWith (Immediate 4)
|
|
||||||
= Y: UpdatedWith (Immediate 0)
|
= Y: UpdatedWith (Immediate 0)
|
||||||
= IndirectIndexed (NamedLocation (Just Word) "position") Y: UpdatedWith A
|
= IndirectIndexed (NamedLocation (Just Word) "position") Y: UpdatedWith A
|
||||||
= NamedLocation Nothing "position": PoisonedWith A
|
= NamedLocation Nothing "position": PoisonedWith A
|
||||||
@ -288,3 +272,49 @@ Poisoning a high byte or low byte of a word poisons the whole word.
|
|||||||
= reset_position ([])
|
= reset_position ([])
|
||||||
= A: UpdatedWith (Immediate 4)
|
= A: UpdatedWith (Immediate 4)
|
||||||
= NamedLocation Nothing "position": UpdatedWith A
|
= NamedLocation Nothing "position": UpdatedWith A
|
||||||
|
|
||||||
|
| assign word position $fb
|
||||||
|
| reserve byte value
|
||||||
|
|
|
||||||
|
| routine reset_position {
|
||||||
|
| lda #$00
|
||||||
|
| sta <position
|
||||||
|
| lda #$04
|
||||||
|
| sta >position
|
||||||
|
| }
|
||||||
|
|
|
||||||
|
| routine main {
|
||||||
|
| inc value
|
||||||
|
| lda value
|
||||||
|
| ldy #0
|
||||||
|
| sta (position), y
|
||||||
|
| if beq {
|
||||||
|
| jsr reset_position
|
||||||
|
| } else {
|
||||||
|
| }
|
||||||
|
| sta value
|
||||||
|
| }
|
||||||
|
? routine 'main' does not preserve 'A'
|
||||||
|
|
||||||
|
| assign word position $fb
|
||||||
|
| reserve byte value
|
||||||
|
|
|
||||||
|
| routine reset_position {
|
||||||
|
| lda #$00
|
||||||
|
| sta <position
|
||||||
|
| lda #$04
|
||||||
|
| sta >position
|
||||||
|
| }
|
||||||
|
|
|
||||||
|
| routine main {
|
||||||
|
| inc value
|
||||||
|
| lda value
|
||||||
|
| ldy #0
|
||||||
|
| sta (position), y
|
||||||
|
| jsr reset_position
|
||||||
|
| if beq {
|
||||||
|
| } else {
|
||||||
|
| sta value
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
? routine 'main' does not preserve 'A'
|
||||||
|
Loading…
Reference in New Issue
Block a user