aboutsummaryrefslogtreecommitdiff
path: root/rip.hs
diff options
context:
space:
mode:
Diffstat (limited to 'rip.hs')
-rw-r--r--rip.hs22
1 files changed, 20 insertions, 2 deletions
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 ()