diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-12-16 19:39:43 +0100 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-12-16 19:39:43 +0100 |
commit | dca4bf883e18431598308645772eb4a87a5ade53 (patch) | |
tree | 612a6294a9fefbdf8cdf906486b8bff0eaa5a3e8 /rip.hs | |
parent | 34a4ab54f7f1e58396a636d322c2a674c04e2344 (diff) |
Some useful additions
Diffstat (limited to 'rip.hs')
-rw-r--r-- | rip.hs | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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 () |