]> Repositorios git - scryer-prolog.git/commitdiff
correct get_byte/1 not emitted -1 upon discovery of end_of_stream position (#555)
authorMark Thom <[email protected]>
Fri, 22 May 2020 20:50:40 +0000 (14:50 -0600)
committerMark Thom <[email protected]>
Fri, 22 May 2020 20:50:40 +0000 (14:50 -0600)
src/prolog/machine/system_calls.rs

index 1fe7b5767164181d0409f0201ec285359944121b..cf7c0a9390ac7a56c318dda77763a8744f2a390d 100644 (file)
@@ -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);
                         }
                     }
                 }