fix throw
This commit is contained in:
parent
b02c775915
commit
f037b2478c
@ -305,11 +305,16 @@ static char tmpbuf[YAP_BUF_SIZE];
|
|||||||
#include "YapErrors.h"
|
#include "YapErrors.h"
|
||||||
//
|
//
|
||||||
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
|
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
|
||||||
|
memset(new_error, 0, sizeof(yap_error_descriptor_t));
|
||||||
new_error->top_error = LOCAL_ActiveError;
|
new_error->top_error = LOCAL_ActiveError;
|
||||||
LOCAL_ActiveError = new_error;
|
LOCAL_ActiveError = new_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
yap_error_descriptor_t *Yap_popErrorContext(void) {
|
yap_error_descriptor_t *Yap_popErrorContext(bool pass) {
|
||||||
|
if (pass && LOCAL_ActiveError->top_error->errorNo == YAP_NO_ERROR &&
|
||||||
|
LOCAL_ActiveError->errorNo != YAP_NO_ERROR)
|
||||||
|
memcpy(LOCAL_ActiveError->top_error, LOCAL_ActiveError,
|
||||||
|
sizeof(yap_error_descriptor_t));
|
||||||
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
|
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
|
||||||
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
|
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
|
||||||
return new_error;
|
return new_error;
|
||||||
|
@ -175,7 +175,7 @@ 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->prologParserPos)) {
|
||||||
if (!LOCAL_ErrorMessage) {
|
if (!LOCAL_ErrorMessage) {
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
||||||
}
|
}
|
||||||
@ -1013,8 +1013,8 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (LOCAL_tokptr->Tok <= Ord(String_tok)) {
|
if (LOCAL_tokptr->Tok <= Ord(String_tok)) {
|
||||||
syntax_msg("line %d: expected operator, got \'%s\'", LOCAL_tokptr->TokLine,
|
syntax_msg("line %d: expected operator, got \'%s\'",
|
||||||
Yap_tokText(LOCAL_tokptr));
|
LOCAL_tokptr->TokLine, Yap_tokText(LOCAL_tokptr));
|
||||||
FAIL;
|
FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1036,6 +1036,7 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
|
|||||||
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
|
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (GLOBAL_Option['p' - 'a' + 1]) {
|
if (GLOBAL_Option['p' - 'a' + 1]) {
|
||||||
|
Yap_DebugPlWrite(MkIntTerm(LOCAL_tokptr->TokLine));
|
||||||
Yap_DebugPutc(stderr, '[');
|
Yap_DebugPutc(stderr, '[');
|
||||||
if (t == 0)
|
if (t == 0)
|
||||||
Yap_DebugPlWrite(MkIntTerm(0));
|
Yap_DebugPlWrite(MkIntTerm(0));
|
||||||
|
158
C/write.c
158
C/write.c
@ -9,10 +9,9 @@
|
|||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: write.c *
|
* File: write.c * Last
|
||||||
* Last rev: *
|
*rev: * mods:
|
||||||
* mods: *
|
** comments: Writing a Prolog Term *
|
||||||
* comments: Writing a Prolog Term *
|
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
#ifdef SCCS
|
#ifdef SCCS
|
||||||
@ -84,25 +83,21 @@ typedef struct write_globs {
|
|||||||
#define lastw wglb->lw
|
#define lastw wglb->lw
|
||||||
#define last_minus wglb->last_atom_minus
|
#define last_minus wglb->last_atom_minus
|
||||||
|
|
||||||
static bool callPortray(Term t, struct DB_TERM **old_EXp, int sno USES_REGS) {
|
static bool callPortray(Term t, int sno USES_REGS) {
|
||||||
PredEntry *pe;
|
PredEntry *pe;
|
||||||
Int b0 = LCL0 - (CELL *)B;
|
Int b0 = LCL0 - (CELL *)B;
|
||||||
|
|
||||||
*old_EXp = Yap_RefToException();
|
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorPortray, USER_MODULE))) &&
|
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorPortray, USER_MODULE))) &&
|
||||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||||
Yap_execute_pred(pe, &t, true PASS_REGS)) {
|
Yap_execute_pred(pe, &t, true PASS_REGS)) {
|
||||||
choiceptr B0 = (choiceptr)(LCL0 - b0);
|
choiceptr B0 = (choiceptr)(LCL0 - b0);
|
||||||
if (Yap_HasException() && !*old_EXp)
|
|
||||||
*old_EXp = Yap_RefToException();
|
|
||||||
Yap_fail_all(B0 PASS_REGS);
|
Yap_fail_all(B0 PASS_REGS);
|
||||||
LOCK(GLOBAL_Stream[sno].streamlock);
|
LOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[sno].streamlock);
|
LOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
if (Yap_HasException() && !*old_EXp)
|
|
||||||
*old_EXp = Yap_RefToException();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,8 +385,8 @@ int Yap_FormatFloat(Float f, char **s, size_t sz) {
|
|||||||
wglb.stream = GLOBAL_Stream + sno;
|
wglb.stream = GLOBAL_Stream + sno;
|
||||||
wrputf(f, &wglb);
|
wrputf(f, &wglb);
|
||||||
so = Yap_MemExportStreamPtr(sno);
|
so = Yap_MemExportStreamPtr(sno);
|
||||||
*s = BaseMalloc( strlen(so)+1 );
|
*s = BaseMalloc(strlen(so) + 1);
|
||||||
strcpy(*s, so );
|
strcpy(*s, so);
|
||||||
Yap_CloseStream(sno);
|
Yap_CloseStream(sno);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -410,10 +405,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
#endif
|
#endif
|
||||||
wrputs(s, stream);
|
wrputs(s, stream);
|
||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes a blob (default) */
|
/* writes a blob (default) */
|
||||||
static int wrputblob(AtomEntry *ref, int Quote_illegal,
|
static int wrputblob(AtomEntry *ref, int Quote_illegal,
|
||||||
struct write_globs *wglb) {
|
struct write_globs *wglb) {
|
||||||
wrf stream = wglb->stream;
|
wrf stream = wglb->stream;
|
||||||
int rc;
|
int rc;
|
||||||
@ -424,10 +419,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int legalAtom(unsigned char *s) /* Is this a legal atom ? */
|
static int legalAtom(unsigned char *s) /* Is this a legal atom ? */
|
||||||
{
|
{
|
||||||
wchar_t ch = *s;
|
wchar_t ch = *s;
|
||||||
|
|
||||||
if (ch == '\0')
|
if (ch == '\0')
|
||||||
@ -461,11 +456,11 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
if (Yap_chtype[ch] > NU)
|
if (Yap_chtype[ch] > NU)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static wtype
|
static wtype
|
||||||
AtomIsSymbols(unsigned char *s) /* Is this atom just formed by symbols ? */
|
AtomIsSymbols(unsigned char *s) /* Is this atom just formed by symbols ? */
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
if (Yap_chtype[(int)s[0]] == SL && s[1] == '\0')
|
if (Yap_chtype[(int)s[0]] == SL && s[1] == '\0')
|
||||||
return (separator);
|
return (separator);
|
||||||
@ -474,9 +469,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
return alphanum;
|
return alphanum;
|
||||||
}
|
}
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_quoted(wchar_t ch, wchar_t quote, wrf stream) {
|
static void write_quoted(wchar_t ch, wchar_t quote, wrf stream) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (!(Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE)) {
|
if (!(Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE)) {
|
||||||
wrputc(ch, stream);
|
wrputc(ch, stream);
|
||||||
@ -550,11 +545,11 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_string(const unsigned char *s,
|
static void write_string(const unsigned char *s,
|
||||||
struct write_globs *wglb) /* writes an integer */
|
struct write_globs *wglb) /* writes an integer */
|
||||||
{
|
{
|
||||||
StreamDesc *stream = wglb->stream;
|
StreamDesc *stream = wglb->stream;
|
||||||
utf8proc_int32_t chr, qt;
|
utf8proc_int32_t chr, qt;
|
||||||
unsigned char *ptr = (unsigned char *)s;
|
unsigned char *ptr = (unsigned char *)s;
|
||||||
@ -566,19 +561,21 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
wrputc(qt, stream);
|
wrputc(qt, stream);
|
||||||
do {
|
do {
|
||||||
int delta;
|
int delta;
|
||||||
ptr += (delta = get_utf8(ptr, -1, &chr) );
|
ptr += (delta = get_utf8(ptr, -1, &chr));
|
||||||
|
|
||||||
if (chr == '\0') {
|
if (chr == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (delta == 0) {chr = *ptr++; }
|
if (delta == 0) {
|
||||||
|
chr = *ptr++;
|
||||||
|
}
|
||||||
write_quoted(chr, qt, stream);
|
write_quoted(chr, qt, stream);
|
||||||
} while (true);
|
} while (true);
|
||||||
wrputc(qt, stream);
|
wrputc(qt, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes an atom */
|
/* writes an atom */
|
||||||
static void putAtom(Atom atom, int Quote_illegal, struct write_globs *wglb) {
|
static void putAtom(Atom atom, int Quote_illegal, struct write_globs *wglb) {
|
||||||
unsigned char *s;
|
unsigned char *s;
|
||||||
wtype atom_or_symbol;
|
wtype atom_or_symbol;
|
||||||
wrf stream = wglb->stream;
|
wrf stream = wglb->stream;
|
||||||
@ -609,23 +606,23 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
while (*s) {
|
while (*s) {
|
||||||
int32_t ch;
|
int32_t ch;
|
||||||
s += get_utf8(s, -1, &ch);
|
s += get_utf8(s, -1, &ch);
|
||||||
write_quoted( ch, '\'', stream);
|
write_quoted(ch, '\'', stream);
|
||||||
}
|
}
|
||||||
wrputc('\'', stream);
|
wrputc('\'', stream);
|
||||||
} else {
|
} else {
|
||||||
wrputs((char *)s, stream);
|
wrputs((char *)s, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_WriteAtom(StreamDesc *s, Atom atom) {
|
void Yap_WriteAtom(StreamDesc *s, Atom atom) {
|
||||||
struct write_globs wglb;
|
struct write_globs wglb;
|
||||||
wglb.stream = s;
|
wglb.stream = s;
|
||||||
wglb.Quote_illegal = FALSE;
|
wglb.Quote_illegal = FALSE;
|
||||||
putAtom(atom, 0, &wglb);
|
putAtom(atom, 0, &wglb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int IsCodesTerm(Term string) /* checks whether this is a string */
|
static int IsCodesTerm(Term string) /* checks whether this is a string */
|
||||||
{
|
{
|
||||||
if (IsVarTerm(string))
|
if (IsVarTerm(string))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
do {
|
do {
|
||||||
@ -647,12 +644,12 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
} while (string != TermNil);
|
} while (string != TermNil);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes a string */
|
/* writes a string */
|
||||||
static void putString(Term string, struct write_globs *wglb)
|
static void putString(Term string, struct write_globs *wglb)
|
||||||
|
|
||||||
{
|
{
|
||||||
wrf stream = wglb->stream;
|
wrf stream = wglb->stream;
|
||||||
wrputc('"', stream);
|
wrputc('"', stream);
|
||||||
while (string != TermNil) {
|
while (string != TermNil) {
|
||||||
@ -662,12 +659,12 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
wrputc('"', stream);
|
wrputc('"', stream);
|
||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes a string */
|
/* writes a string */
|
||||||
static void putUnquotedString(Term string, struct write_globs *wglb)
|
static void putUnquotedString(Term string, struct write_globs *wglb)
|
||||||
|
|
||||||
{
|
{
|
||||||
wrf stream = wglb->stream;
|
wrf stream = wglb->stream;
|
||||||
while (string != TermNil) {
|
while (string != TermNil) {
|
||||||
int ch = IntOfTerm(HeadOfTerm(string));
|
int ch = IntOfTerm(HeadOfTerm(string));
|
||||||
@ -675,9 +672,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
string = TailOfTerm(string);
|
string = TailOfTerm(string);
|
||||||
}
|
}
|
||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term from_pointer(CELL *ptr0, struct rewind_term *rwt,
|
static Term from_pointer(CELL *ptr0, struct rewind_term *rwt,
|
||||||
struct write_globs *wglb) {
|
struct write_globs *wglb) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term t;
|
Term t;
|
||||||
@ -713,9 +710,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CELL *restore_from_write(struct rewind_term *rwt,
|
static CELL *restore_from_write(struct rewind_term *rwt,
|
||||||
struct write_globs *wglb) {
|
struct write_globs *wglb) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL *ptr;
|
CELL *ptr;
|
||||||
@ -729,10 +726,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
rwt->u_sd.s.ptr = 0;
|
rwt->u_sd.s.ptr = 0;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes an unbound variable */
|
/* writes an unbound variable */
|
||||||
static void write_var(CELL *t, struct write_globs *wglb,
|
static void write_var(CELL *t, struct write_globs *wglb,
|
||||||
struct rewind_term *rwt) {
|
struct rewind_term *rwt) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (lastw == alphanum) {
|
if (lastw == alphanum) {
|
||||||
@ -773,9 +770,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
} else {
|
} else {
|
||||||
wrputn(((Int)(t - H0)), wglb);
|
wrputn(((Int)(t - H0)), wglb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term check_infinite_loop(Term t, struct rewind_term *x,
|
static Term check_infinite_loop(Term t, struct rewind_term *x,
|
||||||
struct write_globs *wglb) {
|
struct write_globs *wglb) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (wglb->Keep_terms) {
|
if (wglb->Keep_terms) {
|
||||||
@ -792,9 +789,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_list(Term t, int direction, int depth,
|
static void write_list(Term t, int direction, int depth,
|
||||||
struct write_globs *wglb, struct rewind_term *rwt) {
|
struct write_globs *wglb, struct rewind_term *rwt) {
|
||||||
Term ti;
|
Term ti;
|
||||||
struct rewind_term nrwt;
|
struct rewind_term nrwt;
|
||||||
@ -867,14 +864,14 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
wglb, &nrwt);
|
wglb, &nrwt);
|
||||||
restore_from_write(&nrwt, wglb);
|
restore_from_write(&nrwt, wglb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
||||||
struct write_globs *wglb, struct rewind_term *rwt)
|
struct write_globs *wglb, struct rewind_term *rwt)
|
||||||
/* term to write */
|
/* term to write */
|
||||||
/* context priority */
|
/* context priority */
|
||||||
|
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
struct rewind_term nrwt;
|
struct rewind_term nrwt;
|
||||||
nrwt.parent = rwt;
|
nrwt.parent = rwt;
|
||||||
@ -884,8 +881,6 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
putAtom(Atom3Dots, wglb->Quote_illegal, wglb);
|
putAtom(Atom3Dots, wglb->Quote_illegal, wglb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DBTerm *ex;
|
|
||||||
Yap_ResetException(worker_id);
|
|
||||||
t = Deref(t);
|
t = Deref(t);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
write_var((CELL *)t, wglb, &nrwt);
|
write_var((CELL *)t, wglb, &nrwt);
|
||||||
@ -910,9 +905,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (wglb->Use_portray)
|
if (wglb->Use_portray)
|
||||||
if (callPortray(t, &ex, wglb->stream - GLOBAL_Stream PASS_REGS)) {
|
if (callPortray(t, wglb->stream - GLOBAL_Stream PASS_REGS)) {
|
||||||
Yap_CopyException(ex);
|
|
||||||
Yap_RaiseException();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (trueGlobalPrologFlag(WRITE_STRINGS_FLAG) && IsCodesTerm(t)) {
|
if (trueGlobalPrologFlag(WRITE_STRINGS_FLAG) && IsCodesTerm(t)) {
|
||||||
@ -985,9 +978,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (wglb->Use_portray) {
|
if (wglb->Use_portray) {
|
||||||
if (callPortray(t, &ex, wglb->stream - GLOBAL_Stream PASS_REGS)) {
|
if (callPortray(t, wglb->stream - GLOBAL_Stream PASS_REGS)) {
|
||||||
Yap_CopyException(ex);
|
|
||||||
Yap_RaiseException();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1203,20 +1194,20 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
wrclose_bracket(wglb, TRUE);
|
wrclose_bracket(wglb, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
|
void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
|
||||||
int priority)
|
int priority)
|
||||||
/* term to be written */
|
/* term to be written */
|
||||||
/* consumer */
|
/* consumer */
|
||||||
/* write options */
|
/* write options */
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
struct write_globs wglb;
|
struct write_globs wglb;
|
||||||
struct rewind_term rwt;
|
struct rewind_term rwt;
|
||||||
yhandle_t sls = Yap_CurrentSlot();
|
yhandle_t sls = Yap_CurrentSlot();
|
||||||
|
|
||||||
if (t==0)
|
if (t == 0)
|
||||||
return;
|
return;
|
||||||
if (!mywrite) {
|
if (!mywrite) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1239,7 +1230,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
wglb.Ignore_ops = flags & Ignore_ops_f;
|
wglb.Ignore_ops = flags & Ignore_ops_f;
|
||||||
wglb.Write_strings = flags & BackQuote_String_f;
|
wglb.Write_strings = flags & BackQuote_String_f;
|
||||||
/* protect slots for portray */
|
/* protect slots for portray */
|
||||||
|
yap_error_descriptor_t ne;
|
||||||
|
Yap_pushErrorContext(&ne);
|
||||||
writeTerm(from_pointer(&t, &rwt, &wglb), priority, 1, FALSE, &wglb, &rwt);
|
writeTerm(from_pointer(&t, &rwt, &wglb), priority, 1, FALSE, &wglb, &rwt);
|
||||||
|
Yap_popErrorContext(true);
|
||||||
if (flags & New_Line_f) {
|
if (flags & New_Line_f) {
|
||||||
if (flags & Fullstop_f) {
|
if (flags & Fullstop_f) {
|
||||||
wrputc('.', wglb.stream);
|
wrputc('.', wglb.stream);
|
||||||
@ -1255,9 +1249,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
}
|
}
|
||||||
restore_from_write(&rwt, &wglb);
|
restore_from_write(&rwt, &wglb);
|
||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
|
char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno = Yap_open_buf_write_stream(enc, flags);
|
int sno = Yap_open_buf_write_stream(enc, flags);
|
||||||
const char *sf;
|
const char *sf;
|
||||||
@ -1274,10 +1268,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
|
|
||||||
sf = Yap_MemExportStreamPtr(sno);
|
sf = Yap_MemExportStreamPtr(sno);
|
||||||
size_t len = strlen(sf);
|
size_t len = strlen(sf);
|
||||||
char *new = malloc( len + 1 );
|
char *new = malloc(len + 1);
|
||||||
strcpy( new, sf );
|
strcpy(new, sf);
|
||||||
Yap_CloseStream(sno);
|
Yap_CloseStream(sno);
|
||||||
if (e)
|
if (e)
|
||||||
LOCAL_BallTerm = e;
|
LOCAL_BallTerm = e;
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
|
|||||||
const char *inp;
|
const char *inp;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
strcpy(out, filename);
|
strcpy(out, filename);
|
||||||
if (Yap_IsAbsolutePath(out, false)) {
|
if (Yap_IsAbsolutePath(out, true)) {
|
||||||
out = pop_output_text_stack(lvl, out);
|
out = pop_output_text_stack(lvl, out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
/* The YAP main types */
|
/* The YAP main types */
|
||||||
#include "YapTerm.h"
|
#include "YapTerm.h"
|
||||||
|
|
||||||
@ -75,17 +74,14 @@
|
|||||||
typedef bool YAP_Bool;
|
typedef bool YAP_Bool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This term can never be constructed as a valid term, so it is
|
This term can never be constructed as a valid term, so it is
|
||||||
used as a "BAD" term
|
used as a "BAD" term
|
||||||
*/
|
*/
|
||||||
#define TermZERO ((Term)0)
|
#define TermZERO ((Term)0)
|
||||||
|
|
||||||
|
|
||||||
#include "YapConfig.h"
|
#include "YapConfig.h"
|
||||||
|
|
||||||
|
|
||||||
typedef void *YAP_PredEntryPtr;
|
typedef void *YAP_PredEntryPtr;
|
||||||
|
|
||||||
typedef size_t YAP_Arity;
|
typedef size_t YAP_Arity;
|
||||||
@ -175,7 +171,6 @@ typedef enum {
|
|||||||
#define YAP_RECONSULT_MODE 1
|
#define YAP_RECONSULT_MODE 1
|
||||||
#define YAP_BOOT_MODE 2
|
#define YAP_BOOT_MODE 2
|
||||||
|
|
||||||
|
|
||||||
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
|
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
|
||||||
int Argc, char *Argv[]);
|
int Argc, char *Argv[]);
|
||||||
|
|
||||||
@ -199,7 +194,7 @@ typedef struct yap_boot_params {
|
|||||||
//> if NON-NULL, name for a Prolog file to use when booting
|
//> if NON-NULL, name for a Prolog file to use when booting
|
||||||
const char *PrologBootFile;
|
const char *PrologBootFile;
|
||||||
//> if NON-NULL, directory for a Prolog file to be when booting
|
//> if NON-NULL, directory for a Prolog file to be when booting
|
||||||
const char *PlBootDir;
|
const char *BootPlDir;
|
||||||
//> if NON-NULL, path where we can find the saved state
|
//> if NON-NULL, path where we can find the saved state
|
||||||
const char *SavedState;
|
const char *SavedState;
|
||||||
//> bootstrapping mode: YAP is not properly installed
|
//> bootstrapping mode: YAP is not properly installed
|
||||||
@ -274,7 +269,7 @@ typedef struct yap_boot_params {
|
|||||||
char *def_var[YAP_MAX_YPP_DEFS];
|
char *def_var[YAP_MAX_YPP_DEFS];
|
||||||
char *def_value[YAP_MAX_YPP_DEFS];
|
char *def_value[YAP_MAX_YPP_DEFS];
|
||||||
int def_c;
|
int def_c;
|
||||||
/* End preprocessor code */
|
/* End preprocessor code */
|
||||||
|
|
||||||
#ifdef MYDDAS_MYSQL
|
#ifdef MYDDAS_MYSQL
|
||||||
//> If any myddas option was given
|
//> If any myddas option was given
|
||||||
@ -332,7 +327,7 @@ typedef YAP_Bool (*YAP_Opaque_CallOnGCRelocate)(YAP_opaque_tag_t, void *,
|
|||||||
/// opaque variables can interact with the system
|
/// opaque variables can interact with the system
|
||||||
typedef struct YAP_opaque_handler_struct {
|
typedef struct YAP_opaque_handler_struct {
|
||||||
YAP_Opaque_CallOnCut cut_handler; //< called at cut, which may be a forward
|
YAP_Opaque_CallOnCut cut_handler; //< called at cut, which may be a forward
|
||||||
//cut or an exception.
|
// cut or an exception.
|
||||||
YAP_Opaque_CallOnFail
|
YAP_Opaque_CallOnFail
|
||||||
fail_handler; //< called at exit, it can be used to cleanup resources
|
fail_handler; //< called at exit, it can be used to cleanup resources
|
||||||
YAP_Opaque_CallOnWrite write_handler; //< text representation
|
YAP_Opaque_CallOnWrite write_handler; //< text representation
|
||||||
|
@ -238,6 +238,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
|
|||||||
extern const char *Yap_errorClassName(yap_error_class_number e);
|
extern const char *Yap_errorClassName(yap_error_class_number e);
|
||||||
|
|
||||||
extern void Yap_pushErrorContext(yap_error_descriptor_t * new_error);
|
extern void Yap_pushErrorContext(yap_error_descriptor_t * new_error);
|
||||||
extern yap_error_descriptor_t *Yap_popErrorContext(void);
|
extern yap_error_descriptor_t *Yap_popErrorContext(bool pass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
19
os/charsio.c
19
os/charsio.c
@ -153,9 +153,6 @@ int Yap_peekWithSeek(int sno) {
|
|||||||
int Yap_popChar(int sno) {
|
int Yap_popChar(int sno) {
|
||||||
StreamDesc *s = GLOBAL_Stream + sno;
|
StreamDesc *s = GLOBAL_Stream + sno;
|
||||||
s->buf.on = false;
|
s->buf.on = false;
|
||||||
s->charcount = s->buf.pos;
|
|
||||||
s->linecount = s->buf.line;
|
|
||||||
s->linepos = s->buf.lpos;
|
|
||||||
Yap_DefaultStreamOps(s);
|
Yap_DefaultStreamOps(s);
|
||||||
return s->buf.ch;
|
return s->buf.ch;
|
||||||
}
|
}
|
||||||
@ -174,16 +171,13 @@ int Yap_peekWide(int sno) {
|
|||||||
} else {
|
} else {
|
||||||
s->buf.on = true;
|
s->buf.on = true;
|
||||||
s->buf.ch = ch;
|
s->buf.ch = ch;
|
||||||
s->buf.pos = s->charcount;
|
|
||||||
s->buf.line = s->linecount;
|
|
||||||
s->buf.lpos = s->linepos;
|
|
||||||
s->charcount = pos;
|
s->charcount = pos;
|
||||||
s->linecount = line;
|
s->linecount = line;
|
||||||
s->linepos = lpos;
|
s->linepos = lpos;
|
||||||
s->stream_wgetc = Yap_popChar;
|
s->stream_wgetc = Yap_popChar;
|
||||||
s->stream_getc = NULL;
|
s->stream_getc = NULL;
|
||||||
s->stream_peek= NULL;
|
s->stream_peek = NULL;
|
||||||
s->stream_wpeek= NULL;
|
s->stream_wpeek = NULL;
|
||||||
s->stream_getc = Yap_popChar;
|
s->stream_getc = Yap_popChar;
|
||||||
s->stream_wgetc = Yap_popChar;
|
s->stream_wgetc = Yap_popChar;
|
||||||
// Yap_SetCurInpPos(sno, pos);
|
// Yap_SetCurInpPos(sno, pos);
|
||||||
@ -205,17 +199,14 @@ int Yap_peekChar(int sno) {
|
|||||||
} else {
|
} else {
|
||||||
s->buf.on = true;
|
s->buf.on = true;
|
||||||
s->buf.ch = ch;
|
s->buf.ch = ch;
|
||||||
s->buf.pos = s->charcount;
|
|
||||||
s->buf.line = s->linecount;
|
|
||||||
s->buf.lpos = s->linepos;
|
|
||||||
s->charcount = pos;
|
s->charcount = pos;
|
||||||
s->linecount = line;
|
s->linecount = line;
|
||||||
s->linepos = lpos;
|
s->linepos = lpos;
|
||||||
s->stream_getc = Yap_popChar;
|
s->stream_getc = Yap_popChar;
|
||||||
s->stream_wgetc = NULL;
|
s->stream_wgetc = NULL;
|
||||||
s->stream_peek= NULL;
|
s->stream_peek = NULL;
|
||||||
s->stream_wpeek= NULL;
|
s->stream_wpeek = NULL;
|
||||||
//Yap_SetCurInpPos(sno, pos);
|
// Yap_SetCurInpPos(sno, pos);
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
@ -224,13 +224,11 @@
|
|||||||
|
|
||||||
:- yap_flag(unknown,error).
|
:- yap_flag(unknown,error).
|
||||||
:- style_check(single_var).
|
:- style_check(single_var).
|
||||||
:- start_low_level_trace.
|
|
||||||
:- initialization((
|
:- initialization((
|
||||||
bb_put(logger_filename,'out.dat'),
|
bb_put(logger_filename,'out.dat'),
|
||||||
bb_put(logger_delimiter,';'),
|
bb_put(logger_delimiter,';'),
|
||||||
bb_put(logger_variables,[])
|
bb_put(logger_variables,[])
|
||||||
)).
|
)).
|
||||||
:- stopS_low_level_trace.
|
|
||||||
|
|
||||||
%========================================================================
|
%========================================================================
|
||||||
%= Defines a new variable, possible types are: int, float and time
|
%= Defines a new variable, possible types are: int, float and time
|
||||||
|
Reference in New Issue
Block a user