1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-26 14:49:15 +00:00

Articulate the "union rule" for trashes in if, add failing tests.

This commit is contained in:
Chris Pressey 2018-02-08 12:46:28 +00:00
parent 69f69d35a4
commit cde2824c44

View File

@ -1232,6 +1232,21 @@ initialized, either because it was set previous to the `if`, or is an
input to the routine, and it is initialized in one branch, it need not
be initialized in the other.
| routine foo
| outputs x
| trashes a, z, n, c
| {
| ld x, 0
| ld a, 0
| cmp a, 42
| if z {
| ld x, 7
| } else {
| ld a, 23
| }
| }
= ok
| routine foo
| inputs x
| outputs x
@ -1287,6 +1302,46 @@ An `if` with a single block is analyzed as if it had an empty `else` block.
| }
= ok
The cardinal rule for trashes in an `if` is the "union rule": if one branch
trashes {`a`} and the other branch trashes {`b`} then the whole `if` statement
trashes {`a`, `b`}.
| routine foo
| inputs a, x, z
| trashes a, x
| {
| if z {
| trash a
| } else {
| trash x
| }
| }
= ok
| routine foo
| inputs a, x, z
| trashes a
| {
| if z {
| trash a
| } else {
| trash x
| }
| }
? UnmeaningfulOutputError: x in foo
| routine foo
| inputs a, x, z
| trashes x
| {
| if z {
| trash a
| } else {
| trash x
| }
| }
? UnmeaningfulOutputError: a in foo
### repeat ###
Repeat loop.