From 01ff0985307c430af0fbce7c88ae83c9e7b3815c Mon Sep 17 00:00:00 2001 From: sudoer777 Date: Sat, 30 Sep 2023 03:57:03 -0500 Subject: [PATCH] Update Readme --- README.md | 6 ++++-- example/{1 => 1.hear} | 0 example/{2 => 2.hear} | 0 src/Main.hs | 6 +++--- src/{Forth => Main}/LLVMGen.hs | 4 ++-- src/{Forth/Parser.hs => Main/Parser/Megaparsec.hs} | 12 ++++++------ src/{Forth => Main}/Types/Expr.hs | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) rename example/{1 => 1.hear} (100%) rename example/{2 => 2.hear} (100%) rename src/{Forth => Main}/LLVMGen.hs (95%) rename src/{Forth/Parser.hs => Main/Parser/Megaparsec.hs} (74%) rename src/{Forth => Main}/Types/Expr.hs (75%) diff --git a/README.md b/README.md index e6b3a8f..8d68f4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # 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 @@ -12,7 +14,7 @@ Main repo: https://git.sudoer.ch/me/really-bad-compiler-in-haskell ## Run Instructions -- Use `stack run ` to run the program (for example, `stack run example/1`). +- Use `stack run ` 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`. ## To edit diff --git a/example/1 b/example/1.hear similarity index 100% rename from example/1 rename to example/1.hear diff --git a/example/2 b/example/2.hear similarity index 100% rename from example/2 rename to example/2.hear diff --git a/src/Main.hs b/src/Main.hs index 4bfc1b6..f8a556f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -7,9 +7,9 @@ module Main (main) where import Data.ByteString.Char8 qualified as B import Data.Text.Lazy.IO qualified as T -import Forth.LLVMGen -import Forth.Parser -import Forth.Types.Expr +import Main.LLVMGen +import Main.Parser.Megaparsec +import Main.Types.Expr import System.Environment import System.Process diff --git a/src/Forth/LLVMGen.hs b/src/Main/LLVMGen.hs similarity index 95% rename from src/Forth/LLVMGen.hs rename to src/Main/LLVMGen.hs index 662783b..38fe242 100644 --- a/src/Forth/LLVMGen.hs +++ b/src/Main/LLVMGen.hs @@ -4,10 +4,9 @@ -- 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 Forth.Types.Expr as Expr import LLVM (moduleLLVMAssembly, withModuleFromAST) import LLVM.AST hiding (function) import LLVM.AST.Type @@ -16,6 +15,7 @@ import LLVM.IRBuilder.Constant import LLVM.IRBuilder.Instruction import LLVM.IRBuilder.Module import LLVM.IRBuilder.Monad +import Main.Types.Expr as Expr getLLVM :: Expr -> Module getLLVM expr = diff --git a/src/Forth/Parser.hs b/src/Main/Parser/Megaparsec.hs similarity index 74% rename from src/Forth/Parser.hs rename to src/Main/Parser/Megaparsec.hs index 32247ba..e1c9f27 100644 --- a/src/Forth/Parser.hs +++ b/src/Main/Parser/Megaparsec.hs @@ -2,13 +2,13 @@ {-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE OverloadedStrings #-} -module Forth.Parser (parseExpr, ParseResult) where +module Main.Parser.Megaparsec (parseExpr, ParseResult) where import Control.Monad.Combinators.Expr import Data.Functor.Identity qualified import Data.Text.Lazy import Data.Void (Void) -import Forth.Types.Expr +import Main.Types.Expr import Text.Megaparsec as MP import Text.Megaparsec.Char as C 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 name f = InfixL (f <$ symbolParser name) --- prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a --- prefixOp name f = Prefix (f <$ symbolParser name) +prefixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a +prefixOp name f = Prefix (f <$ symbolParser name) --- postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a --- postfixOp name f = Postfix (f <$ symbolParser name) +postfixOp :: Text -> (a -> a) -> Operator (ParsecT Void Text Data.Functor.Identity.Identity) a +postfixOp name f = Postfix (f <$ symbolParser name) expr :: Parser Expr expr = makeExprParser term table diff --git a/src/Forth/Types/Expr.hs b/src/Main/Types/Expr.hs similarity index 75% rename from src/Forth/Types/Expr.hs rename to src/Main/Types/Expr.hs index 71dbcec..30f0a1d 100644 --- a/src/Forth/Types/Expr.hs +++ b/src/Main/Types/Expr.hs @@ -1,4 +1,4 @@ -module Forth.Types.Expr (Expr (..)) where +module Main.Types.Expr (Expr (..)) where data Expr = Lit Int