~jpl8/piet_interpreter

fafcd4855916fadaa5ae89d2a5f6c2d74e7e2ffb — jpl 3 years ago 057b154
add out(char) and out(num), spec finished
A images/test_char_out.png => images/test_char_out.png +0 -0
A images/test_char_out_newline.png => images/test_char_out_newline.png +0 -0
M images/test_num_in.png => images/test_num_in.png +0 -0
A images/test_num_out.png => images/test_num_out.png +0 -0
M src/interpreter/interpreter_tests.rs => src/interpreter/interpreter_tests.rs +12 -0
@@ 348,3 348,15 @@ fn num_in_input_works() {
    assert_eq!(popped, 2);
}

#[test]
fn char_out_works() {
    let mut interpreter = Interpreter::new("images/test_char_out_newline.png").unwrap();
    interpreter.exec().expect("Execution Failed!");
}

#[test]
fn num_out_works() {
    let mut interpreter = Interpreter::new("images/test_num_out.png").unwrap();
    interpreter.exec().expect("Execution Failed!");
}


M src/interpreter/mod.rs => src/interpreter/mod.rs +19 -2
@@ 1,4 1,4 @@
use std::io::{self, Error, ErrorKind};
use std::io::{self, Error, ErrorKind, Write};
use std::path::Path;

use crate::color::Color;


@@ 263,7 263,24 @@ impl Interpreter {
                    Ok(())
                }

                _ => {Ok(())}
                Op::OutNum => {
                    if let Some(val) = self.stack.pop() {
                            print!("{}", val);
                            io::stdout().flush().expect("Failed to flush to stdout!");
                    }
                    Ok(())
                }

                Op::OutChar => {

                    if let Some(val) = self.stack.pop() {
                        if let Some(c) = char::from_u32(val as u32) {
                            print!("{}", c);
                            io::stdout().flush().expect("Failed to flush to stdout!");
                        }
                    }
                    Ok(())
                }

            }