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:

It also provides the vector types for boolean, float and integer:

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. To initialize vectors the instructions 'ones' and 'zeros' can be used.

For vector instructions the following rules apply:

Usage

The following example shows how to intepret Push program with Prush.

```rust // 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 pushstate = PushState::new(); let mut instructionset = InstructionSet::new();

// Load default instructions instruction_set.load();

// Add program to execution stack PushParser::parseprogram(&mut pushstate, &instruction_set, &input);

// Put initial values pushstate.intstack.push(4);

// Run the program PushInterpreter::run(&mut pushstate, &mut instructionset); ```

For existing types the instruction set can be extended by calling the add function.

```rust pub fn myinstruction(pushstate: &mut PushState, _instructionset: &InstructionCache) { // Does nothing }

...

let mut instructionset = InstructionSet::new(); instructionset.add(String::from("MyInstruction"), Instruction::new(my_instruction));

```