+evalProg :: AST.Program -> IO (Maybe Float)
+evalProg (AST.Program asts) = do
+ let eitherMdl = buildModuleT "main" $ mapM buildAST asts
+ case eitherMdl of
+ Left _ -> return Nothing
+ Right mdl -> withContext $ \ctx ->
+ withMCJIT ctx Nothing Nothing Nothing Nothing $ \mcjit ->
+ withModuleFromAST ctx mdl $ \mdl' ->
+ withModuleInEngine mcjit mdl' $ \emdl -> do
+ Just f <- getFunction emdl "expr"
+ let f' = castFunPtr f :: FunPtr (IO Float)
+ Just <$> exprFun f'
+
+-- | Builds up programs at the top-level of an LLVM Module
+-- >>> evalProg (read "31 - 5")
+-- Just 26.0