aboutsummaryrefslogtreecommitdiff
path: root/src/stack.nim
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-04 18:22:59 +0200
committerJulien Dessaux2021-10-04 18:22:59 +0200
commit1d11df68fc011a023e19b4ec7db4df73bef331d7 (patch)
tree0a86ae37833929ad9972dbc5779fca0e59f91531 /src/stack.nim
parentCosmetics (diff)
downloadnimfunge98-1d11df68fc011a023e19b4ec7db4df73bef331d7.tar.gz
nimfunge98-1d11df68fc011a023e19b4ec7db4df73bef331d7.tar.bz2
nimfunge98-1d11df68fc011a023e19b4ec7db4df73bef331d7.zip
Implemented the stackstack
Diffstat (limited to 'src/stack.nim')
-rw-r--r--src/stack.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/stack.nim b/src/stack.nim
index 2c6826d..eeef5cd 100644
--- a/src/stack.nim
+++ b/src/stack.nim
@@ -58,12 +58,24 @@ func Swap*(s: var Stack) =
s.Push(b)
func Transfert*(toss: var Stack, soss: var Stack, n: int) =
+ ## Implements a value transfert between two stacks, intended for use with the '{'
+ ## (aka begin) and '}' (aka end) stackstack commands
toss.height += n
+ if toss.height > toss.size:
+ toss.size += 32
+ toss.data.setlen(toss.size)
for i in 1..min(soss.height, n):
toss.data[toss.height-i] = soss.data[soss.height-i]
+ for i in min(soss.height, n)+1..n:
+ toss.data[toss.height-i] = 0
soss.height -= n
if soss.height < 0:
soss.height = 0
+func Discard*(s: var Stack, n: int) =
+ s.height -= n
+ if s.height < 0:
+ s.height = 0
+
func Next*(s: Stack): ref Stack =
return s.next