Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
curry-packages
icurry
Commits
c84b909a
Commit
c84b909a
authored
Feb 04, 2020
by
Michael Hanus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Translated Prelude.? directly into IOr, placement of .icy files corrected
parent
52ef02ea
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
27 deletions
+62
-27
README.md
README.md
+11
-1
examples/Arithmetic.curry
examples/Arithmetic.curry
+1
-2
examples/BoolList.curry
examples/BoolList.curry
+5
-2
examples/Various.curry
examples/Various.curry
+1
-2
src/ICurry/Compiler.curry
src/ICurry/Compiler.curry
+18
-9
src/ICurry/Files.curry
src/ICurry/Files.curry
+23
-8
src/ICurry/Main.curry
src/ICurry/Main.curry
+3
-3
No files found.
README.md
View file @
c84b909a
...
...
@@ -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.,
...
...
examples/Arithmetic.curry
View file @
c84b909a
...
...
@@ -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
...
...
examples/BoolList.curry
View file @
c84b909a
-- 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
examples/Various.curry
View file @
c84b909a
...
...
@@ -15,8 +15,7 @@ xor True y = not y
xorSelf x = xor x x
aBool = False
aBool = True
aBool = False ? True
xorSelfBool = xorSelf aBool
...
...
src/ICurry/Compiler.curry
View file @
c84b909a
...
...
@@ -6,7 +6,7 @@
--- * remove declarations/assignments of unused variables in ICurry code
---
--- @author Michael Hanus
--- @version
Jan
uary 2020
--- @version
Febr
uary 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)
------------------------------------------------------------------------------
src/ICurry/Files.curry
View file @
c84b909a
...
...
@@ -2,7 +2,7 @@
--- This library defines I/O actions to read and write ICurry programs.
---
--- @author Michael Hanus
--- @version
Jan
uary 2020
--- @version
Febr
uary 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 ()
...
...
src/ICurry/Main.curry
View file @
c84b909a
...
...
@@ -40,9 +40,9 @@ mainProg opts p = do
let imain = optMain opts
if null imain
then do
writeICurryFile (iCurryFileName p) iprog
p
ri
ntStatus opts $
"ICurry program written to '" ++ i
CurryFileN
ame
p
++ "'"
icyname <- iCurryFilePath p
w
ri
teICurryFile icyname iprog
printStatus opts $
"ICurry program written to '" ++ i
cyn
ame ++ "'"
else do
printStatus opts $ "Executing main function '" ++ imain ++ "'..."
let opts1 = if optShowGraph opts
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment