1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +00:00

I kind of forgot that indirect JSR needs a trampoline first :/

This commit is contained in:
Chris Pressey 2015-10-20 13:15:21 +01:00
parent f16cb75677
commit 16649042cb
4 changed files with 54 additions and 3 deletions

View File

@ -9,7 +9,7 @@ from sixtypical.model import (
)
from sixtypical.emitter import Byte, Label, Offset
from sixtypical.gen6502 import (
Immediate, Absolute, AbsoluteX, AbsoluteY, Relative,
Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, Relative,
LDA, LDX, LDY, STA, STX, STY,
TAX, TAY, TXA, TYA,
CLC, SEC, ADC, SBC, ROL, ROR,
@ -193,8 +193,16 @@ class Compiler(object):
else:
raise UnsupportedOpcodeError(instr)
elif opcode == 'call':
location = instr.location
label = self.labels[instr.location.name]
self.emitter.emit(JSR(Absolute(label)))
if isinstance(location.type, RoutineType):
self.emitter.emit(JSR(Absolute(label)))
elif isinstance(location.type, VectorType):
# XXX NOT QUITE RIGHT, IS IT?
# We need to simulate an indirect JSR!
self.emitter.emit(JMP(Indirect(label)))
else:
raise NotImplementedError
elif opcode == 'if':
cls = {
False: {

View File

@ -1119,3 +1119,32 @@ Routines are read-only.
| copy vec, foo
| }
? TypeMismatchError
Indirect call.
| vector foo outputs x trashes z, n
|
| routine bar outputs x trashes z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo
| call foo
| }
= ok
Calling the vector has indeed trashed stuff etc,
| vector foo trashes x, z, n
|
| routine bar trashes x, z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes z, n {
| ld x, 0
| copy bar, foo
| call foo
| }
? UninitializedOutputError: x

View File

@ -261,3 +261,17 @@ Copy instruction inside interrupts off block.
| }
| }
= 00c078ad0fc08d11c0ad10c08d12c05860e860
Indirect call.
| vector foo outputs x trashes z, n
|
| routine bar outputs x trashes z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo
| call foo
| }
= 00c0

View File

@ -409,7 +409,7 @@ Indirect call.
| ld x, 200
| }
|
| routine main {
| routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo
| call foo
| }