diff --git a/sample-programs/basic-1 b/sample-programs/basic-1 index 7a458eb..a88960b 100644 --- a/sample-programs/basic-1 +++ b/sample-programs/basic-1 @@ -31,20 +31,36 @@ -- main = fibbonaci 10; -- answer: 55 -succ : Int -> Int; -succ x = x - 1; +-- succ : Int -> Int; +-- succ x = x - 1; +-- +-- isZero : Int -> Int; +-- isZero x = case x of { +-- 0 => 1, +-- _ => 0 +-- } : Int; +-- +-- minimization : (Int -> Int) -> Int -> Int; +-- minimization p x = case p x of { +-- 1 => 0, +-- _ => minimization p (succ x) +-- } : Int; +-- +-- main : Int; +-- main = minimization isZero 10; +-- answer: 0 -isZero : Int -> Int; -isZero x = case x of { - 0 => 1, - _ => 0 +posMul : Int -> Int -> Int; +posMul a b = case b of { + 0 => 0, + _ => a + posMul a (b - 1) } : Int; -minimization : (Int -> Int) -> Int -> Int; -minimization p x = case p x of { - 1 => 0, - _ => minimization p (succ x) +facc : Int -> Int; +facc a = case a of { + 1 => 1, + _ => posMul a (facc (a - 1)) } : Int; main : Int; -main = minimization isZero 10; \ No newline at end of file +main = facc 27 \ No newline at end of file diff --git a/src/LlvmIr.hs b/src/LlvmIr.hs index 5c5532a..68f45f2 100644 --- a/src/LlvmIr.hs +++ b/src/LlvmIr.hs @@ -136,7 +136,7 @@ llvmIrToString = go 0 replicate i '\t' <> case l of (Define t (Ident i) params) -> concat - [ "define ", show t, " @", i + [ "define fastcc ", show t, " @", i , "(", intercalate ", " (map (\(Ident y, x) -> unwords [show x, "%" <> y]) params) , ") {\n" ] @@ -170,7 +170,7 @@ llvmIrToString = go 0 ] (Call t vis (Ident i) arg) -> concat - [ "call ", show t, " ", show vis, i, "(" + [ "call fastcc ", show t, " ", show vis, i, "(" , intercalate ", " $ Prelude.map (\(x, y) -> show x <> " " <> show y) arg , ")\n" ]