Documentation
¶
Overview ¶
stack-trace demonstrates the VM stack trace captured when a runtime error escapes to the embedder, with emphasis on the sub-context spanning added in CaptureStackTrace (the "<foreign-call boundary>" frame).
A trace is built by walking the continuation chain. Two things make the output worth studying:
Tail calls leave no frame. Wile is properly tail-recursive, so a chain of tail calls collapses to a single frame. To see depth you need non-tail calls — here each call is wrapped in (+ 1 _) so the caller's frame must survive to receive the return value.
Go primitives that call back into Scheme (a parameter converter, eval, an exception thunk) run that Scheme in a *sub-context*. The walk hops the Go boundary via parentMC and inserts a synthetic "<foreign-call boundary>" frame at the crossing, so the outer Scheme frames that led into the Go primitive are not lost.
Both programs below are wrapped in a single (begin ...) so they parse as one expression: that keeps every define and the call site live on one continuation chain. (EvalMultiple* compiles each top-level form independently, which would drop the very parent frames this example is about.)
Run with: go run ./examples/embedding/stack-trace/main.go