So, no more options... unless... I write my own compiler! I never wrote any and had no idea how hard it could be. And guess what? It's not so hard! All you need is ANTLR4, a grammar of some nice existing modern language (like Kotlin) and the knowledge that 65xx has not three, but 250-something usable registers (thanks 6502.org!)
So it's been a lazy week, and I was able to compile this piece of code into 6510 (see attached assembler.s):
Code: Select all
package pl.qus.wolin
fun sillySum(arg1: Word, arg2: Word): Word {
throw 12345
return arg1+arg2
}
fun main() {
var b: Word = 0
var sumError: Word = 0xcafd
try {
b=sillySum(4,2)
} catch (ex: Word) {
b=sumError
}
b++
}
So how does it work? First it translates Wolin code to intermediate virtual machine assembler that has the following syntax:
Code: Select all
mnemonic destination[type] = arg1[type], arg2[type]
Code: Select all
add pl.qus.wolin.test.main..b[word] = pl.qus.wolin.test.main..b[word], #1[byte]
Code: Select all
add ?dest[word] = ?src[word], #?val[byte] -> """
clc
lda {src}
adc #{val}
sta {dest}
lda {src}+1
adc #0
sta {dest}+1
"""
Code: Select all
clc
lda pl.qus.wolin.test.main..b
adc #1
sta pl.qus.wolin.test.main..b
lda pl.qus.wolin.test.main..b+1
adc #0
sta pl.qus.wolin.test.main..b+1
Of course it's only very beginning and a tiny fraction of what real Kotlin can do. I'm learnig a lot while coding it. Next thing will probably be a look into OO and functional... just because nobody tried it yet and because "65xx is not designed for OO".
Some technical info:
- CPU stack is used only for jsring and temporary register storage
- There's ZP-based "program stack" used for evaluating exproessions (and gee - it really makes everything so simple!)
- There are two non ZP stacks: one for function calls and function local variables (so recurrence is possible) and second for exception handling
- Variables can be fixed to a location like "var background: Ubyte^53281" and even to single bit at some location (for boolean variables)
I'll try to share some more experience if I continue coding this assembler. Feel free to share your ideas/knowledge!