Commit c84b909a authored by Michael Hanus 's avatar Michael Hanus

Translated Prelude.? directly into IOr, placement of .icy files corrected

parent 52ef02ea
......@@ -22,6 +22,14 @@ These tools are available in the `icurry` binary installed
with this package.
Important note:
---------------
Translated ICurry programs have the suffix `icy`.
The suffix `icurry` is already used by the front end
for *interface files* of Curry programs.
Usage:
------
......@@ -38,7 +46,9 @@ In the following, we describe various uses of the `icurry` tool.
> icurry Prog
This will generate the file `.curry/Prog.icy`, i.e., the suffix `icy`
is used for generated ICurry programs.
is used for generated ICurry programs. If the program is located
in a non-local directory, the generated file is placed relative
to the directory of the source program.
In order to see a human-readable presentation of the generated program,
use option `-v`, i.e.,
......
......@@ -22,8 +22,7 @@ prim_Int_mult external
------------------------------------------------------------------------------
-- Combining arithmetic and non-determinism:
coin :: Int
coin = 0
coin = 1
coin = 0 ? 1
coinCoin = coin + coin
......
-- Testing infinitely many results
aBool = False
aBool = True
aBool :: Bool
aBool = False ? True
aBoolList :: [Bool]
aBoolList = []
aBoolList = aBool : aBoolList
-- infinitely many values: use option --interactive
main :: [Bool]
main = normalForm aBoolList
......@@ -15,8 +15,7 @@ xor True y = not y
xorSelf x = xor x x
aBool = False
aBool = True
aBool = False ? True
xorSelfBool = xorSelf aBool
......
......@@ -6,7 +6,7 @@
--- * remove declarations/assignments of unused variables in ICurry code
---
--- @author Michael Hanus
--- @version January 2020
--- @version February 2020
------------------------------------------------------------------------------
module ICurry.Compiler where
......@@ -177,7 +177,7 @@ toIBlock opts vs e root =
Case _ ce brs@(Branch (LPattern _ ) _ : _) ->
let carg = trCaseArg ce
in ICaseLit carg (map (trLBranch carg) brs)
Comb FuncCall fn [] | fn == ("Prelude","failed") -> IExempt
Comb FuncCall fn [] | fn == pre "failed" -> IExempt
_ -> IReturn (toIExpr opts e))
where
varDecls = case e of
......@@ -223,13 +223,16 @@ toIBlock opts vs e root =
toIExpr :: ICOptions -> Expr -> IExpr
toIExpr _ (Var v) = IVar v
toIExpr _ (Lit l) = ILit (trLit l)
toIExpr opts (Comb ct qn@(mn,fn) es) =
let icall = case ct of
FuncCall -> IFCall (mn, fn, posOfFun opts qn)
ConsCall -> ICCall (mn, fn, posOfCons opts qn)
FuncPartCall m -> IFPCall (mn, fn, posOfFun opts qn) m
ConsPartCall m -> ICPCall (mn, fn, posOfCons opts qn) m
in icall (map (toIExpr opts) es)
toIExpr opts (Comb ct qn@(mn,fn) es)
| qn == pre "?" && length es == 2
= toIExpr opts (Or (es!!0) (es!!1))
| otherwise
= let icall = case ct of
FuncCall -> IFCall (mn, fn, posOfFun opts qn)
ConsCall -> ICCall (mn, fn, posOfCons opts qn)
FuncPartCall m -> IFPCall (mn, fn, posOfFun opts qn) m
ConsPartCall m -> ICPCall (mn, fn, posOfCons opts qn) m
in icall (map (toIExpr opts) es)
toIExpr opts (Or e1 e2) = IOr (toIExpr opts e1) (toIExpr opts e2)
toIExpr opts (Typed e _) = toIExpr opts e
toIExpr opts (Let _ e) = toIExpr opts e
......@@ -261,3 +264,9 @@ showIProg (IProg mn imps types funs) = unlines $
"[" : map show funs ++ ["]"]
------------------------------------------------------------------------------
-- Auxiliaries:
pre :: String -> QName
pre s = ("Prelude", s)
------------------------------------------------------------------------------
......@@ -2,7 +2,7 @@
--- This library defines I/O actions to read and write ICurry programs.
---
--- @author Michael Hanus
--- @version January 2020
--- @version February 2020
------------------------------------------------------------------------------
module ICurry.Files where
......@@ -23,15 +23,21 @@ import ICurry.Types
iCurryFileName :: String -> String
iCurryFileName prog = inCurrySubdir (stripCurrySuffix prog) <.> "icy"
--- Gets the standard ICurry file location for a given Curry module name
--- The Curry source program must exist in the Curry load path,
--- otherwise an error is raised.
iCurryFilePath :: String -> IO String
iCurryFilePath mname = do
mbsrc <- lookupModuleSourceInLoadPath mname
case mbsrc of
Nothing -> error $ "Curry source file for module '" ++ mname ++
"' not found!"
Just (dir,_) -> return (iCurryFileName (dir </> mname))
--- Reads an ICurry program from a file in ".icy" format.
--- The argument is the name of the corresponding Curry program.
readICurry :: String -> IO IProg
readICurry progname = do
mbsrc <- lookupModuleSourceInLoadPath progname
case mbsrc of
Nothing -> error $ "ICurry file for program '" ++ progname ++ "' not found!"
Just (dir,_) ->
readICurryFile (iCurryFileName (dir </> takeFileName progname))
readICurry progname = iCurryFilePath progname >>= readICurryFile
--- Reads an ICurry program from a file in ".icy" format
--- where the file name is provided as the argument.
......@@ -44,7 +50,16 @@ readICurryFile filename = do
else error $ "EXISTENCE ERROR: ICurry file '" ++ filename ++
"' does not exist"
--- Writes a ICurry program into a file in ".icy" format.
--- Writes an ICurry program into a file in ".icy" format.
--- The file is written in the standard location for intermediate files,
--- i.e., in the 'iCurryFileName' relative to the directory of the
--- Curry source program (which must exist!).
writeICurry :: IProg -> IO ()
writeICurry prog@(IProg mname _ _ _) = do
fname <- iCurryFilePath mname
writeICurryFile fname prog
--- Writes an ICurry program into a file in ".icy" format.
--- The first argument must be the name of the target file
--- (with suffix ".icy").
writeICurryFile :: String -> IProg -> IO ()
......
......@@ -40,9 +40,9 @@ mainProg opts p = do
let imain = optMain opts
if null imain
then do
writeICurryFile (iCurryFileName p) iprog
printStatus opts $
"ICurry program written to '" ++ iCurryFileName p ++ "'"
icyname <- iCurryFilePath p
writeICurryFile icyname iprog
printStatus opts $ "ICurry program written to '" ++ icyname ++ "'"
else do
printStatus opts $ "Executing main function '" ++ imain ++ "'..."
let opts1 = if optShowGraph opts
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment