1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-01 12:41:30 +00:00

Compile copy byte to byte and word to word.

This commit is contained in:
Chris Pressey 2016-06-16 11:10:03 -05:00
parent fc8c85e670
commit e2daa33dc5
4 changed files with 46 additions and 4 deletions

View File

@ -5,6 +5,8 @@ History of SixtyPical
-------
* User-defined `byte` locations can be given an initial value.
* `word` type locations which can be defined and `copy`ed between.
* Can `copy` directly from one user-defined `byte` location to another.
0.6
---

View File

@ -44,7 +44,7 @@ TODO
For 0.7:
* `word` type.
* `low` and `high` address operators (turn `word` type into `byte`.)
* `word table` type.
For 0.8:

View File

@ -3,7 +3,7 @@
from sixtypical.ast import Program, Routine, Block, Instr
from sixtypical.model import (
ConstantRef,
TYPE_BIT,
TYPE_BIT, TYPE_BYTE, TYPE_WORD,
RoutineType, VectorType,
REG_A, REG_X, REG_Y, FLAG_C
)
@ -275,7 +275,19 @@ class Compiler(object):
self.compile_block(instr.block)
self.emitter.emit(CLI())
elif opcode == 'copy':
if isinstance(src.type, VectorType) and isinstance(dest.type, VectorType):
if src.type == TYPE_BYTE and dest.type == TYPE_BYTE:
src_label = self.labels[src.name]
dest_label = self.labels[dest.name]
self.emitter.emit(LDA(Absolute(src_label)))
self.emitter.emit(STA(Absolute(dest_label)))
elif src.type == TYPE_WORD and dest.type == TYPE_WORD:
src_label = self.labels[src.name]
dest_label = self.labels[dest.name]
self.emitter.emit(LDA(Absolute(src_label)))
self.emitter.emit(STA(Absolute(dest_label)))
self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
elif isinstance(src.type, VectorType) and isinstance(dest.type, VectorType):
src_label = self.labels[src.name]
dest_label = self.labels[dest.name]
self.emitter.emit(LDA(Absolute(src_label)))

View File

@ -239,7 +239,35 @@ Indexed access.
| }
= 00c0a200a9009d0dc0bd0dc060
Copy instruction..
Copy byte to byte.
| byte bar
| byte baz
|
| routine main
| inputs baz
| outputs bar
| trashes a, n, z
| {
| copy baz, bar
| }
= 00c0ad09c08d07c060
Copy word to word.
| word bar
| word baz
|
| routine main
| inputs baz
| outputs bar
| trashes a, n, z
| {
| copy baz, bar
| }
= 00c0ad0fc08d0dc0ad10c08d0ec060
Copy vector to vector.
| vector bar
| vector baz