add put_byte/{1,2}, put_char/{1,2}

This commit is contained in:
Mark Thom
2020-05-05 17:42:18 -06:00
parent 573df892bc
commit 47e3a5e75a
5 changed files with 157 additions and 4 deletions

View File

@@ -278,6 +278,17 @@ impl Stream {
pub(crate)
fn close(&mut self) {
*self.stream_inst.0.borrow_mut() = StreamInstance::Null;
self.past_end_of_stream = true;
}
#[inline]
pub(crate)
fn is_null_stream(&self) -> bool {
if let StreamInstance::Null = *self.stream_inst.0.borrow() {
true
} else {
false
}
}
#[inline]
@@ -485,7 +496,15 @@ impl MachineState {
}
Addr::Stream(h) => {
if let HeapCellValue::Stream(ref stream) = &self.heap[h] {
stream.clone()
if stream.is_null_stream() {
return Err(self.open_permission_error(
Addr::Stream(h),
caller,
arity,
));
} else {
stream.clone()
}
} else {
unreachable!()
}