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
67
68
69
|
module FlatCurry.Annotated.Files where
import System.CurryPath ( lookupModuleSourceInLoadPath
, inCurrySubdir, stripCurrySuffix )
import System.Directory ( doesFileExist )
import System.FilePath ( (</>), (<.>) )
import FlatCurry.Annotated.Types
annotatedFlatCurryFileName :: String -> String
annotatedFlatCurryFileName prog =
inCurrySubdir (stripCurrySuffix prog) <.> "afcy"
annotatedFlatCurryFilePath :: String -> IO String
annotatedFlatCurryFilePath mname = do
mbsrc <- lookupModuleSourceInLoadPath mname
case mbsrc of
Nothing -> error $ "Curry source file for module '" ++ mname ++
"' not found!"
Just (dir,_) -> return (annotatedFlatCurryFileName (dir </> mname))
readAnnotatedFlatCurryFile :: Read a => String -> IO (AProg a)
readAnnotatedFlatCurryFile filename = do
filecontents <- readAnnotatedFlatCurryFileRaw filename
return (read filecontents)
where
readAnnotatedFlatCurryFileRaw fname = do
exafcy <- doesFileExist fname
if exafcy
then readFile fname
else do
let subdirfilename = inCurrySubdir fname
exdirafcy <- doesFileExist subdirfilename
if exdirafcy
then readFile subdirfilename
else error $ "EXISTENCE ERROR: Annotated FlatCurry file '" ++
fname ++ "' does not exist"
writeAnnotatedFlatCurry :: Show a => AProg a -> IO ()
writeAnnotatedFlatCurry prog@(AProg mname _ _ _ _) = do
fname <- annotatedFlatCurryFilePath mname
writeAnnotatedFlatCurryFile fname prog
writeAnnotatedFlatCurryFile :: Show a => String -> AProg a -> IO ()
writeAnnotatedFlatCurryFile file prog = writeFile file (show prog)
|