Post Reply 
Optimized Stack Operations
03-06-2019, 08:50 PM
Post: #30
RE: Optimized Stack Operations
I've been working for years on a system RPL implementation in C++. After getting sick of "stackrobatics" I implemented these two generalized stack manipulation commands. You might want to do something similar in your implementation. These can be used in place of multiple stack manipulations. You could also implement many of the existing stack manipulation routines using these, at a cost in compute time but a possible savings in space.

// New comand SHUFFLE. This shuffles up to 8
// levels of the stack. For example # 2314 SHUFFLE does
// ob4 ob3 ob2 ob1 -> ob2 ob3 ob1 ob4
// In other words, each hex digit specifies the old stack level that
// should go in that position. The "old" level is the level before
// the command executes (but after popping the arg).
// If a hex digit is zero it means "no change in this position."
// This means # 132 SHUFFLE is the same as UNROT
//
// Larger digits will specify larger (original) stack levels, so you
// can actually access up to level 15. E.g., # FFFF SHUFFLE will
// copy level 15 to levels 1-4.

The next command is REARRANGE. It's like SHUFFLE, but lets you add or remove levels from the stack at the same time:

# delta # shuffleSpec -> new stack
// Okay, there are commands and commands that manipulate the stack. Here
// is an efficient way to generalize it. Delta is the number of items
// to add to (delta>0) or remove from (delta<0) the stack.
// ShuffleSpec is a number that says how to shuffle the stack, similar
// to the SHUFFLE command. Note that the values in the spec refer to
// levels BEFORE the delta is applied.

// Example: 2DUP is the same as 2 # 2121 REARRANGE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Optimized Stack Operations - deetee - 02-25-2019, 06:35 AM
RE: Optimized Stack Operations - ijabbott - 02-25-2019, 07:57 AM
RE: Optimized Stack Operations - grsbanks - 02-25-2019, 08:03 AM
RE: Optimized Stack Operations - deetee - 02-25-2019, 08:42 AM
RE: Optimized Stack Operations - deetee - 02-25-2019, 09:04 AM
RE: Optimized Stack Operations - grsbanks - 02-25-2019, 09:14 AM
RE: Optimized Stack Operations - deetee - 02-25-2019, 09:45 AM
RE: Optimized Stack Operations - grsbanks - 02-25-2019, 09:50 AM
RE: Optimized Stack Operations - deetee - 02-25-2019, 09:57 AM
RE: Optimized Stack Operations - grsbanks - 02-25-2019, 10:00 AM
RE: Optimized Stack Operations - grsbanks - 02-25-2019, 10:09 AM
RE: Optimized Stack Operations - Leviset - 02-25-2019, 12:37 PM
RE: Optimized Stack Operations - deetee - 02-26-2019, 06:57 AM
RE: Optimized Stack Operations - rprosperi - 02-25-2019, 08:04 PM
RE: Optimized Stack Operations - rprosperi - 02-25-2019, 09:49 PM
RE: Optimized Stack Operations - deetee - 02-26-2019, 10:40 AM
RE: Optimized Stack Operations - Paul Dale - 02-26-2019, 10:52 AM
RE: Optimized Stack Operations - deetee - 02-26-2019, 03:00 PM
RE: Optimized Stack Operations - deetee - 02-27-2019, 11:04 AM
RE: Optimized Stack Operations - grsbanks - 02-27-2019, 11:13 AM
RE: Optimized Stack Operations - deetee - 03-03-2019, 08:25 AM
RE: Optimized Stack Operations - Paul Dale - 03-03-2019, 08:32 AM
RE: Optimized Stack Operations - deetee - 03-05-2019, 08:36 AM
RE: Optimized Stack Operations - David Hayden - 03-06-2019 08:50 PM



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