Skip to content

Commit 3333d28

Browse files
committed
Cosmetic mostly.
1 parent 01276ea commit 3333d28

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

app/Main.hs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1-
module Main (main) where
1+
{-# LANGUAGE LambdaCase #-}
22

3-
import Lib
3+
import System.Environment ( getArgs )
4+
import Control.Monad.Except ( runExceptT)
5+
import CompilationEngine (Exec, readTheFile, parseProgram, semanticAnalysis, convertAstToIast, typeCheck, generateCode)
6+
import System.IO
7+
8+
compile :: FilePath -> Exec String
9+
compile filePath = readTheFile filePath
10+
>>= parseProgram
11+
>>= semanticAnalysis
12+
>>= convertAstToIast
13+
>>= typeCheck
14+
>>= generateCode
15+
16+
lastN :: Int -> [a] -> [a]
17+
lastN n xs = drop (length xs - n) xs
418

519
main :: IO ()
6-
main = someFunc
20+
main = do
21+
args <- getArgs
22+
if length args == 1 && last3 (head args) == ".lq"
23+
then
24+
do
25+
let filePath = head args
26+
runExceptT (compile filePath) >>= \case
27+
Left err -> putStrLn $ "Error: " ++ show err ++ "!"
28+
Right code ->
29+
do
30+
handle <- openFile outputFile ReadMode
31+
putStr code
32+
hClose handle
33+
where
34+
outputFile = filePath ++ ".qasm"
35+
else
36+
putStrLn "Please supply one argument: a path to a lambdaQ program file!"
37+
where
38+
last3 = lastN 3

lambdaQ.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.1.
3+
-- This file has been generated from package.yaml by hpack version 0.36.0.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -38,7 +38,6 @@ library
3838
Frontend.LambdaQ.Print
3939
Frontend.LambdaQ.Skel
4040
Frontend.LambdaQ.Test
41-
Lib
4241
other-modules:
4342
Paths_lambdaQ
4443
hs-source-dirs:

src/Lib.hs

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/Backend/ASTtoIASTConverterSpec.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,14 @@ spec = do
214214
result `shouldSatisfy` (\str -> "TermQuantumCtrlsGate TermVariable (Var ((3,22),q1)),TermVariable (Var ((3,28),q3)),TermVariable (Var ((3,34),q4)) BasisStateOne,BasisStateOne,BasisStateOne)" `isInfixOf` str)
215215
result `shouldSatisfy` (\str -> "(TermGate GateY)) (TermVariable (Var ((3,67),q2)))" `isInfixOf` str)
216216

217+
-- do let single
218+
-- do let sugar single
219+
-- do let multiple
220+
217221
context "when provided with a small program fragment" $ do
218222
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
219-
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_15.lq"
223+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_18.lq"
220224
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
221225
result `shouldSatisfy` (\str -> "TypeQbit" `isInfixOf` str)
222-
result `shouldSatisfy` (\str -> "TermApply (TermNew (2,7)) (TermBasisState BasisStateZero)" `isInfixOf` str)
226+
result `shouldSatisfy` (\str -> "TermApply (TermNew (2,7)) (TermBasisState BasisStateZero)" `isInfixOf` str)
227+

0 commit comments

Comments
 (0)