 # have the blocks aready we have to terminate them.
 fib.return one
 
-main.return main.callFunction fib, main.value i32, TARGET_INDEX
+fibFrom = mod.makeFunction "fibFromTo", vd, i32
+
+from = fibFrom.parameter 0
+
+max = fibFrom.value i32, MAX_FIB
+ifBig = fibFrom.if fibFrom.uGreaterThan from, max
+ifBig.then.return()
+
+num = fibFrom.callFunction fib, from
+fibFrom.callFunction puti, num
+next = fibFrom.add from, fibFrom.value(i32, 1)
+fibFrom.callFunction fibFrom, next
+fibFrom.return()
+
+main.callFunction fibFrom, main.value(i32, 0)
+main.return 0
 
 mod.writeBitcodeToFile "fib.bc"
 mod.dump()

vd = llvm.type.void

mod = llvm.CodeUnit "fib"

main = mod.makeFunction "main", i32
fib = mod.makeFunction "fib", i32, i32

# fibonacci numbers

MAX_FIB = 29

llvm = require '../'

