Update Readme
parent
e7083c1c40
commit
01ff098530
|
@ -1,6 +1,8 @@
|
||||||
# Really Bad Compiler in Haskell
|
# Really Bad Compiler in Haskell
|
||||||
|
|
||||||
A compiler written in Haskell which can currently perform basic arithmetic. Currently using the megaparsec and llvm-hs-\* libraries, but I may reimplement certain libraries myself. Built for the Introduction to Compiler Design class at The University of Texas at Dallas.
|
A compiler for Hear, a language for when you cannot C.
|
||||||
|
|
||||||
|
Written in Haskell, and currently using the megaparsec and llvm-hs-\* libraries, but I plan to eventually rewrite the lexar/parser from scratch. Built for the Introduction to Compiler Design class at The University of Texas at Dallas.
|
||||||
|
|
||||||
Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell
|
Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell
|
||||||
|
|
||||||
## Run Instructions
|
## Run Instructions
|
||||||
|
|
||||||
- Use `stack run <file>` to run the program (for example, `stack run example/1`).
|
- Use `stack run <file>` to run the program (for example, `stack run example/1.hear`).
|
||||||
- The LLVM will be generated as `a.out.ll`, and the executable will be generated as `a.out`.
|
- The LLVM will be generated as `a.out.ll`, and the executable will be generated as `a.out`.
|
||||||
|
|
||||||
## To edit
|
## To edit
|
||||||
|
|
|
@ -7,9 +7,9 @@ module Main (main) where
|
||||||
|
|
||||||
import Data.ByteString.Char8 qualified as B
|
import Data.ByteString.Char8 qualified as B
|
||||||
import Data.Text.Lazy.IO qualified as T
|
import Data.Text.Lazy.IO qualified as T
|
||||||
import Forth.LLVMGen
|
import Main.LLVMGen
|
||||||
import Forth.Parser
|
import Main.Parser.Megaparsec
|
||||||
import Forth.Types.Expr
|
import Main.Types.Expr
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Process
|
import System.Process
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
|
|
||||||
-- see https://gh.sudoer.ch/danieljharvey/mimsa/blob/trunk/llvm-calc/src/Calc/Compile/ToLLVM.hs
|
-- see https://gh.sudoer.ch/danieljharvey/mimsa/blob/trunk/llvm-calc/src/Calc/Compile/ToLLVM.hs
|
||||||
|
|
||||||
module Forth.LLVMGen (llvmGen) where
|
module Main.LLVMGen (llvmGen) where
|
||||||
|
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Forth.Types.Expr as Expr
|
|
||||||
import LLVM (moduleLLVMAssembly, withModuleFromAST)
|
import LLVM (moduleLLVMAssembly, withModuleFromAST)
|
||||||
import LLVM.AST hiding (function)
|
import LLVM.AST hiding (function)
|
||||||
import LLVM.AST.Type
|
import LLVM.AST.Type
|
||||||
|
@ -16,6 +15,7 @@ import LLVM.IRBuilder.Constant
|
||||||
import LLVM.IRBuilder.Instruction
|
import LLVM.IRBuilder.Instruction
|
||||||
import LLVM.IRBuilder.Module
|
import LLVM.IRBuilder.Module
|
||||||
import LLVM.IRBuilder.Monad
|
import LLVM.IRBuilder.Monad
|
||||||
|
import Main.Types.Expr as Expr
|
||||||
|
|
||||||
getLLVM :: Expr -> Module
|
getLLVM :: Expr -> Module
|
||||||
getLLVM expr =
|
getLLVM expr =
|
|
@ -2,13 +2,13 @@
|
||||||
{-# LANGUAGE ImportQualifiedPost #-}
|
{-# LANGUAGE ImportQualifiedPost #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Forth.Parser (parseExpr, ParseResult) where
|
module Main.Parser.Megaparsec (parseExpr, ParseResult) where
|
||||||
|
|
||||||
import Control.Monad.Combinators.Expr
|
import Control.Monad.Combinators.Expr
|
||||||
import Data.Functor.Identity qualified
|
import Data.Functor.Identity qualified
|
||||||
import Data.Text.Lazy
|
import Data.Text.Lazy
|
||||||
import Data.Void (Void)
|
import Data.Void (Void)
|
||||||
import Forth.Types.Expr
|
import Main.Types.Expr
|
||||||
import Text.Megaparsec as MP
|
import Text.Megaparsec as MP
|
||||||
import Text.Megaparsec.Char as C
|
import Text.Megaparsec.Char as C
|
||||||
import Text.Megaparsec.Char.Lexer as L
|
import Text.Megaparsec.Char.Lexer as L
|
||||||
|
@ -41,11 +41,11 @@ table =
|
||||||
binaryOp :: Text -> (a -> a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
binaryOp :: Text -> (a -> a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||||
binaryOp name f = InfixL (f <$ symbolParser name)
|
binaryOp name f = InfixL (f <$ symbolParser name)
|
||||||
|
|
||||||
-- prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||||
-- prefixOp name f = Prefix (f <$ symbolParser name)
|
prefixOp name f = Prefix (f <$ symbolParser name)
|
||||||
|
|
||||||
-- postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a
|
||||||
-- postfixOp name f = Postfix (f <$ symbolParser name)
|
postfixOp name f = Postfix (f <$ symbolParser name)
|
||||||
|
|
||||||
expr :: Parser Expr
|
expr :: Parser Expr
|
||||||
expr = makeExprParser term table
|
expr = makeExprParser term table
|
|
@ -1,4 +1,4 @@
|
||||||
module Forth.Types.Expr (Expr (..)) where
|
module Main.Types.Expr (Expr (..)) where
|
||||||
|
|
||||||
data Expr
|
data Expr
|
||||||
= Lit Int
|
= Lit Int
|
Reference in New Issue