git @ Cat's Eye Technologies SixtyPical / c98e446
Spec and syntax for vectors and copy instruction. Chris Pressey 7 years ago
5 changed file(s) with 57 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5050 * 6502-mnemonic aliases (`sec`, `clc`)
5151 * other handy aliases (`eq` for `z`, etc.)
5252 * add absolute addressing in shl/shr, absolute-indexed for add, sub, etc.
53 * check and disallow recursion.
00 SixtyPical
11 ==========
22
3 This document describes the SixtyPical programming language version 0.5,
3 This document describes the SixtyPical programming language version 0.6-PRE,
44 both its execution aspect and its static analysis aspect (even though
55 these are, technically speaking, separate concepts.)
66
1313 Types
1414 -----
1515
16 There are three TYPES in SixtyPical:
16 There are five TYPES in SixtyPical:
1717
1818 * bit (2 possible values)
1919 * byte (256 possible values)
2020 * byte table (256 entries, each holding a byte)
21 * routine (code stored somewhere in memory, read-only)
22 * vector (address of a routine)
2123
2224 Memory locations
2325 ----------------
7173 ### User-defined ###
7274
7375 There may be any number of user-defined memory locations. They are defined
74 by giving the type, which must be `byte`, and the name.
76 by giving the type, which must be `byte`, `byte table`, or `vector`, and the
77 name.
7578
7679 byte pos
7780
7881 A location in memory may be given explicitly on a user-defined memory location.
7982
80 byte screen @ 1024
83 byte table screen @ 1024
8184
8285 Routines
8386 --------
324327 } until z
325328
326329 "until" is optional, but if omitted, must be replaced with "forever".
330
331 ### copy ###
332
333 copy <src-memory-location>, <dest-memory-location>
334
335 Reads from src and writes to dest. Differs from `st` in that is able to
336 copy more general types of data (for example, vectors,) and it sets the
337 `z` and `n` flags and trashes the `a` register.
338
339 * It is illegal if dest is read-only.
340 * It is illegal if dest does not occur in the WRITES lists of the current
341 routine.
342 * It is illegal if src is not of same type as dest.
343 * It is illegal if src is uninitialized.
344
345 After execution, dest is considered initialized, as are `z` and `n`, while
346 `a` is considered uninitialized.
327347
328348 Grammar
329349 -------
355375 | "call" RoutineIdent
356376 | "if" ["not"] LocExpr Block ["else" Block]
357377 | "repeat" Block ("until" ["not"] LocExpr | "forever")
378 | "copy" LocExpr "," LocExpr ["+" LocExpr]
358379 .
1616 TYPE_BIT = Type('bit')
1717 TYPE_BYTE = Type('byte')
1818 TYPE_BYTE_TABLE = Type('byte table')
19 TYPE_ROUTINE = Type('routine')
20 TYPE_VECTOR = Type('vector') # the mem loc contains an address of a routine
1921
2022
2123 class Ref(object):
33
44 from sixtypical.ast import Program, Defn, Routine, Block, Instr
55 from sixtypical.model import (
6 TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE,
6 TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE, TYPE_ROUTINE, TYPE_VECTOR,
77 LocationRef, ConstantRef
88 )
99
102102 def program(self):
103103 defns = []
104104 routines = []
105 while self.scanner.on('byte'):
105 while self.scanner.on('byte') or self.scanner.on('vector'):
106106 defn = self.defn()
107107 name = defn.name
108108 if name in self.symbols:
114114 name = routine.name
115115 if name in self.symbols:
116116 raise SyntaxError(name)
117 self.symbols[name] = SymEntry(routine, None)
117 self.symbols[name] = SymEntry(routine, LocationRef(TYPE_ROUTINE, name))
118118 routines.append(routine)
119119 self.scanner.check_type('EOF')
120120 return Program(defns=defns, routines=routines)
121121
122122 def defn(self):
123123 type = TYPE_BYTE
124 self.scanner.expect('byte')
125 if self.scanner.consume('table'):
126 type = TYPE_BYTE_TABLE
124 if self.scanner.consume('byte'):
125 type = TYPE_BYTE
126 if self.scanner.consume('table'):
127 type = TYPE_BYTE_TABLE
128 else:
129 self.scanner.expect('vector')
130 type = TYPE_VECTOR
127131 self.scanner.check_type('identifier')
128132 name = self.scanner.token
129133 self.scanner.scan()
245249 self.scanner.scan()
246250 # TODO: check that is has been defined
247251 return Instr(opcode=opcode, name=name, dest=None, src=None)
252 elif self.scanner.token in ("copy",):
253 opcode = self.scanner.token
254 self.scanner.scan()
255 src = self.locexpr()
256 self.scanner.expect(',')
257 dest = self.locexpr()
258 return Instr(opcode=opcode, dest=dest, src=src)
248259 else:
249260 raise ValueError('bad opcode "%s"' % self.scanner.token)
195195 | st a, tab + y
196196 | }
197197 = ok
198
199 Declaring a vector.
200
201 | vector cinv
202 |
203 | routine foo {
204 | ld a, 0
205 | }
206 | routine main {
207 | copy foo, cinv
208 | }
209 = ok