Implement functions
- Implement function declaration and call - Change the precalculated variable stack positions to contain the offset from the end instead of the absolute position. This is important for passing fun args on the stack - Add the ability to offset the stackframes. This is used to delete the stack where the fun args have been stored before the block executes - Implement exit type for blocks in interpreter. This is used to get the return values and propagate them where needed - Add recursive fibonacci examples
This commit is contained in:
9
examples/recursive_fib.nek
Normal file
9
examples/recursive_fib.nek
Normal file
@@ -0,0 +1,9 @@
|
||||
fun fib(n) {
|
||||
if n <= 1 {
|
||||
return n;
|
||||
} else {
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
}
|
||||
|
||||
print fib(30);
|
||||
6
examples/recursive_fib.py
Normal file
6
examples/recursive_fib.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def fib(n):
|
||||
if n <= 1:
|
||||
return n
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
print(fib(30))
|
||||
Reference in New Issue
Block a user