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

restructured debugger sources

parent 56d143ae
......@@ -4,33 +4,14 @@
# generated by ghc or cc
*.hi
*.o
libdyncoracle.so
src/lib/libcoracle.a
# backup versions/emacs noise
semantic.cache
*~
# files generated by make
src/InstallDir.hs
bin/*
!bin/kghc
!bin/kghci
!bin/makecurrycgi
!bin/cleancurry
src/MyReadline.hs
dist/kics_src.tgz
cpns/CPNS.state
www/registry
www/submitform
# files generated by b.i.o
src/lib/Strict*.hs
# files generated by cabal
dist/*
src/lib/dist/*
debugger/dist/*
# frequently coming files
*.patch
......
Name: KiCS
Version: 0.8.8
Cabal-Version: >= 1.6
Version: 0.9.1
Cabal-Version: == 1.6.*
Author: Bernd Braßel
Maintainer: Bernd Braßel
Homepage: http://curry-language.org
......@@ -22,7 +22,6 @@ Data-Files: *.fcy
*.acy
*.uacy
*.cy
Executable kics
main-is: kics.hs
......@@ -38,7 +37,25 @@ Executable kics
ghc-paths,
process,
curry-base >= 0.2.5,
curry-frontend >= 0.2.6
curry-frontend >= 0.2.7
Other-Modules:
Curry.Compiler.Config
Curry.Compiler.CurryToHaskell
Curry.Compiler.SafeCalls
Curry.Compiler.Names
Curry.Compiler.ShowFlatCurry
Curry.Compiler.KicsSubdir
Curry.Compiler.FunctionalProg
Curry.Compiler.ShowFunctionalProg
Curry.Compiler.PreTrans
Curry.Compiler.Simplification
Curry.Compiler.Brace
Executable kicsi
main-is: kicsi.hs
hs-source-dirs: src
Build-Depends:
readline
Library
hs-source-dirs: src, src/lib
......@@ -94,6 +111,22 @@ Library
Curry.Module.Traversal
Curry.Module.PropertyFile
Curry.Module.Unsafe
Curry.Module.XML
Curry.Module.Distribution
Curry.Module.FlatCurry
Curry.Module.AbstractCurry
Curry.Module.AbstractCurryPrinter
Curry.Module.CompactFlatCurry
Curry.Module.CurryStringClassifier
Curry.Module.CurrySyntax
Curry.Module.FlatCurryGoodies
Curry.Module.FlatCurryRead
Curry.Module.FlatCurryShow
Curry.Module.FlatCurryTools
Curry.Module.FlatCurryXML
Curry.Module.FlexRigid
Curry.Module.PrettyFlat
Curry.Module.Trace
Other-Modules:
Paths_KiCS
......@@ -103,3 +136,4 @@ Library
......@@ -11,7 +11,6 @@ import Distribution.PackageDescription
import Distribution.Verbosity
import Curry.Files.CymakePath
import Curry.Files.KiCSPath
kics :: Program
kics = simpleProgram "kics"
......@@ -47,7 +46,6 @@ callProg verb lbi prog args = do
myPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostConf args confFlags descrs lbi = do
let require = requireProg (configVerbosity confFlags) lbi
require (return kics)
require cymake
postConf simpleUserHooks args confFlags descrs lbi
......@@ -58,13 +56,12 @@ mkModule buildInfo lbi = PreProcessor
runKics :: LocalBuildInfo -> FilePath -> FilePath -> Verbosity -> IO ()
runKics lbi infile outfile verb = do
let call = callProg deafening{-verb-} lbi
let call = callProg verb lbi
datadir = takeDirectory infile
-- nomake not supported
mapM (\ format -> call cymake ["-e",'-':'-':format,"-i"++datadir,infile])
["flat","extended-flat","acy","uacy","parse-only"]
call (return kics) ["-nomake",--"-userlibpath","src/lib/Curry/Module/",
"-o",outfile,infile]
call (return kics) ["-nomake","-o",outfile,infile]
[ForType "Ref" Nothing
,ForFunction "initialize"
,ForFunction "finalize"
,ForFunction "fresh"
,ForFunction "replace"
,ForFunction "collapse"
,ForFunction "closeRef"
,ForFunction "expand"
,Pragma "LANGUAGE EmptyDataDecls, ForeignFunctionInterface"
,Pragma "INCLUDE <coracle.h>"
]
import Foreign
import Foreign
import Foreign.C.String
foreign import ccall unsafe "static coracle.h init" cinitialize :: Ref
foreign import ccall unsafe "static coracle.h nextref" cfresh :: Int -> Ref
foreign import ccall unsafe "static coracle.h collapse" ccollapse :: Ref -> ()
foreign import ccall unsafe "static coracle.h close_ref" ccloseRef :: Ref -> ()
foreign import ccall unsafe "static coracle.h inconly" creplace :: Ref -> ()
foreign import ccall unsafe "static coracle.h expand" cexpand :: Ref -> Int -> ()
foreign import ccall unsafe "coracle.h finalize" cfinalize :: CString -> ()
data CRef
type Ref = Ptr CRef
newtype C_Ref = C_Ref Ref
instance Show C_Ref
instance Read C_Ref
instance Eq C_Ref
instance BaseCurry C_Ref
instance Curry C_Ref
initRef :: Result (C_IO C_Ref)
initRef = let ref = cinitialize in seq ref (Curry.Module.Prelude.return (C_Ref ref))
finalize :: C_String -> Result (C_IO T0)
finalize s _ = C_IO (\ _ -> do
s' <- newCString (fromCurry s)
seq (cfinalize s') (Prelude.return (IOVal (T0))))
--- Side effect that computes a fresh reference.
fresh :: a -> Result C_Ref
fresh _ _ = C_Ref (cfresh 0)
--- increase couter of ref by one
replace :: C_Ref -> a -> b -> a
replace (C_Ref ref) x _ = seq (creplace ref) x
--- Remove a ref and combine and counter +1
collapse :: C_Ref -> a -> b -> a
collapse (C_Ref ref) x _ = seq (ccollapse ref) x
--- Remove a ref and combine and counter +1
closeRef :: C_Ref -> a -> b -> a
closeRef (C_Ref ref) x _ = seq (ccloseRef ref) x
--- Projection on last argument that releases an event as a side effect.
-- increment step counter of first ref and add remaining refs
-- list has to be at least of size 1
expand :: C_Ref -> List C_Ref -> a -> Result a
expand (C_Ref ref) refs x _
= seq (cexpand ref (len refs)) (seq (evalRefs refs) x)
where
len List = 0
len (_ :< rs) = 1+len rs
evalRefs List = ()
evalRefs (r :< rs) = seq r (evalRefs rs)
-- compare to BaseCurry.mapOr
c_onBranches :: (BaseCurry a,BaseCurry b) =>
C_Ref -> (C_Ref -> a -> Result b) -> OrRef -> Branches a -> Result b
c_onBranches r cont orref bs =
evalRef' True (\ r x st -> replace r (cont r x st) st) (branching orref bs) r
liftCase :: (BaseCurry a,BaseCurry b) =>
C_Ref -> (C_Ref -> a -> Result b) -> OrRef -> Branches a -> (Int -> State) -> b
liftCase ref f orref bs =
expand' ref (length bs - 1) (\ refs -> lift ($) orref (zipWith f refs bs))
expand' :: C_Ref -> Int -> ([C_Ref] -> a) -> a
expand' (C_Ref ref) l cont =
cexpand ref l `seq`
evalRefs refs `seq`
cont (map C_Ref (ref:refs))
where
refs = map cfresh (replicate l 0)
evalRefs [] = ()
evalRefs (r : rs) = seq r (evalRefs rs)
--- generating a fresh variable
unknown :: Curry a => C_Ref -> Result a
unknown r st = freeF (\x -> gen r x st)
gen :: Curry a => C_Ref -> a -> Result a
gen r x st = case consKind x of
Val -> push r x st
Branching -> liftCase r gen (orRef x) (branches x) (const st)
push :: Curry a => C_Ref -> a -> Result a
push r x st = case foldCurry (\ _ n _ -> n+1) 0 x st of
0 -> collapse r x st
1 -> replace r (propagate (\_ -> gen r) x st) st
n -> expand' r (n-1) (\ refs -> propagate (distRefs refs) x st)
where
distRefs rs i x = gen (rs!!i) x
type RefFun a b = C_Ref -> Result (Prim (a -> Result b))
($!), ($#),($!!),($##), apply :: (Curry a,Curry b) =>
Prim (RefFun a b) -> a -> C_Ref -> Result b
(cont $! x) r = Curry.Module.CEventOracle.prepApply hnfRef x cont r
(cont $# x) r = Curry.Module.CEventOracle.prepApply (evalRef True) x cont r
(cont $!! x) r st = Curry.Module.CEventOracle.prepApply hnfRef (nfCTC const x st) cont r st
(cont $## x) r st = Curry.Module.CEventOracle.prepApply (evalRef True) (gnfCTC const x st) cont r st
apply cont x r = Curry.Module.CEventOracle.prepApply (\ cont' x' r' st' ->
replace r' (Curry.Module.Prelude.apply (cont' r' st') x' st') st') x cont r
prepApply :: (BaseCurry a,BaseCurry b) =>
(RefFun b a -> b -> C_Ref -> Result a) -> b -> Prim (RefFun b a) -> C_Ref -> Result a
prepApply prep x (PrimValue f) cref st = prep f x cref st
prepApply prep x (PrimOr r bs) cref st =
c_onBranches cref (\ r' f' -> Curry.Module.CEventOracle.prepApply prep x f' r') r bs st
prepApply _ _ f r st = collapse r (patternFail "Prelude.prepApply" f) st
hnfRef :: (BaseCurry a,BaseCurry b) => RefFun b a -> b -> C_Ref -> Result a
hnfRef = evalRef False
evalRef :: (BaseCurry a,BaseCurry b) => HNFMode -> RefFun a b -> a -> C_Ref -> Result b
evalRef mode cont = evalRef' mode (\ r x st -> replace r (Curry.Module.Prelude.apply (cont r st) x st) st)
evalRef' :: (BaseCurry a,BaseCurry b) =>
HNFMode -> (C_Ref -> a -> Result b) -> a -> C_Ref -> Result b
evalRef' mode cont x r state =
case consKind x of
Failed -> closeRef r (addException err x) state
Branching -> let orref = orRef x
bs = branches x in
manipulateStore
(closeRef r (Curry.RunTimeSystem.failed (curryError "=:=")) state)
contEval
(\ ref' contSt -> if mode || not (isGenerator orref)
then liftCase r contEvalRef (narrowOrRef orref) bs contSt
else cont r (branching ref' bs) state)
(\ orref' x' st' -> branching orref' [contEval x' st'])
orref bs state
Val -> cont r x state
where
err = curryError ("Prelude."++if mode then "$#" else "$!")
contEvalRef r' x' st' = evalRef' mode cont x' r' st'
contEval = contEvalRef r
Name: KiCS-debugger
Version: 0.1.0
Cabal-Version: >= 1.6
Author: Bernd Braßel
Maintainer: Bernd Braßel
Homepage: http://curry-language.org
License: OtherLicense
License-File: LICENSE
Category: Debug
build-type: Custom
Synopsis: debug features for kics
Description: This package contains the debugger for the Curry to Haskell compiler "kics".
Stability: experimental
extra-source-files:
Curry/Module/*.hs.include
Data-Dir: Curry/Module/.curry
Data-Files: *.fcy
*.fint
Library
Build-Depends:
base == 4.1.*,
KiCS >= 0.9.0
Exposed-Modules:
Curry.Module.CEventOracle
Curry.Module.EventOracle
Curry.Module.Oracle
install-includes: coracle.h
c-sources: coracle.c
Executable prophecy
main-is: Main.hs
hs-source-dirs: prophecy, .curry/kics
Build-Depends:
base == 4.1.*,
KiCS >= 0.9.0
Other-Modules:
Curry.Module.AddWorld
Curry.Module.Wrapper
Curry.Module.LiftCases
Curry.Module.Make
Curry.Module.Transform
KiCS (Kiel Curry System) License
Copyright (c) 2009, University of Kiel
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- None of the names of the copyright holders and contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module Main where
import System.FilePath
import Data.List
import Monad
import Distribution.Simple
import Distribution.Simple.Setup as SS
import Distribution.Simple.Program
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.PreProcess
import Distribution.PackageDescription
import Distribution.Verbosity
import Curry.Files.CymakePath
import Curry.Files.KiCSPath
kics :: IO Program
kics = mkProg getKiCS
cymake :: IO Program
cymake = mkProg getCymake
mkProg getProg = do
call <- getProg
return (simpleProgram (takeBaseName call))
{programFindLocation = \_-> return (Just call)}
main :: IO ()
main = do
cymakeProg <- cymake
kicsProg <- kics
defaultMainWithHooks simpleUserHooks
{hookedPrograms=kicsProg:cymakeProg:hookedPrograms simpleUserHooks
,postConf=myPostConf
,hookedPreProcessors=[("curry",mkModule)]
}
unflag = fromFlagOrDefault silent
requireProg :: SS.Flag Verbosity -> LocalBuildInfo -> IO Program -> IO ()
requireProg verb lbi prog = do
p <- prog
requireProgram (unflag verb) p AnyVersion (withPrograms lbi)
return ()
callProg :: Verbosity -> LocalBuildInfo -> IO Program -> Args -> IO ()
callProg verb lbi prog args = do
p <- prog
rawSystemProgramConf verb p (withPrograms lbi) args
myPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostConf args confFlags descrs lbi = do
let require = requireProg (configVerbosity confFlags) lbi
require cymake
require kics
postConf simpleUserHooks args confFlags descrs lbi
mkModule :: BuildInfo -> LocalBuildInfo -> PreProcessor
mkModule buildInfo lbi = PreProcessor
{platformIndependent = True
,runPreProcessor = mkSimplePreProcessor (runKics lbi)}
runKics :: LocalBuildInfo -> FilePath -> FilePath -> Verbosity -> IO ()
runKics lbi infile outfile verb = do
let call = callProg verb lbi
datadir <- getKiCSLibDir
mapM (\ format -> call cymake ["-e",'-':'-':format,"-i"++datadir,"-iprophecy/Curry/Module",infile])
["flat"]
if not (isSuffixOf "Transform.curry" infile)
then call kics ["-nomake","-o",outfile,infile]
else call kics ["-nomake","-executable","prophecy","-o",outfile,infile]
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