`inc` and `dec` on a known range usually keeps it known, now.
Chris Pressey
3 years ago
6 | 6 |
* Syntactically, `goto` may only appear at the end of a block.
|
7 | 7 |
It need no longer be the final instruction in a routine,
|
8 | 8 |
as long as the type context is consistent at every exit.
|
|
9 |
* When the range of a location is known, `inc` and `dec`
|
|
10 |
on it will usually shift the known instead of invalidating it.
|
9 | 11 |
* `cmp` instruction can now perform a 16-bit unsigned comparison
|
10 | 12 |
of `word` memory locations (at the cost of trashing `a`.)
|
11 | 13 |
* Fixed pathological memory use in the lexical scanner - should
|
1 | 1 |
// Demonstrates vector tables.
|
2 | 2 |
// Prints "AABAB".
|
3 | 3 |
//
|
4 | |
|
5 | |
// TODO: this doesn't pass the analyzer currently, which suggests a bug.
|
6 | |
//
|
7 | |
// RangeExceededError: Possible range of x:byte (0, 255) exceeds
|
8 | |
// acceptable range of vectors:vector table[32] (0, 31) (in main, line 57)
|
9 | |
//
|
10 | |
// (despite various attempts to work around by calling a setup routine, etc.)
|
11 | |
// It should really be able to figure out that the range of x is 0..4 there.
|
12 | 4 |
|
13 | 5 |
vector routine
|
14 | 6 |
trashes a, z, n
|
596 | 596 |
else:
|
597 | 597 |
self.assert_type(TYPE_BYTE, dest)
|
598 | 598 |
context.set_written(dest, FLAG_Z, FLAG_N)
|
599 | |
context.invalidate_range(dest)
|
|
599 |
bottom = context.get_bottom_of_range(dest)
|
|
600 |
top = context.get_top_of_range(dest)
|
|
601 |
if opcode == 'inc':
|
|
602 |
if bottom == top and top < 255:
|
|
603 |
context.set_range(dest, bottom + 1, top + 1)
|
|
604 |
else:
|
|
605 |
context.invalidate_range(dest)
|
|
606 |
elif opcode == 'dec':
|
|
607 |
if bottom == top and bottom > 0:
|
|
608 |
context.set_range(dest, bottom - 1, top - 1)
|
|
609 |
else:
|
|
610 |
context.invalidate_range(dest)
|
|
611 |
else:
|
|
612 |
raise NotImplementedError
|
600 | 613 |
elif opcode in ('shl', 'shr'):
|
601 | 614 |
context.assert_meaningful(dest, FLAG_C)
|
602 | 615 |
if isinstance(dest, IndexedRef):
|
760 | 760 |
| copy many + x, one
|
761 | 761 |
| }
|
762 | 762 |
? RangeExceededError
|
|
763 |
|
|
764 |
When the range of a location is known, incrementing or
|
|
765 |
decrementing that location's value will shift the known
|
|
766 |
range. It will not invalidate it unless the known range
|
|
767 |
is at the limits of the possible ranges for the type.
|
|
768 |
|
|
769 |
| vector routine
|
|
770 |
| trashes a, z, n
|
|
771 |
| print
|
|
772 |
|
|
|
773 |
| vector (routine
|
|
774 |
| trashes a, z, n)
|
|
775 |
| table[32] vectors
|
|
776 |
|
|
|
777 |
| define main routine
|
|
778 |
| inputs vectors, print
|
|
779 |
| outputs vectors
|
|
780 |
| trashes print, a, x, z, n, c
|
|
781 |
| {
|
|
782 |
| ld x, 0
|
|
783 |
| inc x
|
|
784 |
| copy print, vectors + x
|
|
785 |
| }
|
|
786 |
= ok
|
|
787 |
|
|
788 |
| vector routine
|
|
789 |
| trashes a, z, n
|
|
790 |
| print
|
|
791 |
|
|
|
792 |
| vector (routine
|
|
793 |
| trashes a, z, n)
|
|
794 |
| table[32] vectors
|
|
795 |
|
|
|
796 |
| define main routine
|
|
797 |
| inputs vectors, print
|
|
798 |
| outputs vectors
|
|
799 |
| trashes print, a, x, z, n, c
|
|
800 |
| {
|
|
801 |
| ld x, 32
|
|
802 |
| dec x
|
|
803 |
| copy print, vectors + x
|
|
804 |
| }
|
|
805 |
= ok
|
763 | 806 |
|
764 | 807 |
### add ###
|
765 | 808 |
|