This commit is contained in:
Vitor Santos Costa 2018-09-10 17:06:13 +01:00
parent f1066036ff
commit 5c8f8457fa
9 changed files with 106 additions and 46 deletions

View File

@ -1026,36 +1026,33 @@ restart:
}
#define CREATE_ARRAY_DEFS() \
PAR("type", isatom, CREATE_ARRAY_TYPE), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("int", isnull, CREATE_ARRAY_INT), \
PAR("dbref", isnull, CREATE_ARRAY_DBREF), \
PAR("float", isnull, CREATE_ARRAY_FLOAT), \
PAR("ptr", isnull, CREATE_ARRAY_PTR), \
PAR("atom", isnull, CREATE_ARRAY_ATOM), \
PAR("char", isnull, CREATE_ARRAY_CHAR), \
PAR("unsigned_char", isnull, CREATE_UNSIGNED_CHAR), \
PAR("nb_term", isnull, CREATE_ARRAY_NB_TERM), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("address", isaddress, CREATE_ARRAY_ADDRESS), \
PAR("close_on_abort", booleanFlag, OPEN_CLOSE_ON_ABORT), \
PAR("create", isatom, OPEN_CREATE), \
PAR("encoding", isatom, OPEN_ENCODING), \
PAR("eof_action", isatom, OPEN_EOF_ACTION), \
PAR("expand_filename", booleanFlag, OPEN_EXPAND_FILENAME), \
PAR("file_name", isatom, OPEN_FILE_NAME), PAR("input", ok, OPEN_INPUT), \
PAR("locale", isatom, OPEN_LOCALE), PAR("lock", isatom, OPEN_LOCK), \
PAR("mode", isatom, OPEN_MODE), PAR("output", ok, OPEN_OUTPUT), \
PAR("representation_errors", booleanFlag, OPEN_REPRESENTATION_ERRORS), \
PAR("reposition", booleanFlag, OPEN_REPOSITION), \
PAR("script", booleanFlag, OPEN_SCRIPT), PAR("type", isatom, OPEN_TYPE), \
PAR("wait", booleanFlag, OPEN_WAIT), PAR(NULL, ok, OPEN_END)
#define CREATE_ARRAY_DEFS() \
PAR("type", isatom, CREATE_ARRAY_TYPE), \
PAR("address", filler, CREATE_ARRAY_ADDRESS), \
PAR("int", filler, CREATE_ARRAY_INT), \
PAR("dbref", filler, CREATE_ARRAY_DBREF), \
PAR("float", filler, CREATE_ARRAY_FLOAT), \
PAR("ptr", filler, CREATE_ARRAY_PTR), \
PAR("atom", filler, CREATE_ARRAY_ATOM), \
PAR("char", filler, CREATE_ARRAY_CHAR), \
PAR("unsigned_char", filler, CREATE_UNSIGNED_CHAR), \
PAR("term", filler, CREATE_ARRAY_TERM), \
PAR("nb_term", filler, CREATE_ARRAY_NB_TERM)
#define PAR(x, y, z) z
typedef enum create_array_enum_choices { CREATE_ARRAY_DEFS() } create_array_choices_t;
#undef PAR
#define PAR(x, y, z) \
{ x, y, z }
static const param_t create_array_defs[] = {CREATE_ARRAY_DEFS()};
#undef PAR
/* create an array (+Name, + Size, +Props) */
/** @pred static_array(+ _Name_, + _Size_, + _Type_)
@ -1087,7 +1084,9 @@ static Int
return (FALSE);
}
}
xarg *args =
Yap_ArgListToVector(tprops, create_array_defs, CREATE_ARRAY_NB_TERM, DOMAIN_ERROR_CREATE_ARRAY_OPTION);
if (IsVarTerm(tprops)) {
Yap_Error(INSTANTIATION_ERROR, tprops, "create static array");
return (FALSE);

View File

@ -1,4 +1,3 @@
/*************************************************************************
* *
* YAP Prolog *

View File

@ -642,8 +642,8 @@ void Yap_ThrowExistingError(void) {
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
const char *function, int lineno, yap_error_number type,
Term where, const char *s) {
if (!Yap_pc_add_location(r, CP, B, ENV))
Term where, const char *s) {
if (!Yap_pc_add_location(r, P, B, ENV))
Yap_env_add_location(r, CP, B, ENV, 0);
if (where == 0L || where == TermNil || type == INSTANTIATION_ERROR) {
r->culprit = NULL;
@ -739,7 +739,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
if (LOCAL_PrologMode & BootMode) {
fprintf(stderr, "%% YAP crashed while booting %s\n", tmpbuf);
} else {
Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE);
Yap_output_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE);
if (tmpbuf[0]) {
fprintf(stderr, "%% Bug found while executing %s\n", tmpbuf);
}

View File

@ -1856,9 +1856,9 @@ void Yap_dump_stack(void) {
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n");
fprintf(stderr, "%% Program Position: %s\n\n", Yap_errorName(errno) );
fprintf(stderr, "%% PC: %s\n", (char *)HR);
Yap_detect_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256);
Yap_output_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%% Continuation: %s\n", (char *)HR);
Yap_detect_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256);
Yap_output_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%% Alternative: %s\n", (char *)HR);
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n");
@ -1916,7 +1916,7 @@ fprintf(stderr, "%% \n%% -------------------------------------\n%%\n");
"Use--Local In Use)\n%%\n");
while (b_ptr != NULL) {
while (env_ptr && env_ptr <= (CELL *)b_ptr) {
Yap_detect_bug_location(ipc, FIND_PRED_FROM_ENV, 256);
Yap_output_bug_location(ipc, FIND_PRED_FROM_ENV, 256);
if (env_ptr == (CELL *)b_ptr && (choiceptr)env_ptr[E_CB] > b_ptr) {
b_ptr = b_ptr->cp_b;
fprintf(stderr, "%% %s\n", tp);
@ -1940,7 +1940,7 @@ fprintf(stderr, "%% \n%% -------------------------------------\n%%\n");
b_ptr->cp_ap->opc != Yap_opcode(_or_last) &&
b_ptr->cp_ap->opc != Yap_opcode(_Nstop)) {
/* we can safely ignore ; because there is always an upper env */
Yap_detect_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256);
Yap_output_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256);
fprintf(stderr, "%% %s (%luKB--%luKB)\n", tp,
(unsigned long int)((b_ptr->cp_h - H0) * sizeof(CELL) / 1024),
(unsigned long int)((ADDR)LCL0 - (ADDR)b_ptr) / 1024);
@ -2086,7 +2086,12 @@ void DumpActiveGoals(USES_REGS1) {
}
}
void Yap_detect_bug_location(yamop *yap_pc, int where_from, int psize) {
/**
* Used for debugging.
*
*/
void Yap_output_bug_location(yamop *yap_pc, int where_from, int psize) {
Atom pred_name;
UInt pred_arity;
Term pred_module;

View File

@ -187,6 +187,18 @@ static inline Term isatom(Term inp) {
return TermZERO;
}
static inline Term isadress(Term inp) {
if (IsVarTerm(inp)) {
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag %s",
"value must be bound");
return TermZERO;
}
if (IsAddressTerm(inp))
return inp;
Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag");
return TermZERO;
}
static inline Term options(Term inp) {
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
}

View File

@ -391,7 +391,7 @@ extern void Yap_InitSortPreds(void);
/* stack.c */
extern void Yap_InitStInfo(void);
extern void Yap_dump_stack(void);
extern void Yap_detect_bug_location(yamop *yap_pc, int where_from, int psize);
extern void Yap_output_bug_location(yamop *yap_pc, int where_from, int psize);
#if !defined(YAPOR) && !defined(THREADS)
extern bool Yap_search_for_static_predicate_in_use(struct pred_entry *, bool);

View File

@ -48,12 +48,12 @@ E(DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION, DOMAIN_ERROR,
E(DOMAIN_ERROR_ARRAY_OVERFLOW, DOMAIN_ERROR, "array_overflow")
E(DOMAIN_ERROR_ARRAY_TYPE, DOMAIN_ERROR, "array_type")
E(DOMAIN_ERROR_CLOSE_OPTION, DOMAIN_ERROR, "close_option")
E(DOMAIN_ERROR_CREATE_ARRAY_OPTION, DOMAIN_ERROR, "create_array_option")
E(DOMAIN_ERROR_ENCODING, DOMAIN_ERROR, "encoding")
E(DOMAIN_ERROR_EXPAND_FILENAME_OPTION, DOMAIN_ERROR, "expand_filename")
E(DOMAIN_ERROR_FILE_ERRORS, DOMAIN_ERROR, "file_errors")
E(DOMAIN_ERROR_FILE_TYPE, DOMAIN_ERROR, "file_type")
E(DOMAIN_ERROR_FORMAT_CONTROL_SEQUENCE, DOMAIN_ERROR, "format argument "
"domain")
E(DOMAIN_ERROR_FORMAT_CONTROL_SEQUENCE, DOMAIN_ERROR, "format argument")
E(DOMAIN_ERROR_FORMAT_OUTPUT, DOMAIN_ERROR, "format output")
E(DOMAIN_ERROR_GENERIC_ARGUMENT, DOMAIN_ERROR, "generic_argument")
E(DOMAIN_ERROR_IO_MODE, DOMAIN_ERROR, "io_mode")

View File

@ -1,6 +1,51 @@
A Jupyter Kernel for YAP (#yap_kernel)
=======================
This kernel supports interaction with YAP Prolog.
This Jupyter kernel supports interaction with YAP Prolog. The kernel
patches IPython and PyKernel so that the user interacts with the
Prolog interpreter. Most of the original kernels are unaffected by the
changes.
You will need `python3` and `jupyter notebook`to use this package, plus:
- `setuptools`;
- `wheel`
- `pip`
The configuration script should recognize whether these Python
packages are installed.
See `tut.ipynb` for details on how to use the system.
Both `jupyter notebook` and `jupyter lab` rely on the Javascript
editor ` CodeMirror` for editing tasks such as highlighting, inlining,
and folding. Unfortunately, `CodeMirror` does not support the Prolog
language. Starting from Wielemaker's excellent `CodeMirror` module for
`swish`, YAP includes a codemirror for Prolog, designed to fit easily
with any `CodeMirror`-based application.
+ `Jupyter lab` includes a complex dependency mechanism, that always
tries to download from the Internet. We do a first build to ensure
all packages are there, set the build offline, patch the different
copies of codemirror, and build locally.
~~~~
CM=$HOME/github/CodeMirror
PYLIB=$HOME/.local/lib/python3.6/site-packages
PYSHARE=$HOME/.local/share
cd $PYLIB/jupyterlab
jupyter lab build
cp commands.py commands.py.bk
sed 's/.node., YARN_PATH,/\"node", YARN_PATH, "--offline",/g' commands.py
cd $PYSHARE/jupyter/lab/staging/node_modules/codemirror/mode
split -n l/5 meta.js
cat xaa xab > meta.js
echo ' {name: "Prolog", mime: "text\/x-prolog", mode: "prolog", ext: ["yap","pl", "ypp", "prolog"]}' >> meta.js
cat xac xad xae >> meta.js
cp -a $CM/mode/prolog prolog
cd $PYLIB/jupyterlab
jupyter lab build
mv commands.py.bk commands.py
~~~~

View File

@ -1056,8 +1056,8 @@ query_exception(K0,[H|L],V) :-
(atom(K0) -> atom_to_string(K0, K) ; K = K0),
!,
lists:member(K=V,[H|L]).
query_exception(K,V) :-
'$query_exception'(K,V).
query_exception(M,K,V) :-
'$query_exception'(M,K,V).
/**
@}