Pushr
Pushr is a Rust based interpreter for Push programs.
What is Push?
Push is a stack-based Turing-complete programming language that enables autoconstructive evolution in its programs. More information can be found here.
Supported Stack Types
This implementation supports all Push3 instructions for the types desribed in the Push 3.0 Programming Language Description:
- BOOLEAN
- CODE
- EXECUTION
- FLOAT
- INTEGER
- NAME
Additionally, it provides the vector types for boolean, float and integer:
- BOOLVECTOR
- FLOATVECTOR
- INTVECTOR
The default instructions for vector types are 'dup', 'equal', 'flush', 'get', 'set', 'shove', 'stackdepth', 'rand', 'swap', 'yank' and 'yankdup'. Additionally, the instruction set contains 'add', 'subtract', 'multiply' and 'divide' for float and integer vectors, as well as 'and', 'or' and 'not' for boolean vectors.
Vector lengths do not have to match. Arithmetic operatios are executed element-wise on the overlapping parts. An offset parameter shifts the top vector on the stack to create the desired overlap.
In a Push program the vectors are defined as BOOL[..], FLOAT[..] and INT[..]. For example, BOOL[1,0] defines a BOOLVECTOR with two elements.
Usage
The following example shows how to intepret Push program with Prush.
// Define Push program
let input = "( CODE.QUOTE ( CODE.DUP INTEGER.DUP 1 INTEGER.- CODE.DO INTEGER.* )
CODE.QUOTE ( INTEGER.POP 1 )
INTEGER.DUP 2 INTEGER.< CODE.IF )";
// Define State and Instruction Set
let mut push_state = new;
let mut instruction_set = new;
// Load default instructions
instruction_set.load;
// Add program to execution stack
parse_program;
// Put initial values
push_state.int_stack.push;
// Run the program
run;
For existing types the instruction set can be extended by calling the add function.
...
let mut instruction_set = new;
instruction_set.add;