save eval feature
This commit is contained in:
parent
e34bb583a1
commit
079a78fd5c
|
@ -6,3 +6,6 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
save-eval = []
|
16
src/lib.rs
16
src/lib.rs
|
@ -97,6 +97,14 @@ pub fn eval_mem<'a>(bf_str: &&str, mem: &'a mut [u8], pointer: &mut usize) -> Re
|
||||||
}
|
}
|
||||||
if char == '+' {
|
if char == '+' {
|
||||||
if mem[*pointer] == 255 {
|
if mem[*pointer] == 255 {
|
||||||
|
|
||||||
|
#[cfg(feature = "safe-eval")]
|
||||||
|
{
|
||||||
|
return Err(
|
||||||
|
BrainFuckError::new(format!("Attempt to overflow more than 255 ({})", pos), mem)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
mem[*pointer] = 0;
|
mem[*pointer] = 0;
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -105,6 +113,14 @@ pub fn eval_mem<'a>(bf_str: &&str, mem: &'a mut [u8], pointer: &mut usize) -> Re
|
||||||
}
|
}
|
||||||
if char == '-' {
|
if char == '-' {
|
||||||
if mem[*pointer] == 0 {
|
if mem[*pointer] == 0 {
|
||||||
|
|
||||||
|
#[cfg(feature = "safe-eval")]
|
||||||
|
{
|
||||||
|
return Err(
|
||||||
|
BrainFuckError::new(format!("Attempt to overflow more than 255 ({})", pos), mem)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
mem[*pointer] = 255;
|
mem[*pointer] = 255;
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue