Learn a Lisp (say, Scheme or Common Lisp). For Lisp family, this is bread and butter. Since the source code itself is at the same time a data structure, you can (and often end up doing it) easily generate code at read time, compile time or run time. The border between those three kind of starts to blur.
Your example could look like this in Common Lisp:
(defun fib (n)
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
(defmacro spliced-fibs (x n)
`(case ,x
,(map-iota (lambda (v) (list v (fib v))) n)))
(defun hardcoded-fib (num)
(spliced-fibs num 29))
spliced-fibs macro will generate you a full case block at compile time, so the hardcoded-fib will be basically one big switch/case block. map-iota call maps a function over a list of numbers from 0 to n. Note that a macro can call ordinary functions at compile time, which themselves can use other macros, etc. So a lot of code can be used both at compile and run time.