aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-10-04 11:25:52 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-10-04 11:25:52 +0200
commit6e05f595786839770fe9cdaa477dd3162f540585 (patch)
treeefaafbc07cb7d9da89c0b0c0186f533c4de62f0f
parente44c1a43fb599821e27b593d47285d0499080c42 (diff)
Add l (length) instruction
-rw-r--r--rip-lang.txt1
-rw-r--r--rip.hs3
2 files changed, 4 insertions, 0 deletions
diff --git a/rip-lang.txt b/rip-lang.txt
index 75ed5bf..f5f2146 100644
--- a/rip-lang.txt
+++ b/rip-lang.txt
@@ -11,6 +11,7 @@ i: increment
d: decrement
r: pops the number of items to rotate clockwise
R: pops the number of items to rotate anti-clockwise
+l: push length of stack (before this push)
a s m q: + - * / (add, subtract, multiply, quotient (integer))
G L E: greater, less, equal; booleans are 1 and 0, as you expect
n: not; equivalent to 0E
diff --git a/rip.hs b/rip.hs
index ca8675f..14e7f6f 100644
--- a/rip.hs
+++ b/rip.hs
@@ -150,6 +150,9 @@ rip' code@(x:xs) fns st = do
(begin, rest) = (take n newst, drop n newst)
res = last begin : init begin ++ rest --SLOW!
+ 'l' ->
+ rip' xs fns (fromIntegral (length st) : st)
+
'a' ->
rip' xs fns (a + b : cs)
where (b:a:cs) = st