Commit 4be4a982 authored by Bernd Brassel's avatar Bernd Brassel
Browse files

some more external functions integrated

parent 6ed00464
......@@ -2,17 +2,8 @@
.curry/
# generated by ghc or cc
src/*.hi
src/*.o
src/tools/*.hi
src/tools/*.o
src/oracle/*.hi
src/oracle/*.o
src/MetaProgramming/*.hi
src/MetaProgramming/*.o
src/lib/External*.hi
src/lib/External*.o
src/lib/coracle.o
*.hi
*.o
libdyncoracle.so
src/lib/libcoracle.a
......
......@@ -51,10 +51,9 @@ Library
Build-Depends:
syb
Other-Modules:
Store,
BaseCurry,
RunTimeCurry,
Curry
Curry.RunTimeSystem.Store,
Curry.RunTimeSystem.BaseCurry,
Curry.RunTimeSystem
......
......@@ -47,7 +47,7 @@ all: $(SRC)InstallDir.hs $(BIN)kicslib $(BIN)kics \
$(BIN)kicsi libs cpns www tools
.PHONY: tools
tools: $(SRC)InstallDir.hs $(BIN)makeExternalInterface $(BIN)prettyflat\
tools: $(SRC)InstallDir.hs $(BIN)prettyflat\
$(BIN)currytest $(BIN)prettyacy
$(SRC)InstallDir.hs: prerequisites
......@@ -100,7 +100,7 @@ $(BIN)kics: $(BIN)kicslib $(SRC)kics.hi
.PHONY: runtime
runtime: $(SRC)InstallDir.hs
$(GHC) -fno-cse $(SRC)Curry.hs
$(GHC) -fno-cse Curry.RunTimeSystem
.PHONY: libs
libs: $(BIN)kics runtime $(BIN)makeacy
......@@ -207,9 +207,10 @@ depend : $(SRC)MyReadline.hs
%.hi: %.o %.hs
$(GHC) --make $(HC_OPTS) $*.hs
# DO NOT DELETE: Beginning of Haskell dependencies
src/MyReadline.o : src/MyReadline.hs
src/InstallDir.o : src/InstallDir.hs
src/SafeCalls.o : src/SafeCalls.hs
src/KicsSubdir.o : src/KicsSubdir.hs
src/MetaProgramming/FlatCurry.o : src/MetaProgramming/FlatCurry.hs
src/MetaProgramming/FlatCurry.o : src/KicsSubdir.hi
......@@ -232,7 +233,6 @@ 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/SafeCalls.o : src/SafeCalls.hs
src/Config.o : src/Config.hs
src/Config.o : src/KicsSubdir.hi
src/Config.o : src/Names.hi
......@@ -251,10 +251,7 @@ src/CurryToHaskell.o : src/ShowFunctionalProg.hi
src/CurryToHaskell.o : src/FunctionalProg.hi
src/CurryToHaskell.o : src/MetaProgramming/FlatCurryGoodies.hi
src/CurryToHaskell.o : src/MetaProgramming/FlatCurry.hi
src/kicslib.o : src/kicslib.hs
src/kicslib.o : src/Config.hi
src/kicsi.o : src/kicsi.hs
src/kicsi.o : src/MyReadline.hi
src/kicsi.o : src/Names.hi
src/kicsi.o : src/Config.hi
src/kicsi.o : src/ShowFlatCurry.hi
......@@ -262,8 +259,4 @@ 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
# DO NOT DELETE: End of Haskell dependencies
......@@ -233,7 +233,7 @@ transform typeMapping aux opts0 (Prog name imports types funcs _)
-- import lists
newImports = map modName imports
allIImports = ["Curry"] ++ newImports
allIImports = [curryModule] ++ newImports
{-
-- this is the only special prelude treatment:
......@@ -277,7 +277,7 @@ generateAuxNames fs = (genNewName "aux1" fns,genNewName "aux2" fns)
mainMod (_,aux2) m opts = let aux = (m,snd (funName ("",aux2))) in
C.Prog "Main" ["Curry",modName "Prelude",m]
C.Prog "Main" [curryModule,modName "Prelude",m]
[] [] []
[C.Func (m,"main") public untyped
(Just [C.Rule []
......@@ -401,7 +401,7 @@ inst newModName name vars classname =
curryInstance opts t@(Type origName vis vars consdecls)
= inst newModName name vars "Curry"
= inst newModName name vars curryClass
[strEq,eq,propagate,foldCurry,typeName,showFunction True opts t] --toTerm,fromTerm
where
(newModName,name) = consName opts origName
......@@ -642,7 +642,7 @@ transFType _ _ (TVar (-42)) = Nothing
transFType opts arity t = Just $
C.TConstr
[C.TypeClass c [toTVar tv] | tv <- nub (allVarsInTypeExpr t),
c <- [("Curry","Curry")]]
c <- [(curryModule,"Curry")]]
(addStateType (transFTypeExpr opts arity t))
transFTypeExpr opts 0 t = transTypeExprF opts t
......@@ -932,7 +932,7 @@ failName opts = N.failName . consName opts
orName opts = N.orName . consName opts
suspName opts = N.suspName . consName opts
curryName s = ("Curry",s)
curryName s = (curryModule,s)
curryTCons = C.TCons . curryName
----------------------------------------
......@@ -978,7 +978,8 @@ funcupresym = sym . funName . addPre
concupresym opts = sym . consName opts . addPre
-- symbols from Curry library
curryModule = "Curry"
curryModule = "Curry.RunTimeSystem"
curryClass = "Curry"
cu = (,) curryModule
cusym = sym . cu
......
......@@ -8,7 +8,7 @@ import System.IO
import System.Directory (doesFileExist)
import Control.Monad (unless,when)
import System.FilePath
import System.Console.Readline
import CurryToHaskell
import SafeCalls
......@@ -17,7 +17,7 @@ import MetaProgramming.FlatCurryGoodies
import ShowFlatCurry
import Config
import Names
import MyReadline
allFiles = map snd . files
loadedFiles = map snd . filter fst . files
......@@ -69,7 +69,6 @@ main = do
home <- getEnv "HOME"
(options,state) <- getOptions
mapM_ (safe . put 1 options) welcome
unless (verbosity options==0) initializeReadline
let files = case filename options of
"" -> ["Prelude"]
fn -> [fn]
......
......@@ -4,4 +4,29 @@
,ForFunction "curryRuntime"
,ForFunction "curryRuntimeMajorVersion"
,ForFunction "curryRuntimeMinorVersion"
,ForFunction "installDir"]
,ForFunction "installDir"
]
import qualified InstallDir as ID
curryCompiler :: Result C_String
curryCompiler _ = toCurry "kics"
curryCompilerMajorVersion :: Result C_Int
curryCompilerMajorVersion _ = 0
curryCompilerMinorVersion :: Result C_Int
curryCompilerMinorVersion _ = 9854
installDir :: Result C_String
installDir _ = toCurry (ID.installDir)
curryRuntime :: Result C_String
curryRuntime _ = toCurry "ghc"
curryRuntimeMajorVersion :: Result C_Int
curryRuntimeMajorVersion _ = 6
curryRuntimeMinorVersion :: Result C_Int
curryRuntimeMinorVersion _ = 8
module ExternalDataSocket (module ExternalDataSocket) where
import Curry
import CurryPrelude
import Network
type C_Socket = Prim Socket
instance Read Socket where
instance Generate Socket where
genFree = error "no random sockets"
maxArity = error "no narrowing on sockets"
module ExternalFunctionsDistribution where
import Curry
import CurryPrelude
import qualified InstallDir as ID
curryCompiler :: Result C_String
curryCompiler _ = toCurry "kics"
curryCompilerMajorVersion :: Result C_Int
curryCompilerMajorVersion _ = 0
curryCompilerMinorVersion :: Result C_Int
curryCompilerMinorVersion _ = 9854
installDir :: Result C_String
installDir _ = toCurry (ID.installDir)
curryRuntime :: Result C_String
curryRuntime _ = toCurry "ghc"
curryRuntimeMajorVersion :: Result C_Int
curryRuntimeMajorVersion _ = 6
curryRuntimeMinorVersion :: Result C_Int
curryRuntimeMinorVersion _ = 8
module ExternalFunctionsSocket (module ExternalFunctionsSocket) where
import Curry
import CurryPrelude hiding (return, (>>=))
import ExternalDataSocket
import CurryIO
import Network
import Network.Socket
import Control.Concurrent
import System.IO (Handle)
instance ConvertCH C_Int PortID where
toCurry (PortNumber i) = toCurry (toInteger i)
fromCurry i = PortNumber (fromInteger (fromCurry i))
prim_listenOn :: C_Int -> Result (C_IO C_Socket)
prim_listenOn = CurryPrelude.ioFunc1 listenOn
listenOnFresh :: Result (C_IO (T2 C_Int C_Socket))
listenOnFresh = CurryPrelude.ioFunc0 listenOnFreshPort
listenOnFreshPort :: IO (PortID,Socket)
listenOnFreshPort = do
s <- listenOn (PortNumber aNY_PORT)
p <- Network.socketPort s
return (p,s)
prim_socketListen :: C_Socket -> C_Int -> Result (C_IO T0)
prim_socketListen = CurryPrelude.ioFunc2 listen
prim_socketAccept :: C_Socket -> Result (C_IO (T2 (List C_Char) C_Handle))
prim_socketAccept = ioFunc1 (\ s -> Network.accept s >>= \ (h,s,_) -> return (s,One h))
prim_waitForSocketAccept :: C_Socket -> C_Int -> Result (C_IO (C_Maybe (T2 (List C_Char) C_Handle)))
prim_waitForSocketAccept = CurryPrelude.ioFunc2 wait
wait :: Socket -> Int -> IO (Maybe (String,IOHandle))
wait s t = do
mv <- newEmptyMVar
tacc <- forkIO (Network.accept s >>= \ (h,s,_) -> putMVar mv (Just (s,One h)))
ttim <- forkIO (threadDelay (t*1000) >> putMVar mv Nothing)
res <- takeMVar mv
maybe (killThread tacc) (\_ -> killThread ttim) res
return res
prim_connectToSocket :: List C_Char -> C_Int -> Result (C_IO C_Handle)
prim_connectToSocket = ioFunc2 (\ s i -> connectTo s i >>= return . One)
This diff is collapsed.
......@@ -44,8 +44,8 @@ data IOVal t0 = IOVal t0
data C_Bool = C_False
| C_True
| C_BoolFail Curry.C_Exceptions
| C_BoolOr Curry.OrRef (Curry.Branches C_Bool)
| C_BoolFail Curry.RunTimeSystem.C_Exceptions
| C_BoolOr Curry.RunTimeSystem.OrRef (Curry.RunTimeSystem.Branches C_Bool)
| C_BoolAnd [C_Bool]
data C_Char = C_Char !Char
......@@ -378,10 +378,10 @@ instance (BaseCurry t0) => BaseCurry (C_IO t0) where
instance BaseCurry C_Char where
nf f (SearchChar x1 x2 x3 x4) state0 = Curry.nfCTC(\ v1 state1 -> Curry.nfCTC(\ v2 state2 -> Curry.nfCTC(\ v3 state3 -> Curry.nfCTC(\ v4 state4 -> f(SearchChar(v1)(v2)(v3)(v4))(state4))(x4)(state3))(x3)(state2))(x2)(state1))(x1)(state0)
nf f (SearchChar x1 x2 x3 x4) state0 = Curry.RunTimeSystem.nfCTC(\ v1 state1 -> Curry.RunTimeSystem.nfCTC(\ v2 state2 -> Curry.RunTimeSystem.nfCTC(\ v3 state3 -> Curry.RunTimeSystem.nfCTC(\ v4 state4 -> f(SearchChar(v1)(v2)(v3)(v4))(state4))(x4)(state3))(x3)(state2))(x2)(state1))(x1)(state0)
nf f x store = f(x)(store)
gnf f (SearchChar x1 x2 x3 x4) state0 = Curry.gnfCTC(\ v1 state1 -> Curry.gnfCTC(\ v2 state2 -> Curry.gnfCTC(\ v3 state3 -> Curry.gnfCTC(\ v4 state4 -> f(SearchChar(v1)(v2)(v3)(v4))(state4))(x4)(state3))(x3)(state2))(x2)(state1))(x1)(state0)
gnf f (SearchChar x1 x2 x3 x4) state0 = Curry.RunTimeSystem.gnfCTC(\ v1 state1 -> Curry.RunTimeSystem.gnfCTC(\ v2 state2 -> Curry.RunTimeSystem.gnfCTC(\ v3 state3 -> Curry.RunTimeSystem.gnfCTC(\ v4 state4 -> f(SearchChar(v1)(v2)(v3)(v4))(state4))(x4)(state3))(x3)(state2))(x2)(state1))(x1)(state0)
gnf f x store = f(x)(store)
......@@ -431,10 +431,10 @@ instance Generate a => BaseCurry (Prim a) where
instance (BaseCurry t0) => BaseCurry (List t0) where
nf f ((:<) x1 x2) state0 = Curry.nfCTC(\ v1 state1 -> Curry.nfCTC(\ v2 state2 -> f((:<)(v1)(v2))(state2))(x2)(state1))(x1)(state0)
nf f ((:<) x1 x2) state0 = Curry.RunTimeSystem.nfCTC(\ v1 state1 -> Curry.RunTimeSystem.nfCTC(\ v2 state2 -> f((:<)(v1)(v2))(state2))(x2)(state1))(x1)(state0)
nf f x st = f(x)(st)
gnf f ((:<) x1 x2) state0 = Curry.gnfCTC(\ v1 state1 -> Curry.gnfCTC(\ v2 state2 -> f((:<)(v1)(v2))(state2))(x2)(state1))(x1)(state0)
gnf f ((:<) x1 x2) state0 = Curry.RunTimeSystem.gnfCTC(\ v1 state1 -> Curry.RunTimeSystem.gnfCTC(\ v2 state2 -> f((:<)(v1)(v2))(state2))(x2)(state1))(x1)(state0)
gnf f x st = f(x)(st)
generator i = withRef (\ r -> ListOr (mkRef r 2 i)
......@@ -444,9 +444,9 @@ instance (BaseCurry t0) => BaseCurry (List t0) where
branching = ListOr
consKind (ListOr _ _) = Curry.Branching
consKind (ListFail _) = Curry.Failed
consKind _ = Curry.Val
consKind (ListOr _ _) = Curry.RunTimeSystem.Branching
consKind (ListFail _) = Curry.RunTimeSystem.Failed
consKind _ = Curry.RunTimeSystem.Val
exceptions (ListFail x) = x
......@@ -1011,10 +1011,10 @@ instance (ConvertCH a b) => ConvertCH (C_Maybe a) (Maybe b) where
($##) cont x = prepApply gnfCTC x cont
prim_error :: Curry a => C_String -> Result a
prim_error s _ = Curry.failed (ErrorCall (fromCurry s))
prim_error s _ = Curry.RunTimeSystem.failed (ErrorCall (fromCurry s))
failed :: Curry a => Result a
failed _ = Curry.failed PreludeFailed
failed _ = Curry.RunTimeSystem.failed PreludeFailed
(==) :: Curry a => a -> a -> Result C_Bool
(==) = genEq
......@@ -1068,7 +1068,7 @@ exec f (C_IO m) st = m st Prelude.>>= \ x -> prim_do f x st
-- and everything would work fine. But then for the susp and or cases
-- we would use unsafe io...
-- Thus, prim_do has to copy the code of ctcStore False
-- IMPORTANT: This code should correspond to BaseCurry.ctcStore
-- IMPORTANT: This code should correspond to BaseCurry.RunTimeSystem.ctcStore
prim_do :: (Curry a,Curry b) =>
Prim (a -> Result (C_IO b)) -> IOVal a -> Result (IO (IOVal b))
......@@ -1077,7 +1077,7 @@ prim_do f x state = case x of
IOValFail es -> Prelude.return (IOValFail es)
IOValOr ref bs ->
optChangeStore
(Curry.failed $ curryError "prim_do")
(Curry.RunTimeSystem.failed $ curryError "prim_do")
(\ x st -> x Prelude.>>= \ x' -> prim_do f x' st)
(\ st -> Prelude.return (IOValOr ref
(zipWith (\ i x -> x Prelude.>>= \ x' -> cont x' (st i))
......
[ForType "Socket" Nothing,ForFunction "prim_listenOn",ForFunction "listenOnFresh",ForFunction "prim_socketListen",ForFunction "prim_socketAccept",ForFunction "prim_waitForSocketAccept",ForFunction "prim_connectToSocket"]
\ No newline at end of file
[ForType "Socket" Nothing
,ForFunction "prim_listenOn"
,ForFunction "listenOnFresh"
,ForFunction "prim_socketListen"
,ForFunction "prim_socketAccept"
,ForFunction "prim_waitForSocketAccept"
,ForFunction "prim_connectToSocket"
]
import Network
import Network.Socket
import Control.Concurrent
import System.IO (Handle)
type C_Socket = Prim Socket
instance Read Socket where
instance Generate Socket where
genFree = error "no random sockets"
maxArity = error "no narrowing on sockets"
instance ConvertCH C_Int PortID where
toCurry (PortNumber i) = toCurry (toInteger i)
fromCurry i = PortNumber (fromInteger (fromCurry i))
prim_listenOn :: C_Int -> Result (C_IO C_Socket)
prim_listenOn = Curry.Module.Prelude.ioFunc1 listenOn
listenOnFresh :: Result (C_IO (T2 C_Int C_Socket))
listenOnFresh = Curry.Module.Prelude.ioFunc0 listenOnFreshPort
listenOnFreshPort :: IO (PortID,Socket)
listenOnFreshPort = do
s <- listenOn (PortNumber aNY_PORT)
p <- Network.socketPort s
Prelude.return (p,s)
prim_socketListen :: C_Socket -> C_Int -> Result (C_IO T0)
prim_socketListen = Curry.Module.Prelude.ioFunc2 listen
prim_socketAccept :: C_Socket -> Result (C_IO (T2 (List C_Char) C_Handle))
prim_socketAccept =
ioFunc1 (\ s -> do {(h,s,_) <- Network.accept s; Prelude.return (s,One h)})
prim_waitForSocketAccept :: C_Socket -> C_Int -> Result (C_IO (C_Maybe (T2 (List C_Char) C_Handle)))
prim_waitForSocketAccept = Curry.Module.Prelude.ioFunc2 wait
wait :: Socket -> Int -> IO (Maybe (String,IOHandle))
wait s t = do
mv <- newEmptyMVar
tacc <- forkIO (do {(h,s,_) <- Network.accept s; putMVar mv (Just (s,One h))})
ttim <- forkIO (do {threadDelay (t*1000); putMVar mv Nothing})
res <- takeMVar mv
maybe (killThread tacc) (\_ -> killThread ttim) res
Prelude.return res
prim_connectToSocket :: List C_Char -> C_Int -> Result (C_IO C_Handle)
prim_connectToSocket =
ioFunc2 (\ s i -> do {ct <- connectTo s i; Prelude.return (One ct)})
......@@ -50,7 +50,7 @@ getPID = ioFunc0 (do
Prelude.return (toInteger pid))
getProgName :: Result (C_IO (List C_Char))
getProgName = ioFunc0 (Curry.getProgName)
getProgName = ioFunc0 (Curry.RunTimeSystem.getProgName)
-- conform with haskell would be: SE.getProgName
prim_system :: (List C_Char) -> Result (C_IO C_Int)
......
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