git @ Cat's Eye Technologies SixtyPical / 3a4c2e4
`inc` and `dec` on a known range usually keeps it known, now. Chris Pressey 2 years ago
4 changed file(s) with 59 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
66 * Syntactically, `goto` may only appear at the end of a block.
77 It need no longer be the final instruction in a routine,
88 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.
911 * `cmp` instruction can now perform a 16-bit unsigned comparison
1012 of `word` memory locations (at the cost of trashing `a`.)
1113 * Fixed pathological memory use in the lexical scanner - should
11 // Demonstrates vector tables.
22 // Prints "AABAB".
33 //
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.
124
135 vector routine
146 trashes a, z, n
596596 else:
597597 self.assert_type(TYPE_BYTE, dest)
598598 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
600613 elif opcode in ('shl', 'shr'):
601614 context.assert_meaningful(dest, FLAG_C)
602615 if isinstance(dest, IndexedRef):
760760 | copy many + x, one
761761 | }
762762 ? 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
763806
764807 ### add ###
765808