2 | 2 |
|
3 | 3 |
module Main where
|
4 | 4 |
|
5 | |
import Data.Array (Array, array, (!), (//))
|
6 | |
import Data.Char (chr, ord)
|
7 | |
import Data.Maybe (fromMaybe)
|
8 | |
import Control.Monad (void, forever)
|
9 | |
import Control.Monad.IO.Class (liftIO)
|
10 | |
import Control.Monad.State ( StateT(runStateT)
|
11 | |
, get
|
12 | |
, put
|
13 | |
, modify
|
14 | |
)
|
15 | |
import System.Exit (exitSuccess)
|
16 | |
import System.Environment (getArgs)
|
17 | |
import System.IO (stdout, hFlush)
|
18 | |
import System.Random (randomIO)
|
| 5 |
import Control.Monad (forever, void)
|
| 6 |
import Control.Monad.IO.Class (liftIO)
|
| 7 |
import Control.Monad.State (StateT (runStateT), get, modify, put)
|
| 8 |
import Data.Array (Array, array, (!), (//))
|
| 9 |
import Data.Char (chr, isDigit, ord)
|
| 10 |
import Data.Maybe (fromMaybe)
|
| 11 |
import System.Environment (getArgs)
|
| 12 |
import System.Exit (exitSuccess)
|
| 13 |
import System.IO (hFlush, stdout)
|
| 14 |
import System.Random (randomIO)
|
19 | 15 |
|
20 | 16 |
type Board = Array (Int, Int) Char
|
21 | 17 |
data Direction = U | R | D | L deriving (Eq, Show, Enum)
|
|
37 | 33 |
debug = do
|
38 | 34 |
st <- get
|
39 | 35 |
liftIO $ do
|
40 | |
putStrLn $ "FS {"
|
41 | |
putStrLn $ " , loc=" ++ show (location st)
|
42 | |
putStrLn $ " , stk=" ++ show (stack st)
|
43 | |
putStrLn $ " , dir=" ++ show (direction st)
|
44 | |
putStrLn $ " }"
|
| 36 |
putStrLn "FS {"
|
| 37 |
putStrLn (" , loc=" ++ show (location st))
|
| 38 |
putStrLn (" , stk=" ++ show (stack st))
|
| 39 |
putStrLn (" , dir=" ++ show (direction st))
|
| 40 |
putStrLn " }"
|
45 | 41 |
|
46 | 42 |
pop :: FungeM Int
|
47 | 43 |
pop = do
|
|
140 | 136 |
n <- liftIO getLine
|
141 | 137 |
push (ord (head n))
|
142 | 138 |
step '@' = terminate "Finished"
|
143 | |
step n | n >= '0' && n <= '9' = push (ord n - ord '0')
|
| 139 |
step n | isDigit n = push (ord n - ord '0')
|
144 | 140 |
step _ = return ()
|
145 | 141 |
|
146 | 142 |
run :: FungeM ()
|