plushi.interpreter

Contains function to asist in running a push program.

inspect-outputs

(inspect-outputs state output-types)
Given a state and a list of stack types, returns a vector of values copied
from the corresponding stacks of the state. If multiple instances of the same
type are in output-types, then it will copy deeper from that stack for each
occurance.

load-inputs

(load-inputs state inputs)
Sets the vector of inputs in the push state to be the given inputs.

load-program

(load-program state program)
Sets the exec stack of the push state to be the program.

pop-arguments

(pop-arguments state arg-types)
Given a push state and a vector of stack types, return the following:
1. The push state the top items for each arg-type popped off.
2. A vector of the values popped from each stack to be used as instruction arguments.

push-returns

(push-returns state returned-values expected-types)
Given a push state, a collection of values returned by an instruction, and a
vector of stack types corresponding to each returned-value, check that all
returned values can be coerced into their expected stack type and push them
onto the stack. Return the resulting stack.

run-push

(run-push program inputs output-types)(run-push program inputs output-types verbose)
Runs a push program. Requires a vector of input values availalble to the
program and stack types to use when looking for program outputs.

The general flow of this function is:
  1. Create a new push state
  2. Load the program and inputs.
  3. If the exec stack is empty, return the outputs.
  4. Else, pop the exec stack and process the atom.
  5. Return to step 3.

stack-types

A set of push types supported by the interpreter. This set is computed based
on types manipulated by the set of registered instructions.