pub trait EvaluationStorage<R: Reader> {
    type Stack: ArrayLike<Item = Value>;
    type ExpressionStack: ArrayLike<Item = (R, R)>;
    type Result: ArrayLike<Item = Piece<R>>;
}
Expand description

Specification of what storage should be used for Evaluation.

Normally you would only need to use StoreOnHeap, which places the stacks and the results on the heap using Vec. This is the default storage type parameter for Evaluation.

If you need to avoid Evaluation from allocating memory, e.g. for signal safety, you can provide you own storage specification:

struct StoreOnStack;

impl<R: Reader> EvaluationStorage<R> for StoreOnStack {
    type Stack = [Value; 64];
    type ExpressionStack = [(R, R); 4];
    type Result = [Piece<R>; 1];
}

let mut eval = Evaluation::<_, StoreOnStack>::new_in(bytecode, encoding);
let mut result = eval.evaluate().unwrap();
while result != EvaluationResult::Complete {
  match result {
    EvaluationResult::RequiresRegister { register, base_type } => {
      let value = get_register_value(register, base_type);
      result = eval.resume_with_register(value).unwrap();
    },
    EvaluationResult::RequiresFrameBase => {
      let frame_base = get_frame_base();
      result = eval.resume_with_frame_base(frame_base).unwrap();
    },
    _ => unimplemented!(),
  };
}

let result = eval.as_result();
println!("{:?}", result);

Associated Types

The storage used for the evaluation stack.

The storage used for the expression stack.

The storage used for the results.

Implementors