From 542b0d035444416cae8994f89d1ae11c4e4c5df9 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 30 Jan 2022 18:48:29 +0200 Subject: Move interpreter stuff under interpreter.hs --- src/ltypes.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/ltypes.hs') diff --git a/src/ltypes.hs b/src/ltypes.hs index bb7e0de..27fdd35 100644 --- a/src/ltypes.hs +++ b/src/ltypes.hs @@ -1,5 +1,7 @@ module LTypes where +import Data.Map (Map) +import qualified Data.Map as M import Utils data LWord @@ -22,3 +24,31 @@ reprWord (LChar a) = show a reprWord (LLabel a) = a reprWord (LStringLitRef a) = "StrLit(" ++ a ++ ")" reprWord (LPhrase a) = "P[ " ++ map reprWord a $> unwords ++ " ]" + +data LState = LState + { lDict :: Map String LWord, + lStack :: [LWord], + lPhraseDepth :: Int, + lDefs :: Map String [LWord], + lSource :: [LWord], + lStrLitRefMap :: Map String [LWord] + } + deriving (Show) + +data Config = Config + { configFileNameM :: Maybe String, + configDebugMode :: Bool + } + +data ExecStep = ExecContinue | ExecExit + +debugState Config {configDebugMode = mode} state = + if mode + then do + putStrLn $ "stack: " ++ unwords (map reprWord (lStack state)) + putStrLn $ "source: " ++ unwords (map reprWord (lSource state)) + putStrLn $ "defs: " ++ unwords (M.keys (lDefs state)) + putStrLn $ "dict: " ++ unwords (M.keys (lDict state)) + putStrLn $ "lPhraseDepth: " ++ show (lPhraseDepth state) + putStrLn "" + else pure () -- cgit v1.3