egison 2.0.4 → 2.1.0
raw patch · 6 files changed
+150/−19 lines, 6 filesdep +filepathdep +processnew-component:exe:egisoncPVP ok
version bump matches the API change (PVP)
Dependencies added: filepath, process
API changes (from Hackage documentation)
+ Language.Egison.Core: loadLibraries :: Env -> IO ()
+ Language.Egison.Types: makeCollectionFromValList :: [EgisonVal] -> EgisonVal
Files
- egison.cabal +7/−7
- etc/template.hs +21/−0
- hs-src/Compiler/egisonc.hs +109/−0
- hs-src/Interpreter/egisoni.hs +0/−9
- hs-src/Language/Egison/Core.hs +10/−3
- hs-src/Language/Egison/Types.hs +3/−0
egison.cabal view
@@ -1,5 +1,5 @@ Name: egison-Version: 2.0.4+Version: 2.1.0 Synopsis: An Interpreter for the Programming Language Egison Description: An interpreter for the programming language Egison. A feature of Egison is the strong pattern match facility.@@ -16,7 +16,7 @@ Build-type: Simple Cabal-version: >=1.8 -Data-files: lib/core/base.egi lib/core/number.egi lib/core/collection.egi lib/graph.egi lib/poker-hands.egi sample/number-test.egi sample/collection-test.egi sample/graph-test.egi sample/io-test.egi sample/poker-hands-test.egi elisp/egison-mode.el+Data-files: lib/core/base.egi lib/core/number.egi lib/core/collection.egi lib/graph.egi lib/poker-hands.egi sample/number-test.egi sample/collection-test.egi sample/graph-test.egi sample/io-test.egi sample/poker-hands-test.egi elisp/egison-mode.el etc/template.hs Library@@ -38,11 +38,11 @@ Other-modules: Paths_egison Hs-Source-Dirs: hs-src/Interpreter ---Executable egisonc--- Main-is: egisonc.hs--- Build-depends: base >= 4.0 && < 5, haskell98, mtl, parsec >= 3.0--- Other-modules: Paths_egison--- Hs-Source-Dirs: hs-src/Compiler+Executable egisonc+ Main-is: egisonc.hs+ Build-depends: egison, base >= 4.0 && < 5, array, containers, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, process+ Other-modules: Paths_egison+ Hs-Source-Dirs: hs-src/Compiler Source-Repository head type: git
+ etc/template.hs view
@@ -0,0 +1,21 @@+module Main where+import Language.Egison.Core -- Egison Interpreter+import Language.Egison.Types -- Egison data types+import Language.Egison.Variables -- Egison variable operations+import Language.Egison.Parser -- Egison variable operations+--import Control.Monad (when)+import Control.Monad.Error+import System.IO+import System.Environment+++main :: IO ()+main = do+ args <- getArgs+ env <- primitiveBindings+ _ <- loadLibraries env+ _ <- runIOThrows (do topExprs <- liftThrows (readTopExprList program)+ liftM concat $ mapM (evalTopExpr env) topExprs)+ _ <- runIOThrows $ evalTopExpr env $ Execute args+ return ()+
+ hs-src/Compiler/egisonc.hs view
@@ -0,0 +1,109 @@+module Main where+import Language.Egison.Core+import Language.Egison.Types+--import Language.Egison.Variables+import Control.Monad.Error+import System.Cmd (system)+import System.Console.GetOpt+import System.FilePath (dropExtension)+import System.Environment+import System.Directory (copyFile)+import System.Exit (ExitCode (..), exitWith, exitFailure)+import System.IO+import Paths_egison++templateFile :: String+templateFile = "etc/template.hs"++main :: IO ()+main = do + args <- getArgs+ let (actions, nonOpts, _) = getOpt Permute options args+ opts <- foldl (>>=) (return defaultOptions) actions+ let Options {optOutput = output} = opts+ if null nonOpts+ then showUsage+ else do+ let inFile = nonOpts !! 0+ outExec = case output of+ Just outFile -> outFile+ Nothing -> dropExtension inFile+ process inFile outExec++-- |Data type to handle command line options that take parameters+data Options = Options {+ optOutput :: Maybe String -- Executable file to write+ }++-- |Print a usage message+showUsage :: IO ()+showUsage = do+ putStrLn "egisonc: no input files"+ +-- |Default values for the command line options+defaultOptions :: Options+defaultOptions = Options {+ optOutput = Nothing+ }++options :: [OptDescr (Options -> IO Options)]+options = [+ Option ['V'] ["version"] (NoArg showVersion) "show version number",+ Option ['h', '?'] ["help"] (NoArg showHelp) "show usage information",+ Option ['o'] ["output"] (ReqArg writeExec "FILE") "output file to write"+ ]++-- |Print version information+showVersion :: Options -> IO Options+showVersion _ = do+ putStrLn Language.Egison.Core.egisonVersion+ exitWith ExitSuccess++showHelp :: Options -> IO Options+showHelp _ = do+ putStrLn "Usage: egisonc [options] file"+ putStrLn ""+ putStrLn "Options:"+ putStrLn " --help Display this information"+ putStrLn " --version Display egison version information"+ putStrLn " --output filename Write executable to the given filename"+ putStrLn ""+ exitWith ExitSuccess++-- |Determine executable file to write. +-- This version just takes a name from the command line option+writeExec arg opt = return opt { optOutput = Just arg }+ +-- |High level code to compile the given file+process :: String -> String -> IO ()+process inFile outExec = do+ result <- (runIOThrows $ liftM show $ createHaskellFile inFile outExec)+ case result of+ Just errMsg -> putStrLn errMsg+ _ -> compileHaskellFile outExec++createHaskellFile :: String -> String -> IOThrowsError ()+createHaskellFile inFile outExec = do+ templatePath <- liftIO $ getDataFileName templateFile+ liftIO $ copyFile templatePath "./_tmp.hs"+ egisonProgram <- liftIO $ readFile inFile+ let pLines = lines egisonProgram+ liftIO $ appendFile "./_tmp.hs" "\nprogram :: String\n"+ liftIO $ appendFile "./_tmp.hs" "program = "+ liftIO $ mapM_ (appendFile "./_tmp.hs") $ map (\pLine -> " \"" ++ escapeDoubleQuote pLine ++ "\\n\" ++\n") pLines+ liftIO $ appendFile "./_tmp.hs" " \"\"\n"+ return ()++escapeDoubleQuote :: String -> String+escapeDoubleQuote [] = []+escapeDoubleQuote (c:cs) = case c of+ '"' -> '\\':'"':(escapeDoubleQuote cs)+ _ -> c:(escapeDoubleQuote cs)+ +-- |Compile the intermediate haskell file using GHC+compileHaskellFile :: String -> IO()+compileHaskellFile filename = do+ let ghc = "ghc"+-- compileStatus <- system $ ghc ++ " " ++ " -cpp --make -package ghc -fglasgow-exts -o " ++ filename ++ " _tmp.hs"+ _ <- system $ ghc ++ " -o " ++ filename ++ " _tmp.hs"+ return ()
hs-src/Interpreter/egisoni.hs view
@@ -37,15 +37,6 @@ Just errMsg -> putStrLn errMsg _ -> return ()) --- |Load standard libraries into the given environment-loadLibraries :: Env -> IO ()-loadLibraries env = do- -- Load standard library- _ <- evalString env $ "(load \"lib/core/base.egi\")"- _ <- evalString env $ "(load \"lib/core/number.egi\")"- _ <- evalString env $ "(load \"lib/core/collection.egi\")"- return ()- -- |Start the REPL (interactive interpreter) runRepl :: IO () runRepl = do
hs-src/Language/Egison/Core.hs view
@@ -15,7 +15,7 @@ -- |egison version number egisonVersion :: String-egisonVersion = "2.0.4"+egisonVersion = "2.1.0" -- |A utility function to display the egison console banner showBanner :: IO ()@@ -30,8 +30,15 @@ putStrLn $ "Leaving Egison." putStrLn $ "Byebye. See you again! (^^)/" ---libraries :: [String]---libraries = ["lib/core/base.egi", "lib/core/number.egi", "lib/core/collection.egi"]+-- |Load standard libraries into the given environment+loadLibraries :: Env -> IO ()+loadLibraries env = do+ -- Load standard library+ _ <- evalString env $ "(load \"lib/core/base.egi\")"+ _ <- evalString env $ "(load \"lib/core/number.egi\")"+ _ <- evalString env $ "(load \"lib/core/collection.egi\")"+ return ()+ -- |A utility function to escape backslashes in the given string escapeBackslashes :: String -> String
hs-src/Language/Egison/Types.hs view
@@ -202,6 +202,9 @@ makeTupleFromValList :: [EgisonVal] -> EgisonVal makeTupleFromValList vals = Tuple $ map Element vals +makeCollectionFromValList :: [EgisonVal] -> EgisonVal+makeCollectionFromValList vals = Collection $ map Element vals+ data InnerValRef = IElement ObjectRef | ISubCollection ObjectRef