diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/fib.fwd | 23 | 
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/fib.fwd b/examples/fib.fwd new file mode 100644 index 0000000..8b0e055 --- /dev/null +++ b/examples/fib.fwd @@ -0,0 +1,23 @@ +/* heh, this technically speaking would work but the templating turns out to be + * too much for both GCC and clang. With some manual intervention on the + * generated code I can get fibonacci numbers up to about 35 to work, but then + * I run out of stack space. I guess the compiler can't collapse frames so the + * bifurcating nature of fibonacci just gets mapped to a linear sequence of + * calls? */ + +fib(n, res) +{ +	fwd_if(n < 2) => { +		res(1); +	} => { +		fib(n - 1) => f1; +		fib(n - 2) => f2; +		res(f1 + f2); +	} +} + +main() +{ +	fib(6) => n; +	fwd_println(n); +}  | 
