]> Repositorios git - scryer-prolog.git/commitdiff
print errors as goals (#1408)
authorMark Thom <[email protected]>
Sat, 9 Apr 2022 20:01:48 +0000 (14:01 -0600)
committerMark Thom <[email protected]>
Sat, 9 Apr 2022 20:01:48 +0000 (14:01 -0600)
src/lib/builtins.pl
src/loader.pl
src/toplevel.pl

index 75bda0533e65fcb78338fc90f644a802119d25f4..0c4746d07609bca34e1b7d42a8177434a12960f0 100644 (file)
@@ -1,7 +1,7 @@
-:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2, (;)/2,
-                     (=..)/2, (:)/2, (:)/3, (:)/4, (:)/5, (:)/6,
-                     (:)/7, (:)/8, (:)/9, (:)/10, (:)/11, (:)/12,
-                     abolish/1, asserta/1, assertz/1,
+:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2,
+                     (;)/2, (=..)/2, (:)/2, (:)/3, (:)/4, (:)/5,
+                     (:)/6, (:)/7, (:)/8, (:)/9, (:)/10, (:)/11,
+                     (:)/12, abolish/1, asserta/1, assertz/1,
                      at_end_of_stream/0, at_end_of_stream/1,
                      atom_chars/2, atom_codes/2, atom_concat/3,
                      atom_length/2, bagof/3, call/1, call/2, call/3,
                      close/1, close/2, current_input/1,
                      current_output/1, current_op/3,
                      current_predicate/1, current_prolog_flag/2,
-                     fail/0, false/0, findall/3, findall/4,
+                     error/2, fail/0, false/0, findall/3, findall/4,
                      flush_output/0, flush_output/1, get_byte/1,
                      get_byte/2, get_char/1, get_char/2, get_code/1,
-                     get_code/2, halt/0, halt/1, nl/0,
-                     nl/1, number_chars/2, number_codes/2, once/1,
-                     op/3, open/3, open/4, peek_byte/1, peek_byte/2,
+                     get_code/2, halt/0, halt/1, nl/0, nl/1,
+                     number_chars/2, number_codes/2, once/1, op/3,
+                     open/3, open/4, peek_byte/1, peek_byte/2,
                      peek_char/1, peek_char/2, peek_code/1,
                      peek_code/2, put_byte/1, put_byte/2, put_code/1,
                      put_code/2, put_char/1, put_char/2, read/1,
@@ -1700,3 +1700,6 @@ nl :-
 
 nl(Stream) :-
     put_char(Stream, '\n').
+
+error(Error_term, Imp_def) :-
+   throw(error(Error_term, Imp_def)).
index b0bc5a6d286d9797e7e11c8f4a98c1d8220de0ad..9a130375ce069d05c63c0fe39e461534d173147b 100644 (file)
 :- use_module(library(pairs)).
 
 
+write_error(Error) :-
+    write('   '),
+    (  nonvar(Error),
+       functor(Error, error, 2) ->
+       writeq(Error)
+    ;  writeq(throw(Error))
+    ).
+
 '$print_message_and_fail'(Error) :-
     (  (  Error = error(existence_error(procedure, Expansion), Expansion)
        ;  Error = error(evaluation_error((_:_)/_),Expansion)
           ;  Expansion = term_expansion/2
           )  ->
           true
-       ;  write('caught: '),
-          writeq(Error),
+       ;  write_error(Error),
           nl
        )
-    ;  write('caught: '),
-       writeq(Error),
+    ;  write_error(Error),
        nl
     ),
     '$fail'.
index a86998249212d4ea96bb307d7d2a62f30c10e4e4..a6b14e1d9407fe7b7f89cf79d33a3cb80bf11721 100644 (file)
@@ -129,8 +129,8 @@ run_goals([g(Gs0)|Goals]) :-
     ),
     run_goals(Goals).
 run_goals([Goal|_]) :-
-    write('caught: '),
-    write(error(domain_error(arg_type, Goal), run_goals/1)), nl,
+    loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)),
+    nl,
     halt.
 
 repl :-
@@ -412,13 +412,12 @@ gather_equations([Var = Value | Pairs], OrigVarList, Goals) :-
 
 print_exception(E) :-
     (  E == error('$interrupt_thrown', repl) -> nl % print the
-    % exception on a
-    % newline to evade
-    % "^C".
+                                                   % exception on a
+                                                   % newline to evade
+                                                   % "^C".
     ;  true
     ),
-    write_term('caught: ', [quoted(false), max_depth(20)]),
-    writeq(E),
+    loader:write_error(E),
     nl.
 
 print_exception_with_check(E) :-