mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-16 15:30:26 +00:00
Syntax for "open-faced for loop".
This commit is contained in:
parent
d7ada8949c
commit
d815e05e0c
@ -83,5 +83,10 @@ class Repeat(Instr):
|
|||||||
child_attrs = ('block',)
|
child_attrs = ('block',)
|
||||||
|
|
||||||
|
|
||||||
|
class For(Instr):
|
||||||
|
value_attrs = ('dest', 'direction', 'final')
|
||||||
|
child_attrs = ('block',)
|
||||||
|
|
||||||
|
|
||||||
class WithInterruptsOff(Instr):
|
class WithInterruptsOff(Instr):
|
||||||
child_attrs = ('block',)
|
child_attrs = ('block',)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
|
|
||||||
from sixtypical.ast import Program, Defn, Routine, Block, SingleOp, If, Repeat, WithInterruptsOff
|
from sixtypical.ast import Program, Defn, Routine, Block, SingleOp, If, Repeat, For, WithInterruptsOff
|
||||||
from sixtypical.model import (
|
from sixtypical.model import (
|
||||||
TYPE_BIT, TYPE_BYTE, TYPE_WORD,
|
TYPE_BIT, TYPE_BYTE, TYPE_WORD,
|
||||||
RoutineType, VectorType, TableType, BufferType, PointerType,
|
RoutineType, VectorType, TableType, BufferType, PointerType,
|
||||||
@ -136,11 +136,15 @@ class Parser(object):
|
|||||||
|
|
||||||
return Defn(self.scanner.line_number, name=name, addr=addr, initial=initial, location=location)
|
return Defn(self.scanner.line_number, name=name, addr=addr, initial=initial, location=location)
|
||||||
|
|
||||||
|
def literal_int(self):
|
||||||
|
self.scanner.check_type('integer literal')
|
||||||
|
c = int(self.scanner.token)
|
||||||
|
self.scanner.scan()
|
||||||
|
return c
|
||||||
|
|
||||||
def defn_size(self):
|
def defn_size(self):
|
||||||
self.scanner.expect('[')
|
self.scanner.expect('[')
|
||||||
self.scanner.check_type('integer literal')
|
size = self.literal_int()
|
||||||
size = int(self.scanner.token)
|
|
||||||
self.scanner.scan()
|
|
||||||
self.scanner.expect(']')
|
self.scanner.expect(']')
|
||||||
return size
|
return size
|
||||||
|
|
||||||
@ -372,6 +376,17 @@ class Parser(object):
|
|||||||
else:
|
else:
|
||||||
self.scanner.expect('forever')
|
self.scanner.expect('forever')
|
||||||
return Repeat(self.scanner.line_number, src=src, block=block, inverted=inverted)
|
return Repeat(self.scanner.line_number, src=src, block=block, inverted=inverted)
|
||||||
|
elif self.scanner.consume('for'):
|
||||||
|
dest = self.locexpr()
|
||||||
|
if self.scanner.consume('downto'):
|
||||||
|
direction = -1
|
||||||
|
elif self.scanner.consume('upto'):
|
||||||
|
direction = 1
|
||||||
|
else:
|
||||||
|
self.syntax_error('expected "upto" or "downto", found "%s"' % self.scanner.token)
|
||||||
|
final = self.literal_int()
|
||||||
|
block = self.block()
|
||||||
|
return For(self.scanner.line_number, dest=dest, direction=direction, final=final, block=block)
|
||||||
elif self.scanner.token in ("ld",):
|
elif self.scanner.token in ("ld",):
|
||||||
# the same as add, sub, cmp etc below, except supports an indlocexpr for the src
|
# the same as add, sub, cmp etc below, except supports an indlocexpr for the src
|
||||||
opcode = self.scanner.token
|
opcode = self.scanner.token
|
||||||
|
@ -131,6 +131,22 @@ Repeat with not
|
|||||||
| }
|
| }
|
||||||
= ok
|
= ok
|
||||||
|
|
||||||
|
Basic "open-faced for" loops, up and down.
|
||||||
|
|
||||||
|
| byte table[256] tab
|
||||||
|
|
|
||||||
|
| routine foo trashes a, x, c, z, v {
|
||||||
|
| ld x, 0
|
||||||
|
| for x upto 15 {
|
||||||
|
| ld a, tab + x
|
||||||
|
| }
|
||||||
|
| ld x, 15
|
||||||
|
| for x downto 0 {
|
||||||
|
| ld a, tab + x
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
= ok
|
||||||
|
|
||||||
User-defined memory addresses of different types.
|
User-defined memory addresses of different types.
|
||||||
|
|
||||||
| byte byt
|
| byte byt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user