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
|
module ReadTFCY where
import Directory (doesFileExist)
import FileGoodies (getFileInPath)
import FilePath ((<.>), (</>), takeFileName)
import ReadShowTerm (readUnqualifiedTerm)
import FlatCurry.Annotated.Types
import System.CurryPath ( getLoadPathForModule, inCurrySubdir
, lookupModuleSourceInLoadPath, stripCurrySuffix )
import System.FrontendExec ( FrontendParams, FrontendTarget (TFCY), addTarget
, callFrontendWithParams, defaultParams, setQuiet )
readTFCY :: String -> IO (AProg TypeExpr)
readTFCY progname = readTFCYWithParseOptions progname
(addTarget TFCY (setQuiet True defaultParams))
readTFCYWithParseOptions :: String -> FrontendParams -> IO (AProg TypeExpr)
readTFCYWithParseOptions progname options = do
mbsrc <- lookupModuleSourceInLoadPath progname
case mbsrc of
Nothing -> do
loadpath <- getLoadPathForModule progname
filename <- getFileInPath (tfcyFile (takeFileName progname)) [""]
loadpath
readTFCYFile filename
Just (dir,_) -> do
callFrontendWithParams TFCY options progname
readTFCYFile (tfcyFile (dir </> takeFileName progname))
tfcyFile :: String -> String
tfcyFile prog = inCurrySubdir (stripCurrySuffix prog) <.> "tfcy"
readTFCYFile :: String -> IO (AProg TypeExpr)
readTFCYFile fn = do
exafcy <- doesFileExist fn
if exafcy
then readExistingTFCY fn
else do let subdirfilename = inCurrySubdir fn
exdirfcy <- doesFileExist subdirfilename
if exdirfcy
then readExistingTFCY subdirfilename
else error ("EXISTENCE ERROR: TypedFlatCurry file '" ++ fn ++
"' does not exist")
where
readExistingTFCY fname = do
filecontents <- readFile fname
return $ readUnqualifiedTerm
["FlatCurry.Types","FlatCurry.Annotated.Types","Prelude"] filecontents
|