34
35:- module(rtchecks_rt,
36 [rtchecks_disable/0,
37 rtchecks_enable/0,
38 rtcheck_pred/4,
39 rtcheck_call/3]). 40
41:- use_module(library(assertions)). 42:- use_module(library(metaprops)). 43:- use_module(library(neck)). 44:- use_module(library(rtchecks_flags)). 45:- use_module(library(send_check)). 46:- use_module(library(clambda)). 47:- use_module(library(ctrtchecks)). 48:- use_module(library(call_inoutex)). 49:- reexport(library(ctrtchecks),
50 ['$with_asr'/2,
51 '$with_gloc'/2,
52 '$with_ploc'/2,
53 check_call/3]). 54:- init_expansors.
96:- thread_local rtchecks_disabled/0. 97
98rtchecks_disable :- assertz(rtchecks_disabled).
99
100rtchecks_enable :- retractall(rtchecks_disabled).
101
102:- meta_predicate '$with_ploc'(0 ). 103
104'$with_ploc'(Goal) :-
105 ( prolog_current_frame(Curr),
106 prolog_frame_attribute(Curr, parent, Frame),
107 prolog_frame_attribute(Frame, clause, Clause),
108 prolog_frame_attribute(Curr, pc, PC)
109 ->'$with_ploc'(Goal, clause_pc(Clause, PC))
110 ; Goal
111 ).
112
113:- meta_predicate rtcheck_pred(0, +, +, +). 114
115rtcheck_pred(CM:Goal, M, CM, RAsrL) :-
116 '$with_ploc'(do_rtcheck_pred(CM:Goal, M, CM, RAsrL)).
117
118do_rtcheck_pred(CM:Goal, M, CM, RAsrL) :-
119 ( rtchecks_disabled
120 ->CM:Goal
121 ; call_inoutex(
122 check_goal(rt,
123 call_inoutex(CM:Goal,
124 rtchecks_enable,
125 rtchecks_disable),
126 M, CM, RAsrL),
127 rtchecks_disable,
128 rtchecks_enable)
129 ).
130
131assertions:asr_aprop(rtcheck(Asr), Key, Prop, From) :-
132 curr_prop_asr(Key, Prop, From, Asr).
133
135
136:- meta_predicate do_rtcheck(+, 0, +). 137
138status_cond(false, Call) :- Call.
139status_cond(Status, Call) :-
140 rtcheck_assr_status(Status),
141 Status \= false,
142 neck,
143 \+ Call.
144
145do_rtcheck(Status, Call, PLoc) :-
146 '$with_ploc'(status_cond(Status, Call), PLoc),
147 last_prop_failure(L),
148 send_check([[]/Call-L], pp_check, Status/1, PLoc, []),
149 fail.
150
151:- meta_predicate rtcheck_call(+,0,+). 152
153rtcheck_call(Status, Call, PLoc) :-
154 setup_call_cleanup(
155 rtchecks_disable,
156 \+ do_rtcheck(Status, Call, PLoc),
157 rtchecks_enable)
Predicates that are required to implement run-time checks
Algorithm:
pred :- body.
is executed as if where transformed to:
However the current implementation is an interpreter, rather than a compiler, since SWI-Prolog is fully dynamic and the status of a module could change at run-time. A future improvement could be to apply a partial evaluator to the interpreter.
*/