This commit is contained in:
Vitor Santos Costa 2018-07-02 16:48:00 +01:00
parent 71aed8b870
commit fd492b5b16
8 changed files with 37 additions and 32 deletions

View File

@ -2129,20 +2129,17 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
char *d = Malloc(strlen(fl)+1); char *d = Malloc(strlen(fl)+1);
strcpy(d,fl); strcpy(d,fl);
bool consulted = (mode == YAP_CONSULT_MODE); bool consulted = (mode == YAP_CONSULT_MODE);
sno = Yap_OpenStream(MkStringTerm(fl), "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding); Term tat = MkAtomTerm(Yap_LookupAtom(d));
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding);
if (sno < 0 || if (sno < 0 ||
!Yap_ChDir(dirname((char *)d))) { !Yap_ChDir(dirname((char *)d))) {
pop_text_stack(lvl); pop_text_stack(lvl);
*full = NULL; *full = NULL;
return -1; return -1;
} } LOCAL_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, fl); Yap_init_consult(consulted, fl);
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl); pop_text_stack(lvl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
*full = pop_output_text_stack(lvl, fl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;

View File

@ -161,8 +161,7 @@ static bool consult(const char *b_file USES_REGS) {
/* consult in C */ /* consult in C */
int lvl = push_text_stack(); int lvl = push_text_stack();
char *full = Malloc(YAP_FILENAME_MAX + 1); char *full;
full[0] = '\0';
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) { if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
osno = 0; osno = 0;
@ -213,6 +212,10 @@ static bool consult(const char *b_file USES_REGS) {
} }
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
YAP_EndConsult(c_stream, &osno, full); YAP_EndConsult(c_stream, &osno, full);
if (!Yap_AddAlias(AtomLoopStream, osno)) {
pop_text_stack(lvl);
return false;
}
pop_text_stack(lvl); pop_text_stack(lvl);
return true; return true;
} }

View File

@ -57,6 +57,7 @@
with the `use_module(library(lists))` command. with the `use_module(library(lists))` command.
*/ */
:- include(pl/bootlists).
/** @pred list_concat(+ _Lists_,? _List_) /** @pred list_concat(+ _Lists_,? _List_)

View File

@ -101,7 +101,7 @@ db_import(Connection,RelationName,PredName0) :-
not c_db_check_if_exists_pred(PredName,Arity,Module), not c_db_check_if_exists_pred(PredName,Arity,Module),
R=..[relation,PredName,Arity,RelationName], R=..[relation,PredName,Arity,RelationName],
% assert relation fact % assert relation fact
assert(user:R), assert(Module:R),
Size is 2*Arity, Size is 2*Arity,
length(TypesList, Size), length(TypesList, Size),
@ -114,15 +114,15 @@ db_import(Connection,RelationName,PredName0) :-
% build PredName functor % build PredName functor
functor(P,PredName,Arity), functor(P,PredName,Arity),
P=..[PredName|LA], P=..[PredName|LA],
M=myddas_assert_predicates,
%build PredName clause %build PredName clause
table_access_predicate( ConType, Con, Arity, P, LA, M, Assert ), table_access_predicate( ConType, Con, Arity, P, LA, Modulelisting, Assert ),
assert(Module:Assert), assert_static(Module:Assert),
c_db_add_preds(PredName,Arity,Module,Con). c_db_add_preds(PredName,Arity,Module,Con).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- meta_predicate db_view(:,0).
:- meta_predicate db_view(+,:,0).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_view/3 % db_view/3
@ -289,8 +289,9 @@ table_attributes( sqlite3, Con, RelationName, TypesList ) :-
% predicate for DB-> query % predicate for DB-> query
table_access_predicate( mysql, Con, Arity, P, LA, M, table_access_predicate( mysql, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_), ( P :- user:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code), translate(G,G,Code),
queries_atom(Code,FinalSQL), queries_atom(Code,FinalSQL),
db_my_result_set(Mode), db_my_result_set(Mode),
@ -299,9 +300,9 @@ table_access_predicate( mysql, Con, Arity, P, LA, M,
!, !,
c_db_my_row(ResultSet,Arity,LA) ))). c_db_my_row(ResultSet,Arity,LA) ))).
table_access_predicate( postgres, Con, Arity, P, LA, M, table_access_predicate( postgres, Con, Arity, P, LA, _M,
( P :- M:('$copy_term_nv'(P,[],G,_), ( P :- '$copy_term_nv'(P,[],G,_),
translate(G,G,Code), translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL), queries_atom(Code,FinalSQL),
db_my_result_set(Mode), db_my_result_set(Mode),
'$write_or_not'(FinalSQL), '$write_or_not'(FinalSQL),
@ -310,8 +311,8 @@ table_access_predicate( postgres, Con, Arity, P, LA, M,
c_postgsres_row(ResultSet,Arity,LA) ))). c_postgsres_row(ResultSet,Arity,LA) ))).
table_access_predicate( sqlite3, Con, Arity, P, LA, M, table_access_predicate( sqlite3, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_), ( P :- ('$copy_term_nv'(P,[],G,_),
translate(G,G,Code), translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL), queries_atom(Code,FinalSQL),
sqlite3_result_set(Mode), sqlite3_result_set(Mode),
'$write_or_not'(FinalSQL), '$write_or_not'(FinalSQL),

View File

@ -56,6 +56,11 @@
DBMS(row)/3 DBMS(row)/3
]). ]).
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(myddas,[ :- use_module(myddas,[
db_sql/3 db_sql/3
]). ]).

View File

@ -10,7 +10,7 @@ main :-
main_, main_,
close. close.
main_ :- main_ :-
go, catch(go,E,writeln(E)),
fail. fail.
main_ . main_ .
@ -28,6 +28,11 @@ go :-
db_import('tracks', tracks), db_import('tracks', tracks),
writeln(('tracks -> tracks')). writeln(('tracks -> tracks')).
go :-
% X=1,
artists(X,Y),
writeln(X:Y).
go :- go :-
writeln(db_get_attributes_types), writeln(db_get_attributes_types),
db_get_attributes_types(albums,Als), db_get_attributes_types(albums,Als),
@ -57,6 +62,7 @@ go :-
db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')), db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')),
writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')). writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')).
go :- go :-
writeln(access), writeln(access),
go_cut0. go_cut0.
@ -73,11 +79,6 @@ go :-
go :- go :-
go_cut1. go_cut1.
go :-
% X=1,
artists(X,Y),
writeln(X:Y).
go_cut0 :- go_cut0 :-
artists(X,Y), artists(X,Y),
writeln(X:Y), writeln(X:Y),

View File

@ -7,8 +7,6 @@
* @{ * @{
*/ */
:- system_module( '$_lists', [], []).
:- set_prolog_flag(source, true). % source. :- set_prolog_flag(source, true). % source.
% memberchk(+Element, +Set) % memberchk(+Element, +Set)

View File

@ -1033,7 +1033,6 @@ prolog:print_message(Severity, Term) :-
!. !.
prolog:print_message(Severity, Term) :- prolog:print_message(Severity, Term) :-
translate_message( Term, Severity, Lines0, [ end(Id)]), translate_message( Term, Severity, Lines0, [ end(Id)]),
writeln(Lines0),
Lines = [begin(Severity, Id)| Lines0], Lines = [begin(Severity, Id)| Lines0],
( (
user:message_hook(Term, Severity, Lines) user:message_hook(Term, Severity, Lines)