Rather than simply support closures, we went to the effort of baking them in fairly deeply. Which, we admit, was a bit of a pain since it involved redoing a lot of earlier work.

We’ve added a new register to the PZ abstract machine, an "environment" register. This register points to an environment structure. When calling a closure, which is the most general call type, the closure provides a code pointer and a data pointer. As before, the code pointer is loaded into the program counter register, and the data pointer is loaded into the environment register (call instructions). So that the call can return the previous values of both these registers are pushed onto the call stack. A new instruction is provided to retrieve the current value of the environment register, then this can be dereferenced to lookup variables in that were captured.