1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 03:41:28 +00:00

Initial support for initializing byte tables with list of bytes.

This commit is contained in:
Chris Pressey 2018-03-29 10:45:18 +01:00
parent 9b912de17c
commit 2f513f7291
4 changed files with 42 additions and 5 deletions

View File

@ -122,6 +122,7 @@ class Compiler(object):
elif type_ == TYPE_WORD:
initial_data = Word(defn.initial)
elif TableType.is_a_table_type(type_, TYPE_BYTE):
# FIXME convert defn.initial to a serializable type ... or when parsing.
initial_data = Table(defn.initial, type_.size)
else:
raise NotImplementedError(type_)

View File

@ -138,9 +138,15 @@ class Parser(object):
initial = None
if self.scanner.consume(':'):
if isinstance(type_, TableType) and self.scanner.on_type('string literal'):
initial = self.scanner.token
self.scanner.scan()
if isinstance(type_, TableType):
if self.scanner.on_type('string literal'):
initial = self.scanner.token
self.scanner.scan()
else:
initial = []
initial.append(self.const())
while self.scanner.consume(','):
initial.append(self.const())
else:
initial = self.const().value

View File

@ -162,7 +162,7 @@ Word memory locations with explicit address, initial value.
= $081A .byte $BB
= $081B .byte $0B
Initialized byte table. Bytes allocated, but beyond the string, are 0's.
Initialized byte table, initialized with ASCII string. Bytes allocated, but beyond the string, are 0's.
| byte table[8] message : "WHAT?"
|
@ -184,6 +184,28 @@ Initialized byte table. Bytes allocated, but beyond the string, are 0's.
= $0819 BRK
= $081A BRK
Initialized byte table, initialized with list of byte values.
| byte table[8] message : 255, 0, 129, 128, 127
|
| routine main
| inputs message
| outputs x, a, z, n
| {
| ld x, 0
| ld a, message + x
| }
= $080D LDX #$00
= $080F LDA $0813,X
= $0812 RTS
= $0813 .byte $57
= $0814 PHA
= $0815 EOR ($54,X)
= $0817 .byte $3F
= $0818 BRK
= $0819 BRK
= $081A BRK
Some instructions.
| byte foo

View File

@ -302,7 +302,7 @@ User-defined locations of other types.
| }
= ok
Initialized byte table.
Initialized byte table, initialized with ASCII string.
| byte table[32] message : "WHAT DO YOU WANT TO DO NEXT?"
|
@ -318,6 +318,14 @@ Can't initialize anything but a byte table with a string.
| }
? SyntaxError
Initialized byte table, initialized with list of bytes.
| byte table[8] charmap : 0, 255, 129, 192, 0, 1, 2, 4
|
| routine main {
| }
= ok
Can't access an undeclared memory location.
| routine main {