65:-
user_defined_directive(fragile(
G), cleanup
:cleanup_expansion(
G)).
78 bb_put(expansion_toggle,
1),
79 \+ bb_get(cleanup_level,
_),
90 catch(
G,
X,(do_cleanup(
L),throw(
X)))
100 catch(
G,
X,(do_cleanup(
L),throw(
X)))
113cleanup_context(
CL)
:-
124 next_cleanup,
recorded(cleanup
:handle,(
L,
G),
R),
162 throw(error(instantiation_error,no_cleanup_context(
G))).
165 recorda(cleanup
:handle,(
L,
G),
_).
175 throw(no_cleanup_context(
G)).
178 recordz(cleanup
:handle,(
L,
G),
_).
181cleanup_expansion(
X)
:-
182 var(
X),
var,
throw(error(instantiation_error,fragile(
X))).
183cleanup_expansion((
H,
T))
:- cleanup_expansion,
cleanup_expansion(
H),
cleanup_expansion(
T).
184cleanup_expansion([
H,
T])
:- cleanup_expansion,
cleanup_expansion(
H),
185 (
T = []
-> true
; cleanup_expansion(
T) ).
186cleanup_expansion(
M:G/A)
:-
188 compose_var_goal(
G/A,
GG),
190 assert(( user
:goal_expansion(
GG,
M,
NG)
191 :- bb_get(expansion_toggle,
1)
192 -> bb_put(expansion_toggle,
0),
193 NG=call_cleanup(
M:GG)
194 ; bb_put(expansion_toggle,
1),
196cleanup_expansion(
G/A)
:-
197 cleanup_expansion,
prolog_flag(typein_module,
M),
cleanup_expansion(
M:G/A).
198cleanup_expansion(
X)
:-
199 cleanup_expansion,
throw(error(instantiation_error,fragile(
X))).
201compose_var_goal(
G/A,
NG)
:-
202 arity_to_vars(
A,
L),
NG =.. [
G|L].
205 arity_to_vars(
N,[],
L).
206arity_to_vars(
N,
L1,
L2)
:-
210 arity_to_vars(
NN,
LT,
L2).
216
catch( : Goal,+ Exception,+ Action)
goal_expansion( :G,+ M,- NG)
call_cleanup(: Goal, : CleanUpGoal)
on_cleanup(+ CleanUpGoal)