GitHunt
EN

ensko/typst-stack-pointer

Visualize the execution of (imperative) computer programs in Typst—Moved to https://codeberg.org/ensko/typst-stack-pointer

Stack Pointer

Stack Pointer is a library for visualizing the execution of (imperative) computer programs, particularly in terms of effects on the call stack: stack frames and local variables therein.

Stack Pointer lets you represent an example program (e.g. a C or Java program) using typst code with minimal hassle, and get the execution state of that program at different points in time.

Getting Started

To add this package to your project, use this:

#import "@preview/stack-pointer:0.1.0": *

#execute(...)

For example, the following C program

int main() {
  int x = foo();
  return 0;
}

int foo() {
  return 0;
}

would be represented by the following Typst code:

#let steps = execute({
  let foo() = func("foo", 6, l => {
    l(0)
    l(1); retval(0)
  })
  let main() = func("main", 1, l => {
    l(0)
    l(1)
    let (x, ..rest) = foo(); rest
    l(1, push("x", x))
    l(2)
  })
  main(); l(none)
})

The steps variable now contains an array, where each element corresponds to one of the mentioned lines of code.

Usage

See the manual for details.

Take a look at this complete example of using Stack Pointer together with Touying.

Languages

Typst73.6%Shell20.1%Just6.3%

Contributors

MIT License
Created June 9, 2024
Updated February 4, 2026
ensko/typst-stack-pointer | GitHunt