From cde2824c4428747d71188ae258c384c24885f36d Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Thu, 8 Feb 2018 12:46:28 +0000 Subject: [PATCH] Articulate the "union rule" for trashes in if, add failing tests. --- tests/SixtyPical Analysis.md | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 4a66918..3300e3e 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -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.