Post Reply 
Free42 LSTO REGS
10-23-2019, 12:01 PM
Post: #10
RE: Free42 LSTO REGS
(10-21-2019 03:07 PM)Epidiah Wrote:  I was thinking you could even slap the "LDIM" label on it and make it a program, but that would be self-defeating since it would discard the LSTO'ed matrix once it returns to whatever called it.

Yes, this is a bit of a problem. It would be nice if you could create subroutines for preserving state, like preserving the entire stack, and right now, you can't.

One way to fix this would be to add a modified RTN instruction, let's call it LRTN for now, that has the effect of not popping local variables created at the current level, instead moving them one level up the stack, as if they had been created by the caller. So you could write a stack saver like

LBL "SPUSH" LSTO "X" R↓ LSTO "Y" R↓ LSTO "Z" R↓ LSTO "T" LASTX LSTO "L" LRTN

and restore the entire stack with

LBL "SPOP" RCL "L" STO ST L RCL "T" RCL "Z" RCL"Y" RCL "X" RTN

leaving the local variables to be popped automatically:

LBL "SOMEFUN" XEQ "SPUSH" <do something useful here> XEQ "SPOP" RTN

(Of course the sequence XEQ "FOO" RTN can be replaced by GTO "FOO" (tail call optimization) but that can make the code harder for humans to understand.)

Variations on the SPOP function could be created to mimic the behavior of unary or binary operators as well.

Thoughts? Would LRTN be a good name, or can someone suggest something better, i.e. a better name for that function, or an altogether better way to fix this LSTO limitation?
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Free42 LSTO REGS - Epidiah - 09-25-2019, 03:52 PM
RE: Free42 LSTO REGS - David Hayden - 09-26-2019, 05:50 PM
RE: Free42 LSTO REGS - Guenter Schink - 09-26-2019, 08:10 PM
RE: Free42 LSTO REGS - Thomas Okken - 09-28-2019, 02:53 AM
RE: Free42 LSTO REGS - Thomas Okken - 09-28-2019, 03:19 AM
RE: Free42 LSTO REGS - Namir - 10-04-2019, 12:34 PM
RE: Free42 LSTO REGS - Paul Dale - 10-05-2019, 08:46 AM
RE: Free42 LSTO REGS - SammysHP - 10-21-2019, 09:31 AM
RE: Free42 LSTO REGS - Epidiah - 10-21-2019, 03:07 PM
RE: Free42 LSTO REGS - Thomas Okken - 10-23-2019 12:01 PM
RE: Free42 LSTO REGS - Epidiah - 10-23-2019, 02:22 PM
RE: Free42 LSTO REGS - Epidiah - 10-25-2019, 01:50 AM
RE: Free42 LSTO REGS - SammysHP - 10-25-2019, 07:17 PM
RE: Free42 LSTO REGS - Epidiah - 10-26-2019, 02:52 AM
RE: Free42 LSTO REGS - rprosperi - 10-23-2019, 01:38 PM
RE: Free42 LSTO REGS - Thomas Okken - 10-23-2019, 11:51 PM
RE: Free42 LSTO REGS - Thomas Okken - 10-24-2019, 11:37 AM
RE: Free42 LSTO REGS - Paul Dale - 10-24-2019, 12:26 PM
RE: Free42 LSTO REGS - Epidiah - 10-24-2019, 12:57 PM
RE: Free42 LSTO REGS - Werner - 10-25-2019, 06:21 AM
RE: Free42 LSTO REGS - Epidiah - 10-25-2019, 02:02 PM



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