This commit is contained in:
Vitor Santos Costa 2019-03-04 15:49:53 +00:00
parent 7ab1624401
commit 21ff73dd70
21 changed files with 157 additions and 148 deletions

View File

@ -1341,6 +1341,7 @@ restart_aux:
while (t1 != TermNil) { while (t1 != TermNil) {
inpv[i].type = YAP_STRING_ATOM, inpv[i].val.t = HeadOfTerm(t1); inpv[i].type = YAP_STRING_ATOM, inpv[i].val.t = HeadOfTerm(t1);
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
t1 = TailOfTerm(t1); t1 = TailOfTerm(t1);
} }
@ -1389,6 +1390,7 @@ restart_aux:
while (t1 != TermNil) { while (t1 != TermNil) {
inpv[i].type = YAP_STRING_STRING; inpv[i].type = YAP_STRING_STRING;
inpv[i].val.t = HeadOfTerm(t1); inpv[i].val.t = HeadOfTerm(t1);
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
t1 = TailOfTerm(t1); t1 = TailOfTerm(t1);
} }
@ -1428,8 +1430,6 @@ restart_aux:
if (*tailp != TermNil) { if (*tailp != TermNil) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST; LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else { } else {
seq_tv_t *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t));
seq_tv_t *out = (seq_tv_t *)Malloc(sizeof(seq_tv_t));
int i = 0; int i = 0;
Atom at; Atom at;
@ -1438,6 +1438,8 @@ restart_aux:
pop_text_stack(l); pop_text_stack(l);
return rc; return rc;
} }
seq_tv_t *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t));
seq_tv_t *out = (seq_tv_t *)Malloc(sizeof(seq_tv_t));
if (!inpv) { if (!inpv) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
goto error; goto error;
@ -1448,6 +1450,7 @@ restart_aux:
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_CHARS | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_CHARS |
YAP_STRING_CODES; YAP_STRING_CODES;
inpv[i].val.t = HeadOfTerm(t1); inpv[i].val.t = HeadOfTerm(t1);
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
t1 = TailOfTerm(t1); t1 = TailOfTerm(t1);
} }
@ -1464,6 +1467,7 @@ restart_aux:
} }
error: error:
/* Error handling */ /* Error handling */
pop_text_stack(l);
if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) { if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) {
goto restart_aux; goto restart_aux;
} }
@ -1494,6 +1498,7 @@ restart_aux:
inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT | inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM; YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
inpv[i].val.t = HeadOfTerm(t1); inpv[i].val.t = HeadOfTerm(t1);
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
t1 = TailOfTerm(t1); t1 = TailOfTerm(t1);
} }
@ -1543,10 +1548,12 @@ restart_aux:
inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT | inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM; YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
inpv[i].val.t = HeadOfTerm(t1); inpv[i].val.t = HeadOfTerm(t1);
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT | inpv[i].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM; YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
inpv[i].val.t = t2; inpv[i].val.t = t2;
inpv[i].enc = ENC_ISO_UTF8;
i++; i++;
t1 = TailOfTerm(t1); t1 = TailOfTerm(t1);
} }

View File

