Compare commits
No commits in common. "1d50dd259b1d2d7bca2dd54d712ab175ca497999" and "6a608d7e481a07359f20d019d1cfae369145beb4" have entirely different histories.
1d50dd259b
...
6a608d7e48
17
src/lib.rs
17
src/lib.rs
|
@ -9,6 +9,7 @@ pub fn lint_code(code: &&str) -> Result<(), Vec<String>> {
|
|||
|
||||
let mut loop_stack: Vec<usize> = vec![];
|
||||
let mut pos = 0 as usize;
|
||||
let mut pointer = 0;
|
||||
|
||||
let chars = code.chars().collect::<Vec<char>>();
|
||||
let size = code.len();
|
||||
|
@ -23,6 +24,20 @@ pub fn lint_code(code: &&str) -> Result<(), Vec<String>> {
|
|||
let char = chars[pos];
|
||||
pos += 1;
|
||||
|
||||
if char == '<' {
|
||||
if pointer == 0 {
|
||||
errors.push(format!("ERR: Reducing pointer to less than 0 is not allowed ({})", pos));
|
||||
continue
|
||||
}
|
||||
pointer -= 1;
|
||||
}
|
||||
if char == '>' {
|
||||
if pointer == 29999 {
|
||||
errors.push(format!("ERR: Increasing pointer to more than 29999 is not allowed ({})", pos));
|
||||
continue
|
||||
}
|
||||
pointer += 1;
|
||||
}
|
||||
if char == '[' {
|
||||
loop_stack.push(pos);
|
||||
continue
|
||||
|
@ -75,7 +90,7 @@ pub fn eval_mem(bf_str: &&str, mem: &mut [u8], pointer: &mut usize) -> Result<()
|
|||
}
|
||||
if char == '<' {
|
||||
if *pointer == 0 {
|
||||
return Err(format!("Attempt to reduce pointer to less than 0 ({})", pos));
|
||||
return Err(format!("Attempt to reduce pointer to less than 1 ({})", pos));
|
||||
}
|
||||
*pointer -= 1;
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue