module Feldspar.Run.Frontend
( Run
, MonadRun (..)
, module Feldspar.Run.Frontend
, module Language.Embedded.Imperative.Frontend.General
) where
import Language.Syntactic
import qualified Control.Monad.Operational.Higher as Oper
import Language.Embedded.Imperative.Frontend.General hiding (Ref, Arr, IArr)
import qualified Language.Embedded.Imperative as Imp
import qualified Language.Embedded.Imperative.CMD as Imp
import Data.TypedStruct
import Feldspar.Primitive.Representation
import Feldspar.Primitive.Backend.C ()
import Feldspar.Representation
import Feldspar.Run.Representation
unsafeSwap :: IsPointer a => a -> a -> Run ()
unsafeSwap a b = Run $ Imp.unsafeSwap a b
unsafeSwapArr :: Arr a -> Arr a -> Run ()
unsafeSwapArr arr1 arr2 = Run $ sequence_ $
zipListStruct Imp.unsafeSwap (unArr arr1) (unArr arr2)
fopen :: FilePath -> IOMode -> Run Handle
fopen file = Run . Imp.fopen file
fclose :: Handle -> Run ()
fclose = Run . Imp.fclose
feof :: Handle -> Run (Data Bool)
feof = Run . Imp.feof
class PrintfType r
where
fprf :: Handle -> String -> [Imp.PrintfArg Data] -> r
instance (a ~ ()) => PrintfType (Run a)
where
fprf h form = Run . Oper.singleInj . Imp.FPrintf h form . reverse
instance (Formattable a, PrimType a, PrintfType r) => PrintfType (Data a -> r)
where
fprf h form as = \a -> fprf h form (Imp.PrintfArg a : as)
fprintf :: PrintfType r => Handle -> String -> r
fprintf h format = fprf h format []
fput :: (Formattable a, PrimType a)
=> Handle
-> String
-> Data a
-> String
-> Run ()
fput h pre e post = Run $ Imp.fput h pre e post
fget :: (Formattable a, PrimType a) => Handle -> Run (Data a)
fget = Run . Imp.fget
printf :: PrintfType r => String -> r
printf = fprintf Imp.stdout
newPtr :: PrimType a => Run (Ptr a)
newPtr = newNamedPtr "p"
newNamedPtr :: PrimType a
=> String
-> Run (Ptr a)
newNamedPtr = Run . Imp.newNamedPtr
ptrToArr :: PrimType a => Ptr a -> Data Length -> Run (DArr a)
ptrToArr ptr len = fmap (Arr 0 len . Single) $ Run $ Imp.ptrToArr ptr
newObject
:: String
-> Bool
-> Run Object
newObject = newNamedObject "obj"
newNamedObject
:: String
-> String
-> Bool
-> Run Object
newNamedObject base t p = Run $ Imp.newNamedObject base t p
addInclude :: String -> Run ()
addInclude = Run . Imp.addInclude
addDefinition :: Imp.Definition -> Run ()
addDefinition = Run . Imp.addDefinition
addExternFun :: PrimType res
=> String
-> proxy res
-> [FunArg Data PrimType']
-> Run ()
addExternFun fun res args = Run $ Imp.addExternFun fun res args
addExternProc
:: String
-> [FunArg Data PrimType']
-> Run ()
addExternProc proc args = Run $ Imp.addExternProc proc args
callFun :: PrimType a
=> String
-> [FunArg Data PrimType']
-> Run (Data a)
callFun fun as = Run $ Imp.callFun fun as
callProc
:: String
-> [FunArg Data PrimType']
-> Run ()
callProc fun as = Run $ Imp.callProc fun as
callProcAssign :: Assignable obj
=> obj
-> String
-> [FunArg Data PrimType']
-> Run ()
callProcAssign obj fun as = Run $ Imp.callProcAssign obj fun as
externFun :: PrimType res
=> String
-> [FunArg Data PrimType']
-> Run (Data res)
externFun fun args = Run $ Imp.externFun fun args
externProc
:: String
-> [FunArg Data PrimType']
-> Run ()
externProc proc args = Run $ Imp.externProc proc args
inModule :: String -> Run () -> Run ()
inModule mod = Run . Imp.inModule mod . unRun
getTime :: Run (Data Double)
getTime = Run Imp.getTime
strArg :: String -> FunArg Data PrimType'
strArg = Imp.strArg
valArg :: PrimType' a => Data a -> FunArg Data PrimType'
valArg = Imp.valArg
refArg :: PrimType' (Internal a) => Ref a -> FunArg Data PrimType'
refArg (Ref r) = Imp.refArg (extractSingle r)
arrArg :: PrimType' (Internal a) => Arr a -> FunArg Data PrimType'
arrArg (Arr o _ a) = Imp.offset (Imp.arrArg (extractSingle a)) o
iarrArg :: PrimType' (Internal a) => IArr a -> FunArg Data PrimType'
iarrArg (IArr o _ a) = Imp.offset (Imp.iarrArg (extractSingle a)) o
objArg :: Object -> FunArg Data PrimType'
objArg = Imp.objArg
constArg
:: String
-> String
-> FunArg Data PrimType'
constArg = Imp.constArg
addr :: FunArg Data PrimType' -> FunArg Data PrimType'
addr = Imp.addr
deref :: FunArg Data PrimType' -> FunArg Data PrimType'
deref = Imp.deref