Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
crsn/crsn_buf/src/defs.rs

58 lines
1.4 KiB

use crsn::asm::data::{Rd, RdObj, Wr};
use crsn::asm::data::literal::Value;
use crate::parse::{BUF_IOMODE_QUEUE, BUF_IOMODE_REVERSE_QUEUE, BUF_IOMODE_STACK, BUF_IOMODE_REVERSE_STACK};
#[derive(Clone, Debug, PartialEq)]
pub enum BufValue {
Zeros(Rd),
Values(Vec<Rd>),
Chars(String),
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum BufIoMode {
Queue,
ReverseQueue,
Stack,
ReverseStack,
}
impl BufIoMode {
pub fn to_value(self) -> Value {
match self {
BufIoMode::Queue => BUF_IOMODE_QUEUE,
BufIoMode::ReverseQueue => BUF_IOMODE_REVERSE_QUEUE,
BufIoMode::Stack => BUF_IOMODE_STACK,
BufIoMode::ReverseStack => BUF_IOMODE_REVERSE_STACK,
}
}
}
impl Default for BufIoMode {
fn default() -> Self {
Self::Queue
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum BufOps {
New { dst: Wr, value: BufValue },
SetIoMode { obj: RdObj, mode: BufIoMode },
// Elementary ops
Read { dst: Wr, obj: RdObj, idx: Rd },
GetLen { dst: Wr, obj: RdObj },
Write { obj: RdObj, idx: Rd, value: Rd },
Insert { obj: RdObj, idx: Rd, value: Rd },
Remove { dst: Wr, obj: RdObj, idx: Rd },
// Whole buffer ops
Resize { obj: RdObj, len: Rd },
Reverse { obj: RdObj },
AppendBuf { obj: RdObj, obj2: RdObj },
PrependBuf { obj: RdObj, obj2: RdObj },
// Stack-style ops
Push { obj: RdObj, src: Rd },
Pop { dst: Wr, obj: RdObj },
}