fix: print in single line
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -13,7 +13,7 @@ fn interpret(code: &str) {
|
||||
'<' => head -= 1,
|
||||
'+' => memory[head] = memory[head].wrapping_add(1),
|
||||
'-' => memory[head] = memory[head].wrapping_sub(1),
|
||||
'.' => println!("{}", memory[head]),
|
||||
'.' => print!("{}", memory[head] as char),
|
||||
',' => {
|
||||
let mut input_buf = [0u8; 1];
|
||||
if io::stdin().read_exact(&mut input_buf).is_ok() {
|
||||
@@ -50,6 +50,8 @@ fn interpret(code: &str) {
|
||||
if memory[pc] != 0 {
|
||||
if let Some(start_pc) = loop_stack.last() {
|
||||
pc = *start_pc;
|
||||
} else {
|
||||
panic!("Loop stack empty, but still called!")
|
||||
}
|
||||
} else {
|
||||
// loop done, continue normally
|
||||
@@ -60,10 +62,11 @@ fn interpret(code: &str) {
|
||||
}
|
||||
pc += 1;
|
||||
}
|
||||
print!("\n");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let code = "+++++++++[>++++++++<-]>.";
|
||||
let hello_world = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
|
||||
interpret(hello_world);
|
||||
// let code = "+++++++++[>++++++++<-]>.";
|
||||
let code = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
|
||||
interpret(code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user