mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-25 07:32:16 +00:00
Saving anything except a
trashes a
.
This commit is contained in:
parent
1410989b2c
commit
80c46485f1
@ -777,3 +777,9 @@ class Analyzer(object):
|
|||||||
self.analyze_block(instr.block, context)
|
self.analyze_block(instr.block, context)
|
||||||
# TODO assert no goto was encountered
|
# TODO assert no goto was encountered
|
||||||
context.re_introduce(baton)
|
context.re_introduce(baton)
|
||||||
|
|
||||||
|
if location == REG_A:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
context.set_touched(REG_A)
|
||||||
|
context.set_unmeaningful(REG_A)
|
||||||
|
@ -1955,17 +1955,45 @@ Basic neutral test, where the `save` makes no difference.
|
|||||||
| }
|
| }
|
||||||
= ok
|
= ok
|
||||||
|
|
||||||
|
Saving any location (other than `a`) will trash `a`.
|
||||||
|
|
||||||
|
| routine main
|
||||||
|
| inputs a, x
|
||||||
|
| outputs a, x
|
||||||
|
| trashes z, n
|
||||||
|
| {
|
||||||
|
| ld a, 1
|
||||||
|
| save x {
|
||||||
|
| ld a, 2
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
? UnmeaningfulOutputError
|
||||||
|
|
||||||
|
Saving `a` does not trash anything.
|
||||||
|
|
||||||
|
| routine main
|
||||||
|
| inputs a, x
|
||||||
|
| outputs a, x
|
||||||
|
| trashes z, n
|
||||||
|
| {
|
||||||
|
| ld x, 1
|
||||||
|
| save a {
|
||||||
|
| ld x, 2
|
||||||
|
| }
|
||||||
|
| ld x, 3
|
||||||
|
| }
|
||||||
|
= ok
|
||||||
|
|
||||||
A defined value that has been saved can be trashed inside the block.
|
A defined value that has been saved can be trashed inside the block.
|
||||||
It will continue to be defined outside the block.
|
It will continue to be defined outside the block.
|
||||||
|
|
||||||
| routine main
|
| routine main
|
||||||
| inputs a
|
| outputs x, y
|
||||||
| outputs a, x
|
| trashes a, z, n
|
||||||
| trashes z, n
|
|
||||||
| {
|
| {
|
||||||
| ld x, 0
|
| ld x, 0
|
||||||
| save x {
|
| save x {
|
||||||
| ld a, 0
|
| ld y, 0
|
||||||
| trash x
|
| trash x
|
||||||
| }
|
| }
|
||||||
| }
|
| }
|
||||||
@ -1991,16 +2019,32 @@ It will continue to be trashed outside the block.
|
|||||||
A value which is not output from the routine, is preserved by the
|
A value which is not output from the routine, is preserved by the
|
||||||
routine; and can appear in a `save` exactly because a `save` preserves it.
|
routine; and can appear in a `save` exactly because a `save` preserves it.
|
||||||
|
|
||||||
|
| routine main
|
||||||
|
| outputs y
|
||||||
|
| trashes a, z, n
|
||||||
|
| {
|
||||||
|
| save x {
|
||||||
|
| ld y, 0
|
||||||
|
| ld x, 1
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
= ok
|
||||||
|
|
||||||
|
Because saving anything except `a` trashes `a`, a common idiom is to save `a`
|
||||||
|
first in a nested series of `save`s.
|
||||||
|
|
||||||
| routine main
|
| routine main
|
||||||
| inputs a
|
| inputs a
|
||||||
| outputs a
|
| outputs a
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| {
|
| {
|
||||||
|
| save a {
|
||||||
| save x {
|
| save x {
|
||||||
| ld a, 0
|
| ld a, 0
|
||||||
| ld x, 1
|
| ld x, 1
|
||||||
| }
|
| }
|
||||||
| }
|
| }
|
||||||
|
| }
|
||||||
= ok
|
= ok
|
||||||
|
|
||||||
### copy ###
|
### copy ###
|
||||||
|
Loading…
Reference in New Issue
Block a user