diff --git a/HISTORY.markdown b/HISTORY.markdown index aba3e3d..9fc9f87 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -26,3 +26,4 @@ in future versions. * Added `repeat` loops to the language, which can repeat until a flag is set (or `not` set), or which can repeat `forever`. * `if not` inverts the sense of the test. +* Added explicitly-addressed memory locations. diff --git a/README.markdown b/README.markdown index ff663e3..5f76236 100644 --- a/README.markdown +++ b/README.markdown @@ -31,19 +31,25 @@ Documentation TODO ---- -For 0.4: - -* explicitly-addressed memory locations - For 0.5: -* add line number (or at least routine name) to error messages. -* hexadecimal literals. -* 6502-mnemonic aliases (`sec`, `clc`) -* other handy aliases (`eq` for `z`, etc.) -* source code comments. +* `table` type constructor and indirect addressing. For 0.6: +* hexadecimal literals. +* source code comments. + +For 0.7: + * `word` type. -* `table` type constructor and indirect addressing. + +For 0.8: + +* `vector` type. + +For 0.9: + +* add line number (or at least routine name) to error messages. +* 6502-mnemonic aliases (`sec`, `clc`) +* other handy aliases (`eq` for `z`, etc.) diff --git a/doc/SixtyPical.md b/doc/SixtyPical.md index 99240ce..27a3665 100644 --- a/doc/SixtyPical.md +++ b/doc/SixtyPical.md @@ -75,6 +75,10 @@ by giving the type, which must be `byte`, and the name. byte pos +A location in memory may be given explicitly on a user-defined memory location. + + byte screen @ 1024 + Routines -------- diff --git a/eg/screen.60p b/eg/screen.60p new file mode 100644 index 0000000..6c9173f --- /dev/null +++ b/eg/screen.60p @@ -0,0 +1,8 @@ +byte screen @ 1024 + +routine main + trashes a, z, n, screen +{ + ld a, 100 + st a, screen +} diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 8ffd744..e64ec3b 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -33,6 +33,8 @@ class Compiler(object): for defn in program.defns: label = Label(defn.name) + if defn.addr is not None: + label.set_addr(defn.addr) self.labels[defn.name] = label for routine in program.routines: @@ -48,8 +50,9 @@ class Compiler(object): self.compile_routine(routine) for defn in program.defns: - label = self.labels[defn.name] - self.emitter.resolve_bss_label(label) + if defn.addr is None: + label = self.labels[defn.name] + self.emitter.resolve_bss_label(label) def compile_routine(self, routine): assert isinstance(routine, Routine) diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index a4aefd5..413b7bd 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -98,13 +98,19 @@ class Parser(object): raise KeyError(name) self.symbols[name] = routine routines.append(routine) + self.scanner.check_type('EOF') return Program(defns=defns, routines=routines) def defn(self): self.scanner.expect('byte') name = self.scanner.token self.scanner.scan() - return Defn(name=name) + addr = None + if self.scanner.consume('@'): + self.scanner.check_type('integer literal') + addr = int(self.scanner.token) + self.scanner.scan() + return Defn(name=name, addr=addr) def routine(self): self.scanner.expect('routine') diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 194883c..e3223e8 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -77,6 +77,16 @@ Access a defined memory location. | } = 00c0a0008c09c0ad09c060 + | byte screen @ 1024 + | + | routine main + | trashes a, z, n, screen + | { + | ld a, 100 + | st a, screen + | } + = 00c0a9648d000460 + Some instructions. | byte foo diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index 4220ed4..00713f5 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -27,6 +27,15 @@ Syntax error | ) ? SyntaxError +Another syntax error + + | byte glee + | { + | ld a, 0 + | add a, 1 + | } + ? SyntaxError + Extern routines | routine chrout @@ -92,3 +101,13 @@ Repeat with not | } until not z | } = ok + +Extern memory locations + + | byte screen @ 1024 + | + | routine main { + | ld a, 100 + | st a, screen + | } + = ok