This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Enable to convert from Source syntax
- Loading branch information
Showing
6 changed files
with
59 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Mlx1 where | ||
|
||
import Compile (compileIntermediateFile) | ||
import Reporting.Report (printReport) | ||
|
||
import System.Environment (getArgs) | ||
|
||
|
||
main :: IO () | ||
main = do | ||
args <- getArgs | ||
result <- compileIntermediateFile Nothing $ head args | ||
case result of | ||
Right output -> putStrLn output | ||
Left err -> printReport err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
module Compile where | ||
|
||
import qualified AST.Intermediate as I | ||
import Config (Config, loadConfigFile, | ||
loadDefaultConfigFile) | ||
import qualified Dictionary (compile) | ||
import qualified Emit (emit) | ||
import qualified Overload (compile) | ||
import qualified Parse (parseIntermediate) | ||
import qualified Parse (parseIntermediate, parseSource) | ||
import Reporting.Result (Result) | ||
|
||
import Control.Monad ((<=<)) | ||
import Control.Monad (join, (<=<)) | ||
import Data.Text | ||
import qualified Data.Text.IO as T | ||
|
||
|
||
compileFile :: Maybe FilePath -> FilePath -> IO (Result String) | ||
compileFile mconfig file = do | ||
compileSourceFile :: Maybe FilePath -> FilePath -> IO (Result String) | ||
compileSourceFile = compileFile (Dictionary.compile <=< Parse.parseSource) | ||
|
||
compileIntermediateFile :: Maybe FilePath -> FilePath -> IO (Result String) | ||
compileIntermediateFile = compileFile Parse.parseIntermediate | ||
|
||
compileFile :: (Text -> Result I.Expr) -> Maybe FilePath -> FilePath -> IO (Result String) | ||
compileFile f mconfig file = do | ||
config <- maybe loadDefaultConfigFile loadConfigFile mconfig | ||
content <- T.readFile file | ||
return $ flip compile content =<< config | ||
return . join $ compile <$> config <*> f content | ||
|
||
compile :: Config -> Text -> Result String | ||
compile c = fmap Emit.emit . Overload.compile c <=< Parse.parseIntermediate | ||
compile :: Config -> I.Expr -> Result String | ||
compile c = fmap Emit.emit . Overload.compile c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Dictionary where | ||
|
||
import qualified AST.Intermediate as T | ||
import qualified AST.Source as S | ||
|
||
import Reporting.Result (Result) | ||
|
||
|
||
compile :: S.Expr -> Result T.Expr | ||
compile = undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters