Has anyone thought of any clever ways to swap the top two stack variables without needing a temporary variable? I haven't been able to come up with anything (yet). (But I'm thinking it may just be impossible)
I'm trying to make branch conditionals, but I can't unless I can swap stack values. That's because I need to keep values on the stack for each conditional, dupe them, and multiply them times the addresses of each store. The problem is that the store command is 'value address store'. If it were 'address value store', I could just dup address mult value store.
This is what it would look like (python-like code on the left, translation and comments on the right after the #) if store commands were 'address value store':
#Branch conditionals:
if (foo==2): # *.foo 2 sub sgn abs - ++ (stack holds 1 value now)
if (bar==3): # dup *.bar 3 sub sgn abs - ++ & (stack holds 2 values now)
#Note: The store commands here have the address (variable) and value backwards. It should be 'value address store', and we've written this using 'address value store'. Doing this with the way store really works is probably impossible (without a temporary variable, which would defeat half the point of having conditions on stores).
sx = 1 # dup .sx mult 1 store (stack holds 2 values)
up = 1 # dup .up mult 1 store (stack holds 2 values) (if there was no else, this should omit the dup?)
else: # - ++ (reverse the topmost stack value) (stack holds 2 values)
sx = -1 # dup .sx mult -1 store (stack holds 2 values)
up = -1 # dup .up mult -1 store (stack holds 2 values)
#end of if/else - pop stack: dup xor inc (stack holds 1 value)
elif (foo==3): # dup - ++ dup *.foo 3 sub sgn abs - ++ & (stack holds 3 values - the first is the result of the if, the second is the !if, and the third is the result of this elif): (either TFF, FTF, or FTT)
sx = 2 # dup .sx mult 2 store (stack holds 3 values)
elif (foo==4): # - ++ & (stack TF (if was true), FT (all conditions were false), or FF (a previous condition was true)) dup *.foo 4 sub sgn abs - ++ & (stack TFF, FTT, FTF, or FFF)
sx = 3 # dup .sx mult 3 store (stack holds 3 values)
elif (foo==5): # - ++ & (stack TF (if was true), FF (a previous condition was true), FT (all conditions were false), or FF) dup *.foo 5 sub sgn abs - ++ & (stack TFF, FFF, FTT, FTF, or FFF)
sx = 4 # dup .sx mult 4 store (stack holds 3 values)
#end of elif: # - ++ | - ++ (stack F (a previous condition, or the if, was true), T (all conditions were false))
else: # Note that it was "- ++ | - ++" when an elif ends, and "- ++" when an if ends.
sx = 5 # dup .sx mult 3 store (stack holds 1 value)
#end of if/else - pop stack: Since nothing else is on the stack: dup xor inc (stack holds 0 values)
#That's the end of it