Skip to content

Commit

Permalink
Add fibonacci sequence example program (#1375)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman authored Jul 14, 2022
1 parent fc6a0bb commit cff0194
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions examples/milestone/Fibonacci/Fibonacci.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Fibonacci;

open import Stdlib.Prelude;

fib : ℕ → ℕ → ℕ → ℕ;
fib zero x1 _ ≔ x1;
fib (suc n) x1 x2 ≔ fib n x2 (x1 + x2);

fibonacci : ℕ → ℕ;
fibonacci n ≔ fib n 0 1;

main : IO;
main ≔ putStrLn (natToStr (fibonacci 25));

end;
2 changes: 2 additions & 0 deletions test/BackendC/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ standaloneArgs :: FilePath -> FilePath -> FilePath -> [String]
standaloneArgs sysrootPath wasmOutputFile cOutputFile =
[ "-nodefaultlibs",
"-std=c99",
"-Oz",
"-I",
takeDirectory minicRuntime,
"-I",
Expand All @@ -86,6 +87,7 @@ libcArgs :: FilePath -> FilePath -> FilePath -> [String]
libcArgs sysrootPath wasmOutputFile cOutputFile =
[ "-nodefaultlibs",
"-std=c99",
"-Oz",
"-I",
takeDirectory minicRuntime,
"-I",
Expand Down
3 changes: 2 additions & 1 deletion test/BackendC/Examples.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ allTests =
tests :: [ExampleTest]
tests =
[ ExampleTest "Validity Predicate example" "ValidityPredicates" "Tests.juvix" "ValidityPredicates" "" StdlibExclude,
ExampleTest "MiniTicTacToe example" "MiniTicTacToe" "MiniTicTacToe.juvix" "MiniTicTacToe" "aaa\n0\n10\n1\n2\n3\n3\n4\n5\n6\n7\n8\n9\n" StdlibInclude
ExampleTest "MiniTicTacToe example" "MiniTicTacToe" "MiniTicTacToe.juvix" "MiniTicTacToe" "aaa\n0\n10\n1\n2\n3\n3\n4\n5\n6\n7\n8\n9\n" StdlibInclude,
ExampleTest "Fibonacci example" "Fibonacci" "Fibonacci.juvix" "Fibonacci" "" StdlibInclude
]
1 change: 1 addition & 0 deletions tests/examplesExpected/Fibonacci/expected.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
75025

0 comments on commit cff0194

Please sign in to comment.