module Language.Copilot.AdHocC (
varDecl, includeBracket, includeQuote,
printf, printfNewline
) where
import Data.List (intersperse)
import Language.Atom (Type(..))
import Language.Atom.Code (cType)
varDecl :: Type -> [String] -> String
varDecl t vars =
cType' t ++ " " ++ (unwords (intersperse "," vars)) ++ ";"
where
cType' Bool = "int"
cType' typ = cType typ
includeBracket :: String -> String
includeBracket lib = "#include <" ++ lib ++ ">"
includeQuote :: String -> String
includeQuote lib = "#include \"" ++ lib ++ "\""
printfPre :: String -> String
printfPre = ("printf(\"" ++)
printfPost :: [String] -> String
printfPost vars =
let sep = if null vars then " " else ", "
in "\"" ++ sep ++ unwords (intersperse "," vars) ++ ");"
newline :: String
newline = "\\n"
printf, printfNewline :: String -> [String] -> String
printfNewline text vars = (printfPre text) ++ newline ++ (printfPost vars)
printf text vars = (printfPre text) ++ (printfPost vars)