Solution (source code)

= Solution

The surviving <call stack>, from oldest to newest, is `main, p, r, s, q`. A <dynamic link> identifies the caller's <stack frame>, whereas a <static link> identifies the current activation of the lexically enclosing procedure. These need not identify the same <stack frame>.

\Image[/past-exam-of-the-computer-science-course-of-the-university-of-oxford/2015/compilers-2015-stack-links.png]
{title=The <call stack> during `q`, with <dynamic links> on the left and <static links> on the right; arrows point to older <stack frames>}

The <dynamic chain> is
$$
q\longrightarrow s\longrightarrow r\longrightarrow p\longrightarrow\mathrm{main}.
$$
The individual <static links> are
$$
\boxed{q\longrightarrow p,\qquad s\longrightarrow r,\qquad r\longrightarrow p,\qquad p\longrightarrow\mathrm{main}.}
$$
`main` has no enclosing procedure; its links can be null. The `p` <stack frame> contains `t=3` and `x=3`, and the `q` <stack frame> contains `y=3`. Return addresses are code addresses, not links to another <stack frame>. \b[In particular, `q` returns dynamically to `s` while obtaining `x` statically from `p`.]