|
definition: |
extractCode :: String -> IO Bool
extractCode texfile = do
pid <- getPID
let tmpname = "tmpxxx" ++ show pid
curryfile = tmpname ++ ".curry"
macrofile = dropExtension texfile ++ ".currycode.tex"
absmacrofile <- getAbsolutePath macrofile
cnts <- readFile texfile
hc <- openFile curryfile WriteMode
hPutStrLn hc "import ExecuteBenchmarkPaper\n"
codesnippets <- extractCurryCode hc cnts
if null codesnippets
then do
hClose hc
removeFile curryfile
putStrLn "No code snippets found, nothing done"
return False
else do
saveOldFile absmacrofile
copyFile (packagePath </> "include" </> currycodeFile)
(takeDirectory absmacrofile </> currycodeFile)
hPutStrLn hc $
concatMap genMacro (zip [1..] codesnippets) ++
"\nmain :: IO ()" ++
"\nmain = genMacroFile [" ++
intercalate "," (map (\i->macroOpName i)
[1 .. length codesnippets]) ++
"] \"" ++ absmacrofile ++ "\"\n"
hClose hc
putStrLn "Computing results for Curry code snippets..."
currypath <- bmLoadPath
let evalcmd = unwords [ currySystem
, ":set path", currypath
, ":load", curryfile
, ":eval main"
, ":quit" ]
--putStrLn $ "EXECUTING: " ++ evalcmd
ec <- system evalcmd
system $ cleanCurry ++ " " ++ tmpname
if ec==0
then removeFile curryfile >> return True
else error $
"Something went wrong when executing Curry code snippets\n" ++
"Inspect generated Curry program in \"" ++ curryfile ++ "\"\n"
where
macroOpName i = "runCurryMacro" ++ show i
genMacro (i,m) =
'\n':macroOpName i ++ " :: (String, IO String)\n" ++
macroOpName i ++ " = (" ++ show m ++ "," ++ m ++ ")\n"
|
|
demand: |
no demanded arguments |
|
deterministic: |
deterministic operation |
|
documentation: |
Extract Curry code snippets from a latex file. The code snippets are stored in a temporary Curry program as pairs of the code snippet text and the code snippet. Then the temporary Curry program is executed to generate a latex macro file (with suffix `.currycode.tex`) defining for each code snippet its execution result. |
|
failfree: |
<FAILING> |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{(_) |-> _}
|
|
name: |
extractCode |
|
precedence: |
no precedence defined |
|
result-values: |
_ |
|
signature: |
String -> Prelude.IO Prelude.Bool |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
possibly non-terminating |
|
totally-defined: |
possibly non-reducible on same data term |