@ -164,7 +164,7 @@ PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) {
restart: restart:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t0, pname); Yap_ThrowError(INSTANTIATION_ERROR, t0, pname);
return NULL; return NULL;
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
PredEntry *ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); PredEntry *ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod));
@ -177,7 +177,7 @@ restart:
} else if (IsApplTerm(t)) { } else if (IsApplTerm(t)) {
Functor fun = FunctorOfTerm(t); Functor fun = FunctorOfTerm(t);
if (IsExtensionFunctor(fun)) { if (IsExtensionFunctor(fun)) {
Yap_Error(TYPE_ERROR_CALLABLE, Yap_TermToIndicator(t, tmod), pname); Yap_ThrowError(TYPE_ERROR_CALLABLE, t, pname);
return NULL; return NULL;
} }
if (fun == FunctorModule) { if (fun == FunctorModule) {

View File

@ -1772,6 +1772,8 @@ void Yap_InitFlags(bool bootstrap) {
CACHE_REGS CACHE_REGS
tr_fr_ptr tr0 = TR; tr_fr_ptr tr0 = TR;
flag_info *f = global_flags_setup; flag_info *f = global_flags_setup;
int lvl = push_text_stack();
char *buf = Malloc(4098);
GLOBAL_flagCount = 0; GLOBAL_flagCount = 0;
if (bootstrap) { if (bootstrap) {
GLOBAL_Flags = (union flagTerm *)Yap_AllocCodeSpace( GLOBAL_Flags = (union flagTerm *)Yap_AllocCodeSpace(
@ -1794,7 +1796,16 @@ void Yap_InitFlags(bool bootstrap) {
(union flagTerm *)Yap_AllocCodeSpace(sizeof(union flagTerm) * nflags); (union flagTerm *)Yap_AllocCodeSpace(sizeof(union flagTerm) * nflags);
f = local_flags_setup; f = local_flags_setup;
while (f->name != NULL) { while (f->name != NULL) {
bool itf = setInitialValue(bootstrap, f->def, f->init, char *s;
if (f->init == NULL || f->init[0] == '\0') s = NULL;
else if (strlen(f->init) < 4096) {
s = buf;
strcpy(buf, f->init);
} else {
s = Malloc(strlen(f->init)+1);
strcpy(s, f->init);
}
bool itf = setInitialValue(bootstrap, f->def, s,
LOCAL_Flags + LOCAL_flagCount); LOCAL_Flags + LOCAL_flagCount);
// Term itf = Yap_BufferToTermWithPrioBindings(f->init, // Term itf = Yap_BufferToTermWithPrioBindings(f->init,
// strlen(f->init)+1, // strlen(f->init)+1,
@ -1809,7 +1820,7 @@ void Yap_InitFlags(bool bootstrap) {
if (GLOBAL_Stream[StdInStream].status & Readline_Stream_f) { if (GLOBAL_Stream[StdInStream].status & Readline_Stream_f) {
setBooleanGlobalPrologFlag(READLINE_FLAG, true); setBooleanGlobalPrologFlag(READLINE_FLAG, true);
} }
pop_text_stack(lvl);
if (!bootstrap) { if (!bootstrap) {
Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag, Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag,
cont_yap_flag, 0); cont_yap_flag, 0);

View File

@ -1592,10 +1592,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
while (TRUE) { while (TRUE) {
if (charp > TokImage + (sz - 1)) { if (charp > TokImage + (sz - 1)) {
size_t sz = charp-TokImage;
TokImage = Realloc(TokImage, Yap_Min(sz * 2, sz + MBYTE)); TokImage = Realloc(TokImage, Yap_Min(sz * 2, sz + MBYTE));
if (TokImage == NULL) { if (TokImage == NULL) {
return CodeSpaceError(t, p, l); return CodeSpaceError(t, p, l);
} }
charp = TokImage+sz;
break; break;
} }
if (ch == 10 && trueGlobalPrologFlag(ISO_FLAG)) { if (ch == 10 && trueGlobalPrologFlag(ISO_FLAG)) {

View File

@ -37,9 +37,6 @@
#include "string.h" #include "string.h"
#endif #endif
#define Malloc malloc
#define Realloc realloc
extern int cs[10]; extern int cs[10];
int cs[10]; int cs[10];

View File

@ -18,6 +18,7 @@
#include "Yap.h" #include "Yap.h"
#include "YapEval.h" #include "YapEval.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "YapStreams.h"
#include "YapText.h" #include "YapText.h"
#include "Yatom.h" #include "Yatom.h"
#include "yapio.h" #include "yapio.h"
@ -191,6 +192,8 @@ void *MallocAtLevel(size_t sz, int atL USES_REGS) {
void *Realloc(void *pt, size_t sz USES_REGS) { void *Realloc(void *pt, size_t sz USES_REGS) {
struct mblock *old = pt, *o; struct mblock *old = pt, *o;
if (!pt)
return Malloc(sz PASS_REGS);
old--; old--;
sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), Yap_Max(CELLSIZE,sizeof(struct mblock))); sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), Yap_Max(CELLSIZE,sizeof(struct mblock)));
o = realloc(old, sz); o = realloc(old, sz);
@ -464,10 +467,11 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
} }
} }
if (err0 != LOCAL_Error_TYPE) { if (err0 != LOCAL_Error_TYPE) {
Yap_ThrowError(LOCAL_Error_TYPE, inp->val.t, "while reading text in"); Yap_ThrowError(LOCAL_Error_TYPE,
inp->val.t, "while converting term %s", Yap_TermToBuffer(
inp->val.t, Handle_cyclics_f|Quote_illegal_f | Handle_vars_f));
} }
} }
if ((inp->val.t == TermNil) && inp->type & YAP_STRING_PREFER_LIST ) if ((inp->val.t == TermNil) && inp->type & YAP_STRING_PREFER_LIST )
{ {
out = Malloc(4); out = Malloc(4);
@ -580,6 +584,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
} }
pop_text_stack(lvl); pop_text_stack(lvl);
return inp->val.uc; return inp->val.uc;
} }
if (inp->type & YAP_STRING_WCHARS) { if (inp->type & YAP_STRING_WCHARS) {
@ -591,7 +596,10 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
} }
static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) { static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) {
size_t min = 0, max = strlen((char *)s0); size_t min = 0, max;
if (s0 && s0[0]) max = strlen((char *)s0);
else max = 0;
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) { if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
if (out->type & YAP_STRING_NCHARS) if (out->type & YAP_STRING_NCHARS)
@ -962,7 +970,6 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
// else if (out->type & YAP_STRING_NCHARS && // else if (out->type & YAP_STRING_NCHARS &&
// const unsigned char *ptr = skip_utf8(buf) // const unsigned char *ptr = skip_utf8(buf)
} }
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) { if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
if (out->type & YAP_STRING_UPCASE) { if (out->type & YAP_STRING_UPCASE) {
if (!upcase(buf, out)) { if (!upcase(buf, out)) {

View File

@ -1185,8 +1185,6 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
return YAP_PARSING_FINISHED; return YAP_PARSING_FINISHED;
} }
static int count;
/** /**
* @brief generic routine to read terms from a stream * @brief generic routine to read terms from a stream
* *
@ -1208,6 +1206,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
int emacs_cares = FALSE; int emacs_cares = FALSE;
#endif #endif
int lvl = push_text_stack(); int lvl = push_text_stack();
Term rc;
yap_error_descriptor_t *new = malloc(sizeof *new); yap_error_descriptor_t *new = malloc(sizeof *new);
FEnv *fe = Malloc(sizeof *fe); FEnv *fe = Malloc(sizeof *fe);
REnv *re = Malloc(sizeof *re); REnv *re = Malloc(sizeof *re);
@ -1256,16 +1255,17 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
if (!done) if (!done)
{ {
state = YAP_PARSING_ERROR; state = YAP_PARSING_ERROR;
fe->t = 0; rc = fe->t = 0;
break; break;
} }
#if EMACS #if EMACS
first_char = tokstart->TokPos; first_char = tokstart->TokPos;
#endif /* EMACS */ #endif /* EMACS */
rc = fe->t;
pop_text_stack(lvl); pop_text_stack(lvl);
Yap_popErrorContext(err, true); Yap_popErrorContext(err, true);
Yap_PopHandle(yopts); Yap_PopHandle(yopts);
return fe->t; return rc;
} }
} }
} }

View File

@ -524,7 +524,9 @@ every 5th iteration only.
:- PD = '/usr/local/bin', :- PD = '/usr/local/bin',
set_problog_path(PD). set_problog_path(PD).
%:- stop_low_level_trace. :- PD = '$HOME/,local/bin',
set_problog_path(PD).
%%%%%%%%%%%% %%%%%%%%%%%%
@ -552,10 +554,7 @@ every 5th iteration only.
%%%%%%%%%%%% %%%%%%%%%%%%
% max number of calls to probabilistic facts per derivation (to ensure termination) % max number of calls to probabilistic facts per derivation (to ensure termination)
%%%%%%%%%%%% %%%%%%%%%%%%
:- initialization( problog_define_flag(maxsteps, problog_flag_validate_posint, 'max. number of prob. steps per derivation', 1000, inference) ).
:- initialization(
problog_define_flag(maxsteps, problog_flag_validate_posint, 'max. number of prob. steps per derivation', 1000, inference)
).
%%%%%%%%%%%% %%%%%%%%%%%%
% BDD timeout in seconds, used as option in BDD tool % BDD timeout in seconds, used as option in BDD tool
@ -1826,7 +1825,7 @@ eval_dnf(OriTrie1, Prob, Status) :-
; ;
Trie = OriTrie Trie = OriTrie
), ),
(problog_flag(bdd_static_order, true) -> (problog_flag(bdd_static_order, true) ->
get_order(Trie, Order), get_order(Trie, Order),
problog_flag(static_order_file, SOFName), problog_flag(static_order_file, SOFName),
convert_filename_to_working_path(SOFName, SOFileName), convert_filename_to_working_path(SOFName, SOFileName),

View File

@ -243,7 +243,7 @@
problog_define_flag(refine_anclst, problog_flag_validate_boolean, 'refine the ancestor list with their childs', false, nested_tries), problog_define_flag(refine_anclst, problog_flag_validate_boolean, 'refine the ancestor list with their childs', false, nested_tries),
problog_define_flag(anclst_represent,problog_flag_validate_in_list([list, integer]), 'represent the ancestor list', list, nested_tries) problog_define_flag(anclst_represent,problog_flag_validate_in_list([list, integer]), 'represent the ancestor list', list, nested_tries)
)). )).
:- stop_low_level_trace.
trie_replace_entry(_Trie, Entry, E, false):- trie_replace_entry(_Trie, Entry, E, false):-
trie_get_entry(Entry, Proof), trie_get_entry(Entry, Proof),
@ -486,3 +486,4 @@ get_trie(Trie, Label, Ancestors):-
set_trie(Trie, Label, Ancestors):- set_trie(Trie, Label, Ancestors):-
recordz(problog_trie_table, store(Trie, Ancestors, Label), _). recordz(problog_trie_table, store(Trie, Ancestors, Label), _).

