git @ Cat's Eye Technologies
Articulate the "union rule" for trashes in if, add failing tests. Chris Pressey 4 years ago
1 changed file(s) with 56 addition(s) and 1 deletion(s).
 1232 1232 be initialized in the other. 1233 1233 1234 1234 | routine foo 1235 | inputs x 1236 1235 | outputs x 1237 1236 | trashes a, z, n, c 1238 1237 | { 1238 | ld x, 0 1239 1239 | ld a, 0 1240 1240 | cmp a, 42 1241 1241 | if z { 1246 1246 | } 1247 1247 = ok 1248 1248 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 1249 1264 An `if` with a single block is analyzed as if it had an empty `else` block. 1250 1265 1251 1266 | routine foo 1285 1300 | } 1286 1301 | } 1287 1302 = 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 1288 1343 1289 1344 ### repeat ### 1290 1345