From b2d720b853269ed9c6917f2078d03d28b7b6daeb Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 22 May 2020 14:50:40 -0600 Subject: [PATCH] correct get_byte/1 not emitted -1 upon discovery of end_of_stream position (#555) --- src/prolog/machine/system_calls.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 1fe7b576..cf7c0a93 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -2166,6 +2166,13 @@ impl MachineState { )?; if stream.past_end_of_stream() { + self.eof_action( + self[temp_v!(2)], + &mut stream, + clause_name!("get_byte"), + 2, + )?; + if EOFAction::Reset != stream.options.eof_action { return return_from_clause!(self.last_call, self); } else if self.fail { @@ -2173,12 +2180,6 @@ impl MachineState { } } - if stream.at_end_of_stream() { - stream.set_past_end_of_stream(); - self.unify(self[temp_v!(2)], Addr::Fixnum(-1)); - return return_from_clause!(self.last_call, self); - } - let addr = match self.store(self.deref(self[temp_v!(2)])) { addr if addr.is_ref() => { @@ -2238,18 +2239,9 @@ impl MachineState { } } _ => { - self.eof_action( - self[temp_v!(2)], - &mut stream, - clause_name!("get_byte"), - 2, - )?; - - if EOFAction::Reset != stream.options.eof_action { - return return_from_clause!(self.last_call, self); - } else if self.fail { - return Ok(()); - } + stream.set_past_end_of_stream(); + self.unify(self[temp_v!(2)], Addr::Fixnum(-1)); + return return_from_clause!(self.last_call, self); } } } -- 2.54.0