git @ Cat's Eye Technologies SixtyPical / 7b1ee60
Initial value for locations: changed syntax, executes, compiles. Chris Pressey 8 years ago
9 changed file(s) with 77 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
00 History of SixtyPical
11 =====================
2
3 0.7-PRE
4 -------
5
6 * User-defined `byte` locations can be given an initial value.
27
38 0.6
49 ---
4343
4444 For 0.7:
4545
46 * initialized `byte` memory locations
47 * initialized `byte table` memory locations
4846 * `word` type.
4947 * `word table` type.
5048
5957
6058 At some point...
6159
60 * initialized `byte table` memory locations
6261 * always analyze before executing or compiling, unless told not to
6362 * `trash` instruction.
6463 * `interrupt` routines.
8585 Or, a user-defined memory location may be given an initial value. But in this
8686 case, an explicit address in memory cannot be given.
8787
88 byte pos = 0
89 byte table scores = [1, 3, 8, 17, 26, 100]
88 byte pos : 0
9089
9190 A user-defined vector memory location is decorated with READS and WRITES lists
9291 like a routine (see below), and it may only hold addresses of routines which
5656 self.emitter.resolve_label(label)
5757 self.emitter.emit(JMP(Indirect(self.labels[location.name])))
5858
59 # initialized data
5960 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:
6169 label = self.labels[defn.name]
6270 self.emitter.resolve_bss_label(label)
6371
3636 for ref in (REG_A, REG_X, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C):
3737 context.set(ref, 0)
3838 main = None
39
40 for defn in program.defns:
41 if defn.initial is not None:
42 context.set(defn.location, defn.initial)
43
3944 for routine in program.routines:
4045 context.set(routine.location, routine)
4146 if routine.name == 'main':
4247 main = routine
48
4349 self.eval_routine(main, context)
4450 return context
4551
3535 self.token = None
3636 self.type = 'EOF'
3737 return
38 if self.scan_pattern(r'\,|\@|\+|\{|\}', 'operator'):
38 if self.scan_pattern(r'\,|\@|\+|\:|\{|\}', 'operator'):
3939 return
4040 if self.scan_pattern(r'\d+', 'integer literal'):
4141 return
139139 elif inputs or outputs or trashes:
140140 raise SyntaxError("Cannot apply constraints to non-vector type")
141141
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
142148 addr = None
143149 if self.scanner.consume('@'):
144150 self.scanner.check_type('integer literal')
145151 addr = int(self.scanner.token)
146152 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
147157 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)
149160
150161 def constraints(self):
151162 inputs = set()
7676 | }
7777 = 00c0a0008c09c0ad09c060
7878
79 Memory location with explicit address.
80
7981 | byte screen @ 1024
8082 |
8183 | routine main
8587 | st a, screen
8688 | }
8789 = 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
88102
89103 Some instructions.
90104
4141 = n: 0
4242 = v: 0
4343 = 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
4460 = y: 0
4561 = z: 0
4662
122122 | }
123123 = ok
124124
125 Extern memory locations.
125 Explicit memory address.
126126
127127 | byte screen @ 1024
128128 |
134134
135135 Initialized memory locations.
136136
137 | byte lives = 3
137 | byte lives : 3
138138 |
139139 | routine main {
140140 | ld a, lives
141141 | st a, lives
142142 | }
143143 = ok
144
145 Cannot have both initial value and explicit address.
146
147 | byte screen : 3 @ 1024
148 |
149 | routine main {
150 | ld a, lives
151 | st a, lives
152 | }
153 ? SyntaxError
144154
145155 Can't access an undeclared memory location.
146156