smallStuff

This commit is contained in:
Vitor Santos Costa 2019-03-03 02:01:39 +00:00
parent 5ff09fbf26
commit 908cfe3b77
11 changed files with 188 additions and 167 deletions

View File

@ -616,7 +616,6 @@ yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
memmove(ep, e, sizeof(*e));
ep->top_error = epp;
}
free(e);
return LOCAL_ActiveError;
}
/**

View File

@ -115,14 +115,18 @@ static inline bool CallPredicate(PredEntry *pen, choiceptr cut_pt,
inline static bool CallMetaCall(Term t, Term mod USES_REGS) {
// we have a creep requesr waiting
ARG1 = t;
if (IsVarTerm(t))
Yap_ThrowError(INSTANTIATION_ERROR, t, "meta-call");
if (IsIntTerm(t) || (IsApplTerm(t) && IsExtensionFunctor(FunctorOfTerm(t))))
Yap_ThrowError(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(t, mod), "meta-call");
ARG1 = t;
ARG2 = cp_as_integer(B PASS_REGS); /* p_current_choice_point */
ARG3 = t;
if (mod) {
ARG4 = mod;
} else {
ARG4 = TermProlog;
}
}
if (Yap_GetGlobal(AtomDebugMeta) == TermOn) {
return CallPredicate(PredTraceMetaCall, B,
PredTraceMetaCall->CodeOfPred PASS_REGS);
@ -141,6 +145,10 @@ inline static bool CallMetaCall(Term t, Term mod USES_REGS) {
Term Yap_ExecuteCallMetaCall(Term g, Term mod) {
CACHE_REGS
Term ts[4];
if (IsVarTerm(g))
Yap_ThrowError(INSTANTIATION_ERROR, g, "meta-call");
if (IsIntTerm(g) || (IsApplTerm(g) && IsExtensionFunctor(FunctorOfTerm(g))))
Yap_ThrowError(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(g, mod), "meta-call");
ts[0] = g;
ts[1] = cp_as_integer(B PASS_REGS); /* p_current_choice_point */
ts[2] = g;
@ -210,7 +218,7 @@ Term Yap_TermToIndicator(Term t, Term mod) {
ti[1] = MkIntTerm(0);
}
t = Yap_MkApplTerm(FunctorSlash, 2, ti);
if (mod != CurrentModule) {
if (mod != PROLOG_MODULE && mod != USER_MODULE && mod != TermProlog) {
ti[0] = mod;
ti[1] = t;
return Yap_MkApplTerm(FunctorModule, 2, ti);
@ -231,7 +239,7 @@ Term Yap_PredicateToIndicator(PredEntry *pe) {
}
Term t = Yap_MkApplTerm(FunctorSlash, 2, ti);
Term mod = pe->ModuleOfPred;
if (mod != TermUser && mod!= PROLOG_MODULE) {
if (mod != PROLOG_MODULE && mod != USER_MODULE && mod != TermProlog) {
ti[0] = mod;
ti[1] = t;
return Yap_MkApplTerm(FunctorModule, 2, ti);

View File

@ -1115,7 +1115,6 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
/* protect slots for portray */
writeTerm(tp, priority, 1, false, &wglb, &rwt);
tp = Yap_CyclesInTerm(t PASS_REGS);
if (flags & New_Line_f) {
if (flags & Fullstop_f) {
wrputc('.', wglb.stream);

View File

@ -2,7 +2,7 @@
* @file tries.yap
* @author Ricardo Rocha
*
* @brief
* @brief YAP tries interface
*
*
*/
@ -63,6 +63,8 @@
@ingroup library
@{
@brief Engine Independent trie library
The next routines provide a set of utilities to create and manipulate
prefix trees of Prolog terms. Tries were originally proposed to
implement tabling in Logic Programming, but can be used for other
@ -76,130 +78,6 @@ for efficiency. They are available through the
*/
/** @pred trie_check_entry(+ _Trie_,+ _Term_,- _Ref_)
Succeeds if a variant of term _Term_ is in trie _Trie_. An handle
_Ref_ gives a reference to the term.
*/
/** @pred trie_close(+ _Id_)
Close trie with identifier _Id_.
*/
/** @pred trie_close_all
Close all available tries.
*/
/** @pred trie_get_entry(+ _Ref_,- _Term_)
Unify _Term_ with the entry for handle _Ref_.
*/
/** @pred trie_load(+ _Trie_,+ _FileName_)
Load trie _Trie_ from the contents of file _FileName_.
*/
/** @pred trie_max_stats(- _Memory_,- _Tries_,- _Entries_,- _Nodes_)
Give maximal statistics on tries, including the amount of memory,
_Memory_, the number of tries, _Tries_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_.
*/
/** @pred trie_mode(? _Mode_)
Unify _Mode_ with trie operation mode. Allowed values are either
`std` (default) or `rev`.
*/
/** @pred trie_open(- _Id_)
Open a new trie with identifier _Id_.
*/
/** @pred trie_print(+ _Trie_)
Print trie _Trie_ on standard output.
*/
/** @pred trie_put_entry(+ _Trie_,+ _Term_,- _Ref_)
Add term _Term_ to trie _Trie_. The handle _Ref_ gives
a reference to the term.
*/
/** @pred trie_remove_entry(+ _Ref_)
Remove entry for handle _Ref_.
*/
/** @pred trie_remove_subtree(+ _Ref_)
Remove subtree rooted at handle _Ref_.
*/
/** @pred trie_save(+ _Trie_,+ _FileName_)
Dump trie _Trie_ into file _FileName_.
*/
/** @pred trie_stats(- _Memory_,- _Tries_,- _Entries_,- _Nodes_)
Give generic statistics on tries, including the amount of memory,
_Memory_, the number of tries, _Tries_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_.
*/
/** @pred trie_usage(+ _Trie_,- _Entries_,- _Nodes_,- _VirtualNodes_)
Give statistics on trie _Trie_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_, and the
number of _VirtualNodes_.
*/
:- load_foreign_files([tries], [], init_tries).

View File

@ -4,8 +4,17 @@
Comments: Tries module for Yap Prolog
version: $ID$
****************************************/
/**
@file tries.c
@brief yap-C wrapper for tries.
*/
/**
@addtogroup tries
@{
*/
/* -------------------------- */
/* Includes */
@ -164,6 +173,15 @@ static YAP_Bool p_close_all_tries(void) {
/* put_trie_entry(+Mode,+Trie,+Entry,-Ref) */
/** @pred trie_put_entry(+Mode,+ _Trie_,+ _Term_,- _Ref_)
Add term _Term_ to trie _Trie_. The handle _Ref_ gives
a reference to the term.
*/
#define arg_mode YAP_ARG1
#define arg_trie YAP_ARG2
#define arg_entry YAP_ARG3
@ -198,6 +216,13 @@ static YAP_Bool p_put_trie_entry(void) {
/* get_trie_entry(+Mode,+Ref,-Entry) */
/** @pred trie_get_entry(+ _Ref_,- _Term_)
Unify _Term_ with the entry for handle _Ref_.
*/
#define arg_mode YAP_ARG1
#define arg_ref YAP_ARG2
#define arg_entry YAP_ARG3
@ -228,7 +253,6 @@ static YAP_Bool p_get_trie_entry(void) {
#undef arg_ref
#undef arg_entry
/* remove_trie_entry(+Ref) */
static YAP_Bool p_remove_trie_entry(void) {
return p_trie_remove_entry();
@ -263,6 +287,14 @@ static YAP_Bool p_trie_open(void) {
/* trie_close(+Trie) */
/** @pred trie_close(+ _Id_)
Close trie with identifier _Id_.
*/
#define arg_trie YAP_ARG1
static YAP_Bool p_trie_close(void) {
/* check arg */
@ -277,6 +309,14 @@ static YAP_Bool p_trie_close(void) {
/* trie_close_all() */
/** @pred trie_close_all
Close all available tries.
*/
static YAP_Bool p_trie_close_all(void) {
trie_close_all();
return TRUE;
@ -284,6 +324,15 @@ static YAP_Bool p_trie_close_all(void) {
/* trie_mode(?Mode) */
/** @pred trie_mode(? _Mode_)
Unify _Mode_ with trie operation mode. Allowed values are either
`std` (default) or `rev`.
*/
#define arg_mode YAP_ARG1
static YAP_Bool p_trie_mode(void) {
YAP_Term mode_term;
@ -337,6 +386,15 @@ static YAP_Bool p_trie_put_entry(void) {
/* trie_check_entry(+Trie,+Entry,-Ref) */
/** @pred trie_check_entry(+ _Trie_,+ _Term_,- _Ref_)
Succeeds if a variant of term _Term_ is in trie _Trie_. An handle
_Ref_ gives a reference to the term.
*/
#define arg_trie YAP_ARG1
#define arg_entry YAP_ARG2
#define arg_ref YAP_ARG3
@ -458,6 +516,14 @@ static YAP_Bool p_trie_traverse_cont(void) {
/* trie_remove_entry(+Ref) */
/** @pred trie_remove_entry(+ _Ref_)
Remove entry for handle _Ref_.
*/
#define arg_ref YAP_ARG1
static YAP_Bool p_trie_remove_entry(void) {
/* check arg */
@ -472,6 +538,14 @@ static YAP_Bool p_trie_remove_entry(void) {
/* trie_remove_subtree(+Ref) */
/** @pred trie_remove_subtree(+ _Ref_)
Remove subtree rooted at handle _Ref_.
*/
#define arg_ref YAP_ARG1
static YAP_Bool p_trie_remove_subtree(void) {
/* check arg */
@ -564,8 +638,13 @@ static YAP_Bool p_trie_count_intersect(void) {
#undef arg_trie2
#undef arg_entries
/** @pred trie_save(+ _Trie_,+ _FileName_)
/* trie_save(+Trie,+FileName) */
Dump trie _Trie_ into file _FileName_.
*/
#define arg_trie YAP_ARG1
#define arg_file YAP_ARG2
static YAP_Bool p_trie_save(void) {
@ -594,6 +673,13 @@ static YAP_Bool p_trie_save(void) {
/* trie_load(-Trie,+FileName) */
/** @pred trie_load(- _Trie_,+ _FileName_)
Load trie _Trie_ from the contents of file _FileName_.
*/
#define arg_trie YAP_ARG1
#define arg_file YAP_ARG2
static YAP_Bool p_trie_load(void) {
@ -622,6 +708,15 @@ static YAP_Bool p_trie_load(void) {
#undef arg_trie
#undef arg_file
/** @pred trie_stats(- _Memory_,- _Tries_,- _Entries_,- _Nodes_)
Give generic statistics on tries, including the amount of memory,
_Memory_, the number of tries, _Tries_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_.
*/
/* trie_stats(-Memory,-Tries,-Entries,-Nodes) */
#define arg_memory YAP_ARG1
@ -650,6 +745,15 @@ static YAP_Bool p_trie_stats(void) {
/* trie_max_stats(-Memory,-Tries,-Entries,-Nodes) */
/** @pred trie_max_stats(- _Memory_,- _Tries_,- _Entries_,- _Nodes_)
Give maximal statistics on tries, including the amount of memory,
_Memory_, the number of tries, _Tries_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_.
*/
#define arg_memory YAP_ARG1
#define arg_tries YAP_ARG2
#define arg_entries YAP_ARG3
@ -675,6 +779,15 @@ static YAP_Bool p_trie_max_stats(void) {
#undef arg_nodes
/** @pred trie_usage(+ _Trie_,- _Entries_,- _Nodes_,- _VirtualNodes_)
Give statistics on trie _Trie_, the number of entries,
_Entries_, and the total number of nodes, _Nodes_, and the
number of _VirtualNodes_.
*/
/* trie_usage(+Trie,-Entries,-Nodes,-VirtualNodes) */
#define arg_trie YAP_ARG1
#define arg_entries YAP_ARG2
@ -704,6 +817,15 @@ static YAP_Bool p_trie_usage(void) {
/* trie_print(+Trie) */
/** @pred trie_print(+ _Trie_)
Print trie _Trie_ on standard output.
*/
#define arg_trie YAP_ARG1
static YAP_Bool p_trie_print(void) {
/* check arg */
@ -979,3 +1101,5 @@ int WINAPI win_tries(HANDLE hinst, DWORD reason, LPVOID reserved)
return 1;
}
#endif
/// @}

View File

@ -1144,7 +1144,8 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_PARSING_FINISHED;
}
Term t = syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos, fe->reading_clause, fe->msg);
syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos, fe->reading_clause, fe->msg);
if (ParserErrorStyle == TermException)
{
if (LOCAL_RestartEnv && !LOCAL_delay)
@ -1162,7 +1163,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (ParserErrorStyle == TermDec10)
{
return YAP_SCANNING;
return YAP_START_PARSING;
}
return YAP_PARSING_FINISHED;
}
@ -1184,6 +1185,8 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
return YAP_PARSING_FINISHED;
}
static int count;
/**
* @brief generic routine to read terms from a stream
*
@ -1201,58 +1204,59 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
*/
Term Yap_read_term(int sno, Term opts, bool clause)
{
FEnv fe;
REnv re;
#if EMACS
int emacs_cares = FALSE;
#endif
yap_error_descriptor_t *new = malloc(sizeof *new);
bool err = Yap_pushErrorContext(true, new);
int lvl = push_text_stack();
yap_error_descriptor_t *new = malloc(sizeof *new);
FEnv *fe = Malloc(sizeof *fe);
REnv *re = Malloc(sizeof *re);
bool err = Yap_pushErrorContext(true, new);
parser_state_t state = YAP_START_PARSING;
yhandle_t yopts = Yap_InitHandle(opts);
while (true)
{
switch (state)
{
case YAP_START_PARSING:
state = initParser(opts, &fe, &re, sno, clause);
opts = Yap_GetFromHandle(yopts);
state = initParser(opts, fe, re, sno, clause);
if (state == YAP_PARSING_FINISHED)
{
pop_text_stack(lvl);
Yap_PopHandle(yopts);
pop_text_stack(lvl);
Yap_popErrorContext(err, true);
return 0;
}
break;
case YAP_SCANNING:
state = scan(&re, &fe, sno);
state = scan(re, fe, sno);
break;
case YAP_SCANNING_ERROR:
state = scanError(&re, &fe, sno);
state = scanError(re, fe, sno);
break;
case YAP_PARSING:
state = parse(&re, &fe, sno);
state = parse(re, fe, sno);
break;
case YAP_PARSING_ERROR:
state = parseError(&re, &fe, sno);
state = parseError(re, fe, sno);
break;
case YAP_PARSING_FINISHED: {
CACHE_REGS
bool done;
if (fe.reading_clause)
done = complete_clause_processing(&fe, LOCAL_tokptr);
if (fe->reading_clause)
done = complete_clause_processing(fe, LOCAL_tokptr);
else
done = complete_processing(&fe, LOCAL_tokptr);
done = complete_processing(fe, LOCAL_tokptr);
if (!done)
{
state = YAP_PARSING_ERROR;
fe.t = 0;
fe->t = 0;
break;
}
#if EMACS
@ -1260,10 +1264,12 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
#endif /* EMACS */
pop_text_stack(lvl);
Yap_popErrorContext(err, true);
return fe.t;
Yap_PopHandle(yopts);
return fe->t;
}
}
}
Yap_PopHandle(yopts);
Yap_popErrorContext(err, true);
pop_text_stack(lvl);
return 0;

View File

@ -4,6 +4,7 @@ set (PROGRAMS
problog_lfi.yap
dtproblog.yap
aproblog.yap
problog_lbfgs.yap
problog_learning.yap
problog_learning_lbdd.yap
)

View File

@ -517,13 +517,14 @@ every 5th iteration only.
% directory where simplecudd executable is located
% automatically set during loading -- assumes it is in /usr/local/bin or same place where YAP has
% been installed.)
:- getcwd(PD0),
atom_concat(PD0, '../../bin', PD),
set_problog_path(PD).
:- PD = '/usr/local/bin',
set_problog_path(PD).
%:- stop_low_level_trace.
%%%%%%%%%%%%
@ -626,6 +627,7 @@ every 5th iteration only.
problog_dir(PD):- problog_path(PD).
%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -218,7 +218,7 @@
:- use_module(gflags).
:- use_module(os).
:- use_module(logger).
:- use_module(library(system), [file_exists/1, delete_file/1]).
:- use_module(library(system), [file_exists/1, delete_file/1,file_property/2]).
/** @defgroup ProbLogMiscellaneous ProbLog Miscellaneous Predicates

View File

@ -265,7 +265,7 @@
:- initialization(
( predicate_property(trie_disable_hash, imported_from(_M)) ->
trie_disable_hash
; print_message(warning,'The predicate tries:trie_disable_hash/0 does not exist. Please update trie library.')
; true % stop_low_level_trace, print_message(warning,'The predicate trie_disable_hash/0 does not exist. Please update trie library.')
)
).
@ -276,7 +276,7 @@
:- initialization((
problog_define_flag(use_db_trie, problog_flag_validate_boolean, 'use the builtin trie 2 trie transformation', false),
problog_define_flag(db_trie_opt_lvl, problog_flag_validate_integer, 'optimization level for the trie 2 trie transformation', 0),
problog_define_flag(compare_opt_lvl, problog_flag_validate_boolean, 'comparison mode for optimization level', false),
problog_define_flag(compare_opt_lvl, problog_flag_validate_boolean, 'comparison mode for optimizatione level', false),
problog_define_flag(db_min_prefix, problog_flag_validate_integer, 'minimum size of prefix for dbtrie to optimize', 2),
problog_define_flag(use_naive_trie, problog_flag_validate_boolean, 'use the naive algorithm to generate bdd scripts', false),
problog_define_flag(use_old_trie, problog_flag_validate_boolean, 'use the old trie 2 trie transformation no nested', true),

View File

@ -581,7 +581,8 @@ bdd_input_file(Filename) :-
concat_path_with_filename(Dir,'input.txt',Filename).
init_one_query(QueryID,Query,_Type) :-
% format_learning(3,' ~q example ~q: ~q~n',[Type,QueryID,Query]),
writeln(init_one_query(QueryID,Query,_Type)),
% format_learning(3,' ~q example ~q: ~q~n',[Type,QueryID,Query]),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if BDD file does not exist, call ProbLog
@ -592,13 +593,15 @@ init_one_query(QueryID,Query,_Type) :-
format_learning(3,' Reuse existing BDD ~q~n~n',[QueryID])
;
b_setval(problog_required_keep_ground_ids,false),
(QueryID mod 100 =:= 0 -> writeln(QueryID) ; true),
problog_flag(init_method,(Query,N,Bdd,graph2bdd(X,Y,N,Bdd))),
problog_flag(init_method,(Query,N,Bdd,G)),
Query =.. [_,X,Y]
->
Bdd = bdd(Dir, Tree, MapList),
(
graph2bdd(X,Y,N,Bdd)
G
->
rb_new(H0),
maplist_to_hash(MapList, H0, Hash),
@ -608,8 +611,9 @@ init_one_query(QueryID,Query,_Type) :-
% Grad=[]
),
write('.'),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
;
recordz(QueryID,bdd(Dir, Grad, MapList),_)
).
/* ;
problog_flag(init_method,(Query,NOf,Bdd,problog_kbest_as_bdd(Call,NOf,Bdd))) ->
b_setval(problog_required_keep_ground_ids,false),
rb_new(H0),
@ -624,20 +628,20 @@ init_one_query(QueryID,Query,_Type) :-
tree_to_grad(Tree, Hash, [], Grad),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
;
problog_flag(init_method,(Query,NOf,Bdd,Call)) ->
problog_flag(init_method,(Query,NOf,Bdd,_Call)) ,
Query = gene(X,Y),
b_setval(problog_required_keep_ground_ids,false),
rb_new(H0),
Bdd = bdd(Dir, Tree, MapList),
% trace,
problog:Call,
user:graph2bdd(X,Y,1,Bdd),
maplist_to_hash(MapList, H0, Hash),
Tree \= [],
%put_code(0'.),
tree_to_grad(Tree, Hash, [], Grad),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
).
recordz(QueryID,bdd(Dir, Grad, MapList),_).
*/
%========================================================================