https://github.com/sillyfreak/typst-stack-pointer
Visualize the execution of (imperative) computer programs in Typst
https://github.com/sillyfreak/typst-stack-pointer
typst typst-package
Last synced: 8 months ago
JSON representation
Visualize the execution of (imperative) computer programs in Typst
- Host: GitHub
- URL: https://github.com/sillyfreak/typst-stack-pointer
- Owner: SillyFreak
- License: mit
- Created: 2024-06-09T18:49:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T15:18:33.000Z (over 1 year ago)
- Last Synced: 2025-07-14T02:22:39.712Z (11 months ago)
- Topics: typst, typst-package
- Language: Typst
- Homepage: https://typst.app/universe/package/stack-pointer
- Size: 1.07 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```typ
#import "@preview/stack-pointer:0.1.0": *
#execute(...)
```
For example, the following C program
```c
int main() {
int x = foo();
return 0;
}
int foo() {
return 0;
}
```
would be represented by the following Typst code:
```typ
#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](docs/manual.pdf) for details.
Take a look at [this complete example](gallery/sum.pdf) of using Stack Pointer together with [Touying](https://touying-typ.github.io/).