1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
module ICurry.Files where
import Directory ( doesFileExist )
import FilePath ( takeFileName, (</>), (<.>) )
import ReadShowTerm ( readUnqualifiedTerm, showTerm )
import System.CurryPath ( inCurrySubdir, stripCurrySuffix
, lookupModuleSourceInLoadPath
)
import ICurry.Types
iCurryFileName :: String -> String
iCurryFileName prog = inCurrySubdir (stripCurrySuffix prog) <.> "icy"
iCurryFilePath :: String -> IO String
iCurryFilePath mname = do
mbsrc <- lookupModuleSourceInLoadPath mname
case mbsrc of
Nothing -> error $ "Curry source file for module '" ++ mname ++
"' not found!"
Just (dir,_) -> return (iCurryFileName (dir </> mname))
readICurry :: String -> IO IProg
readICurry progname = iCurryFilePath progname >>= readICurryFile
readICurryFile :: String -> IO IProg
readICurryFile filename = do
exicy <- doesFileExist filename
if exicy
then do contents <- readFile filename
return (readUnqualifiedTerm ["ICurry.Types","Prelude"] contents)
else error $ "EXISTENCE ERROR: ICurry file '" ++ filename ++
"' does not exist"
writeICurry :: IProg -> IO ()
writeICurry prog@(IProg mname _ _ _) = do
fname <- iCurryFilePath mname
writeICurryFile fname prog
writeICurryFile :: String -> IProg -> IO ()
writeICurryFile file prog = writeFile file (showTerm prog)
|