XyMerge /home/vsc/yap
This commit is contained in:
commit
0d47af2ad9
@ -224,7 +224,7 @@ static int stack_overflow(PredEntry *pe, CELL *env, yamop *cp,
|
|||||||
Yap_get_signal(YAP_STOVF_SIGNAL)) {
|
Yap_get_signal(YAP_STOVF_SIGNAL)) {
|
||||||
S = (CELL *)pe;
|
S = (CELL *)pe;
|
||||||
if (!Yap_locked_gc(nargs, env, cp)) {
|
if (!Yap_locked_gc(nargs, env, cp)) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -239,7 +239,7 @@ static int code_overflow(CELL *yenv USES_REGS) {
|
|||||||
/* do a garbage collection first to check if we can recover memory */
|
/* do a garbage collection first to check if we can recover memory */
|
||||||
if (!Yap_locked_growheap(false, 0, NULL)) {
|
if (!Yap_locked_growheap(false, 0, NULL)) {
|
||||||
Yap_NilError(RESOURCE_ERROR_HEAP, "YAP failed to grow heap: %s",
|
Yap_NilError(RESOURCE_ERROR_HEAP, "YAP failed to grow heap: %s",
|
||||||
LOCAL_ErrorMessage);
|
"malloc/mmap failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CACHE_A1();
|
CACHE_A1();
|
||||||
@ -689,7 +689,7 @@ static int interrupt_deallocate(USES_REGS1) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
if (!Yap_locked_gc(0, ENV, YESCODE)) {
|
if (!Yap_locked_gc(0, ENV, YESCODE)) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
|
||||||
}
|
}
|
||||||
S = ASP;
|
S = ASP;
|
||||||
S[E_CB] = (CELL)(LCL0 - cut_b);
|
S[E_CB] = (CELL)(LCL0 - cut_b);
|
||||||
|
@ -1102,7 +1102,7 @@
|
|||||||
PP = NULL;
|
PP = NULL;
|
||||||
#endif
|
#endif
|
||||||
if (!Yap_gc(3, ENV, CP)) {
|
if (!Yap_gc(3, ENV, CP)) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
|
||||||
FAIL();
|
FAIL();
|
||||||
}
|
}
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
@ -1226,7 +1226,7 @@
|
|||||||
PREG = NEXTOP(PREG,Osbpa);
|
PREG = NEXTOP(PREG,Osbpa);
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl(sz, arity, YENV, PREG)) {
|
if (!Yap_gcl(sz, arity, YENV, PREG)) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
FAIL();
|
FAIL();
|
||||||
} else {
|
} else {
|
||||||
@ -10927,7 +10927,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11044,7 +11044,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11154,7 +11154,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) {
|
if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11261,7 +11261,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11388,7 +11388,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11516,7 +11516,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
@ -11892,7 +11892,7 @@
|
|||||||
/* make sure we have something to show for our trouble */
|
/* make sure we have something to show for our trouble */
|
||||||
saveregs();
|
saveregs();
|
||||||
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) {
|
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) {
|
||||||
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
|
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed" );
|
||||||
setregs();
|
setregs();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
} else {
|
} else {
|
||||||
|
105
C/errors.c
105
C/errors.c
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#define set_key_b(k, ks, q, i, t) \
|
#define set_key_b(k, ks, q, i, t) \
|
||||||
if (strcmp(ks, q) == 0) { \
|
if (strcmp(ks, q) == 0) { \
|
||||||
i->k = t == TermTrue ? true : false; \
|
i->k = ( t == TermTrue ? true : false); \
|
||||||
return i->k || t == TermFalse; \
|
return i->k || t == TermFalse; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,18 +67,18 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
|
|||||||
set_key_s(errorFunction, "errorFunction", q, i, t);
|
set_key_s(errorFunction, "errorFunction", q, i, t);
|
||||||
set_key_s(errorFile, "errorFile", q, i, t);
|
set_key_s(errorFile, "errorFile", q, i, t);
|
||||||
set_key_i(prologPredLine, "prologPredLine", q, i, t);
|
set_key_i(prologPredLine, "prologPredLine", q, i, t);
|
||||||
set_key_i(prologPredFirstLine, "prologPredFirstLine", q, i, t);
|
|
||||||
set_key_i(prologPredLastLine, "prologPredLastLine", q, i, t);
|
|
||||||
set_key_s(prologPredName, "prologPredName", q, i, t);
|
set_key_s(prologPredName, "prologPredName", q, i, t);
|
||||||
set_key_i(prologPredArity, "prologPredArity", q, i, t);
|
set_key_i(prologPredArity, "prologPredArity", q, i, t);
|
||||||
set_key_s(prologPredModule, "prologPredModule", q, i, t);
|
set_key_s(prologPredModule, "prologPredModule", q, i, t);
|
||||||
set_key_s(prologPredFile, "prologPredFile", q, i, t);
|
set_key_s(prologPredFile, "prologPredFile", q, i, t);
|
||||||
set_key_i(prologParserPos, "prologParserPos", q, i, t);
|
set_key_i(parserPos, "parserPos", q, i, t);
|
||||||
set_key_i(prologParserLine, "prologParserLine", q, i, t);
|
set_key_i(parserLine, "parserLine", q, i, t);
|
||||||
set_key_i(prologParserFirstLine, "prologParserFirstLine", q, i, t);
|
set_key_i(parserFirstLine, "parserFirstLine", q, i, t);
|
||||||
set_key_i(prologParserLastLine, "prologParserLastLine", q, i, t);
|
set_key_i(parserLastLine, "parserLastLine", q, i, t);
|
||||||
set_key_s(prologParserText, "prologParserText", q, i, t);
|
set_key_s(parserTextA, "parserTextA", q, i, t);
|
||||||
set_key_s(prologParserFile, "prologParserFile", q, i, t);
|
set_key_s(parserTextB, "parserTextB", q, i, t);
|
||||||
|
set_key_s(parserFile, "parserFile", q, i, t);
|
||||||
|
set_key_b(parserReadingCode, "parserReadingcode", q, i, t);
|
||||||
set_key_b(prologConsulting, "prologConsulting", q, i, t);
|
set_key_b(prologConsulting, "prologConsulting", q, i, t);
|
||||||
set_key_s(culprit, "culprit", q, i, t);
|
set_key_s(culprit, "culprit", q, i, t);
|
||||||
set_key_s(errorMsg, "errorMsg", q, i, t);
|
set_key_s(errorMsg, "errorMsg", q, i, t);
|
||||||
@ -116,18 +116,18 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
|
|||||||
query_key_s(errorFunction, "errorFunction", q, i);
|
query_key_s(errorFunction, "errorFunction", q, i);
|
||||||
query_key_s(errorFile, "errorFile", q, i);
|
query_key_s(errorFile, "errorFile", q, i);
|
||||||
query_key_i(prologPredLine, "prologPredLine", q, i);
|
query_key_i(prologPredLine, "prologPredLine", q, i);
|
||||||
query_key_i(prologPredFirstLine, "prologPredFirstLine", q, i);
|
|
||||||
query_key_i(prologPredLastLine, "prologPredLastLine", q, i);
|
|
||||||
query_key_s(prologPredName, "prologPredName", q, i);
|
query_key_s(prologPredName, "prologPredName", q, i);
|
||||||
query_key_i(prologPredArity, "prologPredArity", q, i);
|
query_key_i(prologPredArity, "prologPredArity", q, i);
|
||||||
query_key_s(prologPredModule, "prologPredModule", q, i);
|
query_key_s(prologPredModule, "prologPredModule", q, i);
|
||||||
query_key_s(prologPredFile, "prologPredFile", q, i);
|
query_key_s(prologPredFile, "prologPredFile", q, i);
|
||||||
query_key_i(prologParserPos, "prologParserPos", q, i);
|
query_key_i(parserPos, "parserPos", q, i);
|
||||||
query_key_i(prologParserLine, "prologParserLine", q, i);
|
query_key_i(parserLine, "parserLine", q, i);
|
||||||
query_key_i(prologParserFirstLine, "prologParserFirstLine", q, i);
|
query_key_i(parserFirstLine, "parserFirstLine", q, i);
|
||||||
query_key_i(prologParserLastLine, "prologParserLastLine", q, i);
|
query_key_i(parserLastLine, "parserLastLine", q, i);
|
||||||
query_key_s(prologParserText, "prologParserText", q, i);
|
query_key_s(parserTextA, "parserTextA", q, i);
|
||||||
query_key_s(prologParserFile, "prologParserFile", q, i);
|
query_key_s(parserTextB, "parserTextB", q, i);
|
||||||
|
query_key_s(parserFile, "parserFile", q, i);
|
||||||
|
query_key_b(parserReadingCode, "parserReadingCode", q, i);
|
||||||
query_key_b(prologConsulting, "prologConsulting", q, i);
|
query_key_b(prologConsulting, "prologConsulting", q, i);
|
||||||
query_key_t(culprit, "culprit", q, i);
|
query_key_t(culprit, "culprit", q, i);
|
||||||
query_key_s(errorMsg, "errorMsg", q, i);
|
query_key_s(errorMsg, "errorMsg", q, i);
|
||||||
@ -162,18 +162,18 @@ static void printErr(yap_error_descriptor_t *i) {
|
|||||||
print_key_s("errorFunction", i->errorFunction);
|
print_key_s("errorFunction", i->errorFunction);
|
||||||
print_key_s("errorFile", i->errorFile);
|
print_key_s("errorFile", i->errorFile);
|
||||||
print_key_i("prologPredLine", i->prologPredLine);
|
print_key_i("prologPredLine", i->prologPredLine);
|
||||||
print_key_i("prologPredFirstLine", i->prologPredFirstLine);
|
|
||||||
print_key_i("prologPredLastLine", i->prologPredLastLine);
|
|
||||||
print_key_s("prologPredName", i->prologPredName);
|
print_key_s("prologPredName", i->prologPredName);
|
||||||
print_key_i("prologPredArity", i->prologPredArity);
|
print_key_i("prologPredArity", i->prologPredArity);
|
||||||
print_key_s("prologPredModule", i->prologPredModule);
|
print_key_s("prologPredModule", i->prologPredModule);
|
||||||
print_key_s("prologPredFile", i->prologPredFile);
|
print_key_s("prologPredFile", i->prologPredFile);
|
||||||
print_key_i("prologParserPos", i->prologParserPos);
|
print_key_i("parserPos", i->parserPos);
|
||||||
print_key_i("prologParserLine", i->prologParserLine);
|
print_key_i("parserLine", i->parserLine);
|
||||||
print_key_i("prologParserFirstLine", i->prologParserFirstLine);
|
print_key_i("parserFirstLine", i->parserFirstLine);
|
||||||
print_key_i("prologParserLastLine", i->prologParserLastLine);
|
print_key_i("parserLastLine", i->parserLastLine);
|
||||||
print_key_s("prologParserText", i->prologParserText);
|
print_key_s("parserTextA", i->parserTextA);
|
||||||
print_key_s("prologParserFile", i->prologParserFile);
|
print_key_s("parserTextB", i->parserTextB);
|
||||||
|
print_key_s("parserFile", i->parserFile);
|
||||||
|
print_key_b("parserReadingCode", i->parserReadingCode);
|
||||||
print_key_b("prologConsulting", i->prologConsulting);
|
print_key_b("prologConsulting", i->prologConsulting);
|
||||||
print_key_s("culprit", i->culprit);
|
print_key_s("culprit", i->culprit);
|
||||||
if (i->errorMsgLen) {
|
if (i->errorMsgLen) {
|
||||||
@ -220,18 +220,18 @@ static Term err2list(yap_error_descriptor_t *i) {
|
|||||||
o = add_key_s("errorFunction", i->errorFunction, o);
|
o = add_key_s("errorFunction", i->errorFunction, o);
|
||||||
o = add_key_s("errorFile", i->errorFile, o);
|
o = add_key_s("errorFile", i->errorFile, o);
|
||||||
o = add_key_i("prologPredLine", i->prologPredLine, o);
|
o = add_key_i("prologPredLine", i->prologPredLine, o);
|
||||||
o = add_key_i("prologPredFirstLine", i->prologPredFirstLine, o);
|
|
||||||
o = add_key_i("prologPredLastLine", i->prologPredLastLine, o);
|
|
||||||
o = add_key_s("prologPredName", i->prologPredName, o);
|
o = add_key_s("prologPredName", i->prologPredName, o);
|
||||||
o = add_key_i("prologPredArity", i->prologPredArity, o);
|
o = add_key_i("prologPredArity", i->prologPredArity, o);
|
||||||
o = add_key_s("prologPredModule", i->prologPredModule, o);
|
o = add_key_s("prologPredModule", i->prologPredModule, o);
|
||||||
o = add_key_s("prologPredFile", i->prologPredFile, o);
|
o = add_key_s("prologPredFile", i->prologPredFile, o);
|
||||||
o = add_key_i("prologParserPos", i->prologParserPos, o);
|
o = add_key_i("parserPos", i->parserPos, o);
|
||||||
o = add_key_i("prologParserLine", i->prologParserLine, o);
|
o = add_key_i("parserLine", i->parserLine, o);
|
||||||
o = add_key_i("prologParserFirstLine", i->prologParserFirstLine, o);
|
o = add_key_i("parserFirstLine", i->parserFirstLine, o);
|
||||||
o = add_key_i("prologParserLastLine", i->prologParserLastLine, o);
|
o = add_key_i("parserLastLine", i->parserLastLine, o);
|
||||||
o = add_key_s("prologParserText", i->prologParserText, o);
|
o = add_key_s("parserTextA", i->parserTextA, o);
|
||||||
o = add_key_s("prologParserFile", i->prologParserFile, o);
|
o = add_key_s("parserTextB", i->parserTextB, o);
|
||||||
|
o = add_key_s("parserFile", i->parserFile, o);
|
||||||
|
o = add_key_b("parserReadingCode", i->parserReadingCode, o);
|
||||||
o = add_key_b("prologConsulting", i->prologConsulting, o);
|
o = add_key_b("prologConsulting", i->prologConsulting, o);
|
||||||
o = add_key_s("culprit", i->culprit, o);
|
o = add_key_s("culprit", i->culprit, o);
|
||||||
if (i->errorMsgLen) {
|
if (i->errorMsgLen) {
|
||||||
@ -317,7 +317,7 @@ void Yap_InitError__(const char *file, const char *function, int lineno,
|
|||||||
if (fmt) {
|
if (fmt) {
|
||||||
LOCAL_Error_Size = strlen(tmpbuf);
|
LOCAL_Error_Size = strlen(tmpbuf);
|
||||||
LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
|
LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
|
||||||
strcpy(LOCAL_ActiveError->errorMsg, tmpbuf);
|
strcpy((char *)LOCAL_ActiveError->errorMsg, tmpbuf);
|
||||||
} else {
|
} else {
|
||||||
LOCAL_Error_Size = 0;
|
LOCAL_Error_Size = 0;
|
||||||
}
|
}
|
||||||
@ -334,6 +334,7 @@ bool Yap_PrintWarning(Term twarning) {
|
|||||||
Term ts[2], err;
|
Term ts[2], err;
|
||||||
|
|
||||||
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
|
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
|
||||||
|
LOCAL_ActiveError->errorClass != WARNING &&
|
||||||
(err = LOCAL_ActiveError->errorNo)) {
|
(err = LOCAL_ActiveError->errorNo)) {
|
||||||
fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
|
fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
|
||||||
Yap_TermToBuffer(twarning,
|
Yap_TermToBuffer(twarning,
|
||||||
@ -423,9 +424,7 @@ int Yap_SWIHandleError(const char *s, ...) {
|
|||||||
yap_error_number err = LOCAL_Error_TYPE;
|
yap_error_number err = LOCAL_Error_TYPE;
|
||||||
char *serr;
|
char *serr;
|
||||||
|
|
||||||
if (LOCAL_ErrorMessage) {
|
if (s) {
|
||||||
serr = LOCAL_ErrorMessage;
|
|
||||||
} else {
|
|
||||||
serr = (char *)s;
|
serr = (char *)s;
|
||||||
}
|
}
|
||||||
switch (err) {
|
switch (err) {
|
||||||
@ -575,8 +574,11 @@ static char tmpbuf[YAP_BUF_SIZE];
|
|||||||
|
|
||||||
#include "YapErrors.h"
|
#include "YapErrors.h"
|
||||||
|
|
||||||
bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
|
/// add a new error descriptor, either to the top of the stack,
|
||||||
|
/// or replacing the top;
|
||||||
|
bool Yap_pushErrorContext(bool link , yap_error_descriptor_t *new_error) {
|
||||||
memset(new_error, 0, sizeof(yap_error_descriptor_t));
|
memset(new_error, 0, sizeof(yap_error_descriptor_t));
|
||||||
|
if (link)
|
||||||
new_error->top_error = LOCAL_ActiveError;
|
new_error->top_error = LOCAL_ActiveError;
|
||||||
LOCAL_ActiveError = new_error;
|
LOCAL_ActiveError = new_error;
|
||||||
return true;
|
return true;
|
||||||
@ -645,6 +647,16 @@ void Yap_ThrowExistingError(void) {
|
|||||||
Yap_exit(5);
|
Yap_exit(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Term Yap_MkFullError(void)
|
||||||
|
{
|
||||||
|
yap_error_descriptor_t *i = Yap_local.ActiveError;
|
||||||
|
i->errorAsText = Yap_errorName( i->errorNo );
|
||||||
|
i->errorClass = Yap_errorClass( i-> errorNo );
|
||||||
|
i->classAsText = Yap_errorClassName(i->errorClass);
|
||||||
|
return mkerrort(i->errorNo, TermNil , MkSysError(i) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
|
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
|
||||||
const char *function, int lineno, yap_error_number type,
|
const char *function, int lineno, yap_error_number type,
|
||||||
Term where, const char *s) {
|
Term where, const char *s) {
|
||||||
@ -656,9 +668,9 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
|
|||||||
r->culprit = Yap_TermToBuffer(
|
r->culprit = Yap_TermToBuffer(
|
||||||
where, Quote_illegal_f | Ignore_ops_f);
|
where, Quote_illegal_f | Ignore_ops_f);
|
||||||
}
|
}
|
||||||
if (LOCAL_consult_level > 0) {
|
if (type != SYNTAX_ERROR && LOCAL_consult_level > 0) {
|
||||||
r->prologParserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
|
r->parserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
|
||||||
r->prologParserLine = Yap_source_line_no();
|
r->parserLine = Yap_source_line_no();
|
||||||
}
|
}
|
||||||
r->errorNo = type;
|
r->errorNo = type;
|
||||||
r->errorAsText = Yap_errorName(type);
|
r->errorAsText = Yap_errorName(type);
|
||||||
@ -670,6 +682,7 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
|
|||||||
LOCAL_PrologMode |= InErrorMode;
|
LOCAL_PrologMode |= InErrorMode;
|
||||||
Yap_ClearExs();
|
Yap_ClearExs();
|
||||||
// first, obtain current location
|
// first, obtain current location
|
||||||
|
|
||||||
// sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno,
|
// sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno,
|
||||||
// function);
|
// function);
|
||||||
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf));
|
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf));
|
||||||
@ -694,13 +707,11 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
|
|||||||
}
|
}
|
||||||
// fprintf(stderr, "warning: ");
|
// fprintf(stderr, "warning: ");
|
||||||
if (s && s[0]) {
|
if (s && s[0]) {
|
||||||
|
char *ns;
|
||||||
r->errorMsgLen = strlen(s) + 1;
|
r->errorMsgLen = strlen(s) + 1;
|
||||||
r->errorMsg = malloc(r->errorMsgLen);
|
ns = malloc(r->errorMsgLen);
|
||||||
strcpy(r->errorMsg, s);
|
strcpy(ns, s);
|
||||||
} else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) {
|
r->errorMsg = ns;
|
||||||
r->errorMsgLen = strlen(LOCAL_ErrorMessage) + 1;
|
|
||||||
r->errorMsg = malloc(r->errorMsgLen);
|
|
||||||
strcpy(r->errorMsg, LOCAL_ErrorMessage);
|
|
||||||
} else {
|
} else {
|
||||||
r->errorMsgLen = 0;
|
r->errorMsgLen = 0;
|
||||||
r->errorMsg = 0;
|
r->errorMsg = 0;
|
||||||
|
19
C/parser.c
19
C/parser.c
@ -60,12 +60,12 @@ static void syntax_msg(const char *msg, ...) {
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
if (!LOCAL_ErrorMessage ||
|
if (!LOCAL_ErrorMessage ||
|
||||||
(LOCAL_Error_TYPE == SYNTAX_ERROR &&
|
(LOCAL_Error_TYPE == SYNTAX_ERROR &&
|
||||||
LOCAL_tokptr->TokPos < LOCAL_ActiveError->prologParserPos)) {
|
LOCAL_tokptr->TokPos < LOCAL_ActiveError->parserPos)) {
|
||||||
if (!LOCAL_ErrorMessage) {
|
if (!LOCAL_ErrorMessage) {
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->prologParserLine = LOCAL_tokptr->TokLine;
|
LOCAL_ActiveError->parserLine = LOCAL_tokptr->TokLine;
|
||||||
LOCAL_ActiveError->prologParserPos = LOCAL_tokptr->TokPos;
|
LOCAL_ActiveError->parserPos = LOCAL_tokptr->TokPos;
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
|
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -911,12 +911,17 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
// ensure that if we throw an exception
|
// ensure that if we throw an exception
|
||||||
// t will be 0.
|
// t will be 0.
|
||||||
|
LOCAL_ActiveError->errorMsg=NULL;
|
||||||
|
LOCAL_ActiveError->errorMsgLen=0;
|
||||||
Volatile Term t = 0;
|
Volatile Term t = 0;
|
||||||
JMPBUFF FailBuff;
|
JMPBUFF FailBuff;
|
||||||
yhandle_t sls = Yap_StartSlots();
|
yhandle_t sls = Yap_StartSlots();
|
||||||
|
LOCAL_ErrorMessage = NULL;
|
||||||
LOCAL_toktide = LOCAL_tokptr;
|
LOCAL_toktide = LOCAL_tokptr;
|
||||||
|
|
||||||
if (!sigsetjmp(FailBuff.JmpBuff, 0)) {
|
if (!sigsetjmp(FailBuff.JmpBuff, 0)) {
|
||||||
|
LOCAL_ActiveError->errorMsg=NULL;
|
||||||
|
LOCAL_ActiveError->errorMsgLen=0;
|
||||||
|
|
||||||
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
|
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -936,9 +941,13 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
|
|||||||
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
|
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
|
||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||||
if (LOCAL_tokptr->TokNext) {
|
if (LOCAL_tokptr->TokNext) {
|
||||||
LOCAL_ErrorMessage = "bracket or operator expected.";
|
size_t sz = strlen("bracket or operator expected.");
|
||||||
|
LOCAL_ErrorMessage =malloc(sz+1);
|
||||||
|
strncpy(LOCAL_ErrorMessage, "bracket or operator expected.", sz );
|
||||||
} else {
|
} else {
|
||||||
LOCAL_ErrorMessage = "term must end with . or EOF.";
|
size_t sz = strlen("term must end with . or EOF.");
|
||||||
|
LOCAL_ErrorMessage =malloc(sz+1);
|
||||||
|
strncpy(LOCAL_ErrorMessage,"term must end with . or EOF.", sz );
|
||||||
}
|
}
|
||||||
t = 0;
|
t = 0;
|
||||||
}
|
}
|
||||||
|
22
C/stack.c
22
C/stack.c
@ -1124,7 +1124,7 @@ static Term clause_info(yamop *codeptr, PredEntry *pp) {
|
|||||||
yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
|
yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
|
||||||
yamop *codeptr, PredEntry *pp) {
|
yamop *codeptr, PredEntry *pp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term ts[2];
|
|
||||||
void *begin;
|
void *begin;
|
||||||
if (pp->ArityOfPE == 0) {
|
if (pp->ArityOfPE == 0) {
|
||||||
t->prologPredName = AtomName((Atom)pp->FunctorOfPred);
|
t->prologPredName = AtomName((Atom)pp->FunctorOfPred);
|
||||||
@ -1138,36 +1138,18 @@ yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
|
|||||||
: "prolog");
|
: "prolog");
|
||||||
t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
|
t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
|
||||||
if (codeptr->opc == UNDEF_OPCODE) {
|
if (codeptr->opc == UNDEF_OPCODE) {
|
||||||
t->prologPredFirstLine = 0;
|
|
||||||
t->prologPredLine = 0;
|
t->prologPredLine = 0;
|
||||||
t->prologPredLastLine = 0;
|
|
||||||
return t;
|
return t;
|
||||||
} else if (pp->cs.p_code.NOfClauses) {
|
} else if (pp->cs.p_code.NOfClauses) {
|
||||||
if ((t->prologPredCl = find_code_in_clause(pp, codeptr, &begin, NULL)) <=
|
if ((t->prologPredLine = find_code_in_clause(pp, codeptr, &begin, NULL)) <=
|
||||||
0) {
|
0) {
|
||||||
t->prologPredLine = 0;
|
t->prologPredLine = 0;
|
||||||
} else {
|
} else {
|
||||||
t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
|
t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
|
||||||
}
|
}
|
||||||
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
||||||
t->prologPredFirstLine =
|
|
||||||
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp);
|
|
||||||
t->prologPredLastLine =
|
|
||||||
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause), pp);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
t->prologPredFirstLine = IntegerOfTerm(
|
|
||||||
ts[0] = clause_loc(
|
|
||||||
ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp));
|
|
||||||
t->prologPredLastLine = IntegerOfTerm(
|
|
||||||
ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause),
|
|
||||||
pp));
|
|
||||||
}
|
|
||||||
return t;
|
return t;
|
||||||
} else {
|
} else {
|
||||||
t->prologPredFirstLine = 0;
|
|
||||||
t->prologPredLine = t->errorLine;
|
t->prologPredLine = t->errorLine;
|
||||||
t->prologPredLastLine = 0;
|
|
||||||
t->prologPredFile = t->errorFile;
|
t->prologPredFile = t->errorFile;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
2
C/text.c
2
C/text.c
@ -990,7 +990,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
|
|||||||
else
|
else
|
||||||
fprintf(stderr, "%s", out->val.c);
|
fprintf(stderr, "%s", out->val.c);
|
||||||
fprintf(stderr, "\n]\n"); */
|
fprintf(stderr, "\n]\n"); */
|
||||||
pop_text_stack(l);
|
out->val.uc = pop_output_text_stack(l,out->val.uc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,10 @@ INLINE_ONLY char_kind_t chtype(Int ch) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char *Yap_tokText(void *tokptr);
|
extern const char *Yap_tokText(void *tokptr);
|
||||||
extern Term Yap_tokRep(void *tokptr);
|
/// represent token *_tokptr_ in string s, maxlength is sz-1
|
||||||
|
///
|
||||||
|
/// conversion is based on token type.
|
||||||
|
extern Term Yap_tokRep(void *tokptrXS);
|
||||||
|
|
||||||
// standard strings
|
// standard strings
|
||||||
|
|
||||||
|
@ -200,29 +200,47 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
|
|||||||
|
|
||||||
/// all we need to know about an error/throw
|
/// all we need to know about an error/throw
|
||||||
typedef struct s_yap_error_descriptor {
|
typedef struct s_yap_error_descriptor {
|
||||||
|
/// error identifier
|
||||||
yap_error_number errorNo;
|
yap_error_number errorNo;
|
||||||
|
/// kind of error: derived from errorNo;
|
||||||
yap_error_class_number errorClass;
|
yap_error_class_number errorClass;
|
||||||
|
/// if non-NULL: goal who caused error;
|
||||||
const char *errorGoal;
|
const char *errorGoal;
|
||||||
|
/// errorNo as text
|
||||||
const char *errorAsText;
|
const char *errorAsText;
|
||||||
|
/// errorClass as text
|
||||||
const char *classAsText;
|
const char *classAsText;
|
||||||
|
/// c-code that generated the error
|
||||||
|
/// C-line
|
||||||
intptr_t errorLine;
|
intptr_t errorLine;
|
||||||
|
/// C-function
|
||||||
const char *errorFunction;
|
const char *errorFunction;
|
||||||
|
/// C-file
|
||||||
const char *errorFile;
|
const char *errorFile;
|
||||||
// struct error_prolog_source *errorSource;
|
// struct error_prolog_source *errorSource;
|
||||||
intptr_t prologPredCl;
|
/// Prolog predicate that caused the error: name
|
||||||
uintptr_t prologPredLine;
|
|
||||||
uintptr_t prologPredFirstLine;
|
|
||||||
uintptr_t prologPredLastLine;
|
|
||||||
const char *prologPredName;
|
const char *prologPredName;
|
||||||
|
/// Prolog predicate that caused the error:arity
|
||||||
uintptr_t prologPredArity;
|
uintptr_t prologPredArity;
|
||||||
|
/// Prolog predicate that caused the error:module
|
||||||
const char *prologPredModule;
|
const char *prologPredModule;
|
||||||
|
/// Prolog predicate that caused the error:line
|
||||||
const char *prologPredFile;
|
const char *prologPredFile;
|
||||||
uintptr_t prologParserPos;
|
/// line where error clause defined
|
||||||
uintptr_t prologParserLine;
|
uintptr_t prologPredLine;
|
||||||
uintptr_t prologParserFirstLine;
|
/// syntax and other parsing errors
|
||||||
uintptr_t prologParserLastLine;
|
uintptr_t parserPos;
|
||||||
const char *prologParserText;
|
uintptr_t parserFirstPos;
|
||||||
const char *prologParserFile;
|
uintptr_t parserLastPos;
|
||||||
|
uintptr_t parserLine;
|
||||||
|
uintptr_t parserFirstLine;
|
||||||
|
uintptr_t parserLastLine;
|
||||||
|
const char *parserTextA;
|
||||||
|
const char *parserTextB;
|
||||||
|
const char *parserFile;
|
||||||
|
/// reading a clause, or called from read?
|
||||||
|
bool parserReadingCode;
|
||||||
|
/// whether we are consulting
|
||||||
bool prologConsulting;
|
bool prologConsulting;
|
||||||
const char *culprit;
|
const char *culprit;
|
||||||
YAP_Term errorRawTerm, rawExtraErrorTerm;
|
YAP_Term errorRawTerm, rawExtraErrorTerm;
|
||||||
@ -242,6 +260,7 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
|
|||||||
|
|
||||||
extern void Yap_CatchError(void);
|
extern void Yap_CatchError(void);
|
||||||
extern void Yap_ThrowExistingError(void);
|
extern void Yap_ThrowExistingError(void);
|
||||||
|
extern YAP_Term Yap_MkFullError(void);
|
||||||
extern bool Yap_MkErrorRecord(
|
extern bool Yap_MkErrorRecord(
|
||||||
yap_error_descriptor_t * r, const char *file, const char *function,
|
yap_error_descriptor_t * r, const char *file, const char *function,
|
||||||
int lineno, yap_error_number type, YAP_Term where, const char *msg);
|
int lineno, yap_error_number type, YAP_Term where, const char *msg);
|
||||||
|
@ -32,6 +32,8 @@ ECLASS(SYSTEM_ERROR_CLASS, "system_error", 1)
|
|||||||
ECLASS(TYPE_ERROR, "type_error", 2)
|
ECLASS(TYPE_ERROR, "type_error", 2)
|
||||||
/// should be unbound
|
/// should be unbound
|
||||||
ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1)
|
ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1)
|
||||||
|
/// not quite an error, but almost
|
||||||
|
ECLASS(WARNING, "warning", 1)
|
||||||
/// user defined escape hatch
|
/// user defined escape hatch
|
||||||
ECLASS(EVENT, "event", 1)
|
ECLASS(EVENT, "event", 1)
|
||||||
|
|
||||||
@ -196,7 +198,11 @@ E(TYPE_ERROR_REFERENCE, TYPE_ERROR, "reference")
|
|||||||
E(TYPE_ERROR_STRING, TYPE_ERROR, "string")
|
E(TYPE_ERROR_STRING, TYPE_ERROR, "string")
|
||||||
E(TYPE_ERROR_TEXT, TYPE_ERROR, "text")
|
E(TYPE_ERROR_TEXT, TYPE_ERROR, "text")
|
||||||
E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte")
|
E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte")
|
||||||
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "uchar")
|
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "unsigned char")
|
||||||
|
|
||||||
|
E(WARNING_DISCONTIGUOUS, WARNING, "discontiguous")
|
||||||
|
E(WARNING_SINGLETONS, WARNING, "singletons")
|
||||||
|
E(WARNING_SYNTAX_ERROR, WARNING, "syntax_error")
|
||||||
|
|
||||||
E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")
|
E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")
|
||||||
|
|
||||||
|
62
os/format.c
62
os/format.c
@ -278,32 +278,54 @@ static int format_print_str(Int sno, Int size, Int has_size, Term args,
|
|||||||
while (*pt && (!has_size || size > 0)) {
|
while (*pt && (!has_size || size > 0)) {
|
||||||
utf8proc_int32_t ch;
|
utf8proc_int32_t ch;
|
||||||
|
|
||||||
|
if ((pt += get_utf8(pt, -1, &ch)) > 0) {
|
||||||
|
f_putc(sno, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (IsAtomTerm(args)) {
|
||||||
|
const unsigned char *pt = RepAtom(AtomOfTerm(args))->UStrOfAE;
|
||||||
|
while (*pt && (!has_size || size > 0)) {
|
||||||
|
utf8proc_int32_t ch;
|
||||||
|
|
||||||
if ((pt += get_utf8(pt, -1, &ch)) > 0) {
|
if ((pt += get_utf8(pt, -1, &ch)) > 0) {
|
||||||
f_putc(sno, ch);
|
f_putc(sno, ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (!has_size || size > 0) {
|
while (!has_size || size > 0) {
|
||||||
|
bool maybe_chars = true, maybe_codes = true;
|
||||||
if (IsVarTerm(args)) {
|
if (IsVarTerm(args)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, args, "~s expects a bound argument");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (args == TermNil) {
|
} else if (args == TermNil) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (!IsPairTerm(args)) {
|
} else if (!IsPairTerm(args)) {
|
||||||
Yap_Error(TYPE_ERROR_LIST, args, "format/2");
|
Yap_ThrowError(TYPE_ERROR_TEXT, args, "format expects an atom, string, or list of codes or chars ");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
arghd = HeadOfTerm(args);
|
arghd = HeadOfTerm(args);
|
||||||
args = TailOfTerm(args);
|
args = TailOfTerm(args);
|
||||||
if (IsVarTerm(arghd)) {
|
if (IsVarTerm(arghd)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, arghd, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, arghd, "~s expects a bound argument");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (!IsIntTerm(arghd)) {
|
} else if (maybe_codes && IsIntTerm(arghd)) {
|
||||||
Yap_Error(TYPE_ERROR_LIST, arghd, "format/2");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
f_putc(sno, (int)IntOfTerm(arghd));
|
f_putc(sno, (int)IntOfTerm(arghd));
|
||||||
size--;
|
size--;
|
||||||
|
maybe_chars = false;
|
||||||
|
} else if (maybe_chars && IsAtomTerm(arghd)) {
|
||||||
|
unsigned char *fptr = RepAtom(AtomOfTerm(arghd))->UStrOfAE;
|
||||||
|
int ch;
|
||||||
|
fptr += get_utf8(fptr, -1, &ch);
|
||||||
|
if (fptr[0] != '\0') {
|
||||||
|
Yap_ThrowError(TYPE_ERROR_TEXT, arghd, "~s expects a list of chars ");
|
||||||
|
}
|
||||||
|
f_putc(sno, ch);
|
||||||
|
size--;
|
||||||
|
maybe_codes = false;
|
||||||
|
} else {
|
||||||
|
Yap_ThrowError(TYPE_ERROR_TEXT, arghd, "~s expects an atom, string, or list of codes or chars ");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -313,11 +335,11 @@ static Int format_copy_args(Term args, Term *targs, Int tsz) {
|
|||||||
Int n = 0;
|
Int n = 0;
|
||||||
while (args != TermNil) {
|
while (args != TermNil) {
|
||||||
if (IsVarTerm(args)) {
|
if (IsVarTerm(args)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
|
||||||
return FORMAT_COPY_ARGS_ERROR;
|
return FORMAT_COPY_ARGS_ERROR;
|
||||||
}
|
}
|
||||||
if (!IsPairTerm(args)) {
|
if (!IsPairTerm(args)) {
|
||||||
Yap_Error(TYPE_ERROR_LIST, args, "format/2");
|
Yap_ThrowError(TYPE_ERROR_LIST, args, "format/2");
|
||||||
return FORMAT_COPY_ARGS_ERROR;
|
return FORMAT_COPY_ARGS_ERROR;
|
||||||
}
|
}
|
||||||
if (n == tsz)
|
if (n == tsz)
|
||||||
@ -402,7 +424,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
*HR++ = otail;
|
*HR++ = otail;
|
||||||
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
|
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, otail, "format/2");
|
Yap_ThrowError(RESOURCE_ERROR_HEAP, otail, "format/2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
oargs = HR[-2];
|
oargs = HR[-2];
|
||||||
@ -418,20 +440,20 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
targ = 0;
|
targ = 0;
|
||||||
if (IsVarTerm(tail)) {
|
if (IsVarTerm(tail)) {
|
||||||
format_clean_up(sno0, sno, finfo );
|
format_clean_up(sno0, sno, finfo );
|
||||||
Yap_Error(INSTANTIATION_ERROR, tail, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, tail, "format/2");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
} else if ((fstr = Yap_TextToUTF8Buffer(tail))) {
|
} else if ((fstr = Yap_TextToUTF8Buffer(tail))) {
|
||||||
fptr = fstr;
|
fptr = fstr;
|
||||||
alloc_fstr = true;
|
alloc_fstr = true;
|
||||||
} else {
|
} else {
|
||||||
format_clean_up(sno0, sno, finfo);
|
format_clean_up(sno0, sno, finfo);
|
||||||
Yap_Error(TYPE_ERROR_TEXT, tail, "format/2");
|
Yap_ThrowError(TYPE_ERROR_TEXT, tail, "format/2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (IsVarTerm(args)) {
|
if (IsVarTerm(args)) {
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
format_clean_up(sno0, sno, finfo);
|
format_clean_up(sno0, sno, finfo);
|
||||||
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
while (IsApplTerm(args) && FunctorOfTerm(args) == FunctorModule) {
|
while (IsApplTerm(args) && FunctorOfTerm(args) == FunctorModule) {
|
||||||
@ -440,19 +462,19 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
if (IsVarTerm(fmod)) {
|
if (IsVarTerm(fmod)) {
|
||||||
format_clean_up(sno0, sno, finfo);
|
format_clean_up(sno0, sno, finfo);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
Yap_Error(INSTANTIATION_ERROR, fmod, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, fmod, "format/2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!IsAtomTerm(fmod)) {
|
if (!IsAtomTerm(fmod)) {
|
||||||
format_clean_up(sno0, sno, finfo);
|
format_clean_up(sno0, sno, finfo);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
Yap_Error(TYPE_ERROR_ATOM, fmod, "format/2");
|
Yap_ThrowError(TYPE_ERROR_ATOM, fmod, "format/2");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (IsVarTerm(args)) {
|
if (IsVarTerm(args)) {
|
||||||
format_clean_up(sno0, sno, finfo);
|
format_clean_up(sno0, sno, finfo);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
|
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -968,7 +990,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
Term ta[2];
|
Term ta[2];
|
||||||
ta[0] = otail;
|
ta[0] = otail;
|
||||||
ta[1] = oargs;
|
ta[1] = oargs;
|
||||||
Yap_Error(LOCAL_Error_TYPE,
|
Yap_ThrowError(LOCAL_Error_TYPE,
|
||||||
Yap_MkApplTerm(Yap_MkFunctor(AtomFormat, 2), 2, ta),
|
Yap_MkApplTerm(Yap_MkFunctor(AtomFormat, 2), 2, ta),
|
||||||
"arguments to format");
|
"arguments to format");
|
||||||
}
|
}
|
||||||
@ -1028,7 +1050,7 @@ static Term memStreamToTerm(int output_stream, Functor f, Term inp) {
|
|||||||
} else if (f == FunctorString1) {
|
} else if (f == FunctorString1) {
|
||||||
return Yap_CharsToString(s, enc PASS_REGS);
|
return Yap_CharsToString(s, enc PASS_REGS);
|
||||||
}
|
}
|
||||||
Yap_Error(DOMAIN_ERROR_FORMAT_OUTPUT, inp, NULL);
|
Yap_ThrowError(DOMAIN_ERROR_FORMAT_OUTPUT, inp, NULL);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,7 +1110,7 @@ static Int with_output_to(USES_REGS1) {
|
|||||||
bool mem_stream = false;
|
bool mem_stream = false;
|
||||||
yhandle_t hdl = Yap_PushHandle(tin);
|
yhandle_t hdl = Yap_PushHandle(tin);
|
||||||
if (IsVarTerm(tin)) {
|
if (IsVarTerm(tin)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, tin, "with_output_to/3");
|
Yap_ThrowError(INSTANTIATION_ERROR, tin, "with_output_to/3");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (IsApplTerm(tin) && (f = FunctorOfTerm(tin))) {
|
if (IsApplTerm(tin) && (f = FunctorOfTerm(tin))) {
|
||||||
@ -1129,7 +1151,7 @@ static Int format(Term tf, Term tas, Term tout USES_REGS) {
|
|||||||
bool mem_stream = false;
|
bool mem_stream = false;
|
||||||
|
|
||||||
if (IsVarTerm(tout)) {
|
if (IsVarTerm(tout)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, tout, "format/3");
|
Yap_ThrowError(INSTANTIATION_ERROR, tout, "format/3");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
yhandle_t hl = Yap_StartHandles(), yo = Yap_PushHandle(tout);
|
yhandle_t hl = Yap_StartHandles(), yo = Yap_PushHandle(tout);
|
||||||
|
@ -176,7 +176,7 @@ extern int Yap_peekWide(int sno);
|
|||||||
extern int Yap_peekChar(int sno);
|
extern int Yap_peekChar(int sno);
|
||||||
|
|
||||||
|
|
||||||
extern Term Yap_syntax_error(TokEntry *tokptr, int sno);
|
extern Term Yap_syntax_error(TokEntry *tokptr, int sno, const char *msg);
|
||||||
|
|
||||||
extern int console_post_process_read_char(int, StreamDesc *);
|
extern int console_post_process_read_char(int, StreamDesc *);
|
||||||
extern int console_post_process_eof(StreamDesc *);
|
extern int console_post_process_eof(StreamDesc *);
|
||||||
|
203
os/readterm.c
203
os/readterm.c
@ -95,7 +95,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#define SYSTEM_STAT stat
|
#define SYSTEM_STAT stat
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int start);
|
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int start, bool code, const char *msg);
|
||||||
|
|
||||||
static void clean_vars(VarEntry *p) {
|
static void clean_vars(VarEntry *p) {
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
@ -316,7 +316,7 @@ static Int scan_to_list(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syntaax Error Handler
|
* Syntax Error Handler
|
||||||
*
|
*
|
||||||
* @par tokptr: the sequence of tokens
|
* @par tokptr: the sequence of tokens
|
||||||
* @par sno: the stream numbet
|
* @par sno: the stream numbet
|
||||||
@ -324,123 +324,107 @@ static Int scan_to_list(USES_REGS1) {
|
|||||||
* Implicit arguments:
|
* Implicit arguments:
|
||||||
* +
|
* +
|
||||||
*/
|
*/
|
||||||
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos) {
|
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool code, const char *msg) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term startline, errline, endline;
|
Yap_MkErrorRecord( LOCAL_ActiveError, __FILE__, __FUNCTION__, __LINE__, SYNTAX_ERROR, 0, NULL);
|
||||||
Term tf[4];
|
|
||||||
Term tm;
|
|
||||||
Term *tailp = tf + 3;
|
|
||||||
|
|
||||||
CELL *Hi = HR;
|
|
||||||
TokEntry *tok = LOCAL_tokptr;
|
TokEntry *tok = LOCAL_tokptr;
|
||||||
Int cline = tok->TokLine;
|
Int start_line = tok->TokLine;
|
||||||
|
Int err_line = errtok->TokLine;
|
||||||
|
Int end_line = GetCurInpLine(GLOBAL_Stream+sno);
|
||||||
Int startpos = tok->TokPos;
|
Int startpos = tok->TokPos;
|
||||||
errtok = LOCAL_toktide;
|
|
||||||
Int errpos = errtok->TokPos;
|
Int errpos = errtok->TokPos;
|
||||||
UInt diff = 0;
|
Int endpos = GetCurInpPos(GLOBAL_Stream+sno);
|
||||||
startline = MkIntegerTerm(cline);
|
|
||||||
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
|
|
||||||
Yap_local.ActiveError->prologPredFirstLine = cline;
|
|
||||||
Yap_local.ActiveError->prologPredLastLine = cline;
|
|
||||||
endline = MkIntegerTerm(cline);
|
|
||||||
|
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
|
||||||
errline = MkIntegerTerm(errtok->TokLine);
|
Yap_local.ActiveError->parserFirstLine = start_line;
|
||||||
Yap_local.ActiveError->prologPredLine = errtok->TokLine;
|
Yap_local.ActiveError->parserLine = err_line;
|
||||||
if (!LOCAL_ErrorMessage) {
|
Yap_local.ActiveError->parserLastLine = end_line;
|
||||||
LOCAL_ErrorMessage = "syntax error";
|
Yap_local.ActiveError->parserFirstPos = startpos;
|
||||||
}
|
Yap_local.ActiveError->parserPos = errpos;
|
||||||
tm = MkStringTerm(LOCAL_ErrorMessage);
|
Yap_local.ActiveError->parserLastPos =endpos;
|
||||||
{
|
Yap_local.ActiveError->parserFile =
|
||||||
char *s = malloc(strlen(LOCAL_ErrorMessage) + 1);
|
RepAtom(AtomOfTerm((GLOBAL_Stream+sno)->user_name))->StrOfAE;
|
||||||
strcpy(s, LOCAL_ErrorMessage);
|
Yap_local.ActiveError->parserReadingCode = code;
|
||||||
Yap_local.ActiveError->errorMsg = s;
|
|
||||||
}
|
|
||||||
if (GLOBAL_Stream[sno].status & Seekable_Stream_f) {
|
|
||||||
if (errpos && newpos >= 0) {
|
|
||||||
char o[128 + 1];
|
|
||||||
diff = errpos - startpos;
|
|
||||||
if (diff > 128) {
|
|
||||||
diff = 128;
|
|
||||||
startpos = errpos - diff;
|
|
||||||
}
|
|
||||||
#if HAVE_FTELLO
|
#if HAVE_FTELLO
|
||||||
Int curpos = ftello(GLOBAL_Stream[sno].file);
|
|
||||||
fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
|
fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
|
||||||
#else
|
#else
|
||||||
Int curpos = ftell(GLOBAL_Stream[sno].file);
|
|
||||||
fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
|
fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
|
||||||
#endif
|
#endif
|
||||||
fread(o, diff, 1, GLOBAL_Stream[sno].file);
|
int lvl = push_text_stack();
|
||||||
#if HAVE_FTELLO
|
if (GLOBAL_Stream[sno].status & Seekable_Stream_f) {
|
||||||
fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
|
char *o, *o2;
|
||||||
#else
|
if (errpos <= startpos) {
|
||||||
fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
|
o = malloc(1);
|
||||||
#endif
|
o[0] = '\0';
|
||||||
o[diff] = '\0';
|
|
||||||
tf[3] = MkStringTerm(o);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
while (tok) {
|
Int sza = (errpos-startpos)+1;
|
||||||
|
o = malloc(sza);
|
||||||
|
fread(o,sza-1,1,GLOBAL_Stream[sno].file);
|
||||||
|
o[sza-1] = '\0';
|
||||||
|
|
||||||
if (HR > ASP - 1024) {
|
|
||||||
errline = MkIntegerTerm(0);
|
|
||||||
endline = MkIntegerTerm(0);
|
|
||||||
/* for some reason moving this earlier confuses gcc on solaris */
|
|
||||||
HR = Hi;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (tok->TokLine != cline) {
|
Yap_local.ActiveError->parserTextA = o;
|
||||||
*tailp = MkPairTerm(TermNewLine, TermNil);
|
if (endpos <= errpos) {
|
||||||
tailp = RepPair(*tailp) + 1;
|
o2 = malloc(1);
|
||||||
cline = tok->TokLine;
|
o2[0] = '\0';
|
||||||
}
|
|
||||||
if (tok == errtok && tok->Tok != Error_tok) {
|
|
||||||
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
|
|
||||||
tailp = RepPair(*tailp) + 1;
|
|
||||||
}
|
|
||||||
Term rep = Yap_tokRep(tok);
|
|
||||||
if (tok->TokNext) {
|
|
||||||
tok = tok->TokNext;
|
|
||||||
} else {
|
} else {
|
||||||
endline = MkIntegerTerm(tok->TokLine);
|
Int sza = (endpos-errpos)+1;
|
||||||
tok = NULL;
|
o2 = malloc(sza);
|
||||||
break;
|
fread(o2,sza-1,1,GLOBAL_Stream[sno].file);
|
||||||
|
o2[sza-1] = '\0';
|
||||||
}
|
}
|
||||||
*tailp = MkPairTerm(rep, TermNil);
|
Yap_local.ActiveError->parserTextB = o2;
|
||||||
tailp = RepPair(*tailp) + 1;
|
} else {
|
||||||
|
size_t sz = 1024, total=sz, e;
|
||||||
|
char *o = malloc(1024);
|
||||||
|
char *s = o;
|
||||||
|
o[0] = '\0';
|
||||||
|
while (tok) {
|
||||||
|
if (tok->Tok == Error_tok) {
|
||||||
|
o = realloc(o, strlen(o)+1);
|
||||||
|
Yap_local.ActiveError->parserTextA= o;
|
||||||
|
o = malloc(1024);
|
||||||
|
total = sz = 1024;
|
||||||
|
tok = tok->TokNext;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
const char *ns = Yap_tokText(tok);
|
||||||
|
e = strlen(ns);
|
||||||
|
if (ns && ns[0] && e+1 > sz-256) {
|
||||||
|
strcat(s,ns);
|
||||||
|
o += e;
|
||||||
|
sz -= e;
|
||||||
}
|
}
|
||||||
{
|
if (tok->TokNext && tok->TokNext->TokLine > tok->TokLine) {
|
||||||
Term t[3];
|
strcat(s,"\n")
|
||||||
t[0] = startline;
|
;sz--;
|
||||||
t[1] = errline;
|
|
||||||
t[2] = endline;
|
|
||||||
tf[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t);
|
|
||||||
}
|
}
|
||||||
|
tok = tok->TokNext;
|
||||||
|
}
|
||||||
|
o = realloc(o, strlen(o)+1);
|
||||||
|
Yap_local.ActiveError->parserTextA= o;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* 0: strat, error, end line */
|
/* 0: strat, error, end line */
|
||||||
/*2 msg */
|
/*2 msg */
|
||||||
/* 1: file */
|
/* 1: file */
|
||||||
tf[1] = Yap_StreamUserName(sno);
|
if (!msg)
|
||||||
tf[2] = MkIntegerTerm(LOCAL_ActiveError->prologParserPos);
|
msg = "unspecified";
|
||||||
|
Yap_local.ActiveError->culprit =
|
||||||
|
Yap_local.ActiveError->errorMsg = (char*)msg;
|
||||||
|
Yap_local.ActiveError->errorMsgLen = strlen(msg);
|
||||||
clean_vars(LOCAL_VarTable);
|
clean_vars(LOCAL_VarTable);
|
||||||
clean_vars(LOCAL_AnonVarTable);
|
clean_vars(LOCAL_AnonVarTable);
|
||||||
Term terr = Yap_MkApplTerm(FunctorInfo4, 4, tf);
|
|
||||||
Term tn[2];
|
|
||||||
tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm);
|
|
||||||
tn[1] = terr;
|
|
||||||
terr = Yap_MkApplTerm(FunctorError, 2, tn);
|
|
||||||
#if DEBUG
|
|
||||||
if (Yap_ExecutionMode == YAP_BOOT_MODE) {
|
if (Yap_ExecutionMode == YAP_BOOT_MODE) {
|
||||||
fprintf(stderr, "SYNTAX ERROR while booting: ");
|
fprintf(stderr, "SYNTAX ERROR while booting: ");
|
||||||
fe
|
|
||||||
}
|
}
|
||||||
#endif
|
pop_text_stack(lvl);
|
||||||
return terr;
|
return Yap_MkFullError();
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_syntax_error(TokEntry *errtok, int sno) {
|
Term Yap_syntax_error(TokEntry *errtok, int sno, const char *msg) {
|
||||||
return syntax_error(errtok, sno, CurrentModule, -1);
|
return syntax_error(errtok, sno, CurrentModule, -1, false, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct FEnv {
|
typedef struct FEnv {
|
||||||
@ -457,6 +441,7 @@ typedef struct FEnv {
|
|||||||
encoding_t enc; /// encoding of the stream being read
|
encoding_t enc; /// encoding of the stream being read
|
||||||
Term tcomms; /// Access to comments
|
Term tcomms; /// Access to comments
|
||||||
Term cmod; /// Access to comments
|
Term cmod; /// Access to comments
|
||||||
|
char *msg; /// Error Messagge
|
||||||
} FEnv;
|
} FEnv;
|
||||||
|
|
||||||
typedef struct renv {
|
typedef struct renv {
|
||||||
@ -555,6 +540,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
|
|||||||
} else {
|
} else {
|
||||||
re->prio = LOCAL_default_priority;
|
re->prio = LOCAL_default_priority;
|
||||||
}
|
}
|
||||||
|
fe->msg = NULL;
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,17 +781,19 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream) {
|
|||||||
// check for an user abort
|
// check for an user abort
|
||||||
if (tokstart != NULL && tokstart->Tok != Ord(eot_tok)) {
|
if (tokstart != NULL && tokstart->Tok != Ord(eot_tok)) {
|
||||||
/* we got the end of file from an abort */
|
/* we got the end of file from an abort */
|
||||||
if (LOCAL_ErrorMessage && !strcmp(LOCAL_ErrorMessage, "Abort")) {
|
if (fe->msg && !strcmp(fe->msg, "Abort")) {
|
||||||
fe->t = 0L;
|
fe->t = 0L;
|
||||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||||
return YAP_PARSING_FINISHED;
|
return YAP_PARSING_FINISHED;
|
||||||
}
|
}
|
||||||
// a :- <eof>
|
// a :- <eof>
|
||||||
if (GLOBAL_Stream[inp_stream].status & Past_Eof_Stream_f)
|
if (GLOBAL_Stream[inp_stream].status & Past_Eof_Stream_f) {
|
||||||
|
fe->msg = "parsing stopped at a end-of-file";
|
||||||
return YAP_PARSING_ERROR;
|
return YAP_PARSING_ERROR;
|
||||||
|
}
|
||||||
/* we need to force the next read to also give end of file.*/
|
/* we need to force the next read to also give end of file.*/
|
||||||
GLOBAL_Stream[inp_stream].status |= Push_Eof_Stream_f;
|
GLOBAL_Stream[inp_stream].status |= Push_Eof_Stream_f;
|
||||||
LOCAL_ErrorMessage = "end of file found before end of term";
|
fe->msg = "end of file found before end of term";
|
||||||
return YAP_PARSING;
|
return YAP_PARSING;
|
||||||
} else {
|
} else {
|
||||||
// <eof>
|
// <eof>
|
||||||
@ -838,7 +826,6 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
|||||||
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
|
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
|
||||||
LOCAL_eot_before_eof = false;
|
LOCAL_eot_before_eof = false;
|
||||||
fe->tpos = StreamPosition(inp_stream);
|
fe->tpos = StreamPosition(inp_stream);
|
||||||
fe->old_H = HR;
|
|
||||||
fe->reading_clause = clause;
|
fe->reading_clause = clause;
|
||||||
if (clause) {
|
if (clause) {
|
||||||
fe->args = setClauseReadEnv(opts, fe, re, inp_stream);
|
fe->args = setClauseReadEnv(opts, fe, re, inp_stream);
|
||||||
@ -890,7 +877,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int sno) {
|
|||||||
return YAP_PARSING;
|
return YAP_PARSING;
|
||||||
}
|
}
|
||||||
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
|
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
|
||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_ErrorMessage = ". is end-of-term?";
|
||||||
return YAP_PARSING_ERROR;
|
return YAP_PARSING_ERROR;
|
||||||
}
|
}
|
||||||
return scanEOF(fe, sno);
|
return scanEOF(fe, sno);
|
||||||
@ -950,21 +937,24 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
/* just fail */
|
/* just fail */
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||||
return YAP_PARSING_FINISHED;
|
return YAP_PARSING_FINISHED;
|
||||||
} else {
|
}
|
||||||
|
Term t = syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos, fe->reading_clause, fe->msg);
|
||||||
|
if (ParserErrorStyle == TermException) {
|
||||||
|
if (LOCAL_RestartEnv && !LOCAL_delay) {
|
||||||
|
Yap_RestartYap(5);
|
||||||
|
}
|
||||||
|
Yap_exit(5);
|
||||||
|
}
|
||||||
if (re->seekable) {
|
if (re->seekable) {
|
||||||
re->cpos = GLOBAL_Stream[inp_stream].charcount;
|
re->cpos = GLOBAL_Stream[inp_stream].charcount;
|
||||||
}
|
}
|
||||||
|
LOCAL_Error_TYPE = WARNING_SYNTAX_ERROR;
|
||||||
Term t = syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos);
|
t = Yap_MkFullError();
|
||||||
if (ParserErrorStyle == TermError) {
|
Yap_PrintWarning(t);
|
||||||
LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t);
|
LOCAL_Error_TYPE = YAPC_NO_ERROR;
|
||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
if (ParserErrorStyle == TermDec10) {
|
||||||
// dec-10
|
|
||||||
} else if (Yap_PrintWarning(t)) {
|
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
||||||
return YAP_SCANNING;
|
return YAP_SCANNING;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return YAP_PARSING_FINISHED;
|
return YAP_PARSING_FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1165,6 +1155,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, int sno) {
|
|||||||
re->cpos = GLOBAL_Stream[sno].charcount;
|
re->cpos = GLOBAL_Stream[sno].charcount;
|
||||||
}
|
}
|
||||||
re->prio = LOCAL_default_priority;
|
re->prio = LOCAL_default_priority;
|
||||||
|
fe->msg = NULL;
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ db_files(Fs) :-
|
|||||||
|
|
||||||
'$csult'(Fs, _M) :-
|
'$csult'(Fs, _M) :-
|
||||||
'$skip_list'(_, Fs ,L),
|
'$skip_list'(_, Fs ,L),
|
||||||
vz L \== [],
|
L \== [],
|
||||||
!,
|
!,
|
||||||
user:dot_qualified_goal(Fs).
|
user:dot_qualified_goal(Fs).
|
||||||
'$csult'(Fs, M) :-
|
'$csult'(Fs, M) :-
|
||||||
|
@ -197,8 +197,14 @@ compose_message( halt, _Level) --> !,
|
|||||||
[ 'YAP execution halted.'-[] ].
|
[ 'YAP execution halted.'-[] ].
|
||||||
|
|
||||||
% syntax error.
|
% syntax error.
|
||||||
|
compose_message(error(warning(syntax_error,Info), Exc), Level) -->
|
||||||
|
!,
|
||||||
|
compose_message(error(syntax_error(Info), Exc), Level).
|
||||||
compose_message(error(E, Exc), Level) -->
|
compose_message(error(E, Exc), Level) -->
|
||||||
{ '$show_consult_level'(LC) },
|
{
|
||||||
|
% start_low_level_trace,
|
||||||
|
'$show_consult_level'(LC)
|
||||||
|
},
|
||||||
location(error(E, Exc), Level, LC),
|
location(error(E, Exc), Level, LC),
|
||||||
main_message(error(E,Exc) , Level, LC ),
|
main_message(error(E,Exc) , Level, LC ),
|
||||||
c_goal( error(E, Exc), Level ),
|
c_goal( error(E, Exc), Level ),
|
||||||
@ -249,8 +255,15 @@ compose_message(Throw, _Level) -->
|
|||||||
!,
|
!,
|
||||||
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
|
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
|
||||||
|
|
||||||
location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)), _ , _) -->
|
location(error(syntax_error(_),Info), _Level , LC) -->
|
||||||
|
{ '$error_descriptor'(Info, Desc) },
|
||||||
|
{ query_exception(parserReadingCode, Desc, true) },
|
||||||
|
{LC > 0},
|
||||||
!,
|
!,
|
||||||
|
{
|
||||||
|
query_exception(parserFile, Desc, FileName),
|
||||||
|
query_exception(parserLine, Desc, LN)
|
||||||
|
},
|
||||||
[ '~a:~d:~d: ' - [FileName,LN,0] ] .
|
[ '~a:~d:~d: ' - [FileName,LN,0] ] .
|
||||||
location(style_check(A,LN,FileName,B ), Level , LC) -->
|
location(style_check(A,LN,FileName,B ), Level , LC) -->
|
||||||
!,
|
!,
|
||||||
@ -289,21 +302,17 @@ simplify_pred(F, F).
|
|||||||
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
|
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
|
||||||
main_message(error(Msg,In), _, _) --> {var(Msg)}, !,
|
main_message(error(Msg,In), _, _) --> {var(Msg)}, !,
|
||||||
[ 'Uninstantiated message ~w~n.' - [error(Msg,In)], nl ].
|
[ 'Uninstantiated message ~w~n.' - [error(Msg,In)], nl ].
|
||||||
main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term)), Level, LC ) -->
|
main_message( error(syntax_error(Msg),Info), Level, _LC ) -->
|
||||||
!,
|
!,
|
||||||
|
{
|
||||||
|
'$error_descriptor'(Info, Desc),
|
||||||
|
query_exception(parserTextA, Desc, J),
|
||||||
|
query_exception(parserTextB, Desc, T),
|
||||||
|
query_exception(parserLine, Desc, L)
|
||||||
|
},
|
||||||
[' ~a: syntax error ~s' - [Level,Msg]],
|
[' ~a: syntax error ~s' - [Level,Msg]],
|
||||||
[nl],
|
[nl],
|
||||||
( syntax_error_term( between(L0,LM,LF), Term, LC )
|
[' ~s <<== at line ~d == ~s !' - [J,L,T], nl ].
|
||||||
->
|
|
||||||
[]
|
|
||||||
;
|
|
||||||
[' ~a: failed_processing syntax error term ~q' - [Level,Term]],
|
|
||||||
[nl]
|
|
||||||
).
|
|
||||||
main_message( error(syntax_error(Msg), _Info), Level, _LC ) -->
|
|
||||||
!,
|
|
||||||
[' ~a: syntax error ~s' - [Level,Msg]],
|
|
||||||
[nl].
|
|
||||||
main_message(style_check(singleton(SVs),_Pos,_File,P), _Level, _LC) -->
|
main_message(style_check(singleton(SVs),_Pos,_File,P), _Level, _LC) -->
|
||||||
!,
|
!,
|
||||||
% {writeln(ci)},
|
% {writeln(ci)},
|
||||||
@ -370,6 +379,7 @@ display_consulting( F, Level, _, LC) -->
|
|||||||
display_consulting(_F, _, _, _LC) -->
|
display_consulting(_F, _, _, _LC) -->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
|
c_goal( error(syntax_error(_),Info), _) --> !.
|
||||||
c_goal( error(_,Info), _) -->
|
c_goal( error(_,Info), _) -->
|
||||||
{ '$error_descriptor'(Info, Desc) },
|
{ '$error_descriptor'(Info, Desc) },
|
||||||
({ query_exception(errorGoal, Desc, Call),
|
({ query_exception(errorGoal, Desc, Call),
|
||||||
@ -711,7 +721,7 @@ syntax_error_token(var(_,S), _, _LC) --> !,
|
|||||||
syntax_error_token(string(S), _, _LC) --> !,
|
syntax_error_token(string(S), _, _LC) --> !,
|
||||||
[ '`~s`' - [S] ].
|
[ '`~s`' - [S] ].
|
||||||
syntax_error_token(error, L, _LC) --> !,
|
syntax_error_token(error, L, _LC) --> !,
|
||||||
[ ' <<<< at line %d' - [L] ].
|
[ ' <<<< at line ~d >>>> ' - [L] ].
|
||||||
syntax_error_token('EOT',_, _LC) --> !,
|
syntax_error_token('EOT',_, _LC) --> !,
|
||||||
[ '.' - [], nl ].
|
[ '.' - [], nl ].
|
||||||
syntax_error_token('(',_, _LC) --> !,
|
syntax_error_token('(',_, _LC) --> !,
|
||||||
|
Reference in New Issue
Block a user