Allow multiple print statements
parent
bdbe823bc3
commit
e145e91074
|
@ -1 +1 @@
|
|||
(5*(3-2)+-4-4)
|
||||
print(5*(3-2)+-4-4);
|
|
@ -1 +1,2 @@
|
|||
(6+8/3)
|
||||
print(6+8/3);
|
||||
print(5000);
|
|
@ -56,7 +56,7 @@ getString str = do
|
|||
modify $ \env -> env {strings = M.insert str operand (strings env)}
|
||||
return operand
|
||||
|
||||
getLLVM :: Expr -> Module
|
||||
getLLVM :: [Expr] -> Module
|
||||
getLLVM expr =
|
||||
flip evalState (Env {operands = M.empty, strings = M.empty}) $
|
||||
buildModuleT "program" $ mdo
|
||||
|
@ -66,7 +66,7 @@ getLLVM expr =
|
|||
function "main" [] i32 $ \_ -> mdo
|
||||
printNumStr <- globalStringPtr "%d\n" (mkName "str")
|
||||
lift $ registerString "%d\n" $ ConstantOperand printNumStr
|
||||
_ <- exprToLLVM expr
|
||||
_ <- forM_ expr exprToLLVM
|
||||
ret $ int32 0
|
||||
|
||||
--
|
||||
|
@ -109,7 +109,7 @@ exprToLLVM (Expr.Div a b) = mdo
|
|||
primToLLVM :: Int -> Operand
|
||||
primToLLVM i = int32 $ fromIntegral i
|
||||
|
||||
llvmGen :: Expr -> IO ByteString
|
||||
llvmGen :: [Expr] -> IO ByteString
|
||||
llvmGen expr = do
|
||||
let l = getLLVM expr
|
||||
withContext $ \c -> withModuleFromAST c l moduleLLVMAssembly
|
|
@ -64,10 +64,13 @@ methodOp name f = Prefix $ f <$ (string name <* C.space)
|
|||
expr :: Parser Expr
|
||||
expr = makeExprParser term table
|
||||
|
||||
parseExpr :: Text -> Either (ParseErrorBundle Text Void) Expr
|
||||
parseExpr = MP.parse (C.space *> expr <* eof) ""
|
||||
statement :: Parser Expr
|
||||
statement = expr <* symbol ";"
|
||||
|
||||
parse :: Text -> Expr
|
||||
parseExpr :: Text -> Either (ParseErrorBundle Text Void) [Expr]
|
||||
parseExpr = MP.parse (C.space *> many statement <* eof) ""
|
||||
|
||||
parse :: Text -> [Expr]
|
||||
parse t =
|
||||
case parseExpr t of
|
||||
Right r -> r
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
module Main.Type (Expr (..)) where
|
||||
module Main.Type
|
||||
( Expr (..),
|
||||
-- AST (..)
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Graph (Tree (Node))
|
||||
|
||||
data Expr
|
||||
= Lit Int
|
||||
|
@ -11,3 +17,14 @@ data Expr
|
|||
deriving
|
||||
( Show
|
||||
)
|
||||
|
||||
-- data AST = AST Node
|
||||
|
||||
-- data Node
|
||||
-- = Reg
|
||||
-- { cur :: Expr,
|
||||
-- next :: Node
|
||||
-- }
|
||||
-- | End
|
||||
-- { cur :: Expr
|
||||
-- }
|
Reference in New Issue