Skip to content

Commit 4a48b00

Browse files
authored
Merge pull request #2 from stacky-language/print-allow-empty-stack
change: print/println allow empty stack
2 parents fb68c36 + 062a5e3 commit 4a48b00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ impl<'a> Interpreter<'a> {
19211921
return Err(make_err(ErrorKind::Io(e), pc));
19221922
}
19231923
} else {
1924-
return Err(make_err(ErrorKind::StackIsEmpty, pc));
1924+
// do nothing
19251925
}
19261926

19271927
pc += 1;
@@ -1934,13 +1934,15 @@ impl<'a> Interpreter<'a> {
19341934
));
19351935
}
19361936

1937+
let o = self.output.as_mut().unwrap();
19371938
if let Some(a) = self.stack.pop() {
1938-
let o = self.output.as_mut().unwrap();
19391939
if let Err(e) = writeln!(o, "{a}") {
19401940
return Err(make_err(ErrorKind::Io(e), pc));
19411941
}
19421942
} else {
1943-
return Err(make_err(ErrorKind::StackIsEmpty, pc));
1943+
if let Err(e) = writeln!(o) {
1944+
return Err(make_err(ErrorKind::Io(e), pc));
1945+
}
19441946
}
19451947

19461948
pc += 1;

0 commit comments

Comments
 (0)