https://github.com/alextopher/autoperm
A tool that generates instructions for applying stack effects diagrams. Includes a brainfuck backend <3
https://github.com/alextopher/autoperm
brainfuck programming-languages
Last synced: 10 months ago
JSON representation
A tool that generates instructions for applying stack effects diagrams. Includes a brainfuck backend <3
- Host: GitHub
- URL: https://github.com/alextopher/autoperm
- Owner: Alextopher
- License: gpl-3.0
- Created: 2022-09-02T02:12:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-28T09:30:25.000Z (about 1 year ago)
- Last Synced: 2025-03-29T21:18:14.186Z (10 months ago)
- Topics: brainfuck, programming-languages
- Language: Rust
- Homepage:
- Size: 102 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://crates.io/crates/autoperm)
[](https://docs.rs/autoperm/)
[](https://deps.rs/repo/github/Alextopher/autoperm)
# autoperm
autoperm is a tool for generating programs that apply [stack effect diagrams](https://en.wikipedia.org/wiki/Stack-oriented_programming#Stack_effect_diagrams). The produced result has the fewest number of `MOV`\* instructions. The algorithm has its foundations in [Tarjan's Strongly Connected Components](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm).
The library is backend agnostic. A [brainfuck](https://en.wikipedia.org/wiki/Brainfuck) backend is provided. Installing the crate as a binary gives access to the `autoperm` command which uses this brainfuck backend.
\* A `MOV` Clears the data at a particular memory address and writes it to a list of other cells
Checkout the [explanation](./explanation.md)!
## Install
```shell
cargo install autoperm
```
## Usage
```bf
$ autoperm a b -- b a
[->+<]<[->+<]>>[-<<+>>]<
$ autoperm
a b c -- c a b
[->+<]<[->+<]<[->+<]>>>[-<<<+>>>]<
a -- a a a a
[->>>>+<<<<]>>>>[-<+<+<+<+>>>>]<
a b c d -- d c a b
[->+<]<<[->>+<<]>[-<+>]<<[->>+<<]>>>>[-<<<<+>>>>]<
a b c -- c
<<[-]>[-]>[-<<+>>]<<
a b c d e f -- c d d f e e b
<<<<<[-]>[->>>>>+<<<<<]>[-<<+>>]>[-<+<+>>]>>[-<<+>>]<[->>>+<<<]>>>[-<<+<+>>>]<
```
The program assumes the memory pointer is pointing at the top of the stack. Any new cells should start empty and there must be 1 free cell at the top of the stack for temporary storage.
For example:
```bf
(a b c -- c)
start must be:
a b *c 0 // a and b are cleared
<<[-]>[-]>[-<<+>>]<<
end:
*c 0 0 0
(a -- a a a a)
start must be:
*a 0 0 0 0 // note: no 0s are initialized before usage
[->>>>+<<<<]>>>>[-<+<+<+<+>>>>]<
end:
a a a *a 0
```
A walk through of (a b -- a b a b)
```bf
a b -- a b a b
<[->>>>+<<<<]>>>>[-<<+<<+>>>>]<<<[->>>+<<<]>>>[-<+<<+>>>]<
# the tape
0 *1 2 3 T
a b 0 0 0
<[->>>>+<<<<] 0 → {T}
*0 1 2 3 T
0 b 0 0 a
>>>>[-<<+<<+>>>>] T → {2 0}
0 1 2 3 *T
a b a 0 0
<<<[->>>+<<<] 1 → {T}
0 *1 2 3 T
a 0 a 0 b
>>>[-<+<<+>>>] T → {1 3}
0 1 2 3 *T
a b a b 0
<
0 1 2 *3 T
a b a b 0
```