Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/infinite-recu…
Browse files Browse the repository at this point in the history
…rsion-handling
  • Loading branch information
AxelHumeau committed Jan 12, 2024
2 parents 1e7b3e4 + 807c1de commit ae29f21
Show file tree
Hide file tree
Showing 15 changed files with 1,024 additions and 251 deletions.
34 changes: 8 additions & 26 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,14 @@ jobs:
check_style:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clone Epitech Coding style
run: git clone https://github.com/Epitech/coding-style-checker.git
- name: Access cloned repository content
run: |
chmod +x ./coding-style-checker/coding-style.sh
./coding-style-checker/coding-style.sh . .
cat coding-style-reports.log
- name: Verify coding style
run: |
error=false
while IFS= read -r line; do
if [[ $line =~ (MAJOR|MINOR|INFO) ]]; then
IFS=': '
read -r -a array <<< "$line"
echo "::error title=Coding style error:: file:${array[0]}, line:${array[1]}, coding-style:${array[2]}-${array[3]}"
error=true
fi
done < coding-style-reports.log
if [ $error = true ]
then
exit 1
else
exit 0
fi
- uses: actions/checkout@v3
- name: Set up HLint
uses: haskell-actions/hlint-setup@v2
- name: Run HLint
uses: haskell-actions/hlint-run@v2
with:
path: '["LobsterLang/src/", "LobsterLang/app"]'
fail-on: warning
check_compilation:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ cabal.project.local~
.stack-work
glados
.vscode
output
11 changes: 11 additions & 0 deletions LobsterLang/LobsterLang.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ library
AST
AstEval
AstOptimizer
Compiler
Parse
Scope
SExpr
Expand All @@ -42,6 +43,9 @@ library
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base >=4.7 && <5
, binary
, bytestring
, utf8-string
default-language: Haskell2010

executable LobsterLang-exe
Expand All @@ -56,6 +60,9 @@ executable LobsterLang-exe
build-depends:
LobsterLang
, base >=4.7 && <5
, binary
, bytestring
, utf8-string
default-language: Haskell2010

test-suite LobsterLang-test
Expand All @@ -64,6 +71,7 @@ test-suite LobsterLang-test
other-modules:
AstEvalSpec
AstOptimizerSpec
CompilerSpec
VmSpec
Paths_LobsterLang
autogen-modules:
Expand All @@ -74,5 +82,8 @@ test-suite LobsterLang-test
build-depends:
LobsterLang
, base >=4.7 && <5
, binary
, bytestring
, hspec
, utf8-string
default-language: Haskell2010
53 changes: 32 additions & 21 deletions LobsterLang/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,58 @@ import Scope
import System.IO (isEOF)
import System.Exit (exitWith, ExitCode (ExitFailure))
import System.Environment (getArgs)
import qualified AstEval
import Control.Exception
import SExpr (SExpr)
import qualified AST
-- import Compiler

-- | Return a Result that contain the evaluation of our Lisp String
-- Takes as parameter the string that need to be evaluated and the Stack (Environment)
interpretateLisp :: AST.Ast -> [Scope.ScopeMb] -> Either String (Maybe AST.Ast, [Scope.ScopeMb])
interpretateLisp value stack = case AstEval.evalAst stack value of
(Left err, _) -> Left err
(Right res', stack') -> Right (res', stack')

-- | Infinite loop until EOF from the user
inputLoop :: [Scope.ScopeMb] -> IO ()
-- inputLoop = print
inputLoop stack = isEOF >>= \end -> if end then print "End of Interpretation GLaDOS" else
getLine >>= \line -> case runParser parseLisp (0, 0) line of
Left err -> print err >> exitWith (ExitFailure 84)
Right (res, _, _) -> interpretateInfo res stack
getLine >>= \line -> case runParser parseLobster (0, 0) line of
Left err -> putStrLn ("\ESC[34m\ESC[1mThe lobster is angry: " ++ err ++ "\ESC[0m") >> inputLoop stack
Right (res, [], _) -> interpretateInfo res stack
Right (_, _, pos) -> putStrLn ("\ESC[34m\ESC[1mThe lobster is angry: " ++ errorParsing pos ++ "\ESC[0m") >> inputLoop stack

