fix throw

This commit is contained in:
Vitor Santos Costa 2018-02-07 17:46:36 +00:00
parent b02c775915
commit f037b2478c
8 changed files with 888 additions and 904 deletions

View File

@ -305,11 +305,16 @@ static char tmpbuf[YAP_BUF_SIZE];
#include "YapErrors.h"
//
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
memset(new_error, 0, sizeof(yap_error_descriptor_t));
new_error->top_error = LOCAL_ActiveError;
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;
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
return new_error;

View File

@ -1013,8 +1013,8 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc,
}
}
if (LOCAL_tokptr->Tok <= Ord(String_tok)) {
syntax_msg("line %d: expected operator, got \'%s\'", LOCAL_tokptr->TokLine,
Yap_tokText(LOCAL_tokptr));
syntax_msg("line %d: expected operator, got \'%s\'",
LOCAL_tokptr->TokLine, Yap_tokText(LOCAL_tokptr));
FAIL;
}
break;
@ -1036,6 +1036,7 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
#if DEBUG
if (GLOBAL_Option['p' - 'a' + 1]) {
Yap_DebugPlWrite(MkIntTerm(LOCAL_tokptr->TokLine));
Yap_DebugPutc(stderr, '[');
if (t == 0)
Yap_DebugPlWrite(MkIntTerm(0));

View File

@ -9,10 +9,9 @@
* *
**************************************************************************
* *
* File: write.c *
* Last rev: *
* mods: *
* comments: Writing a Prolog Term *
* File: write.c * Last
*rev: * mods:
** comments: Writing a Prolog Term *
* *
*************************************************************************/
#ifdef SCCS
@ -84,25 +83,21 @@ typedef struct write_globs {
#define lastw wglb->lw
#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;
Int b0 = LCL0 - (CELL *)B;
*old_EXp = Yap_RefToException();
UNLOCK(GLOBAL_Stream[sno].streamlock);
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorPortray, USER_MODULE))) &&
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
Yap_execute_pred(pe, &t, true PASS_REGS)) {
choiceptr B0 = (choiceptr)(LCL0 - b0);
if (Yap_HasException() && !*old_EXp)
*old_EXp = Yap_RefToException();
Yap_fail_all(B0 PASS_REGS);
LOCK(GLOBAL_Stream[sno].streamlock);
return true;
}
LOCK(GLOBAL_Stream[sno].streamlock);
if (Yap_HasException() && !*old_EXp)
*old_EXp = Yap_RefToException();
return false;
}
@ -571,7 +566,9 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
if (chr == '\0') {
break;
}
if (delta == 0) {chr = *ptr++; }
if (delta == 0) {
chr = *ptr++;
}
write_quoted(chr, qt, stream);
} while (true);
wrputc(qt, stream);
@ -884,8 +881,6 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
putAtom(Atom3Dots, wglb->Quote_illegal, wglb);
return;
}
DBTerm *ex;
Yap_ResetException(worker_id);
t = Deref(t);
if (IsVarTerm(t)) {
write_var((CELL *)t, wglb, &nrwt);
@ -910,9 +905,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
return;
}
if (wglb->Use_portray)
if (callPortray(t, &ex, wglb->stream - GLOBAL_Stream PASS_REGS)) {
Yap_CopyException(ex);
Yap_RaiseException();
if (callPortray(t, wglb->stream - GLOBAL_Stream PASS_REGS)) {
return;
}
if (trueGlobalPrologFlag(WRITE_STRINGS_FLAG) && IsCodesTerm(t)) {
@ -985,9 +978,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
}
#endif
if (wglb->Use_portray) {
if (callPortray(t, &ex, wglb->stream - GLOBAL_Stream PASS_REGS)) {
Yap_CopyException(ex);
Yap_RaiseException();
if (callPortray(t, wglb->stream - GLOBAL_Stream PASS_REGS)) {
return;
}
}
@ -1239,7 +1230,10 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
wglb.Ignore_ops = flags & Ignore_ops_f;
wglb.Write_strings = flags & BackQuote_String_f;
/* protect slots for portray */
yap_error_descriptor_t ne;
Yap_pushErrorContext(&ne);
writeTerm(from_pointer(&t, &rwt, &wglb), priority, 1, FALSE, &wglb, &rwt);
Yap_popErrorContext(true);
if (flags & New_Line_f) {
if (flags & Fullstop_f) {
wrputc('.', wglb.stream);

View File

@ -440,7 +440,7 @@ static const char *find_directory(YAP_init_args *iap, const char *paths[],
const char *inp;
if (filename) {
strcpy(out, filename);
if (Yap_IsAbsolutePath(out, false)) {
if (Yap_IsAbsolutePath(out, true)) {
out = pop_output_text_stack(lvl, out);
return out;
}

View File

@ -50,7 +50,6 @@
#include <stdio.h>
#include <stdlib.h>
/* The YAP main types */
#include "YapTerm.h"
@ -75,17 +74,14 @@
typedef bool YAP_Bool;
#endif
/**
This term can never be constructed as a valid term, so it is
used as a "BAD" term
*/
#define TermZERO ((Term)0)
#include "YapConfig.h"
typedef void *YAP_PredEntryPtr;
typedef size_t YAP_Arity;
@ -175,7 +171,6 @@ typedef enum {
#define YAP_RECONSULT_MODE 1
#define YAP_BOOT_MODE 2
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
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
const char *PrologBootFile;
//> 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
const char *SavedState;
//> bootstrapping mode: YAP is not properly installed

View File

@ -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 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

View File

@ -153,9 +153,6 @@ int Yap_peekWithSeek(int sno) {
int Yap_popChar(int sno) {
StreamDesc *s = GLOBAL_Stream + sno;
s->buf.on = false;
s->charcount = s->buf.pos;
s->linecount = s->buf.line;
s->linepos = s->buf.lpos;
Yap_DefaultStreamOps(s);
return s->buf.ch;
}
@ -174,9 +171,6 @@ int Yap_peekWide(int sno) {
} else {
s->buf.on = true;
s->buf.ch = ch;
s->buf.pos = s->charcount;
s->buf.line = s->linecount;
s->buf.lpos = s->linepos;
s->charcount = pos;
s->linecount = line;
s->linepos = lpos;
@ -205,9 +199,6 @@ int Yap_peekChar(int sno) {
} else {
s->buf.on = true;
s->buf.ch = ch;
s->buf.pos = s->charcount;
s->buf.line = s->linecount;
s->buf.lpos = s->linepos;
s->charcount = pos;
s->linecount = line;
s->linepos = lpos;

View File

@ -224,13 +224,11 @@
:- yap_flag(unknown,error).
:- style_check(single_var).
:- start_low_level_trace.
:- initialization((
bb_put(logger_filename,'out.dat'),
bb_put(logger_delimiter,';'),
bb_put(logger_variables,[])
)).
:- stopS_low_level_trace.
%========================================================================
%= Defines a new variable, possible types are: int, float and time