From ba8933937e0b24e5a648ec176c4f0b8515fb0e2d Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 6 Oct 2021 22:06:05 +0200 Subject: Implemented missing functions for the interpreter --- src/field.nim | 3 +++ src/stack.nim | 16 ++++++++++++++++ src/stackStack.nim | 22 ++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/field.nim b/src/field.nim index a9d706e..0a741c9 100644 --- a/src/field.nim +++ b/src/field.nim @@ -213,3 +213,6 @@ func Step*(f: Field, v: tuple[x, y: int], d: tuple[x, y: int]): (int, int) = if not f.IsIn(x2, y2): return (x, y) x = x2; y = y2 + +func GetSize*(f: Field): (int, int, int, int) = + return (f.x, f.y, f.lx, f.ly) diff --git a/src/stack.nim b/src/stack.nim index f08baf0..4565b5c 100644 --- a/src/stack.nim +++ b/src/stack.nim @@ -80,3 +80,19 @@ func Discard*(s: var Stack, n: int) = func Next*(s: Stack): ref Stack = return s.next + +func GetHeights*(s: Stack): seq[int] = + if s.next != nil: + result = s.next[].GetHeights() + result.add(s.height) + else: + return @[s.height] + +func YCommandPick*(s: var Stack, n, h: int) = + if n > s.height: + s.height = 1 + s.data[0] = 0 + else: + let v = s.data[s.height-n] + s.height = h + s.Push(v) diff --git a/src/stackStack.nim b/src/stackStack.nim index d55d5d9..b2bf29f 100644 --- a/src/stackStack.nim +++ b/src/stackStack.nim @@ -52,8 +52,7 @@ func End*(ss: var StackStack, v: var tuple[x, y: int]): bool = let toss = ss.head let soss = toss[].Next() let n = toss[].Pop() - v.y = soss[].Pop() - v.x = soss[].Pop() + (v.x, v.y) = soss[].PopVector() if n > 0: soss[].Transfert(toss[], n) else: @@ -61,3 +60,22 @@ func End*(ss: var StackStack, v: var tuple[x, y: int]): bool = dec ss.height ss.head = soss return false + +func Under*(ss: var StackStack): bool = + if ss.height == 1: + return true + let soss = ss.head[].Next() + let n = ss.Pop() + if n > 0: + for i in 0..