-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: feat: add compile-time if and recursive function (#11)
- Loading branch information
1 parent
8ef3ef4
commit 4ca32ad
Showing
5 changed files
with
132 additions
and
89 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
packages/cosmo/snapshots/TyperTests/fixtures/Type/decls/func.cos-ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
block { | ||
none | ||
def fib@49(n@50: u32): DeclExpr(u32@52) = if ("<="(n@50, 1)) block { | ||
def fib@49(n@50: u32): DeclExpr(u32@52) = if (BinInst(Int(u32,Le),n@50,Int64(1))) block { | ||
n@50 | ||
} else block { | ||
"+"(fib@49("-"(n@50, 1)), fib@49("-"(n@50, 2))) | ||
"+"(fib@49(BinInst(Int(u32,Sub),n@50,Int64(1))), fib@49(BinInst(Int(u32,Sub),n@50,Int64(2)))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
@noCore(); | ||
|
||
def fib(n: u32): u32 = if (n <= 1) { n } else { | ||
fib(n - 1) + fib(n - 2) | ||
} | ||
|
||
def main() = { | ||
println(Type(fib(1))); | ||
println(Type(fib(2))); | ||
println(Type(fib(3))); | ||
println(Type(fib(4))); | ||
println(Type(fib(5))); | ||
println(Type(fib(6))); | ||
println(Type(fib(10))); | ||
println(Type(fib(22))); | ||
} |