git @ Cat's Eye Technologies SixtyPical / d815e05
Syntax for "open-faced for loop". Chris Pressey 3 years ago
3 changed file(s) with 40 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
8282 child_attrs = ('block',)
8383
8484
85 class For(Instr):
86 value_attrs = ('dest', 'direction', 'final')
87 child_attrs = ('block',)
88
89
8590 class WithInterruptsOff(Instr):
8691 child_attrs = ('block',)
00 # encoding: UTF-8
11
2 from sixtypical.ast import Program, Defn, Routine, Block, SingleOp, If, Repeat, WithInterruptsOff
2 from sixtypical.ast import Program, Defn, Routine, Block, SingleOp, If, Repeat, For, WithInterruptsOff
33 from sixtypical.model import (
44 TYPE_BIT, TYPE_BYTE, TYPE_WORD,
55 RoutineType, VectorType, TableType, BufferType, PointerType,
135135
136136 return Defn(self.scanner.line_number, name=name, addr=addr, initial=initial, location=location)
137137
138 def literal_int(self):
139 self.scanner.check_type('integer literal')
140 c = int(self.scanner.token)
141 self.scanner.scan()
142 return c
143
138144 def defn_size(self):
139145 self.scanner.expect('[')
140 self.scanner.check_type('integer literal')
141 size = int(self.scanner.token)
142 self.scanner.scan()
146 size = self.literal_int()
143147 self.scanner.expect(']')
144148 return size
145149
371375 else:
372376 self.scanner.expect('forever')
373377 return Repeat(self.scanner.line_number, src=src, block=block, inverted=inverted)
378 elif self.scanner.consume('for'):
379 dest = self.locexpr()
380 if self.scanner.consume('downto'):
381 direction = -1
382 elif self.scanner.consume('upto'):
383 direction = 1
384 else:
385 self.syntax_error('expected "upto" or "downto", found "%s"' % self.scanner.token)
386 final = self.literal_int()
387 block = self.block()
388 return For(self.scanner.line_number, dest=dest, direction=direction, final=final, block=block)
374389 elif self.scanner.token in ("ld",):
375390 # the same as add, sub, cmp etc below, except supports an indlocexpr for the src
376391 opcode = self.scanner.token
130130 | }
131131 = ok
132132
133 Basic "open-faced for" loops, up and down.
134
135 | byte table[256] tab
136 |
137 | routine foo trashes a, x, c, z, v {
138 | ld x, 0
139 | for x upto 15 {
140 | ld a, tab + x
141 | }
142 | ld x, 15
143 | for x downto 0 {
144 | ld a, tab + x
145 | }
146 | }
147 = ok
148
133149 User-defined memory addresses of different types.
134150
135151 | byte byt