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
|
module FlatCurry.Annotated.Files where
import Directory ( doesFileExist )
import FileGoodies ( getFileInPath)
import FilePath ( takeFileName, (</>), (<.>) )
import ReadShowTerm ( readUnqualifiedTerm )
import System.CurryPath ( inCurrySubdir, stripCurrySuffix
, lookupModuleSourceInLoadPath, getLoadPathForModule
)
import System.FrontendExec ( FrontendParams, FrontendTarget (..)
, defaultParams, setQuiet, callFrontendWithParams )
import FlatCurry.Annotated.Types
readTypedFlatCurry :: String -> IO (AProg TypeExpr)
readTypedFlatCurry progname =
readTypedFlatCurryWithParseOptions progname (setQuiet True defaultParams)
readTypedFlatCurryWithParseOptions :: String -> FrontendParams -> IO (AProg TypeExpr)
readTypedFlatCurryWithParseOptions progname options = do
mbsrc <- lookupModuleSourceInLoadPath progname
case mbsrc of
Nothing -> do
loadpath <- getLoadPathForModule progname
filename <- getFileInPath (typedFlatCurryFileName (takeFileName progname)) [""]
loadpath
readTypedFlatCurryFile filename
Just (dir,_) -> do
callFrontendWithParams TFCY options progname
readTypedFlatCurryFile (typedFlatCurryFileName (dir </> takeFileName progname))
typedFlatCurryFileName :: String -> String
typedFlatCurryFileName prog = inCurrySubdir (stripCurrySuffix prog) <.> "tfcy"
readTypedFlatCurryFile :: String -> IO (AProg TypeExpr)
readTypedFlatCurryFile filename = do
filecontents <- readTypedFlatCurryFileRaw filename
return (readUnqualifiedTerm ["FlatCurry.Annotated.Types", "FlatCurry.Types",
"Prelude"]
filecontents)
readTypedFlatCurryFileRaw :: String -> IO String
readTypedFlatCurryFileRaw filename = do
extfcy <- doesFileExist filename
if extfcy
then readFile filename
else do let subdirfilename = inCurrySubdir filename
exdirtfcy <- doesFileExist subdirfilename
if exdirtfcy
then readFile subdirfilename
else error ("EXISTENCE ERROR: Typed FlatCurry file '" ++ filename ++
"' does not exist")
|