More tests for "for" loops.
Chris Pressey
4 years ago

1807 | 1807 | | } |

1808 | 1808 | ? UnmeaningfulReadError |

1809 | 1809 | |

1810 | Because routines current do not express range constraints, It may not do to take the loop variable as an input. (?) | |

1810 | Because routines currently do not include range constraints, | |

1811 | the loop variable may not be useful as an input (the location | |

1812 | is assumed to have the maximum range.) | |

1811 | 1813 | |

1812 | 1814 | | byte table[16] tab |

1813 | 1815 | | |

1924 | 1926 | | } |

1925 | 1927 | ? UnmeaningfulReadError: y |

1926 | 1928 | |

1929 | The "for" loop does not preserve the `z` or `n` registers. | |

1930 | ||

1931 | | define foo routine trashes x { | |

1932 | | ld x, 0 | |

1933 | | for x up to 15 { | |

1934 | | } | |

1935 | | } | |

1936 | ? ForbiddenWriteError | |

1937 | ||

1938 | But it does preserve the other registers, such as `c`. | |

1939 | ||

1940 | | define foo routine trashes x, z, n { | |

1941 | | ld x, 0 | |

1942 | | for x up to 15 { | |

1943 | | } | |

1944 | | } | |

1945 | = ok | |

1946 | ||

1947 | In fact it does not strictly trash `z` and `n`, as they are | |

1948 | always set to known values after the loop. TODO: document | |

1949 | what these known values are! | |

1950 | ||

1951 | | define foo routine outputs z, n trashes x { | |

1952 | | ld x, 0 | |

1953 | | for x up to 15 { | |

1954 | | } | |

1955 | | } | |

1956 | = ok | |

1957 | ||

1927 | 1958 | #### downward-counting variant |

1928 | 1959 | |

1929 | 1960 | In a "for" loop (downward-counting variant), we know the exact range the loop variable takes on. |

1982 | 2013 | | } |

1983 | 2014 | | } |

1984 | 2015 | ? RangeExceededError |

2016 | ||

2017 | The "for" loop does not preserve the `z` or `n` registers. | |

2018 | ||

2019 | | define foo routine trashes x { | |

2020 | | ld x, 15 | |

2021 | | for x down to 0 { | |

2022 | | } | |

2023 | | } | |

2024 | ? ForbiddenWriteError | |

2025 | ||

2026 | But it does preserve the other registers, such as `c`. | |

2027 | ||

2028 | | define foo routine trashes x, z, n { | |

2029 | | ld x, 15 | |

2030 | | for x down to 0 { | |

2031 | | } | |

2032 | | } | |

2033 | = ok | |

2034 | ||

2035 | In fact it does not strictly trash `z` and `n`, as they are | |

2036 | always set to known values after the loop. TODO: document | |

2037 | what these known values are! | |

2038 | ||

2039 | | define foo routine outputs z, n trashes x { | |

2040 | | ld x, 15 | |

2041 | | for x down to 0 { | |

2042 | | } | |

2043 | | } | |

2044 | = ok | |

1985 | 2045 | |

1986 | 2046 | ### save ### |

1987 | 2047 |