This commit is contained in:
Vitor Santos Costa 2018-06-05 11:20:39 +01:00
parent 40096b3fdc
commit 2d55f41ef6
19 changed files with 84 additions and 83 deletions

View File

@ -33,8 +33,9 @@ static char SccsId[] = "%W% %G%";
/** @defgroup Internal_Database Internal Data Base /** @defgroup Internal_Database Internal Data Base
@ingroup builtins
@{ @ingroup builtins
@{
Some programs need global information for, e.g. counting or collecting Some programs need global information for, e.g. counting or collecting
data obtained by backtracking. As a rule, to keep this information, the data obtained by backtracking. As a rule, to keep this information, the

View File

@ -1237,9 +1237,10 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
encoding_t encoding; encoding_t encoding;
Term tenc; Term tenc;
char io_mode[8]; char io_mode[8];
file_name = Deref( file_name); file_name = Deref(file_name);
if (IsVarTerm(file_name)) { if (IsVarTerm(file_name)) {
Yap_ThrowError(INSTANTIATION_ERROR, file_name, "while opening a list of options"); Yap_ThrowError(INSTANTIATION_ERROR, file_name,
"while opening a list of options");
} }
// open mode // open mode
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
@ -1583,6 +1584,7 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
vfsp->open(vfsp, fname, io_mode, sno)) { vfsp->open(vfsp, fname, io_mode, sno)) {
// read, write, append // read, write, append
user_name = st->user_name; user_name = st->user_name;
st->vfs = vfsp;
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
} else { } else {
st->file = fopen(fname, io_mode); st->file = fopen(fname, io_mode);
@ -1761,8 +1763,8 @@ int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
return sno; return sno;
} }
int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term arg, int Yap_CheckTextWriteStream__(const char *file, const char *f, int line,
const char *msg) { Term arg, const char *msg) {
int sno, kind = Output_Stream_f; int sno, kind = Output_Stream_f;
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0) if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
return -1; return -1;
@ -1779,8 +1781,8 @@ int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term a
return sno; return sno;
} }
int Yap_CheckTextReadStream__(const char *file, const char *f, int line, Term arg, int Yap_CheckTextReadStream__(const char *file, const char *f, int line,
const char *msg) { Term arg, const char *msg) {
int sno, kind = Input_Stream_f; int sno, kind = Input_Stream_f;
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0) if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
return -1; return -1;

View File

@ -10,9 +10,8 @@ YAP_Term TermErrStream, TermOutStream;
static unsigned char *outbuf, *errbuf; static unsigned char *outbuf, *errbuf;
static void pyflush( StreamDesc *st) static void pyflush(StreamDesc *st) {
{ #if 0
#if 0
st->u.w_irl.ptr[0] = '\0'; st->u.w_irl.ptr[0] = '\0';
fprintf(stderr,"%s\n", st->u.w_irl.buf); fprintf(stderr,"%s\n", st->u.w_irl.buf);
term_t tg = python_acquire_GIL(); term_t tg = python_acquire_GIL();
@ -24,8 +23,7 @@ static void pyflush( StreamDesc *st)
} }
python_release_GIL(tg); python_release_GIL(tg);
st->u.w_irl.ptr = st->u.w_irl.buf; st->u.w_irl.ptr = st->u.w_irl.buf;
#endif #endif
} }
static int py_putc(int sno, int ch) { static int py_putc(int sno, int ch) {
@ -43,7 +41,7 @@ static int py_putc(int sno, int ch) {
} }
return ch; return ch;
} }
#endif #endif
char s[2]; char s[2];
PyObject *err; PyObject *err;
s[0] = ch; s[0] = ch;
@ -96,9 +94,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
// } else if (strcmp(name, "input") == 0) { // } else if (strcmp(name, "input") == 0) {
//pystream = PyObject_Call(pystream, PyTuple_New(0), NULL); //pystream = PyObject_Call(pystream, PyTuple_New(0), NULL);
} else */ } else */
{ { st->user_name = YAP_MkAtomTerm(st->name); }
st->user_name = YAP_MkAtomTerm(st->name);
}
st->u.private_data = pystream; st->u.private_data = pystream;
st->vfs = me; st->vfs = me;
st->file = NULL; st->file = NULL;
@ -106,7 +102,6 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
return st; return st;
} }
static void py_flush(int sno) { static void py_flush(int sno) {
StreamDesc *s = YAP_GetStreamFromId(sno); StreamDesc *s = YAP_GetStreamFromId(sno);
term_t tg = python_acquire_GIL(); term_t tg = python_acquire_GIL();
@ -116,10 +111,9 @@ static void py_flush(int sno) {
python_release_GIL(tg); python_release_GIL(tg);
} }
static bool py_close(int sno) { static bool py_close(int sno) {
StreamDesc *st = YAP_RepStreamFromId(sno); StreamDesc *st = YAP_RepStreamFromId(sno);
if (st->status & (Output_Stream_f|Append_Stream_f)) if (st->status & (Output_Stream_f | Append_Stream_f))
py_flush(sno); py_flush(sno);
if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) { if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
Py_XDECREF(st->u.private_data); Py_XDECREF(st->u.private_data);
@ -137,10 +131,11 @@ static bool getLine(int inp) {
term_t ctk = python_acquire_GIL(); term_t ctk = python_acquire_GIL();
Py_ssize_t size; Py_ssize_t size;
PyObject *prompt = PyUnicode_FromString("?- "), PyObject *prompt = PyUnicode_FromString("?- "),
*msg = PyUnicode_FromString(" **input** "); *msg = PyUnicode_FromString(" **input** "),
*o = PyObject_GetAttrString(rl_iostream->u.private_data, "read");
/* window of vulnerability opened */ /* window of vulnerability opened */
myrl_line = PyUnicode_AsUTF8AndSize(PyObject_CallFunctionObjArgs( myrl_line = PyUnicode_AsUTF8AndSize(
rl_instream->u.private_data, msg, prompt, NULL), &size); PyObject_CallFunctionObjArgs(o, msg, prompt, NULL), &size);
python_release_GIL(ctk); python_release_GIL(ctk);
rl_instream->u.irl.ptr = rl_instream->u.irl.buf = rl_instream->u.irl.ptr = rl_instream->u.irl.buf =
(const unsigned char *)malloc(size); (const unsigned char *)malloc(size);

View File

@ -26,13 +26,13 @@
jupyter_query(Caller, Cell, Line ) :- jupyter_query(Caller, Cell, Line ) :-
jupyter_cell(Caller, Cell, Line). jupyter_cell(Caller, Cell, Line).
jupyter_cell(_Caller, Cell, _) :- jupyter_cell(_Caller, Cell, _Line) :-
jupyter_consult(Cell), %stack_dump, jupyter_consult(Cell), %stack_dump,
fail. fail.
jupyter_cell( _Caller, _, '' ) :- !.
jupyter_cell( _Caller, _, Line ) :- jupyter_cell( _Caller, _, Line ) :-
blank( Line ), blank( Line ),
!. !.
jupyter_cell( _Caller, _, '' ) :- !.
jupyter_cell( Caller, _, Line ) :- jupyter_cell( Caller, _, Line ) :-
Self := Caller.query, Self := Caller.query,
python_query(Self,Line). python_query(Self,Line).
@ -54,19 +54,13 @@ jupyter_consult(Text) :-
jupyter_consult(Cell) :- jupyter_consult(Cell) :-
% Name = 'Inp', % Name = 'Inp',
% stream_property(Stream, file_name(Name) ), % stream_property(Stream, file_name(Name) ),
setup_call_cleanup( % setup_call_cleanup(
open_mem_read_stream( Cell, Stream), open_mem_read_stream( Cell, Stream),
load_files(user:'jupyter cell',[stream(Stream)]), load_files(user:'jupyter cell',[stream(Stream)]).
close(Stream)
).
blank(Text) :- blank(Text) :-
atom_codes(Text, L), atom_codes(Text, L),
maplist( blankc, L). maplist( code_type(space), L).
blankc(' ').
blankc('\n').
blankc('\t').
:- dynamic cell_stream/1. :- dynamic cell_stream/1.

View File

@ -36,6 +36,7 @@
/** @defgroup CompilerAnalysis Internal Clause Rewriting /** @defgroup CompilerAnalysis Internal Clause Rewriting
@ingroup YAPCompilerSettings @ingroup YAPCompilerSettings
@{
YAP supports several clause optimisation mechanisms, that YAP supports several clause optimisation mechanisms, that
are designed to improve execution of arithmetic are designed to improve execution of arithmetic
@ -59,7 +60,6 @@
*/ */
%% @{
/** @pred expand_exprs(- _O_,+ _N_) /** @pred expand_exprs(- _O_,+ _N_)
Control term expansion during compilation. Control term expansion during compilation.

View File

@ -15,14 +15,13 @@
* * * *
*************************************************************************/ *************************************************************************/
%% @{
/** /**
@file arithpreds.yap @file arithpreds.yap
@addtogroup arithmetic_preds @addtogroup arithmetic_preds
@{
*/ */
:- system_module(arithmetic_predicates, [ :- system_module(arithmetic_predicates, [

View File

@ -26,7 +26,7 @@
/** /**
* @addtogroup Predicates_on_Atoms * @addtogroup Predicates_on_Atoms
* * @{
*/ */
/** @pred atom_concat(+ As, ? A) /** @pred atom_concat(+ As, ? A)

View File

@ -19,11 +19,11 @@
@file boot.yap @file boot.yap
@brief YAP bootstrap @brief YAP bootstrap
@{
@addtogroup TopLevel Top-Level and Boot Predicates @addtogroup TopLevel Top-Level and Boot Predicates
@ingroup builtins @ingroup builtins
@{
*/ */

View File

@ -3,6 +3,7 @@
@short utilities @short utilities
@addtogroup Internal_Database @addtogroup Internal_Database
@{
*/ */
/** @pred recordaifnot(+ _K_, _T_,- _R_) /** @pred recordaifnot(+ _K_, _T_,- _R_)
@ -41,3 +42,4 @@ recordzifnot(K,T,R) :-
recordzifnot(K,T,R) :- recordzifnot(K,T,R) :-
recordz(K,T,R). recordz(K,T,R).
%% @}

View File

@ -21,8 +21,7 @@
@addtogroup YAPControl Control Predicates @addtogroup YAPControl Control Predicates
@ingroup builtins @ingroup builtins
@{
@{
*/ */

View File

@ -39,10 +39,10 @@ implementation.
*/ */
%% @{ /**
@defgroup Call_Counting Counting Calls
/** @defgroup Call_Counting Counting Calls @ingroup Profiling
@ingroup Profiling @{
Predicates compiled with YAP's flag call_counting set to Predicates compiled with YAP's flag call_counting set to
`on` update counters on the numbers of calls and of `on` update counters on the numbers of calls and of

View File

@ -22,12 +22,11 @@
'$syntax_check_multiple'/2, '$syntax_check_multiple'/2,
'$syntax_check_single_var'/2]). '$syntax_check_single_var'/2]).
%% @{
/** /**
@defgroup YAPStyle Checker @defgroup YAPStyle Checker
@ingroup YAPCompilerSettings @ingroup YAPCompilerSettings
@{
YAP implements a style-checker thay currently verifies whether: YAP implements a style-checker thay currently verifies whether:

View File

@ -83,11 +83,9 @@
@addtogroup YAPControl @addtogroup YAPControl
@ingroup builtins @ingroup builtins
@{
*/ */
%% @{
/** @pred forall(: _Cond_,: _Action_) /** @pred forall(: _Cond_,: _Action_)

View File

@ -30,10 +30,9 @@
%% %%
% @defgroup YAPBigLoad Loading Large Tables % @defgroup YAPBigLoad Loading Large Tables
% @ingroup YAPConsulting % @ingroup YAPConsulting
% % @{
% @brief Fast and Exo Loading % @brief Fast and Exo Loading
% %
% @{
/*! /*!
* @pred load_mega_clause( +Stream ) is detail * @pred load_mega_clause( +Stream ) is detail

View File

@ -24,6 +24,7 @@
/** /**
@defgroup Deb_Interaction Interacting with the debugger @defgroup Deb_Interaction Interacting with the debugger
@{
@ingroup YAPProgramming @ingroup YAPProgramming
Debugging with YAP is similar to debugging with C-Prolog. Both systems Debugging with YAP is similar to debugging with C-Prolog. Both systems
@ -237,6 +238,8 @@ be lost.
*/ */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
spy spy

View File

@ -18,6 +18,7 @@
/** /**
@defgroup DepthLimited Depth Limited Search @defgroup DepthLimited Depth Limited Search
@{
@ingroup extensions @ingroup extensions
YAP implements various extensions to the default Prolog search. One of YAP implements various extensions to the default Prolog search. One of
@ -27,9 +28,12 @@ the most iseful s restricting the maximum search depth.
:- :-
system_module( '$_depth_bound', [depth_bound_call/2], []). system_module( '$_depth_bound', [depth_bound_call/2], []).
%depth_bound_call(A,D) :- %% @pred depth_bound_call(A,D)
%write(depth_bound_call(A,D)), nl, fail. %
% CallError _A_ with maximum stack_el depth_reduction _B_.
%
depth_bound_call(A,D) :- depth_bound_call(A,D) :-
'$execute_under_depth_limit'(A,D). '$execute_under_depth_limit'(A,D).
%% @}

View File

@ -23,6 +23,7 @@
* *
* @brief Extended Abstract Machine * @brief Extended Abstract Machine
* @defgroup EAM Extended Abstract Machine * @defgroup EAM Extended Abstract Machine
* @{
* @ingroup extensions * @ingroup extensions
* *
* *
@ -54,3 +55,5 @@ eamconsult(File):- eam, eam, %fails if eam is disable
assert((user:term_expansion((A :- B),(A :- C)):- eamtrans(B,C))), assert((user:term_expansion((A :- B),(A :- C)):- eamtrans(B,C))),
eam, ( consult(File) ; true), eam, eam, ( consult(File) ; true), eam,
abolish(user:term_expansion,2). abolish(user:term_expansion,2).
%% @}

View File

@ -32,6 +32,7 @@
code_location/3]). code_location/3]).
/** /**
* @namespace yap_hacks
* *
* @defgroup Hacks Low-level access * @defgroup Hacks Low-level access
* @ingroup builtins * @ingroup builtins

View File

@ -25,27 +25,27 @@
*/ */
:- system_module( '$_listing', [listing/0, /*:- system_module( '$_listing', [listing/0,
listing/1, listing/1,
portray_clause/1, portray_clause/1,
portray_clause/2], []). portray_clause/2], []).
*/
/** /**
* @defgroup Listing List predicates in a module * @defgroup listingGroup List predicates in a module
* @{ *
* @ingroup builtins * @ingroup builtins
* *
* @{
*/ */
:- use_system_module( '$_errors', ['$do_error'/2]). :- use_system_module( '$_errors', ['$do_error'/2]).
:- use_system_module( '$_preds', ['$clause'/4,
'$current_predicate'/4]). '$current_predicate'/4]).
/* listing : Listing clauses in the database /** @brief listing : Listing clauses in the database
*
*/ */
/** @pred listing /** @pred listing
@ -347,3 +347,5 @@ portray_clause(Clause) :-
'$list_transform'(L,M). '$list_transform'(L,M).
'$list_transform'([_|L],M) :- '$list_transform'([_|L],M) :-
'$list_transform'(L,M). '$list_transform'(L,M).
%% @}