2015-11-18 15:06:25 +00:00
|
|
|
/**
|
2017-04-07 23:10:59 +01:00
|
|
|
* @file library/hacks.yap
|
2015-11-18 15:06:25 +00:00
|
|
|
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
|
|
|
|
* @date Tue Nov 17 19:00:25 2015
|
2016-01-03 02:06:09 +00:00
|
|
|
*
|
2015-11-18 15:06:25 +00:00
|
|
|
* @brief Prolog hacking
|
2016-01-03 02:06:09 +00:00
|
|
|
*
|
|
|
|
*
|
2015-11-18 15:06:25 +00:00
|
|
|
*/
|
2006-12-27 01:54:21 +00:00
|
|
|
|
|
|
|
:- module(yap_hacks, [
|
2009-05-21 06:39:44 +01:00
|
|
|
current_choicepoint/1,
|
2019-01-31 11:54:17 +00:00
|
|
|
parent_choicepoint/1,
|
|
|
|
parent_choicepoint/2,
|
2009-05-21 06:39:44 +01:00
|
|
|
cut_by/1,
|
|
|
|
cut_at/1,
|
|
|
|
current_choicepoints/1,
|
|
|
|
choicepoint/7,
|
|
|
|
current_continuations/1,
|
|
|
|
continuation/4,
|
|
|
|
stack_dump/0,
|
|
|
|
stack_dump/1,
|
|
|
|
enable_interrupts/0,
|
2009-06-02 03:30:56 +01:00
|
|
|
disable_interrupts/0,
|
2015-03-04 09:44:26 +00:00
|
|
|
virtual_alarm/3,
|
2016-01-03 02:06:09 +00:00
|
|
|
fully_strip_module/3,
|
2015-03-04 09:44:26 +00:00
|
|
|
context_variables/1
|
2015-11-18 15:06:25 +00:00
|
|
|
]).
|
|
|
|
|
|
|
|
|
2018-05-30 21:54:12 +01:00
|
|
|
/**
|
|
|
|
* @addtogroup Hacks
|
|
|
|
* @{
|
|
|
|
* @brief Manipulate the Prolog stacks, including setting and resetting
|
|
|
|
* choice-points.
|
|
|
|
*
|
|
|
|
**/
|
2006-12-27 01:54:21 +00:00
|
|
|
|
2018-05-30 21:54:12 +01:00
|
|
|
/**
|
|
|
|
* @pred stack_dump
|
|
|
|
*
|
|
|
|
* Write the current ancestor stack to the outout. Ancestors may have:
|
|
|
|
* - terminated
|
|
|
|
* - still have sub-goals to execute, if so, they left an _environment_
|
|
|
|
* - still have clauses they may nacktrack to; if so, they left a _choice point_
|
|
|
|
*
|
|
|
|
*/
|
2007-01-24 10:01:40 +00:00
|
|
|
stack_dump :-
|
2008-02-12 17:03:59 +00:00
|
|
|
stack_dump(-1).
|
|
|
|
|
2018-05-30 21:54:12 +01:00
|
|
|
/**
|
|
|
|
* @pred stack_dump(+N)
|
|
|
|
*
|
|
|
|
* Report the last _N_ entries in the stack (see stack_dump/0)
|
|
|
|
*/
|
|
|
|
|
2008-02-12 17:03:59 +00:00
|
|
|
stack_dump(Max) :-
|
2007-01-24 10:01:40 +00:00
|
|
|
current_choicepoints(CPs),
|
|
|
|
current_continuations([Env|Envs]),
|
|
|
|
continuation(Env,_,ContP,_),
|
|
|
|
length(CPs, LCPs),
|
|
|
|
length(Envs, LEnvs),
|
|
|
|
format(user_error,'~n~n~tStack Dump~t~40+~n~nAddress~tChoiceP~16+ Cur/Next Clause Goal~n',[LCPs,LEnvs]),
|
2008-08-25 15:20:18 +01:00
|
|
|
'$hacks':display_stack_info(CPs, Envs, Max, ContP, StackInfo, []),
|
2008-02-22 15:08:37 +00:00
|
|
|
run_formats(StackInfo, user_error).
|
2007-01-24 10:01:40 +00:00
|
|
|
|
2008-02-22 15:08:37 +00:00
|
|
|
run_formats([], _).
|
|
|
|
run_formats([Com-Args|StackInfo], Stream) :-
|
|
|
|
format(Stream, Com, Args),
|
|
|
|
run_formats(StackInfo, user_error).
|
2019-01-31 11:54:17 +00:00
|
|
|
/**
|
|
|
|
* @pred parent_choicepoint(+_ChoicePoint_)
|
|
|
|
*
|
|
|
|
* _ChoicePoint_ is the parent of the current choice-point.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
parent_choicepoint(BP) :-
|
|
|
|
current_choicepoint(B),
|
|
|
|
parent_choicepoint(B, BP).
|
|
|
|
|
2007-01-24 10:01:40 +00:00
|
|
|
|
2018-05-30 21:54:12 +01:00
|
|
|
/**
|
|
|
|
* @pred virtual_alarm(+Interval, 0:Goal, -Left)
|
|
|
|
*
|
|
|
|
* Activate an alarm to execute _Goal_ in _Interval_ seconds. If the alarm was active,
|
|
|
|
* bind _Left_ to the previous value.
|
|
|
|
*
|
|
|
|
* If _Interval_ is 0, disable the current alarm.
|
|
|
|
*/
|
2009-06-02 03:30:56 +01:00
|
|
|
virtual_alarm(Interval, Goal, Left) :-
|
|
|
|
Interval == 0, !,
|
|
|
|
virtual_alarm(0, 0, Left0, _),
|
2009-06-03 16:09:14 +01:00
|
|
|
on_signal(sig_vtalarm, _, Goal),
|
2009-06-02 03:30:56 +01:00
|
|
|
Left = Left0.
|
|
|
|
virtual_alarm(Interval, Goal, Left) :-
|
|
|
|
integer(Interval), !,
|
2009-06-03 16:09:14 +01:00
|
|
|
on_signal(sig_vtalarm, _, Goal),
|
2009-06-02 19:20:17 +01:00
|
|
|
virtual_alarm(Interval, 0, Left, _).
|
2009-06-02 03:30:56 +01:00
|
|
|
virtual_alarm(Interval.USecs, Goal, Left.LUSecs) :-
|
2009-06-03 16:09:14 +01:00
|
|
|
on_signal(sig_vtalarm, _, Goal),
|
2009-06-02 03:30:56 +01:00
|
|
|
virtual_alarm(Interval, USecs, Left, LUSecs).
|
2006-12-27 01:54:21 +00:00
|
|
|
|
2015-12-15 09:28:43 +00:00
|
|
|
fully_strip_module(T,M,S) :-
|
|
|
|
'$hacks':fully_strip_module(T,M,S).
|
2018-05-30 21:54:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
%% @}
|