leuat / TRSE

Turbo Rascal Syntax Error full repo
GNU General Public License v3.0
239 stars 44 forks source link

Passing function pointers as function parameters #862

Open mankeli opened 1 month ago

mankeli commented 1 month ago

I would want to write a function (procedure) like this, that takes a function pointer and then passes the value into somewhere else. Is it possible? Some built-in functions do this, but I'm not sure if it's possible with the syntax.

procedure setstuff(funcaddr : integer);
begin
    asm("
        ldy #>funcaddr
        ldx #<funcaddr
        jsr $F000
    ");
end;

...

procedure myfunc();
begin
    dostuff();
end;

setstuff(myfunc);
mankeli commented 1 month ago

well, found some way to do this. it still uses the intermediate storage though

procedure setstuff(funcaddr : integer);
begin
    asm("
        ldx #funcaddr+0
        ldy #funcaddr+1
        jsr $F000
    ");
end;

...

procedure myfunc();
begin
    dostuff();
end;

setstuff(#myfunc());
mankeli commented 1 month ago

..and if setstuff is set inline, the compiler fails to use the function address at all.

; LineNumber: 55
    lda #<myfunc
    ldy #>myfunc
    ; Calling storevariable on generic assign expression
    sta funcaddr
    sty funcaddr+1

from the callsite isn't generated at all.