summaryrefslogtreecommitdiffstats
path: root/src/main.hs
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-06 19:05:46 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-06 20:03:27 +0200
commitd5fe35bb8a75a74c7b3616b864c4d35bafecaadd (patch)
tree410325cafa976dfa0596872d8c0582e1b36772c0 /src/main.hs
parentc2053ee0585280229375b10283cb9e8dbb903734 (diff)
Add proper cabal setup
Diffstat (limited to 'src/main.hs')
-rw-r--r--src/main.hs67
1 files changed, 0 insertions, 67 deletions
diff --git a/src/main.hs b/src/main.hs
deleted file mode 100644
index b596a84..0000000
--- a/src/main.hs
+++ /dev/null
@@ -1,67 +0,0 @@
-module Main where
-
-import Control.Monad.Except
-import Data.Char
-import Data.Map (Map, (!))
-import qualified Data.Map as M
-import Debug.Trace (trace, traceShow)
-import Interpreter
-import LTypes
-import Parser
-import System.Environment (getArgs)
-import System.Exit (exitFailure, exitSuccess)
-import System.IO (BufferMode (NoBuffering), hSetBuffering, stdin)
-import Utils
-
-getConfig config [] = config
-getConfig config ("--debug" : rest) =
- let newConfig = config {configDebugMode = True}
- in getConfig newConfig rest
-getConfig config (fileName : rest) =
- let newConfig = config {configFileNameM = Just fileName}
- in getConfig newConfig rest
-
-getFileName :: Config -> ExceptT LException IO String
-getFileName Config {configFileNameM = fileNameM} = do
- case fileNameM of
- Just str -> pure str
- Nothing -> throwError $ LException "no filename specified"
-
-bootstrap :: [String] -> ExceptT LException IO ()
-bootstrap args = do
- let initialConfig =
- Config
- { configFileNameM = Nothing,
- configDebugMode = False
- }
-
- let config = getConfig initialConfig args
- fileName <- getFileName config
-
- debugPrint config $ fmt "executing file %%\n" [fileName]
- source <- liftIO . readFile $ fileName
- (parsedSource, strLitRefMap) <- parseSource source
- debugPrint config $ fmt "parsed words:\n%%\n" [show parsedSource]
- debugPrint config $ fmt "string literal refmap:\n%%\n" [show strLitRefMap]
- debugPrint config "interpreter output:"
- let initialState =
- LState
- { lDict = M.empty,
- lStack = [],
- lPhraseDepth = 0,
- lDefs = M.empty,
- lSource = parsedSource,
- lStrLitRefMap = strLitRefMap
- }
- void $ interpretSource config initialState
-
-main :: IO ()
-main = do
- hSetBuffering stdin NoBuffering
- args <- getArgs
- result <- runExceptT $ bootstrap args
- case result of
- Left (LException errStr) -> do
- putStrLn $ "[error] " ++ errStr
- exitFailure
- _ -> exitSuccess