aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-12-16 19:39:43 +0100
committertomsmeding <hallo@tomsmeding.nl>2015-12-16 19:39:43 +0100
commitdca4bf883e18431598308645772eb4a87a5ade53 (patch)
tree612a6294a9fefbdf8cdf906486b8bff0eaa5a3e8
parent34a4ab54f7f1e58396a636d322c2a674c04e2344 (diff)
Some useful additions
-rw-r--r--rip-lang.txt5
-rw-r--r--rip.hs22
2 files changed, 24 insertions, 3 deletions
diff --git a/rip-lang.txt b/rip-lang.txt
index 9c08942..2ddc1ed 100644
--- a/rip-lang.txt
+++ b/rip-lang.txt
@@ -12,7 +12,7 @@ d: decrement
r: pops the number of items to rotate anti-clockwise
R: pops the number of items to rotate clockwise
l: push length of stack (before this push)
-a s m q: + - * / (add, subtract, multiply, quotient (integer))
+a s m q M p: + - * / % ^ (add, subtract, multiply, quotient (integer), modulo, power)
G L E: greater, less, equal; booleans are 1 and 0, as you expect
n: not; equivalent to 0E
[ ... ]: syntactical; a codeblock
@@ -26,6 +26,9 @@ F<bla>[code]: define a function named "bla" with the body "code"
$: outputs a stackdump
whitespace: nop
+'c: pushes the ascii value of c
+#<file.rip>: literally includes contents of 'file.rip' in-place
+
Any error causes the interpreter to exit, saying "rip".
diff --git a/rip.hs b/rip.hs
index 224a09a..3ca7a29 100644
--- a/rip.hs
+++ b/rip.hs
@@ -38,6 +38,9 @@ fromRight (Right r) = r
fromLeft :: Either a b -> a
fromLeft (Left l) = l
+ordI :: (Integral a) => Char -> a
+ordI = fromIntegral . ord
+
safeGetChar :: IO (Maybe Char)
safeGetChar =
catch
@@ -169,6 +172,14 @@ rip' code@(x:xs) fns st = do
rip' xs fns (a `div` b : cs)
where (b:a:cs) = st
+ 'M' ->
+ rip' xs fns (a `mod` b : cs)
+ where (b:a:cs) = st
+
+ 'p' ->
+ rip' xs fns (a ^ b : cs)
+ where (b:a:cs) = st
+
'G' ->
rip' xs fns (booltoint (a > b) : cs)
where (b:a:cs) = st
@@ -251,6 +262,14 @@ rip' code@(x:xs) fns st = do
Right (inblock,afterblock) ->
rip' afterblock (Map.insert name inblock fns) st
+ '#' -> case (getfuncname xs) of
+ Left s -> riperror s
+ Right name -> do
+ contents <- readFile name
+ rip' (contents ++ drop (length name + 2) xs) fns st
+
+ '\'' -> rip' (tail xs) fns $ ordI (head xs) : st
+
'$' -> do
(putStrLn . List.intercalate " " . List.map show . reverse) st
rip' xs fns st
@@ -269,6 +288,5 @@ main = do
putStrLn "Pass a rip file as the command-line argument"
exitFailure
else do
- source <- readFile (argv !! 0)
- rip source
+ readFile (argv !! 0) >>= rip
return ()