git @ Cat's Eye Technologies SixtyPical / 522c771
Add explicitly-addressed memory locations. Chris Pressey 6 years ago
8 changed file(s) with 70 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2525 * Added `repeat` loops to the language, which can repeat until a flag
2626 is set (or `not` set), or which can repeat `forever`.
2727 * `if not` inverts the sense of the test.
28 * Added explicitly-addressed memory locations.
3030 TODO
3131 ----
3232
33 For 0.4:
34
35 * explicitly-addressed memory locations
36
3733 For 0.5:
3834
39 * add line number (or at least routine name) to error messages.
40 * hexadecimal literals.
41 * 6502-mnemonic aliases (`sec`, `clc`)
42 * other handy aliases (`eq` for `z`, etc.)
43 * source code comments.
35 * `table` type constructor and indirect addressing.
4436
4537 For 0.6:
4638
39 * hexadecimal literals.
40 * source code comments.
41
42 For 0.7:
43
4744 * `word` type.
48 * `table` type constructor and indirect addressing.
45
46 For 0.8:
47
48 * `vector` type.
49
50 For 0.9:
51
52 * add line number (or at least routine name) to error messages.
53 * 6502-mnemonic aliases (`sec`, `clc`)
54 * other handy aliases (`eq` for `z`, etc.)
7373 by giving the type, which must be `byte`, and the name.
7474
7575 byte pos
76
77 A location in memory may be given explicitly on a user-defined memory location.
78
79 byte screen @ 1024
7680
7781 Routines
7882 --------
0 byte screen @ 1024
1
2 routine main
3 trashes a, z, n, screen
4 {
5 ld a, 100
6 st a, screen
7 }
3232
3333 for defn in program.defns:
3434 label = Label(defn.name)
35 if defn.addr is not None:
36 label.set_addr(defn.addr)
3537 self.labels[defn.name] = label
3638
3739 for routine in program.routines:
4749 self.compile_routine(routine)
4850
4951 for defn in program.defns:
50 label = self.labels[defn.name]
51 self.emitter.resolve_bss_label(label)
52 if defn.addr is None:
53 label = self.labels[defn.name]
54 self.emitter.resolve_bss_label(label)
5255
5356 def compile_routine(self, routine):
5457 assert isinstance(routine, Routine)
9797 raise KeyError(name)
9898 self.symbols[name] = routine
9999 routines.append(routine)
100 self.scanner.check_type('EOF')
100101 return Program(defns=defns, routines=routines)
101102
102103 def defn(self):
103104 self.scanner.expect('byte')
104105 name = self.scanner.token
105106 self.scanner.scan()
106 return Defn(name=name)
107 addr = None
108 if self.scanner.consume('@'):
109 self.scanner.check_type('integer literal')
110 addr = int(self.scanner.token)
111 self.scanner.scan()
112 return Defn(name=name, addr=addr)
107113
108114 def routine(self):
109115 self.scanner.expect('routine')
7575 | ld a, foo
7676 | }
7777 = 00c0a0008c09c0ad09c060
78
79 | byte screen @ 1024
80 |
81 | routine main
82 | trashes a, z, n, screen
83 | {
84 | ld a, 100
85 | st a, screen
86 | }
87 = 00c0a9648d000460
7888
7989 Some instructions.
8090
2424 | ld a, 0
2525 | add a, 1
2626 | )
27 ? SyntaxError
28
29 Another syntax error
30
31 | byte glee
32 | {
33 | ld a, 0
34 | add a, 1
35 | }
2736 ? SyntaxError
2837
2938 Extern routines
91100 | } until not z
92101 | }
93102 = ok
103
104 Extern memory locations
105
106 | byte screen @ 1024
107 |
108 | routine main {
109 | ld a, 100
110 | st a, screen
111 | }
112 = ok