title: Add nested-function support in a language the based on a stack-machine
body: <p>Suppose I have a simple C-like programming language: </p>
  
  <pre><code>int foo() {
      int x = 10;
      int bar(y int) {
          return y * 2
      }
      return bar() + x
  }
  </code></pre>
  
  <p>Like you can see, it supports nested functions.<br>
  I already implemented the lexing-parsing phases, and now I'm working on the code generation and the stack-machine. most of the operations, and the simple flow-control already implemented but I need some help/ideas how to solve the nested-function task.</p>
  
  <p>The stack-machine has two registers, accumulator, and a temporary register.<br>
  Each frame contains: <code>[arguments, local variables, return address, caller frame and stack pointer, temporaries and data operations]</code>, and I'm using the same stack for the call-frames and for the operations evaluation. Maybe I should split it into two stacks, one for the call frames, and the second for the operation evaluations. </p>
  
  <p>I read about two ways to implement the nested-function. one, using an activation-link (also called static-link), and display. Is there any better idea to handle this?<br>
  If I'll choose one of these idea, is it compile time calculation or do I need to store something in runtime? if it's a runtime thing, what's the time complexity for it? is it O(1) operation, or something like O(k) where k is the depth of the function.</p>