Commit c092c880 authored by Bernd Brassel's avatar Bernd Brassel
Browse files

prelude can be compiled via cabal

parent 6e86d9dc
......@@ -30,6 +30,7 @@ src/lib/Strict*.hs
# files generated by cabal
dist/*
src/lib/dist/*
# frequently coming files
*.patch
......
Name: KiCS
Version: 0.8.5
Version: 0.8.8
Cabal-Version: >= 1.6
Author: Bernd Braßel
Maintainer: Bernd Braßel
......@@ -9,10 +9,12 @@ License-File: LICENSE
Category: Compiler
build-type: Simple
Synopsis: A compiler from Curry to Haskell
Description: This package builds two binaries, kics and kicsi, respectively.
The first is the Curry to Haskell compiler, the latter a text
based interactive environment.
Stability: *INCOMPLETE* do not download yet! (sorry...)
Description: This package builds the Curry to Haskell compiler "kics".
Note, that you need a functional curry module
"Prelude.curry" to get started.
The standard version of that file is contained
in the package KiCS-libraries.
Stability: experimental
Executable kics
main-is: kics.hs
......@@ -25,36 +27,31 @@ Executable kics
old-time,
directory,
containers,
curry-base >= 0.2.4
Other-Modules:
Config
CurryToHaskell
SafeCalls
Names
KicsSubdir
FunctionalProg
ShowFunctionalProg
ShowFlatCurry
PreTrans
Simplification
Brace
Paths_KiCS
Executable kicsi
main-is: kicsi.hs
hs-source-dirs: src
Build-Depends:
readline
curry-base >= 0.2.5,
curry-frontend >= 0.2.6
Library
hs-source-dirs: src
Build-Depends:
syb
Other-Modules:
Exposed-Modules:
Curry.RunTimeSystem.Store,
Curry.RunTimeSystem.BaseCurry,
Curry.RunTimeSystem
Curry.Compiler.Config
Curry.Compiler.CurryToHaskell
Curry.Compiler.SafeCalls
Curry.Compiler.Names
Curry.Compiler.ShowFlatCurry
Curry.Files.KiCSPath
Other-Modules:
Paths_KiCS
Curry.Compiler.KicsSubdir
Curry.Compiler.FunctionalProg
Curry.Compiler.ShowFunctionalProg
Curry.Compiler.PreTrans
Curry.Compiler.Simplification
Curry.Compiler.Brace
......@@ -209,8 +209,14 @@ depend : $(SRC)MyReadline.hs
# DO NOT DELETE: Beginning of Haskell dependencies
src/InstallDir.o : src/InstallDir.hs
src/SafeCalls.o : src/SafeCalls.hs
src/FunctionalProg.o : src/FunctionalProg.hs
src/Brace.o : src/Brace.hs
src/ShowFunctionalProg.o : src/ShowFunctionalProg.hs
src/ShowFunctionalProg.o : src/Brace.hi
src/ShowFunctionalProg.o : src/FunctionalProg.hi
src/Names.o : src/Names.hs
src/Names.o : src/ShowFunctionalProg.hi
src/KicsSubdir.o : src/KicsSubdir.hs
src/MetaProgramming/FlatCurry.o : src/MetaProgramming/FlatCurry.hs
src/MetaProgramming/FlatCurry.o : src/KicsSubdir.hi
......@@ -223,22 +229,14 @@ src/Simplification.o : src/MetaProgramming/FlatCurry.hi
src/PreTrans.o : src/PreTrans.hs
src/PreTrans.o : src/MetaProgramming/FlatCurryGoodies.hi
src/PreTrans.o : src/MetaProgramming/FlatCurry.hi
src/FunctionalProg.o : src/FunctionalProg.hs
src/Brace.o : src/Brace.hs
src/ShowFlatCurry.o : src/ShowFlatCurry.hs
src/ShowFlatCurry.o : src/Brace.hi
src/ShowFlatCurry.o : src/MetaProgramming/FlatCurry.hi
src/ShowFunctionalProg.o : src/ShowFunctionalProg.hs
src/ShowFunctionalProg.o : src/Brace.hi
src/ShowFunctionalProg.o : src/FunctionalProg.hi
src/Names.o : src/Names.hs
src/Names.o : src/ShowFunctionalProg.hi
src/Config.o : src/Config.hs
src/Config.o : src/KicsSubdir.hi
src/Config.o : src/Names.hi
src/Config.o : src/MetaProgramming/FlatCurry.hi
src/Config.o : src/SafeCalls.hi
src/Config.o : src/InstallDir.hi
src/CurryToHaskell.o : src/CurryToHaskell.hs
src/CurryToHaskell.o : src/Names.hi
src/CurryToHaskell.o : src/Names.hi
......@@ -259,4 +257,10 @@ src/kicsi.o : src/MetaProgramming/FlatCurryGoodies.hi
src/kicsi.o : src/MetaProgramming/FlatCurry.hi
src/kicsi.o : src/SafeCalls.hi
src/kicsi.o : src/CurryToHaskell.hi
src/kics.o : src/kics.hs
src/kics.o : src/SafeCalls.hi
src/kics.o : src/CurryToHaskell.hi
src/kics.o : src/Config.hi
src/kicslib.o : src/kicslib.hs
src/kicslib.o : src/Config.hi
# DO NOT DELETE: End of Haskell dependencies
module Brace where
module Curry.Compiler.Brace where
import List
......
module Config (module Config,module KicsSubdir) where
module Curry.Compiler.Config (
module Curry.Compiler.Config,
module Curry.Compiler.KicsSubdir) where
import System.FilePath
import System.Time (ClockTime)
import InstallDir
import SafeCalls
import Char
import System.Environment (getEnvironment,getArgs)
import System.Directory hiding (executable)
import System.Time
import MetaProgramming.FlatCurry(readFlatCurry)
import Names
import KicsSubdir
import Curry.Compiler.SafeCalls
import Curry.FlatCurry.Type (readFlat)
import Curry.Compiler.Names
import Curry.Compiler.KicsSubdir
import Curry.Files.CymakePath
getOptions :: IO (Options,State)
......@@ -34,11 +36,11 @@ parseOptions opts ("-or":xs) = parseOptions (opts{cm=OrBased}) xs
parseOptions opts ("-ctc":xs) = parseOptions (opts{cm=CTC}) xs
parseOptions opts ("-main":x:xs) = parseOptions (opts{mainFunc=x}) xs
parseOptions opts ("-frontend":x:xs) = parseOptions (opts{frontend=x}) xs
parseOptions opts ("-kicspath":x:xs) = parseOptions (opts{kicspath=x}) xs
--parseOptions opts ("-kicspath":x:xs) = parseOptions (opts{kicspath=x}) xs
parseOptions opts ("-userlibpath":x:xs) =
parseOptions (opts{userlibpath=userlibpath opts ++ splitSearchPath x}) xs
parseOptions opts ("-nouserlibpath":xs) = parseOptions (opts{userlibpath=[]}) xs
parseOptions opts ("-ghc":x:xs) = parseOptions (opts{ghc=x}) xs
--parseOptions opts ("-ghc":x:xs) = parseOptions (opts{ghc=x}) xs
parseOptions opts ("-make":xs) = parseOptions (opts{make=True}) xs
parseOptions opts ("-nomake":xs) = parseOptions (opts{make=False}) xs
parseOptions opts ("-executable":xs) = parseOptions (opts{executable=True}) xs
......@@ -52,7 +54,7 @@ parseOptions opts ("-all":"bf":xs) = parseOptions (opts{pm=All BF}) xs
parseOptions opts ("-st":xs) = parseOptions (opts{pm=ST}) xs
parseOptions opts ("-i":"df":xs) = parseOptions (opts{pm=Interactive DF}) xs
parseOptions opts ("-i":"bf":xs) = parseOptions (opts{pm=Interactive BF}) xs
parseOptions opts ("-o":x:xs) = parseOptions (opts{target=x}) xs
parseOptions opts ("-o":x:xs) = parseOptions (opts{target=Just x}) xs
parseOptions opts ("-d":xs) = parseOptions (opts{debug=True,doNotUseInterface=True}) xs
parseOptions opts ("--debug":xs) = parseOptions opts ("-d":xs)
parseOptions opts ("--debugger":d:xs) = parseOptions opts{debugger=Just d} xs
......@@ -92,9 +94,11 @@ usage problem = do
data Options = Opts{ cm :: ChoiceMode,
filename, mainFunc, mainModule, target,
frontend, ghc, ghcOpts,
kicspath :: String,
filename, mainFunc, mainModule,
frontend, ghcOpts
--, ghc, kicspath
:: String,
target :: Maybe String,
userlibpath, done :: [String],
verbosity :: Int,
make, executable, eval,
......@@ -110,14 +114,10 @@ data Options = Opts{ cm :: ChoiceMode,
data ConsUse = DataDef | InstanceDef | FunctionDef deriving (Eq,Show)
cymake_call :: String
cymake_call = unpath [installDir,"bin","parsecurry"]
libpath :: Options -> [String]
libpath opts@Opts{userlibpath=up,kicspath=kp,filename=fn}
libpath opts@Opts{userlibpath=up,{-kicspath=kp,-}filename=fn}
= --(case takeDirectory fn of "" -> id; dir -> ((dir++[pathSeparator]):))
up ++ [unpath [kp,"src","lib",""]]
up ++ [unpath ["src","lib",""]]
cmdLibpath :: Options -> String
......@@ -138,11 +138,11 @@ hasExtInsts opts =
hasExtFuncs opts = not (null (extFuncs opts))
defaultOpts curDir = Opts {cm=CTC,filename="", mainFunc= "main", mainModule="Main",
target = "request",
frontend=cymake_call,
kicspath=installDir,
target = Just "request",
frontend="cymake",
--kicspath=installDir,
userlibpath=[],
ghc=ghc_call,
--ghc="ghc",
ghcOpts=" -fglasgow-exts -fcontext-stack=50 ",
done=[],
make=True,
......@@ -204,13 +204,10 @@ readPMode s = readPM (words (map toLower s))
ghcCall :: Options -> String
ghcCall opts@Opts{filename=fn} =
callnorm (ghc opts
callnorm ("ghc "
++makeGhc (make opts)
++" -i"++show (toPathList
(pathWithSubdirs
(unpath [installDir,"src"]:
unpath [installDir,"src","oracle"]:
libpath opts)))++" "
(pathWithSubdirs $ libpath opts))++" "
++kicsSubdirPathToFile
++linkOpts
++ghcOpts opts
......@@ -219,16 +216,17 @@ ghcCall opts@Opts{filename=fn} =
++" "++show fn)
where
linkOpts | debug opts = linkLib++" -L"++installDir++"/src/lib/ "
| otherwise = ""
linkLib | eval opts = " -ldyncoracle "
| otherwise = " -lcoracle "
linkOpts = ""
-- | debug opts = linkLib++" -L"++installDir++"/src/lib/ "
-- | otherwise = ""
--linkLib | eval opts = " -ldyncoracle "
-- | otherwise = " -lcoracle "
verboseGhc True = ""
verboseGhc False = " -v0 "
ghcTarget Opts{target=""} = ""
ghcTarget Opts{target=t} = " -o "++show t
ghcTarget Opts{target=Nothing} = ""
ghcTarget Opts{target=Just t} = " -o "++show t
makeGhc True = " --make "
makeGhc False = ""
......@@ -239,7 +237,7 @@ ghcCall opts@Opts{filename=fn} =
stricthsCall opts =
callnorm (installDir++"/bin/stricths --hs "
callnorm ("stricths --hs "
++ ("-s"++mainModule opts++" ")
++ (if make opts then "-m " else "")
++ (if force opts then "-f " else "")
......@@ -247,7 +245,7 @@ stricthsCall opts =
++ filename opts)
mkStrictCall opts =
callnorm (installDir++"/bin/mkstrict "
callnorm ("mkstrict "
++ (if verbosity opts < 2 then "--quiet " else "")
++ filename opts++" "
......@@ -267,7 +265,7 @@ cymake opts = do
++ if verbosity opts >= 3 then "" else " 1>/dev/null ")
prophecy opts = safeSystem (verbosity opts >= 4) $
installDir++"/bin/prophecy "
"prophecy "
++ (if make opts then " -m " else "")
++ (if force opts then " -f " else "")
++ (if verbosity opts < 2 then " -q " else "")
......@@ -305,23 +303,23 @@ writeConfig opts state = do
entry n s = (configs!!(n-1)) ++ "="++s++"\n\n"
mkTags = [kicspath,
mkTags = [-- kicspath,
(toPathList . userlibpath),
(show . pm)]
getConfigs home cfgs | cfgs == cfgs = do
punkt <- getCurrentDirectory
cymake_call <- getCymake
let readOpts = selOpts (entries cfgs)
defaultsO = defaultOpts punkt
opts = defaultsO
{cm = OrBased,
kicspath = installDir,
--kicspath = installDir,
userlibpath = let up = readSetting userlibpath splitSearchPath 1
in (punkt ++ [pathSeparator]) : up,
pm = readSetting pm readPMode 2,
ghc = ghc_call,
--ghc = ghc_call,
frontend = cymake_call,
eval = readSetting eval read 3,
force = False}
......@@ -373,7 +371,9 @@ getModTime fn = safeIO (do
safeReadFlat opts s = do
fs <- safeIO (findFileInPath s (libpath opts))
fn <- warning s (cmdLibpath opts) fs
safeIOSeq (readFlatCurry fn)
mprog <- safeIO $ readFlat fn
maybe (fail $ "file not found: "++fn) return mprog
......
module CurryToHaskell where
module Curry.Compiler.CurryToHaskell where
import List
import Char
import Maybe
import Monad
import System
import System.FilePath
import MetaProgramming.FlatCurry
import MetaProgramming.FlatCurryGoodies hiding (consName)
import qualified FunctionalProg as C
import ShowFunctionalProg
import PreTrans hiding (nub,pre)
import Simplification ( simplifyProg )
import Maybe
import SafeCalls
import Brace
import Config
import Names (modName,dbgModName,funcHsName,externalSpecName,
import Curry.FlatCurry.Type
import Curry.FlatCurry.Goodies hiding (consName)
import qualified Curry.Compiler.FunctionalProg as C
import Curry.Compiler.ShowFunctionalProg
import Curry.Compiler.PreTrans hiding (nub,pre)
import Curry.Compiler.Simplification ( simplifyProg )
import Curry.Compiler.SafeCalls
import Curry.Compiler.Brace
import Curry.Compiler.Config as Config
import Curry.Compiler.Names
(modName,dbgModName,funcHsName,externalSpecName,
elimInfix,funName,functionName,constructorName)
import qualified Names as N
import Monad
import qualified Curry.Compiler.Names as N
--import Debug.Trace
--trace' x = trace (show x) x
......@@ -44,11 +45,11 @@ compilations (f:fs) opts =
startCompilation :: Options -> Safe IO Options
startCompilation opts = do
put 2 opts "calling frontend"
newOpts <- callFrontend opts
visited <- compile newOpts >>= return . done
put 2 opts "calling ghc"
ghcProgram False newOpts (funcHsName (filename newOpts))
when (make opts) $ do
put 2 opts "calling ghc"
ghcProgram False newOpts (funcHsName (filename newOpts))
return newOpts{done=visited}
-- compile not only returns the current Options
......@@ -96,8 +97,11 @@ skip opts = do
makeImports :: (String,[String],Options) -> Safe IO Options
makeImports (name,imps,opts@(Opts{filename=fn})) = do
impOpts <- foldCompile imps opts{executable=False}
return impOpts{done=name : done impOpts}
if (make opts)
then do
impOpts <- foldCompile imps opts{executable=False}
return impOpts{done=name : done impOpts}
else return opts{done=name : done opts}
---------------------------------------------------------------------------------
-- sub routines of compilation
......@@ -109,9 +113,11 @@ callFrontend opts@(Opts{filename=givenFile}) = do
foundSources <- if null foundCurry
then safeIO (findFileInPath (replaceExtension givenFile ".lcurry") lib)
else return foundCurry
unless (null foundSources) (if debug opts
then prophecy opts
else cymake opts)
when (make opts) $ do
put 2 opts "calling frontend"
unless (null foundSources) (if debug opts
then prophecy opts
else cymake opts)
return (if debug opts then opts{filename=dbgModName givenFile} else opts)
getFlatCurryFileName opts@(Opts{filename=basename}) = do
......@@ -124,8 +130,8 @@ getFlatCurryFileName opts@(Opts{filename=basename}) = do
notUptodate opts@(Opts{filename=foundBasename}) = do
tSource1 <- getModTime (replaceExtension foundBasename ".fcy")
tSource2 <- getExternalSpecModTime opts foundBasename
let destination = inModuleSubdir (inKicsSubdir (funcHsName foundBasename))
tDestination <- getModTime destination
let dest = destination True (target opts) (funcHsName foundBasename)
tDestination <- getModTime dest
return (tSource1 > tDestination || tSource2 > tDestination)
applyFlatTransformations opts prog = do
......@@ -154,20 +160,18 @@ generateHaskellFiles opts (globals,prog,interfaces,auxNames) = do
return (haskellFiles opts (progName prog))
writeProgram opts (fn,unqualified,prog) = do
let fn' = inModuleSubdir (inKicsSubdir fn)
put 3 opts ("writing "++ fn')
let filename = destination (fn/="Main.hs") (target opts) fn
put 3 opts ("writing "++ filename)
let printOpts = defaultPrintOptions{unqual=unqualified,include=toInclude opts}
safeIO (writeKicsFile (fn/="Main.hs") fn (showProgOpt printOpts prog))
put 3 opts (fn'++" written")
return fn
safeIO (writeKicsFile filename (showProgOpt printOpts prog))
put 3 opts (filename ++ " written")
ghcProgram skipping opts fn =
unless (eval opts && executable opts) $ do
found <- safeIO (findFileInPath fn (libpath opts))
let hsFile = head found
ghc = safeSystem (verbosity opts >= 2)
(ghcCall opts{make=True,filename=hsFile,target=""})
(ghcCall opts{make=True,filename=hsFile,target=Nothing})
shFile = drop 2 (reverse hsFile)
oFile = reverse ('o':shFile)
hiFile = reverse ('i':'h':shFile)
......
......@@ -17,7 +17,7 @@
--- @version August 2005
------------------------------------------------------------------------------
module FunctionalProg where
module Curry.Compiler.FunctionalProg where
------------------------------------------------------------------------------
-- Definition of data types for representing abstract Curry programs:
......
module KicsSubdir where
module Curry.Compiler.KicsSubdir where
import System.Directory
import System.FilePath
......@@ -78,17 +78,20 @@ inKicsSubdir s = inCurrySubdir s `inSubdir` kicsSubdir
inModuleSubdir :: String -> String
inModuleSubdir s = s `inSubdir` "Curry" `inSubdir` "Module"
-- destination file names
destination :: Bool -> Maybe String -> String -> String
destination _ (Just t) _ = t
destination True _ filename = inKicsSubdir filename
destination False _ filename = inModuleSubdir (inKicsSubdir filename)
--write a file to curry subdirectory
writeKicsFile :: Bool -> String -> String -> IO String
writeKicsFile isHsModule filename contents = do
let filename' | isHsModule = inModuleSubdir (inKicsSubdir filename)
| otherwise = inKicsSubdir filename
subdir = dirname filename'
writeKicsFile :: String -> String -> IO ()
writeKicsFile filename contents = do
let subdir = dirname filename
createDirectoryIfMissing True subdir
writeFile filename' contents
return filename'
writeFile filename contents
-- do things with file in subdir
......
module Names where
module Curry.Compiler.Names where
import Char
import List
import System.FilePath
import ShowFunctionalProg (isTuple,isInfixOpName)
import Curry.Compiler.ShowFunctionalProg (isTuple,isInfixOpName)
---------------------------------------------------------------------------
-- generating names to avoid clashes with Haskell
......
......@@ -2,14 +2,14 @@
--------------------------------
-- preliminary transformations
--------------------------------
module PreTrans
where
module Curry.Compiler.PreTrans where
import MetaProgramming.FlatCurry
import MetaProgramming.FlatCurryGoodies
import Maybe
import List hiding (nub)
import Curry.FlatCurry.Type
import Curry.FlatCurry.Goodies
#if __GLASGOW_HASKELL__ >= 604
import qualified Data.Map as FM
......
{-# OPTIONS -cpp #-}
{-# LANGUAGE FlexibleInstances #-}
module SafeCalls where
module Curry.Compiler.SafeCalls where
#if __GLASGOW_HASKELL__ >= 610
import Control.OldException
......
......@@ -18,14 +18,15 @@
--- @version August 2005
------------------------------------------------------------------------------
module ShowFlatCurry(showFlatProg,showFlatType,showFlatFunc,
module Curry.Compiler.ShowFlatCurry(showFlatProg,showFlatType,showFlatFunc,
showCurryType,showCurryExpr,showCurryId,showCurryVar)
where
import MetaProgramming.FlatCurry
import List
import Char
import Brace
import Curry.FlatCurry.Type
import Curry.Compiler.Brace
--- Shows a FlatCurry program term as a string (with some pretty printing).
showFlatProg :: Prog -> String
......
......@@ -17,7 +17,8 @@
-- in May 2007:
-- - prettier representation of Curry and Haskell Strings
------------------------------------------------------------------------------
module ShowFunctionalProg(showProg,showProgOpt,PrintOptions(..),defaultPrintOptions,
module Curry.Compiler.ShowFunctionalProg(
showProg,showProgOpt,PrintOptions(..),defaultPrintOptions,
showTypeDecls,
showTypeDecl,
showTypeExpr,
......@@ -25,13 +26,13 @@ module ShowFunctionalProg(showProg,showProgOpt,PrintOptions(..),defaultPrintOpti
showExpr,showPattern,
isInfixOpName,isTuple) where
import FunctionalProg
import List
import Char(isDigit,ord)
import Maybe (isJust)
import Monad (ap)
import Brace
import Debug.Trace
import Curry.Compiler.FunctionalProg
import Curry.Compiler.Brace
-------------------------------------------------------------------------------
-- Functions to print an AbstractCurry program in standard Curry syntax
......
module Simplification (simplifyProg) where
module Curry.Compiler.Simplification (simplifyProg) where
import Prelude hiding ( or,fail,catch )
import MetaProgramming.FlatCurry
import MetaProgramming.FlatCurryGoodies hiding ( freeVars )
import qualified MetaProgramming.FlatCurryGoodies as FCG
import Curry.FlatCurry.Type
import Curry.FlatCurry.Goodies hiding ( freeVars )
import qualified Curry.FlatCurry.Goodies as FCG
import List ( sortBy, groupBy, partition )
......
module Curry.Files.KiCSPath (getKiCS,kicsVersion) where
import Data.Version
import System.FilePath
import Paths_KiCS
kicsVersion = versionBranch version
getKiCS = do