small bugs, especiall in error processing
This commit is contained in:
parent
6a4dbd91ec
commit
4f423dc16a
47
C/arith1.c
47
C/arith1.c
@ -20,9 +20,9 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/**
|
||||
@file arith1.c
|
||||
|
||||
|
||||
@addtogroup arithmetic_operators
|
||||
|
||||
|
||||
- <b>exp( _X_) [ISO]</b><p> @anchor exp_1
|
||||
|
||||
Natural exponential.
|
||||
@ -109,7 +109,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
- <b>integer( _X_)</b><p> @anchor integer_1_op
|
||||
|
||||
If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an
|
||||
If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an
|
||||
integer, the value of _X_.
|
||||
|
||||
- <b>float( _X_) [ISO]</b><p> @anchor float_1_op
|
||||
@ -178,7 +178,7 @@ A = 3602879701896397 rdiv 36028797018963968
|
||||
Convert the expression _X_ to a rational number or integer. The function is
|
||||
similar to [rational/1](@ref rational_1), but the result is only accurate within the
|
||||
rounding error of floating point numbers, generally producing a much
|
||||
smaller denominator.
|
||||
smaller denominator.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
|
||||
?- A is rationalize(0.25).
|
||||
@ -298,24 +298,24 @@ get_float(Term t) {
|
||||
#else
|
||||
static
|
||||
double my_rint(double x)
|
||||
{
|
||||
double y, z;
|
||||
Int n;
|
||||
|
||||
if (x >= 0) {
|
||||
y = x + 0.5;
|
||||
z = floor(y);
|
||||
n = (Int) z;
|
||||
{
|
||||
double y, z;
|
||||
Int n;
|
||||
|
||||
if (x >= 0) {
|
||||
y = x + 0.5;
|
||||
z = floor(y);
|
||||
n = (Int) z;
|
||||
if (y == z && n % 2)
|
||||
return(z-1);
|
||||
} else {
|
||||
y = x - 0.5;
|
||||
z = ceil(y);
|
||||
n = (Int) z;
|
||||
return(z-1);
|
||||
} else {
|
||||
y = x - 0.5;
|
||||
z = ceil(y);
|
||||
n = (Int) z;
|
||||
if (y == z && n % 2)
|
||||
return(z+1);
|
||||
return(z+1);
|
||||
}
|
||||
return(z);
|
||||
return(z);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -412,7 +412,7 @@ eval1(Int fi, Term t USES_REGS) {
|
||||
{
|
||||
#ifdef USE_GMP
|
||||
Int i = IntegerOfTerm(t);
|
||||
|
||||
|
||||
if (i == Int_MIN) {
|
||||
return Yap_gmp_neg_int(i);
|
||||
}
|
||||
@ -745,7 +745,7 @@ eval1(Int fi, Term t USES_REGS) {
|
||||
if (dbl < 0.0)
|
||||
RBIG_FL(ceil(dbl));
|
||||
else
|
||||
RBIG_FL(floor(dbl));
|
||||
RBIG_FL(floor(dbl));
|
||||
}
|
||||
case op_float:
|
||||
switch (ETypeOfTerm(t)) {
|
||||
@ -967,7 +967,7 @@ Yap_NameOfUnaryOp(int i)
|
||||
return Yap_LookupAtom(InitUnTab[i].OpName);
|
||||
}
|
||||
|
||||
static Int
|
||||
static Int
|
||||
p_unary_is( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
Term t = Deref(ARG2);
|
||||
@ -1017,7 +1017,7 @@ p_unary_is( USES_REGS1 )
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
static Int
|
||||
static Int
|
||||
p_unary_op_as_integer( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
Term t = Deref(ARG1);
|
||||
@ -1075,4 +1075,3 @@ Yap_ReInitUnaryExps(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
24
C/cmppreds.c
24
C/cmppreds.c
@ -83,7 +83,7 @@ static Int a_gen_ge(Term, Term);
|
||||
#define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1))
|
||||
|
||||
static int cmp_atoms(Atom a1, Atom a2) {
|
||||
return strcmp(RepAtom(a1)->StrOfAE, RepAtom(a2)->StrOfAE);
|
||||
return strcmp(RepAtom(a1)->StrOfAE, RepAtom(a2)->StrOfAE);
|
||||
}
|
||||
|
||||
static Int compare_complex(register CELL *pt0, register CELL *pt0_end,
|
||||
@ -382,7 +382,7 @@ inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */
|
||||
if (f != FunctorDot)
|
||||
return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE);
|
||||
else {
|
||||
return compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepAppl(t2) );
|
||||
return compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepAppl(t2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -595,10 +595,12 @@ inline static Int flt_cmp(Float dif) {
|
||||
|
||||
static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" );
|
||||
Yap_ArithError(INSTANTIATION_ERROR, t1,
|
||||
"while doing arithmetic comparison");
|
||||
}
|
||||
if (IsVarTerm(t2)) {
|
||||
Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" );
|
||||
Yap_ArithError(INSTANTIATION_ERROR, t2,
|
||||
"while doing arithmetic comparison");
|
||||
}
|
||||
if (IsFloatTerm(t1) && IsFloatTerm(t2)) {
|
||||
return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2));
|
||||
@ -621,7 +623,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f2 = FloatOfTerm(t2);
|
||||
#if HAVE_ISNAN
|
||||
if (isnan(f2)) {
|
||||
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" );
|
||||
Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
|
||||
"trying to evaluate nan");
|
||||
}
|
||||
#endif
|
||||
return flt_cmp(i1 - f2);
|
||||
@ -636,7 +639,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f1 = FloatOfTerm(t1);
|
||||
#if HAVE_ISNAN
|
||||
if (isnan(f1)) {
|
||||
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t1, 4, "trying to evaluate nan" );
|
||||
Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t1,
|
||||
"trying to evaluate nan");
|
||||
}
|
||||
#endif
|
||||
t2 = Yap_Eval(t2);
|
||||
@ -652,8 +656,9 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f2 = FloatOfTerm(t2);
|
||||
#if HAVE_ISNAN
|
||||
if (isnan(f2)) {
|
||||
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" );
|
||||
}
|
||||
Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
|
||||
"trying to evaluate nan");
|
||||
}
|
||||
#endif
|
||||
return flt_cmp(f1 - f2);
|
||||
#ifdef USE_GMP
|
||||
@ -674,7 +679,8 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) {
|
||||
Float f2 = FloatOfTerm(t2);
|
||||
#if HAVE_ISNAN
|
||||
if (isnan(f2)) {
|
||||
Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" );
|
||||
Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t2,
|
||||
"trying to evaluate nan");
|
||||
}
|
||||
#endif
|
||||
return Yap_gmp_cmp_big_float(t1, f2);
|
||||
|
1
C/exec.c
1
C/exec.c
@ -1446,7 +1446,6 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
/* must be done here, otherwise siglongjmp will clobber all the
|
||||
* registers
|
||||
*/
|
||||
Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
|
||||
/* reset the registers so that we don't have trash in abstract
|
||||
* machine */
|
||||
Yap_set_fpu_exceptions(
|
||||
|
220
C/scanner.c
220
C/scanner.c
@ -1143,17 +1143,17 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
|
||||
out = 0;
|
||||
}
|
||||
#if HAVE_ISWSPACE
|
||||
while (iswspace(ch = getchr(inp)))
|
||||
;
|
||||
while (iswspace(ch = getchr(inp)))
|
||||
;
|
||||
#else
|
||||
while (isspace(ch = getchr(inp)))
|
||||
;
|
||||
while (isspace(ch = getchr(inp)))
|
||||
;
|
||||
#endif
|
||||
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) {
|
||||
Yap_clean_tokenizer(old_tr, NULL, NULL);
|
||||
if (error_on)
|
||||
Yap_clean_tokenizer(old_tr, NULL, NULL);
|
||||
if (error_on)
|
||||
Yap_Error(SYNTAX_ERROR, ARG2, "converting number");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -1172,85 +1172,84 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
|
||||
}
|
||||
|
||||
Term Yap_tokRep(void *tokptre) {
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case Name_tok:
|
||||
if (!info) {
|
||||
info = TermNil;
|
||||
}
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
case QuasiQuotes_tok:
|
||||
info = MkAtomTerm(Yap_LookupAtom("<QQ>"));
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
case Number_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
break;
|
||||
case Var_tok: {
|
||||
Term t[2];
|
||||
VarEntry *varinfo = (VarEntry *)info;
|
||||
if ((t[0]= varinfo->VarAdr) == TermNil) {
|
||||
t[0] = varinfo->VarAdr = MkVarTerm();
|
||||
}
|
||||
t[1] = MkAtomTerm((Atom)(varinfo->VarRep));
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
|
||||
}
|
||||
case String_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
|
||||
case BQString_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
|
||||
case Error_tok:
|
||||
return MkAtomTerm(AtomError);
|
||||
case eot_tok:
|
||||
return MkAtomTerm(Yap_LookupAtom("EOT"));
|
||||
case Ponctuation_tok:
|
||||
return info;
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case Name_tok:
|
||||
if (!info) {
|
||||
info = TermNil;
|
||||
}
|
||||
return TermDot;
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
case QuasiQuotes_tok:
|
||||
info = MkAtomTerm(Yap_LookupAtom("<QQ>"));
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
case Number_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info);
|
||||
break;
|
||||
case Var_tok: {
|
||||
Term t[2];
|
||||
VarEntry *varinfo = (VarEntry *)info;
|
||||
if ((t[0] = varinfo->VarAdr) == TermNil) {
|
||||
t[0] = varinfo->VarAdr = MkVarTerm();
|
||||
}
|
||||
t[1] = MkAtomTerm((Atom)(varinfo->VarRep));
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
|
||||
}
|
||||
case String_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
|
||||
case BQString_tok:
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info);
|
||||
case Error_tok:
|
||||
return MkAtomTerm(AtomError);
|
||||
case eot_tok:
|
||||
return MkAtomTerm(Yap_LookupAtom("EOT"));
|
||||
case Ponctuation_tok:
|
||||
return info;
|
||||
}
|
||||
return TermDot;
|
||||
}
|
||||
|
||||
const char *Yap_tokText(void *tokptre) {
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
const char * Yap_tokText(void *tokptre) {
|
||||
CACHE_REGS
|
||||
TokEntry *tokptr = tokptre;
|
||||
Term info = tokptr->TokInfo;
|
||||
|
||||
switch (tokptr->Tok) {
|
||||
case eot_tok:
|
||||
return "EOT";
|
||||
case Ponctuation_tok:
|
||||
case Error_tok:
|
||||
case BQString_tok:
|
||||
case String_tok:
|
||||
case Name_tok:
|
||||
return AtomOfTerm(info)->StrOfAE;
|
||||
case QuasiQuotes_tok:
|
||||
return "<QQ>";
|
||||
case Number_tok:
|
||||
if (IsIntegerTerm(info)) {
|
||||
char *s = Malloc(36);
|
||||
snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info));
|
||||
return s;
|
||||
}else if (IsFloatTerm(info)) {
|
||||
char *s = Malloc( 64);
|
||||
snprintf(s, 63, "%6g", FloatOfTerm(info));
|
||||
return s;
|
||||
} else {
|
||||
size_t len = Yap_gmp_to_size(info,10);
|
||||
char *s = Malloc(len+2);
|
||||
return Yap_gmp_to_string(info,s, len+1,10);
|
||||
}
|
||||
break;
|
||||
case Var_tok:
|
||||
if (info == 0) return "[]";
|
||||
return ((Atom)info)->StrOfAE;
|
||||
switch (tokptr->Tok) {
|
||||
case eot_tok:
|
||||
return "EOT";
|
||||
case Ponctuation_tok:
|
||||
case Error_tok:
|
||||
case BQString_tok:
|
||||
case String_tok:
|
||||
case Name_tok:
|
||||
return AtomOfTerm(info)->StrOfAE;
|
||||
case QuasiQuotes_tok:
|
||||
return "<QQ>";
|
||||
case Number_tok:
|
||||
if (IsIntegerTerm(info)) {
|
||||
char *s = Malloc(36);
|
||||
snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info));
|
||||
return s;
|
||||
} else if (IsFloatTerm(info)) {
|
||||
char *s = Malloc(64);
|
||||
snprintf(s, 63, "%6g", FloatOfTerm(info));
|
||||
return s;
|
||||
} else {
|
||||
size_t len = Yap_gmp_to_size(info, 10);
|
||||
char *s = Malloc(len + 2);
|
||||
return Yap_gmp_to_string(info, s, len + 1, 10);
|
||||
}
|
||||
return ".";
|
||||
break;
|
||||
case Var_tok:
|
||||
if (info == 0)
|
||||
return "[]";
|
||||
return ((Atom)info)->StrOfAE;
|
||||
}
|
||||
return ".";
|
||||
}
|
||||
|
||||
|
||||
static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
|
||||
CELL *h0 = HR;
|
||||
HR += 5;
|
||||
@ -1311,7 +1310,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
int solo_flag = TRUE;
|
||||
int32_t ch, och;
|
||||
struct qq_struct_t *cur_qq = NULL;
|
||||
int sign = 1;
|
||||
int sign = 1;
|
||||
|
||||
InitScannerMemory();
|
||||
LOCAL_VarTable = NULL;
|
||||
@ -1424,7 +1423,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
Atom ae;
|
||||
/* don't do this in iso */
|
||||
ae = Yap_ULookupAtom(TokImage);
|
||||
Free(TokImage);
|
||||
Free(TokImage);
|
||||
if (ae == NIL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
@ -1434,7 +1433,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->Tok = Ord(kind = Name_tok);
|
||||
} else {
|
||||
VarEntry *ve = Yap_LookupVar((const char *)TokImage);
|
||||
Free(TokImage);
|
||||
Free(TokImage);
|
||||
t->TokInfo = Unsigned(ve);
|
||||
if (cur_qq) {
|
||||
ve->refs++;
|
||||
@ -1444,14 +1443,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
|
||||
} break;
|
||||
|
||||
case NU: {
|
||||
case NU: {
|
||||
int cherr;
|
||||
int cha;
|
||||
sign = 1;
|
||||
sign = 1;
|
||||
|
||||
scan_number:
|
||||
cha = ch;
|
||||
cherr = 0;
|
||||
scan_number:
|
||||
cha = ch;
|
||||
cherr = 0;
|
||||
CHECK_SPACE();
|
||||
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
|
||||
if (p) {
|
||||
@ -1480,8 +1479,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
case 'e':
|
||||
case 'E':
|
||||
och = cherr;
|
||||
TokImage = Malloc(1024 PASS_REGS);
|
||||
goto scan_name;
|
||||
TokImage = Malloc(1024 PASS_REGS);
|
||||
goto scan_name;
|
||||
break;
|
||||
case '=':
|
||||
case '_':
|
||||
@ -1513,13 +1512,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
{
|
||||
TokEntry *e2;
|
||||
|
||||
if (chtype(ch) == NU) {
|
||||
if (och == '-')
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
goto scan_number;
|
||||
}
|
||||
if (chtype(ch) == NU) {
|
||||
if (och == '-')
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
goto scan_number;
|
||||
}
|
||||
t->Tok = Name_tok;
|
||||
if (ch == '(')
|
||||
solo_flag = FALSE;
|
||||
@ -1567,9 +1566,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
LOCAL_ErrorMessage = "layout character \n inside quotes";
|
||||
break;
|
||||
}
|
||||
if (ch == EOFCHAR) {
|
||||
break;
|
||||
}
|
||||
if (ch == EOFCHAR) {
|
||||
break;
|
||||
}
|
||||
if (ch == quote) {
|
||||
ch = getchrq(inp_stream);
|
||||
if (ch != quote)
|
||||
@ -1638,16 +1637,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
break;
|
||||
case SY: {
|
||||
int pch;
|
||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
// consume...
|
||||
if (pch == '%') {
|
||||
t->TokInfo = TermNewLine;
|
||||
return l;
|
||||
}
|
||||
return l;
|
||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
// consume...
|
||||
if (pch == '%') {
|
||||
t->TokInfo = TermNewLine;
|
||||
return l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
if (ch == '`')
|
||||
goto quoted_string;
|
||||
och = ch;
|
||||
@ -1668,7 +1667,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
return l;
|
||||
}
|
||||
}
|
||||
if (och == '/' && ch == '*') {
|
||||
if (och == '/' && ch == '*') {
|
||||
if (store_comments) {
|
||||
CHECK_SPACE();
|
||||
open_comment('/', inp_stream PASS_REGS);
|
||||
@ -1925,7 +1924,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
qq->end.byteno = fseek(inp_stream->file, 0, 0);
|
||||
} else {
|
||||
qq->end.byteno = inp_stream->charcount - 1;
|
||||
}
|
||||
}
|
||||
qq->end.lineno = inp_stream->linecount;
|
||||
qq->end.linepos = inp_stream->linepos - 1;
|
||||
qq->end.charno = inp_stream->charcount - 1;
|
||||
@ -1972,7 +1971,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
return (l);
|
||||
}
|
||||
|
||||
|
||||
void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable,
|
||||
VarEntry *anonvartable) {
|
||||
CACHE_REGS
|
||||
|
3
H/ATOMS
3
H/ATOMS
@ -294,6 +294,7 @@ A PastEndOfStream N "past_end_of_stream"
|
||||
A PermissionError N "permission_error"
|
||||
A Pi N "pi"
|
||||
A Pipe N "pipe"
|
||||
A Priority N "priority"
|
||||
A Plus N "+"
|
||||
A Pointer N "pointer"
|
||||
A Portray F "portray"
|
||||
@ -546,11 +547,13 @@ F NBQueue Queue 4
|
||||
F Not Not 1
|
||||
F Obj Obj 1
|
||||
F Or Semic 2
|
||||
F Output Output 1
|
||||
F PermissionError PermissionError 3
|
||||
F Plus Plus 2
|
||||
F Portray Portray 1
|
||||
F PrintMessage PrintMessage 2
|
||||
F Procedure Procedure 5
|
||||
F Priority Priority 1
|
||||
F PrologConstraint Prolog 2
|
||||
F ProtectStack ProtectStack 4
|
||||
F Query Query 1
|
||||
|
@ -204,7 +204,7 @@ typedef struct x_el {
|
||||
} xarg;
|
||||
|
||||
typedef struct struct_param {
|
||||
char *name;
|
||||
const char *name;
|
||||
flag_func type;
|
||||
int id;
|
||||
} param_t;
|
||||
|
@ -2452,10 +2452,10 @@ extern yamop *headoftrace;
|
||||
ENDD(d0);
|
||||
#endif
|
||||
|
||||
#define Yap_AsmError(e, d) \
|
||||
#define Yap_AsmError(e, d) \
|
||||
{ \
|
||||
saveregs(); \
|
||||
Yap_ThrowError(e, d, 4, ""); \
|
||||
Yap_ThrowError(e, d, "while exwcuting inlined built-in"); \
|
||||
setregs(); \
|
||||
}
|
||||
|
||||
|
2
H/eval.h
2
H/eval.h
@ -407,7 +407,7 @@ yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
|
||||
...);
|
||||
|
||||
#define Yap_ArithError(id, t, ...) \
|
||||
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, 2, __VA_ARGS__)
|
||||
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
|
||||
#define Yap_BinError(id) \
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
|
||||
#define Yap_AbsmiError(id) \
|
||||
|
@ -289,6 +289,7 @@
|
||||
AtomPermissionError = Yap_LookupAtom("permission_error"); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
||||
AtomPi = Yap_LookupAtom("pi"); TermPi = MkAtomTerm(AtomPi);
|
||||
AtomPipe = Yap_LookupAtom("pipe"); TermPipe = MkAtomTerm(AtomPipe);
|
||||
AtomPriority = Yap_LookupAtom("priority"); TermPriority = MkAtomTerm(AtomPriority);
|
||||
AtomPlus = Yap_LookupAtom("+"); TermPlus = MkAtomTerm(AtomPlus);
|
||||
AtomPointer = Yap_LookupAtom("pointer"); TermPointer = MkAtomTerm(AtomPointer);
|
||||
AtomPortray = Yap_FullLookupAtom("portray"); TermPortray = MkAtomTerm(AtomPortray);
|
||||
@ -541,11 +542,13 @@
|
||||
FunctorNot = Yap_MkFunctor(AtomNot,1);
|
||||
FunctorObj = Yap_MkFunctor(AtomObj,1);
|
||||
FunctorOr = Yap_MkFunctor(AtomSemic,2);
|
||||
FunctorOutput = Yap_MkFunctor(AtomOutput,1);
|
||||
FunctorPermissionError = Yap_MkFunctor(AtomPermissionError,3);
|
||||
FunctorPlus = Yap_MkFunctor(AtomPlus,2);
|
||||
FunctorPortray = Yap_MkFunctor(AtomPortray,1);
|
||||
FunctorPrintMessage = Yap_MkFunctor(AtomPrintMessage,2);
|
||||
FunctorProcedure = Yap_MkFunctor(AtomProcedure,5);
|
||||
FunctorPriority = Yap_MkFunctor(AtomPriority,1);
|
||||
FunctorPrologConstraint = Yap_MkFunctor(AtomProlog,2);
|
||||
FunctorProtectStack = Yap_MkFunctor(AtomProtectStack,4);
|
||||
FunctorQuery = Yap_MkFunctor(AtomQuery,1);
|
||||
|
@ -289,6 +289,7 @@
|
||||
AtomPermissionError = AtomAdjust(AtomPermissionError); TermPermissionError = MkAtomTerm(AtomPermissionError);
|
||||
AtomPi = AtomAdjust(AtomPi); TermPi = MkAtomTerm(AtomPi);
|
||||
AtomPipe = AtomAdjust(AtomPipe); TermPipe = MkAtomTerm(AtomPipe);
|
||||
AtomPriority = AtomAdjust(AtomPriority); TermPriority = MkAtomTerm(AtomPriority);
|
||||
AtomPlus = AtomAdjust(AtomPlus); TermPlus = MkAtomTerm(AtomPlus);
|
||||
AtomPointer = AtomAdjust(AtomPointer); TermPointer = MkAtomTerm(AtomPointer);
|
||||
AtomPortray = AtomAdjust(AtomPortray); TermPortray = MkAtomTerm(AtomPortray);
|
||||
@ -541,11 +542,13 @@
|
||||
FunctorNot = FuncAdjust(FunctorNot);
|
||||
FunctorObj = FuncAdjust(FunctorObj);
|
||||
FunctorOr = FuncAdjust(FunctorOr);
|
||||
FunctorOutput = FuncAdjust(FunctorOutput);
|
||||
FunctorPermissionError = FuncAdjust(FunctorPermissionError);
|
||||
FunctorPlus = FuncAdjust(FunctorPlus);
|
||||
FunctorPortray = FuncAdjust(FunctorPortray);
|
||||
FunctorPrintMessage = FuncAdjust(FunctorPrintMessage);
|
||||
FunctorProcedure = FuncAdjust(FunctorProcedure);
|
||||
FunctorPriority = FuncAdjust(FunctorPriority);
|
||||
FunctorPrologConstraint = FuncAdjust(FunctorPrologConstraint);
|
||||
FunctorProtectStack = FuncAdjust(FunctorProtectStack);
|
||||
FunctorQuery = FuncAdjust(FunctorQuery);
|
||||
|
@ -289,6 +289,7 @@ EXTERNAL Atom AtomPastEndOfStream; EXTERNAL Term TermPastEndOfStream;
|
||||
EXTERNAL Atom AtomPermissionError; EXTERNAL Term TermPermissionError;
|
||||
EXTERNAL Atom AtomPi; EXTERNAL Term TermPi;
|
||||
EXTERNAL Atom AtomPipe; EXTERNAL Term TermPipe;
|
||||
EXTERNAL Atom AtomPriority; EXTERNAL Term TermPriority;
|
||||
EXTERNAL Atom AtomPlus; EXTERNAL Term TermPlus;
|
||||
EXTERNAL Atom AtomPointer; EXTERNAL Term TermPointer;
|
||||
EXTERNAL Atom AtomPortray; EXTERNAL Term TermPortray;
|
||||
@ -645,6 +646,8 @@ EXTERNAL Functor FunctorObj;
|
||||
|
||||
EXTERNAL Functor FunctorOr;
|
||||
|
||||
EXTERNAL Functor FunctorOutput;
|
||||
|
||||
EXTERNAL Functor FunctorPermissionError;
|
||||
|
||||
EXTERNAL Functor FunctorPlus;
|
||||
@ -655,6 +658,8 @@ EXTERNAL Functor FunctorPrintMessage;
|
||||
|
||||
EXTERNAL Functor FunctorProcedure;
|
||||
|
||||
EXTERNAL Functor FunctorPriority;
|
||||
|
||||
EXTERNAL Functor FunctorPrologConstraint;
|
||||
|
||||
EXTERNAL Functor FunctorProtectStack;
|
||||
|
40
os/iopreds.c
40
os/iopreds.c
@ -1,19 +1,19 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: iopreds.c *
|
||||
* Last rev: 5/2/88 *
|
||||
* mods: *
|
||||
* comments: Input/Output C implemented predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: iopreds.c *
|
||||
* Last rev: 5/2/88 *
|
||||
* mods: *
|
||||
* comments: Input/Output C implemented predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
@ -545,12 +545,14 @@ static int NullPutc(int sno, int ch) {
|
||||
}
|
||||
|
||||
int ResetEOF(StreamDesc *s) {
|
||||
s->status &= ~Push_Eof_Stream_f;
|
||||
if (s->status & Eof_Error_Stream_f) {
|
||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, MkAtomTerm(s->name),
|
||||
Atom name = s->name;
|
||||
// Yap_CloseStream(s - GLOBAL_Stream);
|
||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, MkAtomTerm(name),
|
||||
"GetC");
|
||||
return FALSE;
|
||||
} else if (s->status & Reset_Eof_Stream_f) {
|
||||
s->status &= ~Push_Eof_Stream_f;
|
||||
/* reset the eof indicator on file */
|
||||
if (feof(s->file))
|
||||
clearerr(s->file);
|
||||
@ -654,9 +656,9 @@ int post_process_weof(StreamDesc *s) {
|
||||
*
|
||||
* @return EOF
|
||||
*/
|
||||
int EOFPeek(int sno) { return EOFGetc(sno); }
|
||||
int EOFPeek(int sno) { return EOFCHAR; }
|
||||
|
||||
int EOFWPeek(int sno) { return EOFWGetc(sno); }
|
||||
int EOFWPeek(int sno) { return EOFCHAR; }
|
||||
|
||||
/* standard routine, it should read from anything pointed by a FILE *.
|
||||
It could be made more efficient by doing our own buffering and avoiding
|
||||
|
109
os/readterm.c
109
os/readterm.c
@ -211,19 +211,31 @@ static const param_t read_defs[] = {READ_DEFS()};
|
||||
static Term add_output(Term t, Term tail) {
|
||||
Term topt = Yap_MkNewApplTerm(Yap_MkFunctor(AtomOutput, 1), 1);
|
||||
Yap_unify(t, ArgOfTerm(1, topt));
|
||||
return MkPairTerm(topt, tail);
|
||||
if (IsPairTerm(tail) || tail == TermNil) {
|
||||
return MkPairTerm(topt, tail);
|
||||
} else {
|
||||
return MkPairTerm(topt, MkPairTerm(tail, TermNil));
|
||||
}
|
||||
}
|
||||
|
||||
static Term add_names(Term t, Term tail) {
|
||||
Term topt = Yap_MkNewApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1);
|
||||
Yap_unify(t, ArgOfTerm(1, topt));
|
||||
return MkPairTerm(topt, tail);
|
||||
if (IsPairTerm(tail) || tail == TermNil) {
|
||||
return MkPairTerm(topt, tail);
|
||||
} else {
|
||||
return MkPairTerm(topt, MkPairTerm(tail, TermNil));
|
||||
}
|
||||
}
|
||||
|
||||
static Term add_priority(Term t, Term tail) {
|
||||
Term topt = Yap_MkNewApplTerm(Yap_MkFunctor(AtomPriority, 1), 1);
|
||||
Yap_unify(t, ArgOfTerm(1, topt));
|
||||
return MkPairTerm(topt, tail);
|
||||
if (IsPairTerm(tail) || tail == TermNil) {
|
||||
return MkPairTerm(topt, tail);
|
||||
} else {
|
||||
return MkPairTerm(topt, MkPairTerm(tail, TermNil));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,13 +378,14 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
|
||||
} else {
|
||||
fe->t0 = 0;
|
||||
}
|
||||
if (args[READ_MODULE].used) {
|
||||
fe->cmod = args[READ_MODULE].tvalue;
|
||||
} else {
|
||||
fe->cmod = CurrentModule;
|
||||
if (fe->cmod == TermProlog)
|
||||
fe->cmod = PROLOG_MODULE;
|
||||
} if (args[READ_BACKQUOTED_STRING].used) {
|
||||
if (args[READ_MODULE].used) {
|
||||
fe->cmod = args[READ_MODULE].tvalue;
|
||||
} else {
|
||||
fe->cmod = CurrentModule;
|
||||
if (fe->cmod == TermProlog)
|
||||
fe->cmod = PROLOG_MODULE;
|
||||
}
|
||||
if (args[READ_BACKQUOTED_STRING].used) {
|
||||
if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue)) {
|
||||
return false;
|
||||
}
|
||||
@ -586,7 +599,7 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
|
||||
CACHE_REGS
|
||||
Term v1, v2, v3, vc, tp;
|
||||
|
||||
if (fe->t0 && !(Yap_unify(fe->t, fe->t0)))
|
||||
if (fe->t0 && fe->t && !(Yap_unify(fe->t, fe->t0)))
|
||||
return false;
|
||||
|
||||
if (fe->t && fe->vp)
|
||||
@ -625,7 +638,7 @@ static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) {
|
||||
CACHE_REGS
|
||||
Term v_vp, v_vnames, v_comments, v_pos;
|
||||
|
||||
if (fe->t0 && !Yap_unify(fe->t, fe->t0))
|
||||
if (fe->t0 & fe->t && !Yap_unify(fe->t, fe->t0))
|
||||
return false;
|
||||
if (fe->t && fe->vp)
|
||||
v_vp = get_variables(fe, tokstart);
|
||||
@ -682,6 +695,8 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream) {
|
||||
return YAP_PARSING_FINISHED;
|
||||
}
|
||||
// a :- <eof>
|
||||
if (GLOBAL_Stream[inp_stream].status & Past_Eof_Stream_f)
|
||||
return YAP_PARSING_ERROR;
|
||||
/* we need to force the next read to also give end of file.*/
|
||||
GLOBAL_Stream[inp_stream].status |= Push_Eof_Stream_f;
|
||||
LOCAL_ErrorMessage = "end of file found before end of term";
|
||||
@ -818,14 +833,11 @@ static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
|
||||
static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
|
||||
CACHE_REGS
|
||||
fe->t = 0;
|
||||
if (LOCAL_Error_TYPE == RESOURCE_ERROR_TRAIL ||
|
||||
LOCAL_Error_TYPE == RESOURCE_ERROR_AUXILIARY_STACK ||
|
||||
LOCAL_Error_TYPE == RESOURCE_ERROR_HEAP ||
|
||||
LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
|
||||
if (LOCAL_Error_TYPE != SYNTAX_ERROR && LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
return YAP_SCANNING_ERROR;
|
||||
}
|
||||
Term ParserErrorStyle = re->sy;
|
||||
if (ParserErrorStyle == TermQuiet) {
|
||||
if (ParserErrorStyle == TermQuiet || LOCAL_Error_TYPE == YAP_NO_ERROR) {
|
||||
/* just fail */
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
return YAP_PARSING_FINISHED;
|
||||
@ -948,7 +960,7 @@ static Int read_term(
|
||||
if (inp_stream == -1) {
|
||||
return (FALSE);
|
||||
}
|
||||
out = Yap_read_term(inp_stream, add_output(ARG1, ARG2), false);
|
||||
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), false);
|
||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
||||
return out != 0L;
|
||||
}
|
||||
@ -1404,16 +1416,73 @@ static Int read_term_from_string(USES_REGS1) {
|
||||
return Yap_unify(rc, ARG2);
|
||||
}
|
||||
|
||||
static Int atomic_to_term(USES_REGS1) {
|
||||
Term t1 = Deref(ARG1);
|
||||
size_t len;
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
|
||||
return (FALSE);
|
||||
} else if (!IsAtomicTerm(t1)) {
|
||||
Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3");
|
||||
return (FALSE);
|
||||
} else {
|
||||
Term t = Yap_AtomicToString(t1 PASS_REGS);
|
||||
const unsigned char *us = UStringOfTerm(t);
|
||||
len = strlen_utf8(us);
|
||||
return Yap_BufferToTerm(us, len,
|
||||
add_output(ARG2, add_names(ARG3, TermNil)));
|
||||
}
|
||||
}
|
||||
|
||||
static Int atom_to_term(USES_REGS1) {
|
||||
Term t1 = Deref(ARG1);
|
||||
size_t len;
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
|
||||
return (FALSE);
|
||||
} else if (!IsAtomTerm(t1)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM, t1, "read_term_from_atomic/3");
|
||||
return (FALSE);
|
||||
} else {
|
||||
Term t = Yap_AtomicToString(t1 PASS_REGS);
|
||||
const unsigned char *us = UStringOfTerm(t);
|
||||
len = strlen_utf8(us);
|
||||
return Yap_BufferToTerm(us, len,
|
||||
add_output(ARG2, add_names(ARG3, TermNil)));
|
||||
}
|
||||
}
|
||||
|
||||
static Int string_to_term(USES_REGS1) {
|
||||
Term t1 = Deref(ARG1);
|
||||
size_t len;
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
|
||||
return (FALSE);
|
||||
} else if (!IsStringTerm(t1)) {
|
||||
Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3");
|
||||
return (FALSE);
|
||||
} else {
|
||||
const unsigned char *us = UStringOfTerm(t1);
|
||||
len = strlen_utf8(us);
|
||||
return Yap_BufferToTerm(us, len,
|
||||
add_output(ARG2, add_names(ARG3, TermNil)));
|
||||
}
|
||||
}
|
||||
|
||||
void Yap_InitReadTPreds(void) {
|
||||
Yap_InitCPred("read", 1, read1, SyncPredFlag);
|
||||
Yap_InitCPred("read", 2, read2, SyncPredFlag);
|
||||
Yap_InitCPred("read_term", 2, read_term2, SyncPredFlag);
|
||||
Yap_InitCPred("read_term", 3, read_term, SyncPredFlag);
|
||||
|
||||
Yap_InitCPred("read", 1, read1, SyncPredFlag);
|
||||
Yap_InitCPred("read", 2, read2, SyncPredFlag);
|
||||
Yap_InitCPred("read_clause", 2, read_clause2, SyncPredFlag);
|
||||
Yap_InitCPred("read_clause", 3, read_clause, 0);
|
||||
Yap_InitCPred("read_term_from_atom", 3, read_term_from_atom, 0);
|
||||
Yap_InitCPred("read_term_from_atomic", 3, read_term_from_atomic, 0);
|
||||
Yap_InitCPred("read_term_from_string", 3, read_term_from_string, 0);
|
||||
Yap_InitCPred("atom_to_term", 3, atom_to_term, 0);
|
||||
Yap_InitCPred("atomic_to_term", 3, atomic_to_term, 0);
|
||||
Yap_InitCPred("string_to_term", 3, string_to_term, 0);
|
||||
|
||||
Yap_InitCPred("fileerrors", 0, fileerrors, SyncPredFlag);
|
||||
Yap_InitCPred("nofileeleerrors", 0, nofileerrors, SyncPredFlag);
|
||||
|
Reference in New Issue
Block a user