-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile.pl
43 lines (37 loc) · 1.15 KB
/
compile.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
:- module(compile,[
compile/1
]).
:- meta_predicate
catch_messages(0, -).
catch_messages(Goal, Messages) :-
nb_setval(messages, []),
thread_self(Me),
setup_call_cleanup(assert((user:message_hook(Term, Kind, Lines) :-
catch_message(Me, message(Term,Kind,Lines))),
Ref),
once(Goal),
collect_messages(Messages, Ref)).
catch_message(Me, message(Term,Kind,Lines)) :-
Kind \= silent,
thread_self(Me),
!,
nb_getval(messages, L0),
message_to_string(Term, String),
( source_location(File, Line)
-> true
; File = "",
Line = 0
),
nb_linkval(messages, [message(Term,Kind,Lines,File,Line,String)|L0]).
collect_messages(Messages, Ref) :-
erase(Ref),
nb_getval(messages, L),
nb_delete(messages),
reverse(L, Messages).
compile(Errors) :-
catch_messages(
load_files(['code.pl'],[]),
Messages
),
maplist(format_message,Messages,Errors).
format_message(message(_Term,_Kind,_Lines,_File,Line,Error),error(Line,Error)).