Wolin - a minimal Kotlin-like language compiler for 65xx
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
qus wrote:
Thanks for your insights - yes, the optimizer code is a real mess, especialy pointer/reference substitution is rather... chaotic and probably wrong and will kick me in the face some day, but it works... for now.
qus wrote:
Reading your PLASMA docs I guess I could learn a lot from you, so when you have time I would probably have some questions to ask!
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Great, thanks!
So now I'm working on the last thing that is stopping Wolin from generating sane code - shuffling allocations and deallocations around. First - due to how optimizer works, sometimes a register is moved beyond its deallocation. Second - I need to move allocations/deallocations out of loops, so they don't get unnecessarily created and destroyed on each iteration. When this is ready, all that will be left (besides those damn pointers) is the language itself.
But meantime I have a question for anyone who ever created a copiler. How do you handle a return witha value that is not last piece of code before endproc? How do you clean open stacks?
So now I'm working on the last thing that is stopping Wolin from generating sane code - shuffling allocations and deallocations around. First - due to how optimizer works, sometimes a register is moved beyond its deallocation. Second - I need to move allocations/deallocations out of loops, so they don't get unnecessarily created and destroyed on each iteration. When this is ready, all that will be left (besides those damn pointers) is the language itself.
But meantime I have a question for anyone who ever created a copiler. How do you handle a return witha value that is not last piece of code before endproc? How do you clean open stacks?
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
qus wrote:
Great, thanks!
...
But meantime I have a question for anyone who ever created a copiler. How do you handle a return witha value that is not last piece of code before endproc? How do you clean open stacks?
...
But meantime I have a question for anyone who ever created a copiler. How do you handle a return witha value that is not last piece of code before endproc? How do you clean open stacks?
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Heh! Indeed, the easiest solution. I probably need to do the same to frame stack.
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Can anyone help with linking in ca65/cl65?
I've added "external" annotation to Wolin, so I can have empty functions like these:
Mangled into asm as: "__wolin_pl_qus_wolin_extPrint". The function is implemented in some asm library, ie:
I compile the above library into library.o and try to link it:
What's wrong?
I've added "external" annotation to Wolin, so I can have empty functions like these:
Code: Select all
external fun extPrint(what: string)Code: Select all
__wolin_spf := 251 ; function stack ptr
.macro lda_spf_lo idx
ldy #idx
lda (__wolin_spf),y
.endmacro
.macro lda_spf_hi
iny
lda (__wolin_spf),y
.endmacro
.macro sta_sp idx
sta idx, x
.endmacro
.macro allocsp_byte
dex
.endmacro
.macro allocsp_word
dex
dex
.endmacro
.macro freesp_word
inx
inx
.endmacro
.macro alloc_spf count
sec
lda __wolin_spf
sbc #count
sta __wolin_spf
bcs :+
dec __wolin_spf+1
:
.endmacro
.macro free_spf count
clc
lda __wolin_spf
adc #count
sta __wolin_spf
bcc :+
inc __wolin_spf+1
:
.endmacro
.export __wolin_pl_qus_wolin_extPrint
__wolin_pl_qus_wolin_extPrint:
allocsp_word
lda_spf_lo 0
sta_sp 0
lda_spf_hi
sta_sp 1
lda (0,x)
sta 53280
freesp_word
free_spf 2
Code: Select all
cl65.exe -o assembler.prg -t c64 -C c64-asm.cfg -g -Ln assembler.lbl -l assembler.lst --obj library.o assembler.s
assembler.s(92): Error: Symbol '__wolin_pl_qus_wolin_extPrint' is undefined
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Is it possible you have to put the export after the definition?
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
It was possible, but it didn't help.
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Hmm, can you show the source with the line numbers, just a few lines above and below the line it reports?
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
sure
Code: Select all
; 8: function __wolin_pl_qus_wolin_main
__wolin_pl_qus_wolin_main:
; 9: alloc SPF<__wolin_pl_qus_wolin_extPrint> , #2
sec
lda __wolin_spf
sbc #2
sta __wolin_spf
bcs :+
dec __wolin_spf+1
:
; 10: let SPF(0)<pl.qus.wolin.extPrint.what>[ubyte*] = #__wolin_lab_stringConst_0[uword]
lda #<__wolin_lab_stringConst_0
ldy #0
sta (__wolin_spf),y
lda #>__wolin_lab_stringConst_0
iny
sta (__wolin_spf),y
; 11: call __wolin_pl_qus_wolin_extPrint[uword]
jsr __wolin_pl_qus_wolin_extPrint
; 12: endfunction
rts
; 13: string __wolin_lab_stringConst_0[uword] = $"dupa"
__wolin_lab_stringConst_0:
.asciiz "dupa"
;.byt 0
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Is it now reporting line 11 as the problem line?
(Edit: Previously it was line 92 of the assembler.s)
(Edit: Previously it was line 92 of the assembler.s)
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
This is not a full source. The line is the same - where __wolin_pl_qus_wolin_extPrint is referenced.
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
What if you remove the --obj and just mention library.o as a parameter?
Are you certain that library.o is recently built and from the source that you expect
Are you certain that library.o is recently built and from the source that you expect
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Same thing. I added "--obj" when trying to make it work. I've built the "library" a moment ago, with just "ca65 library.s".
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
The only other thing I can think of is to try putting library.o after assembler.s, even though that feels wrong!
Re: Wolin - a minimal Kotlin-like language compiler for 65xx
Code: Select all
>cl65.exe -o assembler.prg -t c64 -C c64-asm.cfg -g -Ln assembler.lbl -l assembler.lst assembler.s library.o
assembler.s(92): Error: Symbol '__wolin_pl_qus_wolin_extPrint' is undefined