Post Reply 
User-defined functions in Free42
01-14-2021, 12:56 PM
Post: #35
RE: User-defined functions in Free42
(01-14-2021 03:21 AM)Thomas Okken Wrote:  Deciding the number of inputs and outputs dynamically could be handled by having another function that overrides the number saved by FUNC. That would be pretty easy to implement, since the two-digit number passed to FUNC is just saved to a hidden variable and not used until RTN and friends perform the stack restoration. Maybe in some later release... I just released 2.5.24 with FUNC nn and RTNYES/RTNNO/RTNERR, let's see how that goes first...

This is all starting to sound like structured programming, which RPN definitely is not. Smile I would vote against having to declare the number of inputs and outputs at the beginning of the function. It starts making this look like RPL or other high-level languages, and adds complexity to allowing for functions like COMPLEX that can have different behavior depending on the inputs.

If I were implementing it, I'd have one instruction such as FUNC (or possibly even just a different LBL, maybe FLBL for example) to push the entire stack, and leave the details of the stack restoration to just before the RTN. Either have multiple different RTN instructions that specify what to restore, or a separate instruction placed just before RTN that restores the stack using the registers that were saved in the current stack frame. Pop and discard the stack frame on RTN/END.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: User-defined functions in Free42 - Dave Britten - 01-14-2021 12:56 PM



User(s) browsing this thread: 1 Guest(s)