1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use osiris_data::memory::{MemoryError, MemoryResult};

use crate::operation::Instruction;
use crate::operation::scheme::ArgumentType;

#[derive(Debug)]
pub enum OperationError {
    HaltError,
    Panic(String),
    InvalidArgumentType { expected: ArgumentType, provided: ArgumentType },
    MemoryError(MemoryError),
    CannotReturnFromEmptyStack,
    MismatchedInstruction(Instruction),
}

pub type OperationResult<T> = Result<T, OperationError>;

pub fn promote<T>(memory_result: MemoryResult<T>) -> OperationResult<T> {
    match memory_result {
        Ok(ok_value) => Ok(ok_value),
        Err(e) => Err(OperationError::MemoryError(e))
    }
}