View File

@ -69,7 +69,7 @@ elif platform.system() == 'Darwin':
win_libs = [] win_libs = []
local_libs = ['Py4YAP'] local_libs = ['Py4YAP']
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/lib','-Wl,-rpath,'+join('/lib','..'),'-Wl,-rpath,../yap4py'] my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-L','/lib','-Wl,-rpath,/lib','-Wl,-rpath,'+join('/lib','..'),'-Wl,-rpath,../yap4py']
win_libs = [] win_libs = []
local_libs = ['Py4YAP'] local_libs = ['Py4YAP']

View File

@ -862,7 +862,6 @@ nb_setval('$if_level',0).
'__NB_getval__'('$lf_status', TOpts, fail), '__NB_getval__'('$lf_status', TOpts, fail),
'$lf_opt'( initialization, TOpts, Ref), '$lf_opt'( initialization, TOpts, Ref),
nb:nb_queue_close(Ref, Answers, []), nb:nb_queue_close(Ref, Answers, []),
writeln(init:Answers),
'$process_init_goal'(Answers). '$process_init_goal'(Answers).
'$exec_initialization_goals'. '$exec_initialization_goals'.
@ -1150,11 +1149,11 @@ exists_source(File) :-
'$full_filename'(F0, F) :- '$full_filename'(F0, F) :-
'$undefined'('$absolute_file_name'(F0,[],F),prolog_complete), '$undefined'(absolute_file_name(F0,[],F),prolog),
!, !,
absolute_file_system_path(F0, F). absolute_file_system_path(F0, F).
'$full_filename'(F0, F) :- '$full_filename'(F0, F) :-
'$absolute_file_name'(F0,[access(read), absolute_file_name(F0,[access(read),
file_type(prolog), file_type(prolog),
file_errors(fail), file_errors(fail),
solutions(first), solutions(first),
@ -1450,9 +1449,7 @@ environment. Use initialization/2 for more flexible behavior.
'$initialization_queue'(G) :- '$initialization_queue'(G) :-
b_getval('$lf_status', TOpts), b_getval('$lf_status', TOpts),
'$lf_opt'( initialization, TOpts, Ref), '$lf_opt'( initialization, TOpts, Ref),
writeln(G),
nb:nb_queue_enqueue(Ref, G), nb:nb_queue_enqueue(Ref, G),
writeln(Ref),
fail. fail.
'$initialization_queue'(_). '$initialization_queue'(_).

View File

@ -304,9 +304,8 @@ prolog:when(_,Goal) :-
% %
% %
'$declare_when'(Cond, G) :- '$declare_when'(Cond, G) :-
generate_code_for_when(Cond, G, Code), generate_code_for_when(Cond, G, Code),
'$current_module'(Module), '$$compile'(Code, Module, assertz, Code, _), fail.
'$$compile'(Code, Code, 5, Module), fail.
'$declare_when'(_,_). '$declare_when'(_,_).
% %
@ -434,8 +433,8 @@ suspend_when_goals([_|_], _).
% %
prolog:'$block'(Conds) :- prolog:'$block'(Conds) :-
generate_blocking_code(Conds, _, Code), generate_blocking_code(Conds, _, Code),
'$current_module'(Module), '$yap_strip_module'(Code, Module, NCode),
'$$compile'(Code, Code, 5, Module), fail. '$$compile'(Code, assertz, Code, _), fail.
prolog:'$block'(_). prolog:'$block'(_).
generate_blocking_code(Conds, G, Code) :- generate_blocking_code(Conds, G, Code) :-
@ -515,8 +514,7 @@ generate_for_each_arg_in_block([V|L], (var(V),If), (nonvar(V);Whens)) :-
prolog:'$wait'(Na/Ar) :- prolog:'$wait'(Na/Ar) :-
functor(S, Na, Ar), functor(S, Na, Ar),
arg(1, S, A), arg(1, S, A),
'$current_module'(M), '$$compile'((S :- var(A), !, freeze(A, S)), assertz, (S :- var(A), !, freeze(A, S)), _), fail.
'$$compile'((S :- var(A), !, freeze(A, S)), (S :- var(A), !, freeze(A, S)), 5, M), fail.
prolog:'$wait'(_). prolog:'$wait'(_).
/** @pred frozen( _X_, _G_) /** @pred frozen( _X_, _G_)

View File

@ -20,8 +20,6 @@
:- module('$db_load', :- module('$db_load',
[]). []).
:- use_system_module( '$_boot', ['$$compile'/4]).
:- use_system_module( '$_errors', ['$do_error'/2]). :- use_system_module( '$_errors', ['$do_error'/2]).
:- use_system_module( attributes, [get_module_atts/2, :- use_system_module( attributes, [get_module_atts/2,

View File

@ -477,7 +477,7 @@ be lost.
'$trace_goal'(G, M, GoalNumber, H) :- '$trace_goal'(G, M, GoalNumber, H) :-
'$undefined'(G, M), '$undefined'(G, M),
!, !,
'$get_undefined_predicates'(M:G, NM:Goal), '$get_predicate_definition'(M:G, NM:Goal),
( ( M == NM ; NM == prolog), G == Goal ( ( M == NM ; NM == prolog), G == Goal
-> ->
yap_flag( unknown, Action ), yap_flag( unknown, Action ),

View File

@ -33,50 +33,75 @@ fail.
%:- start_low_level_trace. %:- start_low_level_trace.
% parent module mechanism % parent module mechanism
'$get_undefined_predicates'(ImportingMod:G,ExportingMod:G0) :- %% system has priority
recorded('$import','$import'(ExportingMod,ImportingMod,G,G0,_,_),_) '$get_predicate_definition'(_ImportingMod:G,prolog:G) :-
-> '$pred_exists'(G,prolog).
true %% I am there, no need to import
; '$get_predicate_definition'(Mod:Pred,Mod:Pred) :-
%% this should have been caught before '$pred_exists'(Pred, Mod).
'$is_system_predicate'(G, ImportingMod) %% export table
-> '$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
true recorded('$import','$import'(ExportingMod,ImportingMod,G0,G,_,_),_).
; %% parent/user
% autoload '$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
current_prolog_flag(autoload, true) ( '$parent_module'(ImportingMod, PMod) ), %; PMod = user),
-> ('$pred_exists'(PMod,G0), PMod:G0 = ExportingMod:G;
'$autoload'(G, ImportingMod, ExportingMod, swi) recorded('$import','$import'(ExportingMod,PMod,G0,G,_,_),_)
; ).
'$parent_module'(ImportingMod, NewImportingMod) %% autoload`
-> '$get_predicate_definition'(ImportingMod:G,ExportingMod:G) :-
'$get_undefined_predicates'(NewImportingMod:G, ExportingMod:G0). current_prolog_flag(autoload, true),
'$autoload'(G, ImportingMod, ExportingMod, swi).
'$continue_imported'(Mod:Pred,Mod,Pred) :-
'$pred_exists'(Pred, Mod), '$predicate_definition'(Imp:Pred,Exp:NPred) :-
'$predicate_definition'(Imp:Pred,[],Exp:NPred),
%writeln((Imp:Pred -> Exp:NPred )).
!. !.
'$continue_imported'(FM:FPred,Mod:Pred) :-
'$get_undefined_predicates'(FM:FPred, ModI:PredI), '$one_predicate_definition'(Imp:Pred,Exp:NPred) :-
'$continue_imported'(ModI:PredI,Mod:Pred). '$predicate_definition'(Imp:Pred,[],Exp:NPred),
%writeln((Imp:Pred -> Exp:NPred )).
!.
'$one_predicate_definition'(Exp:Pred,Exp:Pred).
'$predicate_definition'(M0:Pred0,Path,ModF:PredF) :-
'$get_predicate_definition'(M0:Pred0, Mod:Pred),
\+ lists:member(Mod:Pred,Path),
(
'$predicate_definition'(Mod:Pred,[Mod:Pred|Path],ModF:PredF)
;
Mod = ModF, Pred = PredF
).
% %
'$get_undefined_pred'(ImportingMod:G, ExportingMod:G0) :- '$get_undefined_predicate'(ImportingMod:G, ExportingMod:G0) :-
must_be_callable( ImportingMod:G ), is_callable( ImportingMod:G ),
'$get_undefined_predicates'(ImportingMod:G, ExportingMod:G0). '$predicate_definition'(ImportingMod:G,[], ExportingMod:G0),
ImportingMod:G \= ExportingMod:G0,
!.
% be careful here not to generate an undefined exception. % be careful here not to generate an undefined exception.
'$imported_predicate'(ImportingMod:G, ExportingMod:G0) :- '$imported_predicate'(ImportingMod:G, ExportingMod:G0) :-
var(G) -> ( var(ImportingMod) ->
'$current_predicate'(_,G,ImportingMod,_), current_module(ImportingMod)
'$imported_predicate'(ImportingMod:G, ExportingMod:G0) ;
; true
var(ImportingMod) -> ),
current_module(ImportingMod), (
'$imported_predicate'(ImportingMod:G, ExportingMod:G0) var(G) ->
; '$current_predicate'(_,G,ImportingMod,_)
'$undefined'(G, ImportingMod), ;
'$get_undefined_predicates'(ImportingMod:G, ExportingMod:G0), true
ExportingMod \= ImportingMod. ),
(
'$undefined'(G, ImportingMod)
->
'$predicate_definition'(ImportingMod:G, ExportingMod:G0),
ExportingMod \= ImportingMod
;
ExportingMod = ImportingMod, G = G0
).
% check if current module redefines an imported predicate. % check if current module redefines an imported predicate.
@ -92,16 +117,6 @@ fail.
'$not_imported'(_, _). '$not_imported'(_, _).
'$verify_import'(_M:G, prolog:G) :-
'$is_system_predicate'(G, prolog).
'$verify_import'(M:G, NM:NG) :-
'$get_undefined_predicates'(M:G, M, NM:NG),
!.
'$verify_import'(MG, MG).
'$autoload'(G, _mportingMod, ExportingMod, Dialect) :- '$autoload'(G, _mportingMod, ExportingMod, Dialect) :-
functor(G, Name, Arity), functor(G, Name, Arity),
'$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect), '$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect),

View File

@ -201,7 +201,7 @@ meta_predicate(P) :-
'$yap_strip_module'(CM:G, NCM, NG). '$yap_strip_module'(CM:G, NCM, NG).
'$match_mod'(G, _HMod, _SMod, M, O) :- '$match_mod'(G, _HMod, _SMod, M, O) :-
'$is_system_predicate'(G,M), M = prolog,
!, !,
O = G. O = G.
'$match_mod'(G, M, M, M, G) :- !. '$match_mod'(G, M, M, M, G) :- !.

View File

@ -41,7 +41,6 @@
'$convert_for_export'/7, '$convert_for_export'/7,
'$do_import'/3, '$do_import'/3,
'$extend_exports'/3, '$extend_exports'/3,
'$get_undefined_pred'/4,
'$imported_predicate'/2, '$imported_predicate'/2,
'$meta_expand'/6, '$meta_expand'/6,
'$meta_predicate'/2, '$meta_predicate'/2,
@ -85,6 +84,8 @@
/** /**
@pred use_module( +Files ) is directive @pred use_module( +Files ) is directive
@brief load a module file @brief load a module file
This predicate loads the file specified by _Files_, importing all This predicate loads the file specified by _Files_, importing all
@ -311,16 +312,6 @@ use_module(F,Is) :-
'$not_imported'(_, _). '$not_imported'(_, _).
'$verify_import'(_M:G, prolog:G) :-
'$is_system_predicate'(G, prolog).
'$verify_import'(M:G, NM:NG) :-
'$get_undefined_pred'(G, M, NG, NM),
!.
'$verify_import'(MG, MG).
/** @pred current_module( ? Mod:atom) is nondet /** @pred current_module( ? Mod:atom) is nondet
@ -453,8 +444,10 @@ export_list(Module, List) :-
'$add_to_imports'(Tab, Module, ContextModule). '$add_to_imports'(Tab, Module, ContextModule).
%'$do_import'(K, _, _) :- writeln(K), fail. %'$do_import'(K, _, _) :- writeln(K), fail.
'$do_import'(op(Prio,Assoc,Name), _Mod, ContextMod) :- '$do_import'(op(Prio,Assoc,Name), Mod, ContextMod) :-
op(Prio,Assoc,ContextMod:Name). op(Prio,Assoc,Mod:Name),
op(Prio,Assoc,ContextMod:Name),
!.
'$do_import'(N0/K0-N0/K0, Mod, Mod) :- !. '$do_import'(N0/K0-N0/K0, Mod, Mod) :- !.
'$do_import'(N0/K0-N0/K0, _Mod, prolog) :- !. '$do_import'(N0/K0-N0/K0, _Mod, prolog) :- !.
'$do_import'(_N/K-N1/K, _Mod, ContextMod) :- '$do_import'(_N/K-N1/K, _Mod, ContextMod) :-
@ -465,26 +458,17 @@ export_list(Module, List) :-
\+ '$undefined'(S,ContextMod), !. \+ '$undefined'(S,ContextMod), !.
'$do_import'( N/K-N1/K, Mod, ContextMod) :- '$do_import'( N/K-N1/K, Mod, ContextMod) :-
functor(G,N,K), functor(G,N,K),
'$follow_import_chain'(Mod,G,M0,G0), '$one_predicate_definition'(Mod:G,M0:G0),
M0\=prolog,
(Mod\=M0->N\=N1;true),
G0=..[_N0|Args], G0=..[_N0|Args],
G1=..[N1|Args], G1=..[N1|Args],
( '$check_import'(M0,ContextMod,N1,K) -> recordaifnot('$import','$import'(M0,ContextMod,G0,G1,N1,K),_),
( ContextMod == prolog -> %\+ '$is_system_predicate'(G1, prolog),
recordzifnot('$import','$import'(M0,user,G0,G1,N1,K),_), %'$compile'((G1:-M0:G0), reconsult,(ContextMod:G1:-M0:G0) , ContextMod, R),
\+ '$is_system_predicate'(G1, prolog), fail.
'$compile'((G1:-M0:G0), reconsult,(user:G1:-M0:G0) , user, R), % always succeed.
fail '$do_import'(_,_,_).
;
recordaifnot('$import','$import'(M0,ContextMod,G0,G1,N1,K),_),
\+ '$is_system_predicate'(G1, prolog),
'$compile'((G1:-M0:G0), reconsult,(ContextMod:G1:-M0:G0) , ContextMod, R),
fail
;
true
)
;
true
).
'$follow_import_chain'(M,G,M0,G0) :- '$follow_import_chain'(M,G,M0,G0) :-
recorded('$import','$import'(M1,M,G1,G,_,_),_), M \= M1, !, recorded('$import','$import'(M1,M,G1,G,_,_),_), M \= M1, !,

View File

@ -50,9 +50,8 @@ assert(Clause) :-
'$assert'(Clause, assertz, _). '$assert'(Clause, assertz, _).
'$assert'(Clause, Where, R) :- '$assert'(Clause, Where, R) :-
'$yap_strip_clause'(Clause, _, _Clause0), '$expand_clause'(Clause0,C0,C),
'$expand_clause'(Clause,C0,C), '$$compile'(CC, Where, C0, R).
'$$compile'(C, Where, C0, R).
/** @pred asserta(+ _C_,- _R_) /** @pred asserta(+ _C_,- _R_)

View File

@ -395,15 +395,7 @@ predicate_property(Pred,Prop) :-
'$current_predicate'(_,M,Pred,system), '$current_predicate'(_,M,Pred,system),
'$yap_strip_module'(M:Pred, Mod, TruePred) '$yap_strip_module'(M:Pred, Mod, TruePred)
), ),
'$predicate_definition'(Mod:TruePred, M:NPred),
(
'$pred_exists'(TruePred, Mod)
->
M = Mod,
NPred = TruePred
;
'$get_undefined_pred'(Mod:TruePred, M:NPred)
),
'$predicate_property'(NPred,M,Mod,Prop). '$predicate_property'(NPred,M,Mod,Prop).
'$predicate_property'(P,M,_,built_in) :- '$predicate_property'(P,M,_,built_in) :-

View File

@ -218,22 +218,23 @@ live :-
'$go_compile_clause'(G, _Vs, _Pos, Where, Source) :- '$go_compile_clause'(G, _Vs, _Pos, Where, Source) :-
'$precompile_term'(G, Source, G1), '$precompile_term'(G, Source, G1),
!, !,
'$$compile'(G1, Where, Source, _). '$$compile'(G1, M, Where, Source, _).
'$go_compile_clause'(G,_Vs,_Pos, _Where, _Source) :- '$go_compile_clause'(G,_Vs,_Pos, _Where, _Source) :-
throw(error(system, compilation_failed(G))). throw(error(system, compilation_failed(G))).
'$$compile'(C, Where, C0, R) :- '$$compile'(C, Where, C0, R) :-
'$head_and_body'( C, MH, B ), '$head_and_body'( M0:C, MH, B ),
strip_module( MH, Mod, H), '$yap_strip_module'( MH, Mod, H),
'$yap_strip_module'( MB, ModB, BF),
( (
'$undefined'(H, Mod) '$undefined'(H, Mod)
-> ->
'$init_pred'(H, Mod, Where) '$init_pred'(H, Mod, Where)
; ;
true trueq
), ),
% writeln(Mod:((H:-B))), % writeln(Mod:((H:-B))),
'$compile'((H:-B), Where, C0, Mod, R). '$compile'((H:-ModB:BF), Where, C0, Mod, R).
'$init_pred'(H, Mod, _Where ) :- '$init_pred'(H, Mod, _Where ) :-
recorded('$import','$import'(NM,Mod,NH,H,_,_),RI), recorded('$import','$import'(NM,Mod,NH,H,_,_),RI),
@ -783,7 +784,8 @@ Command = (H --> B) ->
'$boot_dcg'( H, B, Where ) :- '$boot_dcg'( H, B, Where ) :-
'$translate_rule'((H --> B), (NH :- NB) ), '$translate_rule'((H --> B), (NH :- NB) ),
'$$compile'((NH :- NB), Where, ( H --> B), _R), '$yap_strip_module'((NH :- NB), M, G),
'$$compile'(G, M, Where, ( H --> B), _R),
!. !.
'$boot_dcg'( H, B, _ ) :- '$boot_dcg'( H, B, _ ) :-
format(user_error, ' ~w --> ~w failed.~n', [H,B]). format(user_error, ' ~w --> ~w failed.~n', [H,B]).
@ -875,7 +877,7 @@ gated_call(Setup, Goal, Catcher, Cleanup) :-
'$precompile_term'(Term, Term, Term). '$precompile_term'(Term, Term, Term).
'$expand_clause'(InputCl, C1, CO) :- '$expand_clause'(InputCl, C1, CO) :-
'$yap_strip_clause'(InputCl, M, ICl), '$yap_strip_module'(InputCl, M, ICl),
'$expand_a_clause'( M:ICl, M, C1, CO), '$expand_a_clause'( M:ICl, M, C1, CO),
!. !.
'$expand_clause'(Cl, Cl, Cl). '$expand_clause'(Cl, Cl, Cl).

View File

@ -91,23 +91,23 @@ undefined_query(G0, M0, Cut) :-
user:unknown_predicate_handler(GM0,EM0,MG), user:unknown_predicate_handler(GM0,EM0,MG),
!. !.
'$undefp_search'(M0:G0, MG) :- '$undefp_search'(M0:G0, MG) :-
'$get_undefined_predicates'(M0:G0, MG), !. '$predicate_definition'(M0:G0, MG), !.
% undef handler % undef handler
'$undefp'([M0|G0],MG) :- '$undefp'([M0|G0],true) :-
% make sure we do not loop on undefined predicates % make sure we do not loop on undefined predicates
setup_call_cleanup( setup_call_cleanup(
'$undef_setup'(M0:G0, Action,Debug,Current, MGI), '$undef_setup'(M0:G0, Action,Debug,Current, MGI),
ignore('$get_undefined_predicates'( MGI, MG )), '$get_undefined_predicate'( MGI, MG ),
'$undef_cleanup'(Action,Debug,Current) '$undef_cleanup'(Action,Debug,Current)
), ),
'$undef_error'(Action, M0:G0, MGI, MG). '$undef_error'(Action, M0:G0, MGI, MG).
'$undef_setup'(G0,Action,Debug,Current,GI) :- '$undef_setup'(G0,Action,Debug,Current,G0) :-
yap_flag( unknown, Action, fail), yap_flag( unknown, Action, fail),
yap_flag( debug, Debug, false), yap_flag( debug, Debug, false),
'$stop_creeping'(Current), '$stop_creeping'(Current).
'$g2i'(G0,GI).
'$g2i'(user:G, Na/Ar ) :- '$g2i'(user:G, Na/Ar ) :-
!, !,
@ -141,7 +141,7 @@ The unknown predicate, informs about what the user wants to be done
nonvar(M), nonvar(M),
nonvar(G), nonvar(G),
!, !,
'$start_creep'([prolog|true], creep). '$start_creep'([M|G], creep).
'$undef_error'(_, M0:G0, _, MG) :- '$undef_error'(_, M0:G0, _, MG) :-
'$pred_exists'(unknown_predicate_handler(_,_,_,_), user), '$pred_exists'(unknown_predicate_handler(_,_,_,_), user),
'$yap_strip_module'(M0:G0, EM0, GM0), '$yap_strip_module'(M0:G0, EM0, GM0),
@ -151,12 +151,12 @@ The unknown predicate, informs about what the user wants to be done
'$undef_error'(error, Mod:Goal, I,_) :- '$undef_error'(error, Mod:Goal, I,_) :-
'$do_error'(existence_error(procedure,I), Mod:Goal). '$do_error'(existence_error(procedure,I), Mod:Goal).
'$undef_error'(warning,Mod:Goal,I,_) :- '$undef_error'(warning,Mod:Goal,I,_) :-
'program_continuation'(PMod,PName,PAr), '$program_continuation'(PMod,PName,PAr),
print_message(warning,error(existence_error(procedure,I), context(Mod:Goal,PMod:PName/PAr))), print_message(warning,error(existence_error(procedure,I), context(Mod:Goal,PMod:PName/PAr))),
'$start_creep'([fail|true], creep), %'$start_creep'([prolog|fail], creep),
fail. fail.
'$undef_error'(fail,_Goal,_,_Mod) :- '$undef_error'(fail,_Goal,_,_Mod) :-
'$start_creep'([fail|true], creep), % '$start_creep'([prolog|fail], creep),
fail. fail.
unknown(P, NP) :- unknown(P, NP) :-