23.03.2013 Views

Performance and Evaluation of Lisp Systems - Dreamsongs

Performance and Evaluation of Lisp Systems - Dreamsongs

Performance and Evaluation of Lisp Systems - Dreamsongs

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

60<br />

3. Activating the frame by making the open frame the active<br />

frame, by stashing the next PC in the current function in<br />

the PC slot <strong>of</strong> the call frame, <strong>and</strong> by making the function<br />

that it contains the current function.<br />

In the third step, the microcode checks to see that the function is being<br />

called with the proper number <strong>of</strong> arguments, <strong>and</strong> if the function can take different<br />

numbers <strong>of</strong> arguments, it selects an entry point. The called function then defaults<br />

any unsupplied optional arguments <strong>and</strong> bumps the stack pointer to allocate space<br />

for local variables. A call frame looks like this:<br />

Frame Header<br />

Function<br />

Previous Active Frame<br />

Previous Open Frame<br />

Previous Binding Stack Pointer<br />

Saved PC <strong>of</strong> Caller<br />

Argument 0<br />

Argument 1<br />

. . .<br />

Local 0<br />

Local 1<br />

. . .<br />

If a function tries to return multiple values, the microcode looks at the stack<br />

frame’s header word, which indicates whether or not the caller is expecting mul-<br />

tiple values. If the caller is not expecting multiple values, only the first value is<br />

returned.<br />

CATCH <strong>and</strong> THROW are implemented in much the same way as call <strong>and</strong> re-<br />

turn (indeed, the microcoded instructions share a good deal <strong>of</strong> code). The CATCH<br />

instruction creates a catch frame, which looks much like a call frame except that<br />

the function that created the catch frame takes the place <strong>of</strong> the ‘function to be<br />

called,’ <strong>and</strong> the PC <strong>of</strong> the code to be executed when the catch frame is thrown to<br />

takes the place <strong>of</strong> the ‘return PC.’ A catch frame looks like this:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!