]> Repositorios git - scryer-prolog.git/commitdiff
throw '' whenever an interrupt is made (#365, #366)
authorMark Thom <[email protected]>
Sun, 19 Apr 2020 18:58:44 +0000 (12:58 -0600)
committerMark Thom <[email protected]>
Sun, 19 Apr 2020 18:58:44 +0000 (12:58 -0600)
src/prolog/lib/iso_ext.pl
src/prolog/machine/machine_errors.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/toplevel.pl

index a1944d1369b2d6d6e07e6a9c1101e507041c9275..68708250ceca394cf05d2a62bd3ccadb5760e589 100644 (file)
@@ -22,9 +22,9 @@ bb_put(Key, _) :- throw(error(type_error(atom, Key), bb_put/2)).
 bb_b_put(Key, NewValue) :-
     (  '$bb_get_with_offset'(Key, OldValue, OldOffset) ->
        call_cleanup((store_global_var_with_offset(Key, NewValue) ; false),
-                   reset_global_var_at_offset(Key, OldValue, OldOffset))
+                           reset_global_var_at_offset(Key, OldValue, OldOffset))
     ;  call_cleanup((store_global_var_with_offset(Key, NewValue) ; false),
-                   reset_global_var_at_key(Key))
+                           reset_global_var_at_key(Key))
     ).
 
 store_global_var_with_offset(Key, Value) :- '$store_global_var_with_offset'(Key, Value).
index c5173afc035a753fc6a4ccee91ba58729483f7b4..68b7a3ff87731a64d61ebb3c478468898541b273 100644 (file)
@@ -154,6 +154,18 @@ impl MachineError {
         )
     }
 
+    #[inline]
+    pub(super)
+    fn interrupt_error() -> Self {
+        let stub = functor!("$interrupt_thrown");
+        
+        MachineError {
+            stub,
+            location: None,
+            from: ErrorProvenance::Received,
+        }
+    }
+
     pub(super)
     fn evaluation_error(eval_error: EvalError) -> Self {
         let stub = functor!("evaluation_error", [atom(eval_error.as_str())]);
index 941fa4cbac4c314e82fe5ec488adb74885f53ae9..dfcb08be401fcad05594b12178ef96b27d27c80c 100644 (file)
@@ -3089,6 +3089,14 @@ impl MachineState {
         self.p += 1;
     }
 
+    fn throw_interrupt_exception(&mut self) {
+        let err = MachineError::interrupt_error();
+        let src = functor!("repl");
+        let err = self.error_form(err, src);
+
+        self.throw_exception(err);
+    }
+
     fn handle_call_clause(
         &mut self,
         indices: &mut IndexStore,
@@ -3105,8 +3113,7 @@ impl MachineState {
            let interrupted = INTERRUPT.load(std::sync::atomic::Ordering::Relaxed);
 
            if INTERRUPT.compare_and_swap(interrupted, false, std::sync::atomic::Ordering::Relaxed) {
-               self.reset();
-               self.fail = true;
+            self.throw_interrupt_exception();
                return;
            }
 
index d826b1b5dbbc4046fb24bc1b57aeb8f8b0b05998..099bc9f973fe1d17676670d3f2321e18b6e26c51 100644 (file)
@@ -214,6 +214,9 @@ gather_goals([Var = Value | Pairs], VarList, Goals) :-
     ).
 
 print_exception(E) :-
+    (  E == error('$interrupt_thrown', repl) -> nl % print the exception on a newline to evade "^C".
+    ;  true
+    ),
     write_term('caught: ', [quoted(false), max_depth(20)]),
     writeq(E),
     nl.