imperative-edsl-0.7.1: Deep embedding of imperative programs with code generation

Safe HaskellNone
LanguageHaskell2010

Language.Embedded.Backend.C

Contents

Description

C code generation for Program

Synopsis

Documentation

Utilities

namedType :: String -> Type Source #

Create a named type

viewNotExp :: Exp -> Maybe Exp Source #

Return the argument of a boolean negation expression

Code generation user interface

compile :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> String Source #

Compile a program to C code represented as a string. To compile the resulting C code, use something like

cc -std=c99 YOURPROGRAM.c

This function returns only the first (main) module. To get all C translation unit, use compileAll.

compileAll :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> [(String, String)] Source #

Compile a program to C modules, each one represented as a pair of a name and the code represented as a string. To compile the resulting C code, use something like

cc -std=c99 YOURPROGRAM.c

icompile :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source #

Compile a program to C code and print it on the screen. To compile the resulting C code, use something like

cc -std=c99 YOURPROGRAM.c

data ExternalCompilerOpts Source #

Constructors

ExternalCompilerOpts 

Fields

compileC Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to compile

-> IO FilePath

Path to the generated executable

Generate C code and use CC to compile it

compileAndCheck' :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => ExternalCompilerOpts -> Program instr (Param2 exp pred) a -> IO () Source #

Generate C code and use CC to check that it compiles (no linking)

compileAndCheck :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source #

Generate C code and use CC to check that it compiles (no linking)

runCompiled' :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => ExternalCompilerOpts -> Program instr (Param2 exp pred) a -> IO () Source #

Generate C code, use CC to compile it, and run the resulting executable

runCompiled :: (Interp instr CGen (Param2 exp pred), HFunctor instr) => Program instr (Param2 exp pred) a -> IO () Source #

Generate C code, use CC to compile it, and run the resulting executable

withCompiled' Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to compile

-> ((String -> IO String) -> IO b)

Function that has access to the compiled executable as a function

-> IO b 

Compile a program and make it available as an IO function from String to String (connected to stdin/stdout. respectively). Note that compilation only happens once, even if the IO function is used many times in the body.

withCompiled Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> Program instr (Param2 exp pred) a

Program to compile

-> ((String -> IO String) -> IO b)

Function that has access to the compiled executable as a function

-> IO b 

Compile a program and make it available as an IO function from String to String (connected to stdin/stdout. respectively). Note that compilation only happens once, even if the IO function is used many times in the body.

captureCompiled' Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to run

-> String

Input to send to stdin

-> IO String

Result from stdout

Like runCompiled' but with explicit input/output connected to stdin/stdout. Note that the program will be compiled every time the function is applied to a string. In order to compile once and run many times, use the function withCompiled'.

captureCompiled Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> Program instr (Param2 exp pred) a

Program to run

-> String

Input to send to stdin

-> IO String

Result from stdout

Like runCompiled but with explicit input/output connected to stdin/stdout. Note that the program will be compiled every time the function is applied to a string. In order to compile once and run many times, use the function withCompiled.

compareCompiled' Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> ExternalCompilerOpts 
-> Program instr (Param2 exp pred) a

Program to run

-> IO a

Reference program

-> String

Input to send to stdin

-> IO () 

Compare the content written to stdout from the reference program and from running the compiled C code

compareCompiled Source #

Arguments

:: (Interp instr CGen (Param2 exp pred), HFunctor instr) 
=> Program instr (Param2 exp pred) a

Program to run

-> IO a

Reference program

-> String

Input to send to stdin

-> IO () 

Compare the content written to stdout from the reference program and from running the compiled C code

class Default a where #

A class for types with a default value.

Methods

def :: a #

The default value for this type.

Instances

Default Double 

Methods

def :: Double #

Default Float 

Methods

def :: Float #

Default Int 

Methods

def :: Int #

Default Int8 

Methods

def :: Int8 #

Default Int16 

Methods

def :: Int16 #

Default Int32 

Methods

def :: Int32 #

Default Int64 

Methods

def :: Int64 #

Default Integer 

Methods

def :: Integer #

Default Ordering 

Methods

def :: Ordering #

Default Word 

Methods

def :: Word #

Default Word8 

Methods

def :: Word8 #

Default Word16 

Methods

def :: Word16 #

Default Word32 

Methods

def :: Word32 #

Default Word64 

Methods

def :: Word64 #

Default () 

Methods

def :: () #

Default CShort 

Methods

def :: CShort #

Default CUShort 

Methods

def :: CUShort #

Default CInt 

Methods

def :: CInt #

Default CUInt 

Methods

def :: CUInt #

Default CLong 

Methods

def :: CLong #

Default CULong 

Methods

def :: CULong #

Default CLLong 

Methods

def :: CLLong #

Default CULLong 

Methods

def :: CULLong #

Default CFloat 

Methods

def :: CFloat #

Default CDouble 

Methods

def :: CDouble #

Default CPtrdiff 

Methods

def :: CPtrdiff #

Default CSize 

Methods

def :: CSize #

Default CSigAtomic 

Methods

def :: CSigAtomic #

Default CClock 

Methods

def :: CClock #

Default CTime 

Methods

def :: CTime #

Default CUSeconds 

Methods

def :: CUSeconds #

Default CSUSeconds 

Methods

def :: CSUSeconds #

Default CIntPtr 

Methods

def :: CIntPtr #

Default CUIntPtr 

Methods

def :: CUIntPtr #

Default CIntMax 

Methods

def :: CIntMax #

Default CUIntMax 

Methods

def :: CUIntMax #

Default All 

Methods

def :: All #

Default Any 

Methods

def :: Any #

Default ExternalCompilerOpts # 
Default [a] 

Methods

def :: [a] #

Default (Maybe a) 

Methods

def :: Maybe a #

Integral a => Default (Ratio a) 

Methods

def :: Ratio a #

Default a => Default (IO a) 

Methods

def :: IO a #

(Default a, RealFloat a) => Default (Complex a) 

Methods

def :: Complex a #

Default a => Default (Dual a) 

Methods

def :: Dual a #

Default (Endo a) 

Methods

def :: Endo a #

Num a => Default (Sum a) 

Methods

def :: Sum a #

Num a => Default (Product a) 

Methods

def :: Product a #

Default (First a) 

Methods

def :: First a #

Default (Last a) 

Methods

def :: Last a #

Default r => Default (e -> r) 

Methods

def :: e -> r #

(Default a, Default b) => Default (a, b) 

Methods

def :: (a, b) #

(Default a, Default b, Default c) => Default (a, b, c) 

Methods

def :: (a, b, c) #

(Default a, Default b, Default c, Default d) => Default (a, b, c, d) 

Methods

def :: (a, b, c, d) #

(Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) 

Methods

def :: (a, b, c, d, e) #

(Default a, Default b, Default c, Default d, Default e, Default f) => Default (a, b, c, d, e, f) 

Methods

def :: (a, b, c, d, e, f) #

(Default a, Default b, Default c, Default d, Default e, Default f, Default g) => Default (a, b, c, d, e, f, g) 

Methods

def :: (a, b, c, d, e, f, g) #