git @ Cat's Eye Technologies SixtyPical / d88757c
Rudimentarily document `for`; add failing test cases for it. Chris Pressey 3 years ago
2 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
529529 if z {
530530 }
531531 } until not z
532
533 ### for ###
534
535 for <dest-memory-location> (up|down) to <literal-byte> {
536 <block>
537 }
538
539 Executes the block repeatedly, incrementing or decrementing the
540 dest-memory-location at the end of the block, until the value of
541 the dest-memory-location has gone past the literal-byte.
542
543 The block is always executed as least once.
544
545 * It is illegal if any memory location is uninitialized at the exit of
546 the loop when that memory location is initialized at the start of
547 the loop.
532548
533549 Grammar
534550 -------
17541754 | }
17551755 ? RangeExceededError
17561756
1757 You can initialize something inside the loop that was uninitialized outside.
1758
1759 | routine main
1760 | outputs x, y, n, z
1761 | trashes c
1762 | {
1763 | ld x, 0
1764 | for x up to 15 {
1765 | ld y, 15
1766 | }
1767 | }
1768 = ok
1769
1770 But you can't UNinitialize something at the end of the loop that you need
1771 initialized at the start of that loop.
1772
1773 | routine foo
1774 | trashes y
1775 | {
1776 | }
1777 |
1778 | routine main
1779 | outputs x, y, n, z
1780 | trashes c
1781 | {
1782 | ld x, 0
1783 | ld y, 15
1784 | for x up to 15 {
1785 | inc y
1786 | call foo
1787 | }
1788 | }
1789 ? UnmeaningfulReadError: y
1790
17571791 ### copy ###
17581792
17591793 Can't `copy` from a memory location that isn't initialized.