From 7f588ec5611e308ebfe69715d5babf7adbb8fc37 Mon Sep 17 00:00:00 2001 From: sudoer777 Date: Fri, 29 Sep 2023 18:01:47 -0500 Subject: [PATCH] Reorganize program --- package.yaml | 2 +- really-bad-compiler-in-haskell.cabal | 8 ++++---- {main/Compiler => src/Forth}/LLVMGen.hs | 9 +++------ main/Parser/Expr.hs => src/Forth/Parser.hs | 4 ++-- {main => src/Forth}/Types/Expr.hs | 2 +- {main => src}/Main.hs | 7 ++++--- 6 files changed, 15 insertions(+), 17 deletions(-) rename {main/Compiler => src/Forth}/LLVMGen.hs (89%) rename main/Parser/Expr.hs => src/Forth/Parser.hs (91%) rename {main => src/Forth}/Types/Expr.hs (71%) rename {main => src}/Main.hs (91%) diff --git a/package.yaml b/package.yaml index 99c82b0..84d4766 100644 --- a/package.yaml +++ b/package.yaml @@ -19,7 +19,7 @@ ghc-options: -threaded -Wall -j8 +RTS -A64M -RTS -fllvm # source-dirs: src executable: - source-dirs: main + source-dirs: src main: Main.hs # tests: # testall: diff --git a/really-bad-compiler-in-haskell.cabal b/really-bad-compiler-in-haskell.cabal index d82f626..d55ad95 100644 --- a/really-bad-compiler-in-haskell.cabal +++ b/really-bad-compiler-in-haskell.cabal @@ -16,12 +16,12 @@ tested-with: executable really-bad-compiler-in-haskell main-is: Main.hs other-modules: - Compiler.LLVMGen - Parser.Expr - Types.Expr + Forth.LLVMGen + Forth.Parser + Forth.Types.Expr Paths_really_bad_compiler_in_haskell hs-source-dirs: - main + src default-extensions: OverloadedStrings, LambdaCase ghc-options: -threaded -Wall -j8 +RTS -A64M -RTS -fllvm diff --git a/main/Compiler/LLVMGen.hs b/src/Forth/LLVMGen.hs similarity index 89% rename from main/Compiler/LLVMGen.hs rename to src/Forth/LLVMGen.hs index d36277d..662783b 100644 --- a/main/Compiler/LLVMGen.hs +++ b/src/Forth/LLVMGen.hs @@ -4,13 +4,11 @@ -- see https://gh.sudoer.ch/danieljharvey/mimsa/blob/trunk/llvm-calc/src/Calc/Compile/ToLLVM.hs -module Compiler.LLVMGen (llvmGen) where - --- import LLVM.Pretty +module Forth.LLVMGen (llvmGen) where import Data.ByteString (ByteString) -import Debug.Trace -import LLVM (moduleLLVMAssembly, withModuleFromAST, writeLLVMAssemblyToFile) +import Forth.Types.Expr as Expr +import LLVM (moduleLLVMAssembly, withModuleFromAST) import LLVM.AST hiding (function) import LLVM.AST.Type import LLVM.Context @@ -18,7 +16,6 @@ import LLVM.IRBuilder.Constant import LLVM.IRBuilder.Instruction import LLVM.IRBuilder.Module import LLVM.IRBuilder.Monad -import Types.Expr as Expr getLLVM :: Expr -> Module getLLVM expr = diff --git a/main/Parser/Expr.hs b/src/Forth/Parser.hs similarity index 91% rename from main/Parser/Expr.hs rename to src/Forth/Parser.hs index a2f3f4c..d2726c7 100644 --- a/main/Parser/Expr.hs +++ b/src/Forth/Parser.hs @@ -1,15 +1,15 @@ -- see https://markkarpov.com/tutorial/megaparsec.html {-# LANGUAGE ImportQualifiedPost #-} -module Parser.Expr (parseExpr, ParseResult) where +module Forth.Parser (parseExpr, ParseResult) where import Control.Monad.Combinators.Expr import Data.Functor.Identity qualified import Data.Void (Void) +import Forth.Types.Expr import Text.Megaparsec as MP import Text.Megaparsec.Char as C import Text.Megaparsec.Char.Lexer as L -import Types.Expr type Parser = Parsec Void String diff --git a/main/Types/Expr.hs b/src/Forth/Types/Expr.hs similarity index 71% rename from main/Types/Expr.hs rename to src/Forth/Types/Expr.hs index 51c8925..ff8741d 100644 --- a/main/Types/Expr.hs +++ b/src/Forth/Types/Expr.hs @@ -1,4 +1,4 @@ -module Types.Expr (Expr (..)) where +module Forth.Types.Expr (Expr (..)) where data Expr = Lit Int diff --git a/main/Main.hs b/src/Main.hs similarity index 91% rename from main/Main.hs rename to src/Main.hs index dda57c6..d0795c1 100644 --- a/main/Main.hs +++ b/src/Main.hs @@ -4,13 +4,14 @@ module Main (main) where -- import Compiler.ExeGen -import Compiler.LLVMGen + import Data.ByteString.Char8 qualified as B import Data.Text.Lazy.IO qualified as T -import Parser.Expr +import Forth.LLVMGen +import Forth.Parser +import Forth.Types.Expr import System.Environment import System.Process -import Types.Expr getRight :: ParseResult -> Expr getRight (Right r) = r