Expand description
Autoperm is a tool for generating programs to apply stack effect diagrams.
It is backend agnostic and could be used to generate programs for any language as long
as the language implements the Model
trait.
A brainfuck backend is provided and accessible
with autoperm_bf
.
Binary
Installing the crate as a binary gives access to the autoperm
command which uses this brainfuck backend as REPL.
cargo install autoperm
Usage:
$ 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 starts by pointing at the top of the stack. Any “new” cells (cells that are not defined in the input) should start empty. There must also be 1 free cell at the top of the stack for temporary storage.
For example:
(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 for (a b – a b a b)
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
Modules
- Predefined models for certain programming languages
Structs
- Represents a stack effect diagram.
Enums
- Represents an instruction within the computation model
- Returned when
parse
fails
Traits
- The assumed model of computation
Functions
- Generate a program to apply a given
StackEffectDiagram
. - Generate a brainfuck program that applies a given
StackEffectDiagram
- Generate a program from a list of
Instruction
s using a givenModel
. - A very simple parser for parsing
StackEffectDiagram
s. - Given a
StackEffectDiagram
generate a list of instructions to apply that diagram.