6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 7:27 am

All times are UTC




Post new topic Reply to topic  [ 171 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next
Author Message
PostPosted: Tue Apr 21, 2020 2:23 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 143
Location: Lake Tahoe
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.

Parsing and code generation for indirection and dereferencing expressions was without a doubt the hardest part of the PLASMA compiler. I guarantee there are cases it still gets wrong.
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!

I'd be happy to share any insight I may have. Our projects are aimed at slightly different environments, but any way to move the 6502 forward as a compilation target is helpful to all of us. Ping me on the PLASMA project page or PM me any time.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 24, 2020 7:13 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 24, 2020 6:49 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 143
Location: Lake Tahoe
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?

For PLASMA, I keep a count of how many items are on the stack. It's really easy for me though, PLASMA only keeps values on the evaluation stack (your SP) between expressions during FOR/NEXT loops. For your case, the easiest and most bullet-proof approach could be to save the SP index (X register) on the stack (HW or SPF) as part of your function entry setup, and restore it when leaving the function.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 25, 2020 8:54 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
Heh! Indeed, the easiest solution. I probably need to do the same to frame stack.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:26 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
Can anyone help with linking in ca65/cl65?

I've added "external" annotation to Wolin, so I can have empty functions like these:

Code:
external fun extPrint(what: string)


Mangled into asm as: "__wolin_pl_qus_wolin_extPrint". The function is implemented in some asm library, ie:

Code:
__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


I compile the above library into library.o and try to link it:

Code:
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


What's wrong?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:31 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Is it possible you have to put the export after the definition?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:39 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
It was possible, but it didn't help.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:44 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Hmm, can you show the source with the line numbers, just a few lines above and below the line it reports?


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:45 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
sure

Code:
; 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


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 10:47 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Is it now reporting line 11 as the problem line?
(Edit: Previously it was line 92 of the assembler.s)


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 11:40 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
This is not a full source. The line is the same - where __wolin_pl_qus_wolin_extPrint is referenced.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 11:46 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
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


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 11:52 am 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
Same thing. I added "--obj" when trying to make it work. I've built the "library" a moment ago, with just "ca65 library.s".


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 11:58 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
The only other thing I can think of is to try putting library.o after assembler.s, even though that feels wrong!


Top
 Profile  
Reply with quote  
PostPosted: Sat May 02, 2020 12:00 pm 
Offline

Joined: Sat Apr 20, 2019 5:31 pm
Posts: 104
Code:
>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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 171 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: