git @ Cat's Eye Technologies SixtyPical / cde2824
Articulate the "union rule" for trashes in if, add failing tests. Chris Pressey 3 years ago
1 changed file(s) with 56 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
12321232 be initialized in the other.
12331233
12341234 | routine foo
1235 | inputs x
12361235 | outputs x
12371236 | trashes a, z, n, c
12381237 | {
1238 | ld x, 0
12391239 | ld a, 0
12401240 | cmp a, 42
12411241 | if z {
12461246 | }
12471247 = ok
12481248
1249 | routine foo
1250 | inputs x
1251 | outputs x
1252 | trashes a, z, n, c
1253 | {
1254 | ld a, 0
1255 | cmp a, 42
1256 | if z {
1257 | ld x, 7
1258 | } else {
1259 | ld a, 23
1260 | }
1261 | }
1262 = ok
1263
12491264 An `if` with a single block is analyzed as if it had an empty `else` block.
12501265
12511266 | routine foo
12851300 | }
12861301 | }
12871302 = ok
1303
1304 The cardinal rule for trashes in an `if` is the "union rule": if one branch
1305 trashes {`a`} and the other branch trashes {`b`} then the whole `if` statement
1306 trashes {`a`, `b`}.
1307
1308 | routine foo
1309 | inputs a, x, z
1310 | trashes a, x
1311 | {
1312 | if z {
1313 | trash a
1314 | } else {
1315 | trash x
1316 | }
1317 | }
1318 = ok
1319
1320 | routine foo
1321 | inputs a, x, z
1322 | trashes a
1323 | {
1324 | if z {
1325 | trash a
1326 | } else {
1327 | trash x
1328 | }
1329 | }
1330 ? UnmeaningfulOutputError: x in foo
1331
1332 | routine foo
1333 | inputs a, x, z
1334 | trashes x
1335 | {
1336 | if z {
1337 | trash a
1338 | } else {
1339 | trash x
1340 | }
1341 | }
1342 ? UnmeaningfulOutputError: a in foo
12881343
12891344 ### repeat ###
12901345