interpretateInfo :: [SExpr] -> [Scope.ScopeMb] -> IO ()
interpretateInfo [] _ = putStr ""
interpretateInfo :: [AST.Ast] -> [Scope.ScopeMb] -> IO ()
interpretateInfo [] stack = inputLoop stack
interpretateInfo (x:xs) stack = case interpretateLisp x stack of
Left err -> print err
Left err -> putStrLn ("\ESC[31m\ESC[1mThe lobster is angry: " ++ err ++ "\ESC[0m") >> inputLoop stack
Right (res, stack') -> case res of
Nothing -> interpretateInfo xs stack'
Just value -> print value >> print stack' >> interpretateInfo xs stack'
Just value -> print value >> interpretateInfo xs stack'

compileInfo :: [AST.Ast] -> [Scope.ScopeMb] -> IO ()
compileInfo [] _ = putStr ""
compileInfo (x:xs) stack = case interpretateLisp x stack of
Left err -> putStrLn ("\ESC[31m\ESC[1mThe lobster is angry: " ++ err ++ "\ESC[0m") >> exitWith (ExitFailure 84)
Right (res, stack') -> case res of
Nothing -> compileInfo xs stack'
Just value -> print value >> compileInfo xs stack'

compileFile :: String -> IO ()
compileFile s = case runParser parseLisp (0, 0) s of
compileFile s = case runParser parseLobster (0, 0) s of
Left err -> print err >> exitWith (ExitFailure 84)
Right (res, _, _) -> interpretateInfo res []
Right (res, [], _) -> print res >> compileInfo res []
Right (_, _, (row, col)) -> print ("Error on parsing on '" ++ show row ++ "' '" ++ show col)
-- (Right (Just res), stack') -> let instructions = (astToInstructions (AST.Cond (Boolean True) (Value 1) (Just (AST.Call "CallHere" [(Value 0)])))) in showInstructions instructions >> writeCompiledInstructionsToFile "output" (compileInstructions instructions)


checkArgs :: [String] -> IO ()
checkArgs ("-i": _) = print "Launch Interpreter" >> inputLoop []
checkArgs [] = print "Launch Interpreter" >> inputLoop []
checkArgs (file:_) = either
(\_ -> print "File doesn't exist" >> exitWith (ExitFailure 84))
compileFile
=<< (try (readFile file) :: IO (Either SomeException String))
checkArgs _ = exitWith (ExitFailure 84)

-- | Main
main :: IO ()
main = getArgs >>= \argv -> checkArgs argv
-- inputLoop new = isEOF >>= \end -> if end then putStrLn "End of Interpretation GLaDOS" else
-- getLine >>= \line -> case parseLisp line new of
-- (Left err, _) -> putStrLn ("\ESC[31m\ESC[1mThe lobster is angry: " ++ err ++ "\ESC[0m") >> inputLoop new
-- (Right Nothing, stack) -> inputLoop stack
-- (Right (Just res), stack') -> print res >> inputLoop stack'

-- -- | Main
-- main :: IO ()
-- main = putStrLn "Start of Interpretation Lisp" >> inputLoop []
3 changes: 3 additions & 0 deletions LobsterLang/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ description: Please see the README on GitHub at <https://github.com/gith

dependencies:
- base >= 4.7 && < 5
- bytestring
- utf8-string
- binary

ghc-options:
- -Wall
Expand Down
17 changes: 1 addition & 16 deletions LobsterLang/src/AstEval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
-}

module AstEval
( sexprToAst,
evalAst,
( evalAst,
evalBiValOp,
evalBiBoolOp,
evalBiCompValOp,
Expand All @@ -16,22 +15,8 @@ where

import AST
import Data.Bifunctor
import SExpr
import Scope

-- | Convert a S-expression into an 'Ast',
-- return Nothing if the expression is invalid or Just the Ast
sexprToAst :: SExpr -> Maybe Ast
sexprToAst (SExpr.List [SExpr.Symbol "define", SExpr.Symbol s, t]) =
Define s <$> sexprToAst t
sexprToAst (SExpr.List (SExpr.Symbol f : xs)) =
Call f <$> mapM sexprToAst xs
sexprToAst (SExpr.List _) = Nothing
sexprToAst (SExpr.Value i) = Just (AST.Value i)
sexprToAst (SExpr.Symbol "true") = Just (Boolean True)
sexprToAst (SExpr.Symbol "false") = Just (Boolean False)
sexprToAst (SExpr.Symbol s) = Just (AST.Symbol s Nothing)

noEvaluationError :: String -> String
noEvaluationError s = "No evaluation in one or more parameters of " ++ s

Expand Down
Loading

0 comments on commit ae29f21

Please sign in to comment.