Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap
This commit is contained in:
commit
ba00e98ad8
19
C/atomic.c
19
C/atomic.c
@ -592,8 +592,9 @@ restart_aux:
|
|||||||
|
|
||||||
|
|
||||||
The predicate holds when at least one of the arguments is
|
The predicate holds when at least one of the arguments is
|
||||||
ground (otherwise, YAP will generate an error event. _A_ must be unifiable with an atom, and the
|
ground (otherwise, YAP will generate an error event. _A_ must be unifiable
|
||||||
argument _L_ with the list of the character codes for string _A_.
|
with an atom, and the argument _L_ with the list of the character codes for
|
||||||
|
string _A_.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -620,7 +621,7 @@ restart_aux:
|
|||||||
}
|
}
|
||||||
/* error handling */
|
/* error handling */
|
||||||
} else {
|
} else {
|
||||||
Yap_ThrowError( TYPE_ERROR_ATOM, t1, NULL);
|
Yap_ThrowError(TYPE_ERROR_ATOM, t1, NULL);
|
||||||
}
|
}
|
||||||
if (LOCAL_Error_TYPE && Yap_HandleError("atom_codes/2")) {
|
if (LOCAL_Error_TYPE && Yap_HandleError("atom_codes/2")) {
|
||||||
goto restart_aux;
|
goto restart_aux;
|
||||||
@ -727,14 +728,14 @@ static Int number_chars(USES_REGS1) {
|
|||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
return Yap_unify(ARG1, tf);
|
return Yap_unify(ARG1, tf);
|
||||||
}
|
}
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
|
|
||||||
LOCAL_ActiveError->errorRawTerm = 0;
|
LOCAL_ActiveError->errorRawTerm = 0;
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1377,7 +1378,7 @@ restart_aux:
|
|||||||
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 *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t));
|
||||||
seq_tv_t *out = (seq_tv_t *)Malloc( sizeof(seq_tv_t));
|
seq_tv_t *out = (seq_tv_t *)Malloc(sizeof(seq_tv_t));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (!inpv) {
|
if (!inpv) {
|
||||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||||
@ -1465,9 +1466,7 @@ error:
|
|||||||
if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) {
|
if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) {
|
||||||
goto restart_aux;
|
goto restart_aux;
|
||||||
}
|
}
|
||||||
{
|
{ return FALSE; }
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int atomics_to_string2(USES_REGS1) {
|
static Int atomics_to_string2(USES_REGS1) {
|
||||||
@ -2766,6 +2765,8 @@ void Yap_InitAtomPreds(void) {
|
|||||||
Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0);
|
Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0);
|
||||||
Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0);
|
Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0);
|
||||||
Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0);
|
Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0);
|
||||||
|
Yap_InitCPred("text_to_string", 2, downcase_text_to_string, 0);
|
||||||
|
Yap_InitCPred("text_to_atom", 2, downcase_text_to_string, 0);
|
||||||
Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0);
|
Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0);
|
||||||
Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0);
|
Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0);
|
||||||
Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0);
|
Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0);
|
||||||
|
29
C/exec.c
29
C/exec.c
@ -1460,7 +1460,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
|||||||
*/
|
*/
|
||||||
/* reset the registers so that we don't have trash in abstract
|
/* reset the registers so that we don't have trash in abstract
|
||||||
* machine */
|
* machine */
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
Yap_set_fpu_exceptions(
|
Yap_set_fpu_exceptions(
|
||||||
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
|
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
|
||||||
P = (yamop *)FAILCODE;
|
P = (yamop *)FAILCODE;
|
||||||
@ -1470,12 +1470,12 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
|||||||
} break;
|
} break;
|
||||||
case 3: { /* saved state */
|
case 3: { /* saved state */
|
||||||
// LOCAL_ActiveError = err_info;
|
// LOCAL_ActiveError = err_info;
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
LOCAL_CBorder = OldBorder;
|
LOCAL_CBorder = OldBorder;
|
||||||
LOCAL_RestartEnv = sighold;
|
LOCAL_RestartEnv = sighold;
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
LOCAL_DoingUndefp = false;
|
LOCAL_DoingUndefp = false;
|
||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
@ -1485,16 +1485,16 @@ Yap_CloseSlots(sls);
|
|||||||
// LOCAL_ActiveError = err_info;
|
// LOCAL_ActiveError = err_info;
|
||||||
while (B) {
|
while (B) {
|
||||||
LOCAL_ActiveError->errorNo = ABORT_EVENT;
|
LOCAL_ActiveError->errorNo = ABORT_EVENT;
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
Yap_JumpToEnv();
|
Yap_JumpToEnv();
|
||||||
}
|
}
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
LOCAL_DoingUndefp = false;
|
LOCAL_DoingUndefp = false;
|
||||||
P = (yamop *)FAILCODE;
|
P = (yamop *)FAILCODE;
|
||||||
LOCAL_RestartEnv = sighold;
|
LOCAL_RestartEnv = sighold;
|
||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
@ -1517,15 +1517,15 @@ Yap_CloseSlots(sls);
|
|||||||
(CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) {
|
(CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) {
|
||||||
LOCAL_RestartEnv = sighold;
|
LOCAL_RestartEnv = sighold;
|
||||||
LOCAL_CBorder = OldBorder;
|
LOCAL_CBorder = OldBorder;
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
P = FAILCODE;
|
P = FAILCODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
YENV = ASP;
|
YENV = ASP;
|
||||||
YENV[E_CB] = Unsigned(B);
|
YENV[E_CB] = Unsigned(B);
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
out = Yap_absmi(0);
|
out = Yap_absmi(0);
|
||||||
/* make sure we don't leave a FAIL signal hanging around */
|
/* make sure we don't leave a FAIL signal hanging around */
|
||||||
Yap_get_signal(YAP_FAIL_SIGNAL);
|
Yap_get_signal(YAP_FAIL_SIGNAL);
|
||||||
@ -1533,7 +1533,7 @@ Yap_CloseSlots(sls);
|
|||||||
CalculateStackGap(PASS_REGS1);
|
CalculateStackGap(PASS_REGS1);
|
||||||
LOCAL_CBorder = OldBorder;
|
LOCAL_CBorder = OldBorder;
|
||||||
LOCAL_RestartEnv = sighold;
|
LOCAL_RestartEnv = sighold;
|
||||||
pop_text_stack(i+1);
|
pop_text_stack(i + 1);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2116,7 +2116,8 @@ static Int jump_env(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
// Yap_DebugPlWriteln(t);
|
// Yap_DebugPlWriteln(t);
|
||||||
// char *buf = Yap_TermToBuffer(t, ENC_ISO_UTF8,
|
// char *buf = Yap_TermToBuffer(t, ENC_ISO_UTF8,
|
||||||
// Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
|
// Quote_illegal_f | Ignore_ops_f |
|
||||||
|
// Unfold_cyclics_f);
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " throw(%s)", buf);
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " throw(%s)", buf);
|
||||||
LOCAL_ActiveError = Yap_UserError(t0, LOCAL_ActiveError);
|
LOCAL_ActiveError = Yap_UserError(t0, LOCAL_ActiveError);
|
||||||
bool out = JumpToEnv(PASS_REGS1);
|
bool out = JumpToEnv(PASS_REGS1);
|
||||||
@ -2124,7 +2125,7 @@ static Int jump_env(USES_REGS1) {
|
|||||||
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
||||||
// we're failing up to the top layer
|
// we're failing up to the top layer
|
||||||
}
|
}
|
||||||
pop_text_stack(LOCAL_MallocDepth+1);
|
pop_text_stack(LOCAL_MallocDepth + 1);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ Moyle. All rights reserved.
|
|||||||
|
|
||||||
static atom_t ATOM_nil;
|
static atom_t ATOM_nil;
|
||||||
|
|
||||||
extern int PL_unify_termv(term_t l, va_list args);
|
|
||||||
|
|
||||||
extern X_API Atom YAP_AtomFromSWIAtom(atom_t at);
|
extern X_API Atom YAP_AtomFromSWIAtom(atom_t at);
|
||||||
extern X_API atom_t YAP_SWIAtomFromAtom(Atom at);
|
extern X_API atom_t YAP_SWIAtomFromAtom(Atom at);
|
||||||
|
48
os/iopreds.c
48
os/iopreds.c
@ -1129,13 +1129,14 @@ static void check_bom(int sno, StreamDesc *st) {
|
|||||||
bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
|
bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
|
||||||
Term file_name, encoding_t encoding, stream_flags_t flags,
|
Term file_name, encoding_t encoding, stream_flags_t flags,
|
||||||
void *vfs) {
|
void *vfs) {
|
||||||
fprintf(stderr,"+ %s --> %d\n", name, sno);
|
// fprintf(stderr,"+ %s --> %d\n", name, sno);
|
||||||
StreamDesc *st = &GLOBAL_Stream[sno];
|
StreamDesc *st = &GLOBAL_Stream[sno];
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>",
|
__android_log_print(
|
||||||
io_mode, CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
|
||||||
name,
|
CurrentModule == 0 ? "prolog"
|
||||||
sno);
|
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||||
if (io_mode == NULL)
|
name, sno);
|
||||||
|
if (io_mode == NULL)
|
||||||
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
||||||
"File opened with NULL Permissions");
|
"File opened with NULL Permissions");
|
||||||
if (strchr(io_mode, 'a')) {
|
if (strchr(io_mode, 'a')) {
|
||||||
@ -1232,13 +1233,10 @@ typedef enum open_enum_choices { OPEN_DEFS() } open_choices_t;
|
|||||||
static const param_t open_defs[] = {OPEN_DEFS()};
|
static const param_t open_defs[] = {OPEN_DEFS()};
|
||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
|
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
|
||||||
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, Term user_name,
|
Term user_name, encoding_t enc) {
|
||||||
encoding_t enc)
|
|
||||||
{
|
|
||||||
struct vfs *vfsp = NULL;
|
struct vfs *vfsp = NULL;
|
||||||
const char *fname;
|
const char *fname;
|
||||||
|
|
||||||
|
|
||||||
if (IsAtomTerm(tin))
|
if (IsAtomTerm(tin))
|
||||||
fname = RepAtom(AtomOfTerm(tin))->StrOfAE;
|
fname = RepAtom(AtomOfTerm(tin))->StrOfAE;
|
||||||
@ -1290,9 +1288,10 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buf = pop_output_text_stack(i, buf);
|
buf = pop_output_text_stack(i, buf);
|
||||||
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf,32));
|
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
|
||||||
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
||||||
MEM_BUF_MALLOC, nat, MkAtomTerm(NameOfFunctor(f)));
|
MEM_BUF_MALLOC, nat,
|
||||||
|
MkAtomTerm(NameOfFunctor(f)));
|
||||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
||||||
@ -1364,9 +1363,9 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
|
|||||||
} else {
|
} else {
|
||||||
open_mode = AtomOfTerm(t2);
|
open_mode = AtomOfTerm(t2);
|
||||||
}
|
}
|
||||||
/* get options */
|
/* get options */
|
||||||
xarg *args = Yap_ArgListToVector(tlist, open_defs, OPEN_END,
|
xarg *args =
|
||||||
DOMAIN_ERROR_OPEN_OPTION);
|
Yap_ArgListToVector(tlist, open_defs, OPEN_END, DOMAIN_ERROR_OPEN_OPTION);
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||||
Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3");
|
Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3");
|
||||||
@ -1375,7 +1374,7 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
|
|||||||
}
|
}
|
||||||
/* done */
|
/* done */
|
||||||
st->status = 0;
|
st->status = 0;
|
||||||
const char *s_encoding;
|
const char *s_encoding;
|
||||||
if (args[OPEN_ENCODING].used) {
|
if (args[OPEN_ENCODING].used) {
|
||||||
tenc = args[OPEN_ENCODING].tvalue;
|
tenc = args[OPEN_ENCODING].tvalue;
|
||||||
s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE;
|
s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE;
|
||||||
@ -1436,14 +1435,14 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
|
|||||||
"type is ~a, must be one of binary or text", t);
|
"type is ~a, must be one of binary or text", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
st = &GLOBAL_Stream[sno];
|
st = &GLOBAL_Stream[sno];
|
||||||
|
|
||||||
if (!fill_stream(sno, st, file_name,io_mode,st->user_name,st->encoding)) {
|
if (!fill_stream(sno, st, file_name, io_mode, st->user_name, st->encoding)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[OPEN_BOM].used) {
|
if (args[OPEN_BOM].used) {
|
||||||
if (args[OPEN_BOM].tvalue == TermTrue) {
|
if (args[OPEN_BOM].tvalue == TermTrue) {
|
||||||
avoid_bom = false;
|
avoid_bom = false;
|
||||||
needs_bom = true;
|
needs_bom = true;
|
||||||
@ -1671,9 +1670,8 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
|
|||||||
st = GLOBAL_Stream + sno;
|
st = GLOBAL_Stream + sno;
|
||||||
// fname = Yap_VF(fname);
|
// fname = Yap_VF(fname);
|
||||||
|
|
||||||
|
if (fill_stream(sno, st, tin, io_mode, user_name, enc))
|
||||||
if (fill_stream(sno, st, tin,io_mode,user_name,enc))
|
return sno;
|
||||||
return sno;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1868,13 +1866,13 @@ static Int always_prompt_user(USES_REGS1) {
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @pred close(+ _S_) is iso
|
/** @pred close(+ _S_) is iso
|
||||||
|
|
||||||
Closes the stream _S_. If _S_ does not stand for a stream
|
Closes the stream _S_. If _S_ does not stand for a stream
|
||||||
currently opened an error is reported. The streams user_input,
|
currently opened an error is reported. The streams user_input,
|
||||||
user_output, and user_error can never be closed.
|
user_output, and user_error can never be closed.
|
||||||
*/
|
*/
|
||||||
static Int close1(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
static Int close1(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
|
||||||
int sno = CheckStream(
|
int sno = CheckStream(
|
||||||
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
|
@ -998,7 +998,7 @@ static void CloseStream(int sno) {
|
|||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>",
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>",
|
||||||
// sno);
|
// sno);
|
||||||
VFS_t *me;
|
VFS_t *me;
|
||||||
fprintf( stderr, "- %d\n",sno);
|
//fprintf( stderr, "- %d\n",sno);
|
||||||
if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
|
if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
|
||||||
GLOBAL_Stream[sno].file == NULL) {
|
GLOBAL_Stream[sno].file == NULL) {
|
||||||
if (me->close) {
|
if (me->close) {
|
||||||
|
@ -46,11 +46,11 @@ foreign_t assign_to_symbol(term_t t, PyObject *e) {
|
|||||||
PyObject *dic;
|
PyObject *dic;
|
||||||
if (!lookupPySymbol(s, NULL, &dic))
|
if (!lookupPySymbol(s, NULL, &dic))
|
||||||
dic = py_Main;
|
dic = py_Main;
|
||||||
Py_INCREF(e);
|
Py_INCREF(e);
|
||||||
return PyObject_SetAttrString(dic, s, e) == 0;
|
return PyObject_SetAttrString(dic, s, e) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign_t python_to_term(PyObject *pVal, term_t t) {
|
static int python_to_term__(PyObject *pVal, term_t t) {
|
||||||
bool rc = true;
|
bool rc = true;
|
||||||
term_t to = PL_new_term_ref();
|
term_t to = PL_new_term_ref();
|
||||||
// fputs(" <<*** ",stderr); PyObject_Print(pVal,stderr,0);
|
// fputs(" <<*** ",stderr); PyObject_Print(pVal,stderr,0);
|
||||||
@ -89,14 +89,17 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
|
|||||||
#else
|
#else
|
||||||
const char *s = PyUnicode_AsUTF8(pVal);
|
const char *s = PyUnicode_AsUTF8(pVal);
|
||||||
#endif
|
#endif
|
||||||
// if (PyDict_GetItemString(py_Atoms, s))
|
// if (PyDict_GetItemString(py_Atoms, s))
|
||||||
// rc = rc && PL_unify_atom_chars(t, s);
|
// rc = rc && PL_unify_atom_chars(t, s);
|
||||||
// else
|
// else
|
||||||
rc = rc && PL_unify_atom_chars(t, s);
|
rc =
|
||||||
} else if (PyByteArray_Check(pVal)) {
|
rc && (PL_is_string(t) ? PL_unify_string_chars(t, s)
|
||||||
rc = rc && PL_unify_string_chars(t, PyByteArray_AsString(pVal));
|
: PL_is_variable(t) ? PL_unify_atom_chars(t, s)
|
||||||
#if PY_MAJOR_VERSION < 3
|
: PL_unify_atom_chars(t, s));
|
||||||
} else if (PyString_Check(pVal)) {
|
} else if (PyByteArray_Check(pVal)) {
|
||||||
|
rc = rc && PL_unify_string_chars(t, PyByteArray_AsString(pVal));
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
} else if (PyString_Check(pVal)) {
|
||||||
rc = rc && PL_unify_string_chars(t, PyString_AsString(pVal));
|
rc = rc && PL_unify_string_chars(t, PyString_AsString(pVal));
|
||||||
#endif
|
#endif
|
||||||
} else if (PyTuple_Check(pVal)) {
|
} else if (PyTuple_Check(pVal)) {
|
||||||
@ -137,7 +140,7 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
|
|||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
}
|
}
|
||||||
rc = rc && python_to_term(p, to);
|
rc = rc && python_to_term__(p, to);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rc = false;
|
rc = false;
|
||||||
@ -154,7 +157,7 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
|
|||||||
if ((obj = PyList_GetItem(pVal, i)) == NULL) {
|
if ((obj = PyList_GetItem(pVal, i)) == NULL) {
|
||||||
obj = Py_None;
|
obj = Py_None;
|
||||||
}
|
}
|
||||||
rc = rc && python_to_term(obj, to);
|
rc = rc && python_to_term__(obj, to);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -174,10 +177,10 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
|
|||||||
term_t tkey = PL_new_term_ref(), tval = PL_new_term_ref(), tint,
|
term_t tkey = PL_new_term_ref(), tval = PL_new_term_ref(), tint,
|
||||||
tnew = PL_new_term_ref();
|
tnew = PL_new_term_ref();
|
||||||
/* do something interesting with the values... */
|
/* do something interesting with the values... */
|
||||||
if (!python_to_term(key, tkey)) {
|
if (!python_to_term__(key, tkey)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!python_to_term(value, tval)) {
|
if (!python_to_term__(value, tval)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* reuse */
|
/* reuse */
|
||||||
@ -209,18 +212,26 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
|
|||||||
X_API YAP_Term pythonToYAP(PyObject *pVal) {
|
X_API YAP_Term pythonToYAP(PyObject *pVal) {
|
||||||
|
|
||||||
term_t t = PL_new_term_ref();
|
term_t t = PL_new_term_ref();
|
||||||
if (pVal == NULL || !python_to_term(pVal, t)) {
|
if (pVal == NULL || !python_to_term__(pVal, t)) {
|
||||||
PL_reset_term_refs(t);
|
PL_reset_term_refs(t);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
YAP_Term tt = YAP_GetFromSlot(t);
|
YAP_Term tt = YAP_GetFromSlot(t);
|
||||||
PL_reset_term_refs(t);
|
PL_reset_term_refs(t);
|
||||||
//Py_DECREF(pVal);
|
// Py_DECREF(pVal);
|
||||||
return tt;
|
return tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *py_Local, *py_Global;
|
PyObject *py_Local, *py_Global;
|
||||||
|
|
||||||
|
X_API foreign_t python_to_term(PyObject *pVal, term_t t) {
|
||||||
|
yap_error_descriptor_t *ctx = malloc(sizeof(yap_error_descriptor_t));
|
||||||
|
bool newxp = Yap_pushErrorContext(true, ctx);
|
||||||
|
int rc = python_to_term(pVal, t);
|
||||||
|
Yap_popErrorContext(newxp, true);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* assigns the Python RHS to a Prolog term LHS, ie LHS = RHS
|
* assigns the Python RHS to a Prolog term LHS, ie LHS = RHS
|
||||||
*
|
*
|
||||||
@ -317,7 +328,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
if (PySequence_Check(o) && PyInt_Check(i)) {
|
if (PySequence_Check(o) && PyInt_Check(i)) {
|
||||||
long int j;
|
long int j;
|
||||||
j = PyInt_AsLong(i);
|
j = PyInt_AsLong(i);
|
||||||
return PySequence_SetItem(o, i, exp) == 0;
|
return PySequence_SetItem(o, i, exp) == 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (PyDict_Check(o)) {
|
if (PyDict_Check(o)) {
|
||||||
|
@ -23,8 +23,12 @@
|
|||||||
|
|
||||||
:- python_import(sys).
|
:- python_import(sys).
|
||||||
|
|
||||||
jupyter_query(Caller, Cell, Line ) :-
|
jupyter_query(Caller, Prog, Query ) :-
|
||||||
jupyter_cell(Caller, Cell, Line).
|
catch(
|
||||||
|
jupyter_cell(Caller, Prog, Query),
|
||||||
|
E,
|
||||||
|
'$Error'(E, top)
|
||||||
|
).
|
||||||
|
|
||||||
jupyter_cell(_Caller, Cell, _Line) :-
|
jupyter_cell(_Caller, Cell, _Line) :-
|
||||||
jupyter_consult(Cell), %stack_dump,
|
jupyter_consult(Cell), %stack_dump,
|
||||||
@ -33,8 +37,8 @@ jupyter_cell( _Caller, _, '' ) :- !.
|
|||||||
jupyter_cell( _Caller, _, Line ) :-
|
jupyter_cell( _Caller, _, Line ) :-
|
||||||
blank( Line ),
|
blank( Line ),
|
||||||
!.
|
!.
|
||||||
jupyter_cell( Caller, _, Line ) :-
|
jupyter_cell( Self, _, Line ) :-
|
||||||
Self := Caller.query,
|
%Self := Caller.query,
|
||||||
python_query(Self,Line).
|
python_query(Self,Line).
|
||||||
|
|
||||||
restreams(call) :-
|
restreams(call) :-
|
||||||
@ -52,143 +56,77 @@ jupyter_consult(Text) :-
|
|||||||
blank( Text ),
|
blank( Text ),
|
||||||
!.
|
!.
|
||||||
jupyter_consult(Cell) :-
|
jupyter_consult(Cell) :-
|
||||||
% Name = 'Inp',
|
|
||||||
% stream_property(Stream, file_name(Name) ),
|
|
||||||
% 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)]).
|
||||||
|
|
||||||
blank(Text) :-
|
blank(Text) :-
|
||||||
atom_codes(Text, L),
|
atom(Text),
|
||||||
maplist( code_type(space), L).
|
!,
|
||||||
|
atom_codes(Text, L),
|
||||||
|
maplist( code_type(space), L).
|
||||||
|
blank(Text) :-
|
||||||
|
string(Text),
|
||||||
|
!,
|
||||||
|
string_codes(Text, L),
|
||||||
|
maplist( code_type(space), L).
|
||||||
|
|
||||||
:- dynamic cell_stream/1.
|
|
||||||
|
|
||||||
streams(false) :-
|
streams(false) :-
|
||||||
nb_setval(jupyter_cell, false),
|
nb_setval(jupyter_cell, false),
|
||||||
retract(cell_stream(S)),
|
close(user_input),
|
||||||
close(S),
|
close(user_output),
|
||||||
fail.
|
close(user_error).
|
||||||
streams(false).
|
|
||||||
streams(true) :-
|
streams(true) :-
|
||||||
streams( false ),
|
|
||||||
nb_setval(jupyter_cell, true),
|
nb_setval(jupyter_cell, true),
|
||||||
% \+ current_stream('/python/input',_,_),
|
open('/python/input', read, _Input, [alias(user_input),bom(false),script(false)]),
|
||||||
open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]),
|
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
||||||
assert( cell_stream( Input) ),
|
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
|
||||||
set_prolog_flag(user_input,Input),
|
|
||||||
fail.
|
|
||||||
streams(true) :-
|
|
||||||
% \+ current_stream('/python/sys.stdout',_,_),
|
|
||||||
open('/python/sys.stdout', append, Output, [alias(user_output)]),
|
|
||||||
set_prolog_flag(user_output, Output),
|
|
||||||
assert( cell_stream( Output) ),
|
|
||||||
fail.
|
|
||||||
streams(true) :-
|
|
||||||
% \+ current_stream('/python/sys.stderr',_,_),
|
|
||||||
open('/python/sys.stderr', append, Error, [alias(user_error)]),
|
|
||||||
assert( cell_stream( Error) ),
|
|
||||||
set_prolog_flag(user_error, Error),
|
|
||||||
fail.
|
|
||||||
streams(true).
|
|
||||||
|
|
||||||
ready(_Self, Line ) :-
|
ready(Self, Cell, P, Q ) :-
|
||||||
blank( Line ),
|
catch(
|
||||||
!.
|
all_clear(Self, Cell, P, Q)
|
||||||
ready(Self, Line ) :-
|
E,
|
||||||
errors( Self, Line ),
|
system_error(error,E).
|
||||||
\+ syntax_error(_,_).
|
|
||||||
|
|
||||||
errors( Self, Text ) :-
|
all_clear( Self, _Cell, P, Q) :-
|
||||||
|
no_errors( Self, P ),
|
||||||
|
yap_flag(singleton_variables, Old, false)
|
||||||
|
no_errors( Self, Q ).
|
||||||
|
|
||||||
|
no_errors( _Self, Text ) :-
|
||||||
|
blank(Text),
|
||||||
|
no_errors( Self, Text ) :-
|
||||||
setup_call_cleanup(
|
setup_call_cleanup(
|
||||||
open_events( Self, Text, Stream),
|
open_esh( Self, Text, Stream),
|
||||||
goals(Self, Stream),
|
esh(Self, Stream),
|
||||||
close_events( Self )
|
close_esh( Self, Stream )
|
||||||
).
|
).
|
||||||
|
|
||||||
clauses(_Self, Stream) :-
|
esh(Self, Stream) :-
|
||||||
repeat,
|
repeat,
|
||||||
read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
catch(
|
||||||
% command( Self, Cl ),
|
read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||||
|
Error,
|
||||||
|
syntax(Self, Error)
|
||||||
|
),
|
||||||
Cl == end_of_file,
|
Cl == end_of_file,
|
||||||
!.
|
!.
|
||||||
|
|
||||||
goals(_Self, Stream) :-
|
|
||||||
repeat,
|
|
||||||
read_term(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
|
||||||
% command( Self, Cl ),
|
|
||||||
Cl == end_of_file,
|
|
||||||
!.
|
|
||||||
|
|
||||||
command(_, end_of_file) :- !.
|
syntax(_Self, E) :- writeln(user_error, E), fail.
|
||||||
|
syntax(Self, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||||
|
Self.errors := [t(Cause,LN,CharPos,Details)] + Self.errors,
|
||||||
|
!.
|
||||||
|
syntax(_Self, E) :- throw(E).
|
||||||
|
|
||||||
command( _Self, ( :- op(Prio,Assoc,Name) ) ) :-
|
open_esh(Self, Text, Stream) :-
|
||||||
addop(Prio,Assoc,Name).
|
|
||||||
|
|
||||||
command( _Self, ( :- module(Name, Exports) )) :-
|
|
||||||
retract( active_module( M0 ) ),
|
|
||||||
atom_concat( '__m0_', Name, M ),
|
|
||||||
assert( active_module(M) ),
|
|
||||||
assert( undo( active_module(M0) ) ),
|
|
||||||
maplist( addop2(M), Exports).
|
|
||||||
|
|
||||||
|
|
||||||
addop(Prio,Assoc,Name) :-
|
|
||||||
(
|
|
||||||
current_op(OPrio, SimilarAssoc, Name),
|
|
||||||
op(Prio, Assoc, Name),
|
|
||||||
matched_op(Assoc, SimilarAssoc)
|
|
||||||
->
|
|
||||||
assertz( undo(op( OPrio, Assoc, Name ) ) )
|
|
||||||
;
|
|
||||||
assertz( undo(op( 0, Assoc, Name ) ) )
|
|
||||||
).
|
|
||||||
|
|
||||||
addop2(M, op(Prio, Assoc, Name)) :-
|
|
||||||
addop( Prio, Assoc, M:Name ).
|
|
||||||
|
|
||||||
matched_op(A, B) :-
|
|
||||||
optype( A, T),
|
|
||||||
optype( B, T).
|
|
||||||
|
|
||||||
optype(fx,pre).
|
|
||||||
optype(fy,pre).
|
|
||||||
optype(xfx,in).
|
|
||||||
optype(xfy,in).
|
|
||||||
optype(yfx,in).
|
|
||||||
optype(yfy,in).
|
|
||||||
optype(xf,pos).
|
|
||||||
optype(yf,pos).
|
|
||||||
|
|
||||||
:- dynamic user:portray_message/2.
|
|
||||||
:- multifile user:portray_message/2.
|
|
||||||
|
|
||||||
:- dynamic syntax_error/4, undo/1.
|
|
||||||
|
|
||||||
user:portray_message(_Severity, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
|
||||||
nb_getval(jupyter_cell, on),
|
|
||||||
assert( syntax_error(Cause,LN,CharPos,Details) ).
|
|
||||||
user:portray_message(_Severity, error(style_check(_),_) ) :-
|
|
||||||
nb_getval(jupyter_cell, on).
|
|
||||||
|
|
||||||
open_events(Self, Text, Stream) :-
|
|
||||||
Self.errors := [],
|
Self.errors := [],
|
||||||
nb_setval( jupyter, on),
|
|
||||||
open_mem_read_stream( Text, Stream ).
|
open_mem_read_stream( Text, Stream ).
|
||||||
|
|
||||||
:- initialization( nb_setval( jupyter, off ) ).
|
:- initialization( nb_setval( jupyter, off ) ).
|
||||||
|
|
||||||
close_events( _Self ) :-
|
close_esh( _Self, Stream ) :-
|
||||||
nb_setval( jupyter, off ),
|
close(Stream).
|
||||||
retract( undo(G) ),
|
|
||||||
call(G),
|
|
||||||
fail.
|
|
||||||
close_events( Self ) :-
|
|
||||||
retract( syntax_error( C, L, N, A )),
|
|
||||||
Self.errors := [t(C,L,N,A)] + Self.errors,
|
|
||||||
fail.
|
|
||||||
close_events( _ ).
|
|
||||||
|
|
||||||
|
|
||||||
:- if( current_prolog_flag(apple, true) ).
|
:- if( current_prolog_flag(apple, true) ).
|
||||||
|
|
||||||
|
@ -23,11 +23,11 @@ library = namedtuple('library', 'list')
|
|||||||
v = namedtuple('_', 'slot')
|
v = namedtuple('_', 'slot')
|
||||||
load_files = namedtuple('load_files', 'file ofile args')
|
load_files = namedtuple('load_files', 'file ofile args')
|
||||||
python_query = namedtuple('python_query', 'query_mgr string')
|
python_query = namedtuple('python_query', 'query_mgr string')
|
||||||
jupyter_query = namedtuple('jupyter_query', 'self text query')
|
jupyter_query = namedtuple('jupyter_query', 'self text p q')
|
||||||
enter_cell = namedtuple('enter_cell', 'self' )
|
enter_cell = namedtuple('enter_cell', 'self' )
|
||||||
exit_cell = namedtuple('exit_cell', 'self' )
|
exit_cell = namedtuple('exit_cell', 'self' )
|
||||||
completions = namedtuple('completions', 'txt self' )
|
completions = namedtuple('completions', 'txt self' )
|
||||||
errors = namedtuple('errors', 'self text' )
|
errors = namedtuple('errors', 'self text p q' )
|
||||||
streams = namedtuple('streams', ' text' )
|
streams = namedtuple('streams', ' text' )
|
||||||
nostreams = namedtuple('nostreams', ' text' )
|
nostreams = namedtuple('nostreams', ' text' )
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class YAPInputSplitter(InputSplitter):
|
|||||||
if not line:
|
if not line:
|
||||||
line = text.rstrip()
|
line = text.rstrip()
|
||||||
self.errors = []
|
self.errors = []
|
||||||
engine.mgoal(errors(self, line),"user",True)
|
engine.mgoal(errors(self, text ,text,''),"user",True)
|
||||||
return self.errors != []
|
return self.errors != []
|
||||||
|
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ class YAPRun:
|
|||||||
self.shell.yapeng = self.yapeng
|
self.shell.yapeng = self.yapeng
|
||||||
self._get_exc_info = shell._get_exc_info
|
self._get_exc_info = shell._get_exc_info
|
||||||
|
|
||||||
def syntaxErrors(self, text):
|
def syntaxErrors(self, text,program,query):
|
||||||
"""Return whether a legal query
|
"""Return whether a legal query
|
||||||
"""
|
"""
|
||||||
if not text:
|
if not text:
|
||||||
@ -528,8 +528,7 @@ class YAPRun:
|
|||||||
if text == self.os:
|
if text == self.os:
|
||||||
return self.errors
|
return self.errors
|
||||||
self.errors=[]
|
self.errors=[]
|
||||||
(text,_,_,_) = self.clean_end(text)
|
self.yapeng.mgoal(errors(self,text,program,query),"user",True)
|
||||||
self.yapeng.mgoal(errors(self,text),"user",True)
|
|
||||||
return self.errors
|
return self.errors
|
||||||
|
|
||||||
def jupyter_query(self, s):
|
def jupyter_query(self, s):
|
||||||
@ -655,7 +654,8 @@ class YAPRun:
|
|||||||
# except SyntaxError:
|
# except SyntaxError:
|
||||||
# preprocessing_exc_tuple = self.shell.syntax_error() # sys.exc_info()
|
# preprocessing_exc_tuple = self.shell.syntax_error() # sys.exc_info()
|
||||||
cell = raw_cell # cell has to exist so it can be stored/logged
|
cell = raw_cell # cell has to exist so it can be stored/logged
|
||||||
for i in self.syntaxErrors(raw_cell):
|
(text,program,query,_) = self.clean_end(raw_cell)
|
||||||
|
for i in self.syntaxErrors(raw_cell,raw_cell,''):
|
||||||
try:
|
try:
|
||||||
(what,lin,_,text) = i
|
(what,lin,_,text) = i
|
||||||
e = SyntaxError(what, ("<string>", lin, 1, text))
|
e = SyntaxError(what, ("<string>", lin, 1, text))
|
||||||
|
Reference in New Issue
Block a user