Initial value for locations: changed syntax, executes, compiles.
Chris Pressey
8 years ago
0 | 0 |
History of SixtyPical
|
1 | 1 |
=====================
|
|
2 |
|
|
3 |
0.7-PRE
|
|
4 |
-------
|
|
5 |
|
|
6 |
* User-defined `byte` locations can be given an initial value.
|
2 | 7 |
|
3 | 8 |
0.6
|
4 | 9 |
---
|
43 | 43 |
|
44 | 44 |
For 0.7:
|
45 | 45 |
|
46 | |
* initialized `byte` memory locations
|
47 | |
* initialized `byte table` memory locations
|
48 | 46 |
* `word` type.
|
49 | 47 |
* `word table` type.
|
50 | 48 |
|
|
59 | 57 |
|
60 | 58 |
At some point...
|
61 | 59 |
|
|
60 |
* initialized `byte table` memory locations
|
62 | 61 |
* always analyze before executing or compiling, unless told not to
|
63 | 62 |
* `trash` instruction.
|
64 | 63 |
* `interrupt` routines.
|
85 | 85 |
Or, a user-defined memory location may be given an initial value. But in this
|
86 | 86 |
case, an explicit address in memory cannot be given.
|
87 | 87 |
|
88 | |
byte pos = 0
|
89 | |
byte table scores = [1, 3, 8, 17, 26, 100]
|
|
88 |
byte pos : 0
|
90 | 89 |
|
91 | 90 |
A user-defined vector memory location is decorated with READS and WRITES lists
|
92 | 91 |
like a routine (see below), and it may only hold addresses of routines which
|
56 | 56 |
self.emitter.resolve_label(label)
|
57 | 57 |
self.emitter.emit(JMP(Indirect(self.labels[location.name])))
|
58 | 58 |
|
|
59 |
# initialized data
|
59 | 60 |
for defn in program.defns:
|
60 | |
if defn.addr is None:
|
|
61 |
if defn.initial is not None:
|
|
62 |
label = self.labels[defn.name]
|
|
63 |
self.emitter.resolve_label(label)
|
|
64 |
self.emitter.emit(Byte(defn.initial))
|
|
65 |
|
|
66 |
# uninitialized, "BSS" data
|
|
67 |
for defn in program.defns:
|
|
68 |
if defn.initial is None and defn.addr is None:
|
61 | 69 |
label = self.labels[defn.name]
|
62 | 70 |
self.emitter.resolve_bss_label(label)
|
63 | 71 |
|
36 | 36 |
for ref in (REG_A, REG_X, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C):
|
37 | 37 |
context.set(ref, 0)
|
38 | 38 |
main = None
|
|
39 |
|
|
40 |
for defn in program.defns:
|
|
41 |
if defn.initial is not None:
|
|
42 |
context.set(defn.location, defn.initial)
|
|
43 |
|
39 | 44 |
for routine in program.routines:
|
40 | 45 |
context.set(routine.location, routine)
|
41 | 46 |
if routine.name == 'main':
|
42 | 47 |
main = routine
|
|
48 |
|
43 | 49 |
self.eval_routine(main, context)
|
44 | 50 |
return context
|
45 | 51 |
|
35 | 35 |
self.token = None
|
36 | 36 |
self.type = 'EOF'
|
37 | 37 |
return
|
38 | |
if self.scan_pattern(r'\,|\@|\+|\{|\}', 'operator'):
|
|
38 |
if self.scan_pattern(r'\,|\@|\+|\:|\{|\}', 'operator'):
|
39 | 39 |
return
|
40 | 40 |
if self.scan_pattern(r'\d+', 'integer literal'):
|
41 | 41 |
return
|
|
139 | 139 |
elif inputs or outputs or trashes:
|
140 | 140 |
raise SyntaxError("Cannot apply constraints to non-vector type")
|
141 | 141 |
|
|
142 |
initial = None
|
|
143 |
if self.scanner.consume(':'):
|
|
144 |
self.scanner.check_type('integer literal')
|
|
145 |
initial = int(self.scanner.token)
|
|
146 |
self.scanner.scan()
|
|
147 |
|
142 | 148 |
addr = None
|
143 | 149 |
if self.scanner.consume('@'):
|
144 | 150 |
self.scanner.check_type('integer literal')
|
145 | 151 |
addr = int(self.scanner.token)
|
146 | 152 |
self.scanner.scan()
|
|
153 |
|
|
154 |
if initial is not None and addr is not None:
|
|
155 |
raise SyntaxError("Definition cannot have both initial value and explicit address")
|
|
156 |
|
147 | 157 |
location = LocationRef(type, name)
|
148 | |
return Defn(name=name, addr=addr, location=location)
|
|
158 |
|
|
159 |
return Defn(name=name, addr=addr, initial=initial, location=location)
|
149 | 160 |
|
150 | 161 |
def constraints(self):
|
151 | 162 |
inputs = set()
|
76 | 76 |
| }
|
77 | 77 |
= 00c0a0008c09c0ad09c060
|
78 | 78 |
|
|
79 |
Memory location with explicit address.
|
|
80 |
|
79 | 81 |
| byte screen @ 1024
|
80 | 82 |
|
|
81 | 83 |
| routine main
|
|
85 | 87 |
| st a, screen
|
86 | 88 |
| }
|
87 | 89 |
= 00c0a9648d000460
|
|
90 |
|
|
91 |
Memory location with initial value.
|
|
92 |
|
|
93 |
| byte lives : 3
|
|
94 |
|
|
|
95 |
| routine main
|
|
96 |
| inputs lives
|
|
97 |
| trashes a, z, n
|
|
98 |
| {
|
|
99 |
| ld a, lives
|
|
100 |
| }
|
|
101 |
= 00c0ad04c06003
|
88 | 102 |
|
89 | 103 |
Some instructions.
|
90 | 104 |
|
41 | 41 |
= n: 0
|
42 | 42 |
= v: 0
|
43 | 43 |
= x: 1
|
|
44 |
= y: 0
|
|
45 |
= z: 0
|
|
46 |
|
|
47 |
Program accesses a memory location with initial value.
|
|
48 |
|
|
49 |
| byte lives : 3
|
|
50 |
|
|
|
51 |
| routine main {
|
|
52 |
| ld a, lives
|
|
53 |
| }
|
|
54 |
= a: 3
|
|
55 |
= c: 0
|
|
56 |
= lives: 3
|
|
57 |
= n: 0
|
|
58 |
= v: 0
|
|
59 |
= x: 0
|
44 | 60 |
= y: 0
|
45 | 61 |
= z: 0
|
46 | 62 |
|