Guile’s virtual machine can be configured to call out at key points to arbitrary user-specified procedures.
In principle, these hooks allow Scheme code to implement any model it chooses for examining the evaluation stack as program execution proceeds, and for suspending execution to be resumed later.
VM hooks are very low-level, though, and so Guile also has a library of higher-level traps on top of the VM hooks. A trap is an execution condition that, when fulfilled, will fire a handler. For example, Guile defines a trap that fires when control reaches a certain source location.
Finally, Guile also defines a third level of abstractions: per-thread trap states. A trap state exists to give names to traps, and to hold on to the set of traps so that they can be enabled, disabled, or removed. The trap state infrastructure defines the most useful abstractions for most cases. For example, Guile’s REPL uses trap state functions to set breakpoints and tracepoints.
The following subsections describe all this in detail, for both the user wanting to use traps, and the developer interested in understanding how the interface hangs together.
|• VM Hooks||Modifying Guile’s virtual machine.|
|• Trap Interface||Traps are on or off.|
|• Low-Level Traps||The various kinds of low-level traps.|
|• Tracing Traps||Traps to trace procedure calls and returns.|
|• Trap States||One state (per thread) to bind them.|
|• High-Level Traps||The highest-level trap interface. Use this.|