add interpreter path to module search path

This commit is contained in:
darkf 2014-02-12 00:36:30 -08:00
parent 32252b8d89
commit fe280dca78
5 changed files with 12 additions and 6 deletions

View File

@ -14,7 +14,9 @@ import Control.Monad.Trans.State (StateT, runStateT, evalStateT, get, put)
import System.IO (Handle, hPutStr, hGetLine, hClose, hIsEOF, hSetBuffering, import System.IO (Handle, hPutStr, hGetLine, hClose, hIsEOF, hSetBuffering,
hSetBinaryMode, openBinaryFile, IOMode(..), BufferMode(NoBuffering), stdout, stdin) hSetBinaryMode, openBinaryFile, IOMode(..), BufferMode(NoBuffering), stdout, stdin)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import System.FilePath (FilePath, splitExtension, takeBaseName) import System.FilePath (takeDirectory)
import System.FilePath (FilePath, splitExtension, takeBaseName, (</>))
import System.Environment (getExecutablePath)
import AST import AST
import Parser (parseProgram) import Parser (parseProgram)
@ -233,11 +235,15 @@ _Import (StrV modname) = do
where where
findModule :: FilePath -> IO (FilePath, String) findModule :: FilePath -> IO (FilePath, String)
findModule modname = do findModule modname = do
let path = modname ++ ".lamb" execPath <- fmap takeDirectory getExecutablePath
exists <- doesFileExist path findModuleIn [".", execPath </> "mods"] -- search paths for modules
if exists then where
return (path, takeBaseName path) findModuleIn [] = error $ "module " ++ modname ++ " couldn't be found"
else error $ "module " ++ modname ++ " couldn't be found" findModuleIn (dir:xs) = do
let path = dir </> modname ++ ".lamb"
exists <- doesFileExist path
if exists then return (path, takeBaseName path)
else findModuleIn xs
initialState = ([stdout, stdin], initialState = ([stdout, stdin],
[M.fromList [("id", FnV emptyEnv [(VarP "x", Var "x")]), [M.fromList [("id", FnV emptyEnv [(VarP "x", Var "x")]),