The output directory is now cleared when the program is ran.

This commit is contained in:
Samuel Hammersberg 2023-02-20 15:27:13 +01:00
parent a36de2bde1
commit cd0f9dd456
2 changed files with 29 additions and 11 deletions

View file

@ -19,16 +19,32 @@
-- main = apply (krimp) 2 3; -- main = apply (krimp) 2 3;
-- answer: 5 -- answer: 5
fibbonaci : Int -> Int; -- fibbonaci : Int -> Int;
fibbonaci x = case x of { -- fibbonaci x = case x of {
0 => 0, -- 0 => 0,
1 => 1, -- 1 => 1,
-- abusing overflows to represent negatives like a boss -- -- abusing overflows to represent negatives like a boss
_ => (fibbonaci (x - 2)) -- _ => (fibbonaci (x - 2))
+ (fibbonaci (x - 1)) -- + (fibbonaci (x - 1))
-- } : Int;
-- main : Int;
-- main = fibbonaci 10;
-- answer: 55
succ : Int -> Int;
succ x = x - 1;
isZero : Int -> Int;
isZero x = case x of {
0 => 1,
_ => 0
} : Int; } : Int;
minimization : (Int -> Int) -> Int -> Int;
minimization p x = case p x of {
1 => 0,
_ => minimization p (succ x)
} : Int;
main : Int; main : Int;
main = fibbonaci 10; main = minimization isZero 10;
-- answer: 55

View file

@ -14,7 +14,8 @@ import Data.List.Extra (isSuffixOf)
import LambdaLifter (lambdaLift) import LambdaLifter (lambdaLift)
import Renamer (rename) import Renamer (rename)
import System.Directory (createDirectory, doesPathExist, import System.Directory (createDirectory, doesPathExist,
getDirectoryContents, getDirectoryContents, removeDirectory,
removeDirectoryRecursive,
setCurrentDirectory) setCurrentDirectory)
import System.Environment (getArgs) import System.Environment (getArgs)
import System.Exit (exitFailure, exitSuccess) import System.Exit (exitFailure, exitSuccess)
@ -54,7 +55,8 @@ main' debug s = do
--putStrLn compiled --putStrLn compiled
check <- doesPathExist "output" check <- doesPathExist "output"
unless check (createDirectory "output") when check (removeDirectoryRecursive "output")
createDirectory "output"
writeFile "output/llvm.ll" compiled writeFile "output/llvm.ll" compiled
if debug then debugDotViz else putStrLn compiled if debug then debugDotViz else putStrLn compiled