Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe1cd74
commit 9a0b734
Showing
13 changed files
with
145 additions
and
68 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.stack-work/ | ||
compiler-demo.cabal | ||
keli-compiler.cabal | ||
*~ | ||
youtube |
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,3 +1,3 @@ | ||
# Changelog for compiler-demo | ||
# Changelog for keli-compiler | ||
|
||
## Unreleased changes |
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,7 +1,8 @@ | ||
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-} -- for exhasutive pattern checking | ||
module Main where | ||
|
||
import Keli | ||
import Repl | ||
import Cli | ||
|
||
main :: IO () | ||
main = print "hello world" | ||
main = keliRepl |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Cli where | ||
|
||
import Text.Pretty.Simple (pPrint) | ||
import StaticError | ||
import Interpreter | ||
|
||
|
||
cli :: String -> IO (Either KeliError String) | ||
cli filename = do | ||
contents <- readFile filename | ||
keliInterpret contents |
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 Compiler where | ||
|
||
import Data.List | ||
|
||
import StaticError | ||
import Analyzer | ||
import Parser | ||
import Transpiler | ||
|
||
|
||
keliCompile :: String -> Either KeliError String | ||
keliCompile input | ||
= keliParse input | ||
>>= analyze | ||
>>= \symbols -> return (keliTranspile symbols) |
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,25 @@ | ||
module Interpreter where | ||
|
||
import StaticError | ||
import Compiler | ||
import System.Process | ||
|
||
|
||
getBaseCode :: IO String | ||
getBaseCode = readFile "./kelilib/base.keli" | ||
|
||
|
||
keliInterpret :: String -> IO (Either KeliError String) | ||
keliInterpret contents = do | ||
baseCode <- getBaseCode | ||
-- baseCode is loaded automaticall by default | ||
case (keliCompile $ baseCode ++ contents) of | ||
Right code -> do | ||
-- pPrint code | ||
output <- keliExecute code | ||
return (Right output) | ||
|
||
Left err -> return (Left err) | ||
|
||
keliExecute :: String -> IO String | ||
keliExecute code = readProcess "node" ["-e", code] [] |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Repl where | ||
|
||
import System.IO | ||
import Control.Monad | ||
import Parser | ||
import Analyzer | ||
import Symbol | ||
import Interpreter | ||
import StaticError | ||
import Transpiler | ||
|
||
keliRead :: IO String | ||
keliRead | ||
= putStr "keli > " | ||
>> hFlush stdout | ||
>> getLine | ||
|
||
keliEval :: (KeliSymTab, String) -> String -> Either KeliError (IO String, (KeliSymTab, String)) | ||
keliEval (prevSymtab, prevBytecode) input | ||
= keliParse input >>= | ||
analyzeDecls prevSymtab >>= \(newSymtab, symbols) -> | ||
let newBytecodeToBeExecuted = keliTranspile symbols in | ||
|
||
let onlyDeclarationSymbols = filter (\s -> case s of KeliSymInlineExprs {} -> False; _ -> True) symbols in | ||
let newByteCodeToBePassFoward = keliTranspile onlyDeclarationSymbols in | ||
Right (keliExecute (prevBytecode ++ newBytecodeToBeExecuted), (newSymtab, newByteCodeToBePassFoward)) | ||
|
||
|
||
|
||
|
||
keliPrint :: String -> IO () | ||
keliPrint = putStrLn | ||
|
||
keliRepl' :: KeliSymTab -> String -> IO () | ||
keliRepl' prevSymtab prevBytecode = do | ||
input <- keliRead | ||
unless (input == ":quit") | ||
(case keliEval (prevSymtab, prevBytecode) input of | ||
Right (evaluatedOutput, (newSymtab,newBytecode)) -> | ||
evaluatedOutput >>= keliPrint >> keliRepl' newSymtab (prevBytecode ++ newBytecode) | ||
Left err -> | ||
keliPrint (show err) >> keliRepl' prevSymtab prevBytecode) | ||
|
||
|
||
|
||
|
||
keliRepl :: IO () | ||
keliRepl = keliRepl' emptyKeliSymTab "" |
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