diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-31 22:49:36 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-31 22:49:36 +0200 |
| commit | b235c2887ed60a8fd48263f6c53e90ee7e2073fd (patch) | |
| tree | 2a47ec5bc38ef95b65b130d277e6ba41dc9f2213 /src/interpreter.hs | |
| parent | 7390af67e18e6d17934541dd3c2d6d46cfad84d0 (diff) | |
Some general refactoring
Diffstat (limited to 'src/interpreter.hs')
| -rw-r--r-- | src/interpreter.hs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/interpreter.hs b/src/interpreter.hs index 9ba4b3c..fb3b34a 100644 --- a/src/interpreter.hs +++ b/src/interpreter.hs @@ -5,13 +5,11 @@ import Data.Char import Data.Map (Map, (!)) import qualified Data.Map as M import LTypes -import System.IO (BufferMode (NoBuffering), hSetBuffering, stdin) import Utils -debugWaitForChar Config {configDebugMode = mode} = +debugWaitForChar Config {configDebugMode = mode} = do if mode then do - hSetBuffering stdin NoBuffering c <- getChar pure $ case c of 'q' -> ExecExit @@ -23,16 +21,16 @@ debugPrint Config {configDebugMode = mode} message = then liftIO $ putStrLn $ "[debug] " ++ message else pure () -interpretSource :: Config -> LState -> ExceptT LException IO () -interpretSource config LState {lSource = []} = pure () +interpretSource :: Config -> LState -> ExceptT LException IO LState +interpretSource config state@LState {lSource = []} = pure state interpretSource config state@LState {lSource = (word : rest)} = do + liftIO $ debugPrint config $ "processing " ++ show word ++ ", current state =" + liftIO $ debugState config state newState <- interpretWord state {lSource = rest} word - liftIO $ debugPrint config $ "processed " ++ show word ++ ", newState =" - liftIO $ debugState config newState step <- liftIO $ debugWaitForChar config case step of ExecContinue -> interpretSource config newState - ExecExit -> pure () + ExecExit -> pure newState interpretWord :: LState -> LWord -> ExceptT LException IO LState -- non-nestable structures |
