From 94eea6e32f59f406f7b30e46fae8f7795a58435d Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Tue, 11 Apr 2017 23:49:19 +0200 Subject: [PATCH] strict fns, recursive fns are working --- lish.cabal | 10 ++++++++++ package.yaml | 2 ++ src/Lish/Core.hs | 2 +- src/Lish/Eval.hs | 21 +++++++++++++-------- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lish.cabal b/lish.cabal index 5d93de0..a88b282 100644 --- a/lish.cabal +++ b/lish.cabal @@ -35,6 +35,8 @@ library , parsec >= 3 && < 4 , pipes , protolude + , pretty + , pretty-show , process , text exposed-modules: @@ -61,6 +63,8 @@ executable lish , parsec >= 3 && < 4 , pipes , protolude + , pretty + , pretty-show , process , text , lish @@ -80,6 +84,8 @@ test-suite lish-benchmark , parsec >= 3 && < 4 , pipes , protolude + , pretty + , pretty-show , process , text , lish @@ -101,6 +107,8 @@ test-suite lish-doctest , parsec >= 3 && < 4 , pipes , protolude + , pretty + , pretty-show , process , text , lish @@ -124,6 +132,8 @@ test-suite lish-test , parsec >= 3 && < 4 , pipes , protolude + , pretty + , pretty-show , process , text , lish diff --git a/package.yaml b/package.yaml index 43ed5ae..4653c3e 100644 --- a/package.yaml +++ b/package.yaml @@ -20,6 +20,8 @@ dependencies: - parsec >= 3 && < 4 - pipes - protolude + - pretty + - pretty-show - process - text diff --git a/src/Lish/Core.hs b/src/Lish/Core.hs index 09c2475..e76cf39 100644 --- a/src/Lish/Core.hs +++ b/src/Lish/Core.hs @@ -26,7 +26,7 @@ runLish :: IO () runLish = do env <- toEnv <$> getEnvironment runInputT (defaultSettings { historyFile = Just ".lish-history" }) - (mainLoop Nothing mempty "") + (mainLoop Nothing env "") -- | System Environment -> LISH Env toEnv :: [(String,String)] -> Env diff --git a/src/Lish/Eval.hs b/src/Lish/Eval.hs index 28d0398..fcbfaa1 100644 --- a/src/Lish/Eval.hs +++ b/src/Lish/Eval.hs @@ -13,6 +13,8 @@ import Data.Fix import qualified Data.Map.Strict as Map import Protolude import System.Process hiding (env) +import Text.PrettyPrint (render) +import qualified Text.Show.Pretty as Pr import Lish.InternalCommands (toArg) import qualified Lish.InternalCommands as InternalCommands @@ -90,13 +92,15 @@ _reduceLambda x = return x reduceLambda :: SExp -> StateT Env IO SExp reduceLambda x = do - -- DEBUG --env <- get - -- DEBUG --liftIO $ do - -- DEBUG -- putText "------" - -- DEBUG -- putStr ("Env: " :: Text) - -- DEBUG -- print env - -- DEBUG -- putStr ("Arg: " :: Text) - -- DEBUG -- putStrLn $ pprint (Fix x) + env <- get + case (Map.lookup "LISH_DEBUG" env) of + Just _ -> liftIO $ do + putText "------" + putStr ("Env: " :: Text) + putStrLn $ Pr.ppShow env + putStr ("Arg: " :: Text) + putStrLn $ pprint (Fix x) + _ -> return () _reduceLambda x @@ -105,7 +109,8 @@ applyFn (Fn par bod clos _) args = if length par /= length args then shellErr "wrong number of arguments" else do - let localClosure = bindVars clos (zip par args) + reducedArgs <- mapM reduceLambda args + let localClosure = bindVars clos (zip par reducedArgs) currentEnv <- get -- Run the function in its own closure fmap fst $ liftIO $