Merge vcosta-laptop:github/yap-6.3

This commit is contained in:
Vitor Santos Costa
2018-02-21 17:41:20 +00:00
17 changed files with 188 additions and 73 deletions

View File

@@ -68,7 +68,24 @@ bool Yap_Warning(const char *s, ...) {
rc = Yap_execute_pred(pred, ts, true PASS_REGS);
return rc;
}
void Yap_InitError(yap_error_number e, Term t, const char *msg) {
void Yap_InitError__(const char *file, const char *function, int lineno, yap_error_number e, Term t, ...) {
CACHE_REGS
va_list ap;
va_start(ap, t);
const char *fmt;
char tmpbuf[MAXPATHLEN];
fmt = va_arg(ap, char *);
if (fmt != NULL) {
#if HAVE_VSNPRINTF
vsnprintf(tmpbuf, MAXPATHLEN - 1, fmt, ap);
#else
(void)vsprintf(tmpbuf, fmt, ap);
#endif
} else
return;
va_end(ap);
if (LOCAL_ActiveError->status) {
Yap_exit(1);
}
@@ -76,10 +93,10 @@ void Yap_InitError(yap_error_number e, Term t, const char *msg) {
LOCAL_ActiveError->errorFile = NULL;
LOCAL_ActiveError->errorFunction = NULL;
LOCAL_ActiveError->errorLine = 0;
if (msg) {
LOCAL_Error_Size = strlen(msg);
if (fmt) {
LOCAL_Error_Size = strlen(tmpbuf);
LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
strcpy(LOCAL_ActiveError->errorMsg, msg);
strcpy(LOCAL_ActiveError->errorMsg, tmpbuf);
} else {
LOCAL_Error_Size = 0;
}

View File

@@ -970,6 +970,10 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
number_overflow();
*sp++ = ch;
ch = getchr(st);
if (!iswhexnumber(ch)) {
Yap_InitError(SYNTAX_ERROR, TermNil, "empty hexadecimal number 0x%C",ch) ;
return 0;
}
while (my_isxdigit(ch, 'F', 'f')) {
Int oval = val;
int chval =
@@ -982,16 +986,27 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
if (oval != (val - chval) / 16) /* overflow */
has_overflow = TRUE;
ch = getchr(st);
}
*chp = ch;
} else if (ch == 'o' && base == 0) {
might_be_float = FALSE;
might_be_float = false;
base = 8;
ch = getchr(st);
if (ch < '0' || ch > '7') {
Yap_InitError(SYNTAX_ERROR, TermNil, "empty octal number 0b%C", ch) ;
return 0;
}
} else if (ch == 'b' && base == 0) {
might_be_float = FALSE;
might_be_float = false;
base = 2;
ch = getchr(st);
if (ch < '0' || ch > '1') {
Yap_InitError(SYNTAX_ERROR, TermNil, "empty binary 0b%C", ch) ;
return 0;
}
} else {
val = base;
base = 10;
@@ -1011,7 +1026,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
}
val = val * base + ch - '0';
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
has_overflow = TRUE;
has_overflow = true;
ch = getchr(st);
}
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
@@ -1162,8 +1177,7 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
#endif
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) {
Yap_clean_tokenizer(old_tr, NULL, NULL);
if (error_on)
Yap_Error(SYNTAX_ERROR, ARG2, "converting number");
Yap_InitError(SYNTAX_ERROR, ARG2, "while converting stream %d to number", inp-GLOBAL_Stream );
return 0;
}
return out;
@@ -1472,7 +1486,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
cherr = 0;
CHECK_SPACE();
if ((t->TokInfo = get_num(&cha, &cherr, st, sign)) == 0L) {
if (p) {
if (t->TokInfo == 0) {
p->Tok = eot_tok;
t->TokInfo = TermError;
}

View File

@@ -736,21 +736,23 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out USES_REGS) {
static Term write_number(unsigned char *s, seq_tv_t *out,
bool error_on USES_REGS) {
Term t;
yap_error_number erro = LOCAL_Error_TYPE;
int i = push_text_stack();
yap_error_descriptor_t new_error;
int i = push_text_stack();
Yap_pushErrorContext(&new_error);
t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on);
pop_text_stack(i);
LOCAL_Error_TYPE = erro;
Yap_popErrorContext(true);
return t;
}
static Term string_to_term(void *s, seq_tv_t *out USES_REGS) {
Term o;
yap_error_number erro = LOCAL_Error_TYPE;
o = out->val.t = Yap_BufferToTerm(s, TermNil);
LOCAL_Error_TYPE = erro;
yap_error_descriptor_t new_error;
Yap_pushErrorContext(&new_error);
o = out->val.t = Yap_BufferToTerm(s, TermNil);
Yap_popErrorContext(true);
return o;
return o;
}
bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {