CurryInfo: prolog2curry-1.2.0 / Main.transformProgram

definition:
transformProgram :: TransState -> String -> IO ()
transformProgram ts pname = do
  let progname = dropExtension pname
      fffile   = optFailFuncs ts
  ts1 <- if null fffile
           then return ts
           else do
             exff <- doesFileExist fffile
             unless exff $ error $ "File '" ++ fffile ++ "' does not exist"
             ffs <- fmap (concatMap readQNameLine . lines) (readFile fffile)
             return (ts { failFuncs = ffs })
  pp <- readPrologFile (progname ++ ".pl")
  when (optVerb ts > 2) $ putStrLn $ encloseInLines $
    "Prolog program '" ++ pname ++ "':\n\n" ++ showPlProg pp
  let (cprog,ts2) = prolog2Curry (setModName progname ts1) pp
      ucprog   = unlines (filter (not . (":: ()" `isSuffixOf`))
                                 (lines (showCProg cprog)))
      outfile  = case optOutput ts of "-" -> ""
                                      ""  -> modName ts2 ++ ".curry"
                                      f   -> f
  when (optVerb ts > 0 && not (null (ignoredCls ts2))) $ putStrLn $
    "The following queries/directives/clauses are ignored:\n" ++
    unlines (map showPlClause (ignoredCls ts2))
  when (optVerb ts > 2 && useAnalysis ts) $ putStrLn $
    "Inductively sequential arguments of predicates:\n" ++ showIndSeqArgs ts2
  when (optVerb ts > 2) $ putStrLn $
    "Function information used in the transformation:\n" ++ showResultArgs ts2
  when (optVerb ts > 2 && not (null (optFailFuncs ts))) $ putStrLn $
    "Possibly failing functions:\n" ++
    unlines (map (\(mn,fn) -> mn ++ "." ++ fn) (failFuncs ts2))
  when (optVerb ts > 1 || optOutput ts == "-") $ putStrLn $ encloseInLines $
    "Generated Curry module:\n\n" ++ ucprog
  unless (null outfile) $ do
    writeFile outfile $
      (if optNoWarn ts then noWarnings else missSigOpt) ++ ucprog
    when (optVerb ts > 0) $ putStrLn $
      "Generated Curry module written into '" ++ outfile ++ "'"
  when (optLoad ts && null (optOutput ts)) $ do
    let cmd = installDir </> "bin" </> "pakcs --nocypm :load " ++ modName ts2
    when (optVerb ts > 1) $ putStrLn $ "Executing: " ++ cmd
    ec <- system cmd
    exitWith ec
 where
  hline = take 78 (repeat '-')

  encloseInLines s = unlines [hline, s, hline]

  missSigOpt = "{-# OPTIONS_FRONTEND -Wno-missing-signatures #-}\n\n"
  noWarnings = "{-# OPTIONS_FRONTEND -Wnone #-}\n\n"
  
  -- reads a line containing a module and a function name separated by a space:
  readQNameLine s = let (mn,fn) = break (==' ') s
                    in if null fn then [] else [(mn, tail fn)]
demand:
no demanded arguments
deterministic:
deterministic operation
documentation:
-- Reads Prolog program from a file (with suffix `.pl`)
-- and print the transformed program.
failfree:
<FAILING>
indeterministic:
might be indeterministic
infix:
no fixity defined
iotype:
{(_,_) |-> _}
name:
transformProgram
precedence:
no precedence defined
result-values:
_
signature:
Language.Prolog.ToCurry.TransState -> String -> Prelude.IO ()
solution-complete:
operation might suspend on free variables
terminating:
possibly non-terminating
totally-defined:
possibly non-reducible on same data term