Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3
This commit is contained in:
24
C/absmi.c
24
C/absmi.c
@@ -9222,7 +9222,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, plus_vc_unk, plus_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A+B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A+ " Int_FORMAT, PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9322,7 +9322,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, plus_y_vc_unk, plus_y_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A+B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A+ " Int_FORMAT, PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9408,7 +9408,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, minus_cv_unk, minus_cv_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A-B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is " Int_FORMAT "-A", PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9508,7 +9508,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, minus_y_cv_unk, minus_y_cv_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A-B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is " Int_FORMAT "-A", PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9594,7 +9594,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, times_vc_unk, times_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A*B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A* " Int_FORMAT, PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9694,7 +9694,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, times_y_vc_unk, times_y_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A*B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A* " Int_FORMAT, PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9830,7 +9830,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, div_cv_unk, div_cv_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A//B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is " Int_FORMAT "// A", PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -9988,7 +9988,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, div_y_cv_unk, div_y_cv_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A//B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is " Int_FORMAT "// A", PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -10075,7 +10075,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, and_vc_unk, and_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A/\\B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A /\\ " Int_FORMAT , PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -10175,7 +10175,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, and_y_vc_unk, and_y_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A/\\B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A /\\ " Int_FORMAT , PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -10261,7 +10261,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, or_vc_unk, or_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A\\/B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A \\/ " Int_FORMAT , PREG->u.xxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
@@ -10361,7 +10361,7 @@ Yap_absmi(int inp)
|
||||
BEGP(pt0);
|
||||
deref_body(d0, pt0, or_y_vc_unk, or_y_vc_nvar);
|
||||
saveregs();
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A\\/B");
|
||||
Yap_Error(INSTANTIATION_ERROR, TermNil, "X is A \\/ " Int_FORMAT , PREG->u.yxn.c);
|
||||
setregs();
|
||||
FAIL();
|
||||
ENDP(pt0);
|
||||
|
54
C/adtdefs.c
54
C/adtdefs.c
@@ -493,41 +493,43 @@ Yap_GetOpProp(Atom a, op_type type USES_REGS)
|
||||
{ /* look property list of atom a for kind */
|
||||
AtomEntry *ae = RepAtom(a);
|
||||
PropEntry *pp;
|
||||
OpEntry *info = NULL;
|
||||
|
||||
READ_LOCK(ae->ARWLock);
|
||||
pp = RepProp(ae->PropsOfAE);
|
||||
while (!EndOfPAEntr(pp) &&
|
||||
( pp->KindOfPE != OpProperty ||
|
||||
((OpEntry *)pp)->OpModule != CurrentModule))
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
if ((info = (OpEntry *)pp)) {
|
||||
if ((type == INFIX_OP && !info->Infix) ||
|
||||
(type == POSFIX_OP && !info->Posfix) ||
|
||||
(type == PREFIX_OP && !info->Prefix))
|
||||
pp = RepProp(NIL);
|
||||
}
|
||||
if (EndOfPAEntr(pp)) {
|
||||
pp = RepProp(ae->PropsOfAE);
|
||||
while (!EndOfPAEntr(pp) &&
|
||||
( pp->KindOfPE != OpProperty ||
|
||||
((OpEntry *)pp)->OpModule != PROLOG_MODULE))
|
||||
while (!EndOfPAEntr(pp)) {
|
||||
OpEntry *info = NULL;
|
||||
if ( pp->KindOfPE != OpProperty) {
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
if ((info = (OpEntry *)pp)) {
|
||||
if ((type == INFIX_OP && !info->Infix) ||
|
||||
(type == POSFIX_OP && !info->Posfix) ||
|
||||
(type == PREFIX_OP && !info->Prefix))
|
||||
pp = RepProp(NIL);
|
||||
continue;
|
||||
}
|
||||
info = (OpEntry *)pp;
|
||||
if (info->OpModule != CurrentModule &&
|
||||
info->OpModule != PROLOG_MODULE) {
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
continue;
|
||||
}
|
||||
if (type == INFIX_OP) {
|
||||
if (!info->Infix) {
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
continue;
|
||||
}
|
||||
} else if (type == POSFIX_OP) {
|
||||
if (!info->Posfix) {
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!info->Prefix) {
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!info) {
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return NULL;
|
||||
} else {
|
||||
READ_LOCK(info->OpRWLock);
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
}
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2429,13 +2429,13 @@ a_fetch_vv(cmp_op_info *cmp_info, int pass_no, struct intermediates *cip)
|
||||
PInstr *p = cip->cpc->nextInst;
|
||||
Ventry *ve;
|
||||
ve = (Ventry *) p->rnd1;
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op) {
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
|
||||
p->rnd2 = ve->NoOfVE & MaskVarAdrs;
|
||||
p->op = nop_op;
|
||||
}
|
||||
p = p->nextInst;
|
||||
ve = (Ventry *) p->rnd1;
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op) {
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
|
||||
p->rnd2 = ve->NoOfVE & MaskVarAdrs;
|
||||
p->op = nop_op;
|
||||
}
|
||||
@@ -2458,7 +2458,7 @@ a_fetch_vc(cmp_op_info *cmp_info, int pass_no, struct intermediates *cip)
|
||||
PInstr *p = cip->cpc->nextInst;
|
||||
Ventry *ve;
|
||||
ve = (Ventry *) p->rnd1;
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op) {
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
|
||||
p->rnd2 = ve->NoOfVE & MaskVarAdrs;
|
||||
p->op = nop_op;
|
||||
}
|
||||
@@ -2479,7 +2479,7 @@ a_fetch_cv(cmp_op_info *cmp_info, int pass_no, struct intermediates *cip)
|
||||
PInstr *p = cip->cpc->nextInst;
|
||||
Ventry *ve;
|
||||
ve = (Ventry *) p->rnd1;
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op) {
|
||||
if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
|
||||
p->rnd2 = ve->NoOfVE & MaskVarAdrs;
|
||||
p->op = nop_op;
|
||||
}
|
||||
|
41
C/bignum.c
41
C/bignum.c
@@ -294,8 +294,8 @@ Yap_MkBlobStringTerm(const char *s, size_t len)
|
||||
H[1] = BLOB_STRING;
|
||||
|
||||
siz = (sizeof(size_t)+len+sizeof(CELL))/sizeof(CELL);
|
||||
dst->_mp_size = siz;
|
||||
dst->_mp_alloc = 0L;
|
||||
dst->_mp_size = 0L;
|
||||
dst->_mp_alloc = siz;
|
||||
sp = (blob_string_t *)(dst+1);
|
||||
H = (CELL *)sp;
|
||||
sp->len = sz;
|
||||
@@ -314,10 +314,39 @@ Yap_MkBlobWideStringTerm(const wchar_t *s, size_t len)
|
||||
size_t sz;
|
||||
MP_INT *dst = (MP_INT *)(H+2);
|
||||
blob_string_t *sp;
|
||||
size_t siz;
|
||||
size_t siz, i = 0;
|
||||
|
||||
sz = wcslen(s);
|
||||
if (len > 0 && sz > len) sz = len;
|
||||
while (i < sz) {
|
||||
if (s[i++] >= 255) break;
|
||||
}
|
||||
if (i == sz) {
|
||||
char *target;
|
||||
size_t i = 0;
|
||||
|
||||
if (len/sizeof(CELL) > (ASP-ret)-1024) {
|
||||
return TermNil;
|
||||
}
|
||||
H[0] = (CELL)FunctorBigInt;
|
||||
H[1] = BLOB_STRING;
|
||||
|
||||
siz = (sizeof(size_t)+len+sizeof(CELL))/sizeof(CELL);
|
||||
dst->_mp_size = 0L;
|
||||
dst->_mp_alloc = siz;
|
||||
sp = (blob_string_t *)(dst+1);
|
||||
H = (CELL *)sp;
|
||||
sp->len = sz;
|
||||
target = (char *)(sp+1);
|
||||
while (i < sz+1) {
|
||||
target[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
H += siz;
|
||||
H[0] = EndSpecials;
|
||||
H++;
|
||||
return AbsAppl(ret);
|
||||
}
|
||||
if (len/sizeof(CELL) > (ASP-ret)-1024) {
|
||||
return TermNil;
|
||||
}
|
||||
@@ -325,12 +354,12 @@ Yap_MkBlobWideStringTerm(const wchar_t *s, size_t len)
|
||||
H[1] = BLOB_WIDE_STRING;
|
||||
|
||||
siz = (sizeof(size_t)+(len+2)*sizeof(wchar_t))/sizeof(CELL);
|
||||
dst->_mp_size = siz;
|
||||
dst->_mp_alloc = 0L;
|
||||
dst->_mp_size = 0L;
|
||||
dst->_mp_alloc = siz;
|
||||
sp = (blob_string_t *)(dst+1);
|
||||
H = (CELL *)sp;
|
||||
sp->len = sz;
|
||||
wcsncpy((wchar_t *)(sp+1), s, sz);
|
||||
wcsncpy((wchar_t *)(sp+1), s, sz+1);
|
||||
H += siz;
|
||||
H[0] = EndSpecials;
|
||||
H++;
|
||||
|
@@ -2528,20 +2528,20 @@ YAP_Read(IOSTREAM *inp)
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, &tpos);
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, FALSE, &tpos);
|
||||
if (LOCAL_ErrorMessage)
|
||||
{
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return 0;
|
||||
}
|
||||
if (inp->flags & (SIO_FEOF|SIO_FEOF2)) {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return MkAtomTerm (AtomEof);
|
||||
}
|
||||
t = Yap_Parse();
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return t;
|
||||
|
15
C/errors.c
15
C/errors.c
@@ -1771,6 +1771,21 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
|
||||
serious = TRUE;
|
||||
}
|
||||
break;
|
||||
case TYPE_ERROR_STRING:
|
||||
{
|
||||
int i;
|
||||
Term ti[2];
|
||||
|
||||
i = strlen(tmpbuf);
|
||||
ti[0] = MkAtomTerm(AtomString);
|
||||
ti[1] = where;
|
||||
nt[0] = Yap_MkApplTerm(FunctorTypeError, 2, ti);
|
||||
tp = tmpbuf+i;
|
||||
psize -= i;
|
||||
fun = FunctorError;
|
||||
serious = TRUE;
|
||||
}
|
||||
break;
|
||||
case TYPE_ERROR_UBYTE:
|
||||
{
|
||||
int i;
|
||||
|
64
C/iopreds.c
64
C/iopreds.c
@@ -402,19 +402,19 @@ Yap_StringToTerm(char *s,Term *tp)
|
||||
if (sno == NULL)
|
||||
return FALSE;
|
||||
TR_before_parse = TR;
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(sno, &tpos);
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(sno, FALSE, &tpos);
|
||||
if (tokstart == NIL || tokstart->Tok == Ord (eot_tok)) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(AtomEOFBeforeEOT);
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
Sclose(sno);
|
||||
return FALSE;
|
||||
} else if (LOCAL_ErrorMessage) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
Sclose(sno);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -422,11 +422,11 @@ Yap_StringToTerm(char *s,Term *tp)
|
||||
TR = TR_before_parse;
|
||||
if (!t || LOCAL_ErrorMessage) {
|
||||
GenerateSyntaxError(tp, tokstart, sno PASS_REGS);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
Sclose(sno);
|
||||
return FALSE;
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
Sclose(sno);
|
||||
return t;
|
||||
}
|
||||
@@ -512,25 +512,25 @@ Yap_readTerm(void *st0, Term *tp, Term *varnames, Term *terror, Term *tpos)
|
||||
if (st == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(st, tpos);
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(st, FALSE, tpos);
|
||||
if (LOCAL_ErrorMessage)
|
||||
{
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
if (terror)
|
||||
*terror = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return FALSE;
|
||||
}
|
||||
pt = Yap_Parse();
|
||||
if (LOCAL_ErrorMessage || pt == (CELL)0) {
|
||||
GenerateSyntaxError(terror, tokstart, st PASS_REGS);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return FALSE;
|
||||
}
|
||||
if (varnames) {
|
||||
*varnames = Yap_VarNames(LOCAL_VarTable, TermNil);
|
||||
if (!*varnames) {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -548,6 +548,7 @@ Yap_readTerm(void *st0, Term *tp, Term *varnames, Term *terror, Term *tpos)
|
||||
Vars: ARG4
|
||||
Pos: ARG5
|
||||
Err: ARG6
|
||||
Comments: ARG7
|
||||
*/
|
||||
static Int
|
||||
do_read(IOSTREAM *inp_stream, int nargs USES_REGS)
|
||||
@@ -556,6 +557,8 @@ static Int
|
||||
TokEntry *tokstart;
|
||||
Term tmod = Deref(ARG3), OCurrentModule = CurrentModule, tpos;
|
||||
extern void Yap_setCurrentSourceLocation(IOSTREAM **s);
|
||||
Term tcomms = Deref(ARG7);
|
||||
int store_comments = IsVarTerm(tcomms);
|
||||
|
||||
Yap_setCurrentSourceLocation(&inp_stream);
|
||||
if (IsVarTerm(tmod)) {
|
||||
@@ -565,11 +568,6 @@ static Int
|
||||
return FALSE;
|
||||
}
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
tpos = Yap_StreamPosition(inp_stream);
|
||||
if (!Yap_unify(tpos,ARG5)) {
|
||||
/* do this early so that we do not have to protect it in case of stack expansion */
|
||||
return FALSE;
|
||||
}
|
||||
while (TRUE) {
|
||||
CELL *old_H;
|
||||
int64_t cpos = 0;
|
||||
@@ -583,10 +581,12 @@ static Int
|
||||
while (TRUE) {
|
||||
old_H = H;
|
||||
tpos = Yap_StreamPosition(inp_stream);
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp_stream, &tpos);
|
||||
LOCAL_Comments = TermNil;
|
||||
LOCAL_CommentsNextChar = LOCAL_CommentsTail = NULL;
|
||||
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp_stream, store_comments, &tpos);
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR && seekable) {
|
||||
H = old_H;
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
if (seekable) {
|
||||
Sseek64(inp_stream, cpos, SIO_SEEK_SET);
|
||||
}
|
||||
@@ -616,6 +616,10 @@ static Int
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!Yap_unify(tpos,ARG5)) {
|
||||
/* do this early so that we do not have to protect it in case of stack expansion */
|
||||
return FALSE;
|
||||
}
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
/* preserve value of H after scanning: otherwise we may lose strings
|
||||
and floats */
|
||||
@@ -624,10 +628,10 @@ static Int
|
||||
/* did we get the end of file from an abort? */
|
||||
if (LOCAL_ErrorMessage &&
|
||||
!strcmp(LOCAL_ErrorMessage,"Abort")) {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return FALSE;
|
||||
} else {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm (AtomEof))
|
||||
&& Yap_unify_constant(ARG4, TermNil);
|
||||
@@ -670,7 +674,7 @@ static Int
|
||||
}
|
||||
if (ParserErrorStyle == QUIET_ON_PARSER_ERROR) {
|
||||
/* just fail */
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return FALSE;
|
||||
} else if (ParserErrorStyle == CONTINUE_ON_PARSER_ERROR) {
|
||||
LOCAL_ErrorMessage = NULL;
|
||||
@@ -682,14 +686,14 @@ static Int
|
||||
LOCAL_ErrorMessage = "SYNTAX ERROR";
|
||||
|
||||
if (ParserErrorStyle == EXCEPTION_ON_PARSER_ERROR) {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
Yap_Error(SYNTAX_ERROR,terr,LOCAL_ErrorMessage);
|
||||
return FALSE;
|
||||
} else /* FAIL ON PARSER ERROR */ {
|
||||
Term t[2];
|
||||
t[0] = terr;
|
||||
t[1] = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return Yap_unify(ARG6,Yap_MkApplTerm(Yap_MkFunctor(AtomError,2),2,t));
|
||||
}
|
||||
}
|
||||
@@ -701,6 +705,8 @@ static Int
|
||||
}
|
||||
if (!Yap_unify(t, ARG2))
|
||||
return FALSE;
|
||||
if (store_comments && !Yap_unify(LOCAL_Comments, ARG7))
|
||||
return FALSE;
|
||||
if (AtomOfTerm (Deref (ARG1)) == AtomTrue) {
|
||||
while (TRUE) {
|
||||
CELL *old_H = H;
|
||||
@@ -721,10 +727,10 @@ static Int
|
||||
TR = old_TR;
|
||||
}
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return Yap_unify (v, ARG4);
|
||||
} else {
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -732,7 +738,7 @@ static Int
|
||||
static Int
|
||||
p_read ( USES_REGS1 )
|
||||
{ /* '$read'(+Flag,?Term,?Module,?Vars,-Pos,-Err) */
|
||||
return do_read(NULL, 6 PASS_REGS);
|
||||
return do_read(NULL, 7 PASS_REGS);
|
||||
}
|
||||
|
||||
extern int Yap_getInputStream(Int, IOSTREAM **);
|
||||
@@ -743,10 +749,10 @@ p_read2 ( USES_REGS1 )
|
||||
IOSTREAM *inp_stream;
|
||||
Int out;
|
||||
|
||||
if (!Yap_getInputStream(Yap_InitSlot(Deref(ARG7) PASS_REGS), &inp_stream)) {
|
||||
if (!Yap_getInputStream(Yap_InitSlot(Deref(ARG8) PASS_REGS), &inp_stream)) {
|
||||
return(FALSE);
|
||||
}
|
||||
out = do_read(inp_stream, 7 PASS_REGS);
|
||||
out = do_read(inp_stream, 8 PASS_REGS);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -1108,8 +1114,8 @@ Yap_InitIOPreds(void)
|
||||
/* here the Input/Output predicates */
|
||||
Yap_InitCPred ("$set_read_error_handler", 1, p_set_read_error_handler, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$get_read_error_handler", 1, p_get_read_error_handler, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$read", 6, p_read, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$read", 7, p_read2, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$read", 7, p_read, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$read", 8, p_read2, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("$start_line", 1, p_startline, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$change_type_of_char", 2, p_change_type_of_char, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$type_of_char", 2, p_type_of_char, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
@@ -267,7 +267,7 @@ IsPosfixOp(Atom op, int *pptr, int *lpptr USES_REGS)
|
||||
{
|
||||
int p;
|
||||
|
||||
OpEntry *opp = Yap_GetOpProp(op, INFIX_OP PASS_REGS);
|
||||
OpEntry *opp = Yap_GetOpProp(op, POSFIX_OP PASS_REGS);
|
||||
if (!opp)
|
||||
return FALSE;
|
||||
if (opp->OpModule &&
|
||||
|
160
C/scanner.c
160
C/scanner.c
@@ -8,7 +8,7 @@
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: %W% %G% *
|
||||
* File: %W% %G% *
|
||||
* Last rev: 22-1-03 *
|
||||
* mods: *
|
||||
* comments: Prolog's scanner *
|
||||
@@ -746,7 +746,7 @@ Yap_scan_num(IOSTREAM *inp)
|
||||
ch = getchr(inp);
|
||||
}
|
||||
if (chtype(ch) != NU) {
|
||||
Yap_clean_tokenizer(NULL, NULL, NULL);
|
||||
Yap_clean_tokenizer(NULL, NULL, NULL, 0L);
|
||||
return TermNil;
|
||||
}
|
||||
cherr = '\0';
|
||||
@@ -754,13 +754,68 @@ Yap_scan_num(IOSTREAM *inp)
|
||||
return TermNil;
|
||||
out = get_num(&ch, &cherr, inp, ptr, 4096, sign); /* */
|
||||
PopScannerMemory(ptr, 4096);
|
||||
Yap_clean_tokenizer(NULL, NULL, NULL);
|
||||
Yap_clean_tokenizer(NULL, NULL, NULL, 0L);
|
||||
if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr)
|
||||
return TermNil;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
#define CHECK_SPACE() \
|
||||
if (ASP-H < 1024) { \
|
||||
LOCAL_ErrorMessage = "Stack Overflow"; \
|
||||
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR; \
|
||||
LOCAL_Error_Size = 0L; \
|
||||
if (p) \
|
||||
p->Tok = Ord(kind = eot_tok); \
|
||||
/* serious error now */ \
|
||||
return l; \
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
open_comment(int ch, IOSTREAM *inp_stream) {
|
||||
CELL *h0 = H;
|
||||
H += 5;
|
||||
h0[0] = AbsAppl(h0+2);
|
||||
h0[1] = TermNil;
|
||||
if (!LOCAL_CommentsTail) {
|
||||
/* first comment */
|
||||
LOCAL_Comments = AbsPair(h0);
|
||||
} else {
|
||||
/* extra comment */
|
||||
*LOCAL_CommentsTail = AbsPair(h0);
|
||||
}
|
||||
LOCAL_CommentsTail = h0+1;
|
||||
h0 += 2;
|
||||
h0[0] = (CELL)FunctorMinus;
|
||||
h0[1] = Yap_StreamPosition(inp_stream);
|
||||
h0[2] = TermNil;
|
||||
LOCAL_CommentsNextChar = h0+2;
|
||||
LOCAL_CommentsBuff = (wchar_t *)malloc(1024*sizeof(wchar_t));
|
||||
LOCAL_CommentsBuffLim = 1024;
|
||||
LOCAL_CommentsBuff[0] = ch;
|
||||
LOCAL_CommentsBuffPos = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
extend_comment(int ch) {
|
||||
LOCAL_CommentsBuff[LOCAL_CommentsBuffPos] = ch;
|
||||
LOCAL_CommentsBuffPos++;
|
||||
if (LOCAL_CommentsBuffPos == LOCAL_CommentsBuffLim-1) {
|
||||
LOCAL_CommentsBuff = (wchar_t *)realloc(LOCAL_CommentsBuff,sizeof(wchar_t)*(LOCAL_CommentsBuffLim+4096));
|
||||
LOCAL_CommentsBuffLim += 4096;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
close_comment(void) {
|
||||
LOCAL_CommentsBuff[LOCAL_CommentsBuffPos] = '\0';
|
||||
*LOCAL_CommentsNextChar = Yap_MkBlobWideStringTerm(LOCAL_CommentsBuff, LOCAL_CommentsBuffPos);
|
||||
free(LOCAL_CommentsBuff);
|
||||
LOCAL_CommentsBuffLim = 0;
|
||||
}
|
||||
|
||||
static wchar_t *
|
||||
ch_to_wide(char *base, char *charp)
|
||||
{
|
||||
@@ -791,7 +846,7 @@ ch_to_wide(char *base, char *charp)
|
||||
}
|
||||
|
||||
TokEntry *
|
||||
Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
|
||||
{
|
||||
CACHE_REGS
|
||||
TokEntry *t, *l, *p;
|
||||
@@ -846,7 +901,27 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
switch (chtype(ch)) {
|
||||
|
||||
case CC:
|
||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
|
||||
if (store_comments) {
|
||||
CHECK_SPACE();
|
||||
open_comment(ch, inp_stream);
|
||||
continue_comment:
|
||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
|
||||
CHECK_SPACE();
|
||||
extend_comment(ch);
|
||||
}
|
||||
CHECK_SPACE();
|
||||
extend_comment(ch);
|
||||
if (chtype(ch) != EF) {
|
||||
ch = getchr(inp_stream);
|
||||
if (chtype(ch) == CC) {
|
||||
extend_comment(ch);
|
||||
goto continue_comment;
|
||||
}
|
||||
}
|
||||
close_comment();
|
||||
} else {
|
||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
|
||||
}
|
||||
if (chtype(ch) != EF) {
|
||||
/* blank space */
|
||||
if (t == l) {
|
||||
@@ -854,15 +929,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
while (chtype(ch) == BS) {
|
||||
ch = getchr(inp_stream);
|
||||
}
|
||||
if (ASP-H < 1024) {
|
||||
LOCAL_ErrorMessage = "Stack Overflow";
|
||||
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
|
||||
LOCAL_Error_Size = 0L;
|
||||
if (p)
|
||||
p->Tok = Ord(kind = eot_tok);
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
CHECK_SPACE();
|
||||
*tposp = Yap_StreamPosition(inp_stream);
|
||||
}
|
||||
goto restart;
|
||||
@@ -947,15 +1014,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
if (ASP-H < 1024) {
|
||||
LOCAL_ErrorMessage = "Stack Overflow";
|
||||
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
|
||||
LOCAL_Error_Size = 0L;
|
||||
if (p)
|
||||
p->Tok = Ord(kind = eot_tok);
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
CHECK_SPACE();
|
||||
if ((t->TokInfo = get_num(&cha,&cherr,inp_stream,ptr,4096,1)) == 0L) {
|
||||
if (p)
|
||||
p->Tok = Ord(kind = eot_tok);
|
||||
@@ -1157,29 +1216,39 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
och = ch;
|
||||
ch = getchr(inp_stream);
|
||||
if (och == '/' && ch == '*') {
|
||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||
och = ch;
|
||||
ch = getchr(inp_stream);
|
||||
if (store_comments) {
|
||||
CHECK_SPACE();
|
||||
open_comment('/', inp_stream);
|
||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||
och = ch;
|
||||
CHECK_SPACE();
|
||||
extend_comment(ch);
|
||||
ch = getchr(inp_stream);
|
||||
}
|
||||
if (chtype(ch) != EF) {
|
||||
CHECK_SPACE();
|
||||
extend_comment(ch);
|
||||
}
|
||||
close_comment();
|
||||
} else {
|
||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||
och = ch;
|
||||
ch = getchr(inp_stream);
|
||||
}
|
||||
}
|
||||
if (chtype(ch) == EF) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
}
|
||||
ch = getchr(inp_stream);
|
||||
if (t == l) {
|
||||
/* we found a comment before reading characters */
|
||||
while (chtype(ch) == BS) {
|
||||
ch = getchr(inp_stream);
|
||||
} else {
|
||||
/* leave comments */
|
||||
ch = getchr(inp_stream);
|
||||
if (t == l) {
|
||||
/* we found a comment before reading characters */
|
||||
while (chtype(ch) == BS) {
|
||||
ch = getchr(inp_stream);
|
||||
}
|
||||
CHECK_SPACE();
|
||||
*tposp = Yap_StreamPosition(inp_stream);
|
||||
}
|
||||
if (ASP-H < 1024) {
|
||||
LOCAL_ErrorMessage = "Stack Overflow";
|
||||
LOCAL_Error_TYPE = OUT_OF_STACK_ERROR;
|
||||
LOCAL_Error_Size = 0L;
|
||||
if (p)
|
||||
p->Tok = Ord(kind = eot_tok);
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
*tposp = Yap_StreamPosition(inp_stream);
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
@@ -1189,8 +1258,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
if (chtype(ch) == CC)
|
||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TokImage = ((AtomEntry *) ( Yap_PreAllocCodeSpace()))->StrOfAE;
|
||||
charp = TokImage;
|
||||
*charp++ = och;
|
||||
@@ -1293,7 +1361,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, Term *tposp)
|
||||
}
|
||||
|
||||
void
|
||||
Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, VarEntry *anonvartable)
|
||||
Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, VarEntry *anonvartable, Term commentable)
|
||||
{
|
||||
CACHE_REGS
|
||||
struct scanner_extra_alloc *ptr = LOCAL_ScannerExtraBlocks;
|
||||
@@ -1302,5 +1370,7 @@ Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, VarEntry *anonvartab
|
||||
free(ptr);
|
||||
ptr = next;
|
||||
}
|
||||
LOCAL_Comments = TermNil;
|
||||
LOCAL_CommentsNextChar = LOCAL_CommentsTail = NULL;
|
||||
}
|
||||
|
||||
|
261
C/stdpreds.c
261
C/stdpreds.c
@@ -1065,6 +1065,263 @@ p_name( USES_REGS1 )
|
||||
|
||||
}
|
||||
|
||||
static Int
|
||||
p_string_to_atom( USES_REGS1 )
|
||||
{ /* name(?Atomic,?String) */
|
||||
char *String; /* alloc temp space on trail */
|
||||
Term t = Deref(ARG1), NewT, AtomNameT = Deref(ARG2);
|
||||
|
||||
restart_aux:
|
||||
if (!IsVarTerm(t)) {
|
||||
Atom at;
|
||||
do {
|
||||
if (Yap_IsWideStringTerm(t)) {
|
||||
at = Yap_LookupWideAtom(Yap_BlobWideStringOfTerm(t));
|
||||
} else if (Yap_IsStringTerm(t)) {
|
||||
at = Yap_LookupAtom(Yap_BlobStringOfTerm(t));
|
||||
} else if (IsAtomTerm(t)) {
|
||||
return Yap_unify(t, ARG2);
|
||||
} else if (IsIntTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
sprintf(String, Int_FORMAT, IntOfTerm(t));
|
||||
at = Yap_LookupAtom(String);
|
||||
} else if (IsFloatTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, "%f", FloatOfTerm(t));
|
||||
at = Yap_LookupAtom(String);
|
||||
} else if (IsLongIntTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, Int_FORMAT, LongIntOfTerm(t));
|
||||
at = Yap_LookupAtom(String);
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(t)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (!Yap_gmp_to_string(t, String, ((char *)AuxSp-String)-1024, 10 ))
|
||||
goto expand_auxsp;
|
||||
at = Yap_LookupAtom(String);
|
||||
#endif
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (at != NIL)
|
||||
break;
|
||||
if (!Yap_growheap(FALSE, 0, NULL)) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, ARG2, "generating atom from string in string_to_atom/2");
|
||||
return FALSE;
|
||||
}
|
||||
t = Deref(ARG1);
|
||||
} while(TRUE);
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm(at));
|
||||
}
|
||||
if (IsVarTerm(AtomNameT)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, ARG1, "string_to_atom/2");
|
||||
return(FALSE);
|
||||
}
|
||||
else if (IsAtomTerm(AtomNameT)) {
|
||||
Atom at = AtomOfTerm(AtomNameT);
|
||||
if (IsWideAtom(at)) {
|
||||
wchar_t *s = RepAtom(at)->WStrOfAE;
|
||||
NewT = Yap_MkBlobWideStringTerm(s, wcslen(s));
|
||||
return Yap_unify(NewT, ARG1);
|
||||
} else
|
||||
String = RepAtom(at)->StrOfAE;
|
||||
} else if (IsIntTerm(AtomNameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
sprintf(String, Int_FORMAT, IntOfTerm(AtomNameT));
|
||||
} else if (IsFloatTerm(AtomNameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, "%f", FloatOfTerm(AtomNameT));
|
||||
} else if (IsLongIntTerm(AtomNameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, Int_FORMAT, LongIntOfTerm(AtomNameT));
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(AtomNameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (!Yap_gmp_to_string(AtomNameT, String, ((char *)AuxSp-String)-1024, 10 ))
|
||||
goto expand_auxsp;
|
||||
#endif
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_ATOMIC,AtomNameT,"name/2");
|
||||
return FALSE;
|
||||
}
|
||||
NewT = Yap_MkBlobStringTerm(String, strlen(String));
|
||||
return Yap_unify(NewT, ARG1);
|
||||
|
||||
/* error handling */
|
||||
expand_auxsp:
|
||||
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
||||
if (String + 1024 > (char *)AuxSp) {
|
||||
/* crash in flames */
|
||||
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in string_to_atom/2");
|
||||
return FALSE;
|
||||
}
|
||||
AtomNameT = Deref(ARG1);
|
||||
t = Deref(ARG2);
|
||||
goto restart_aux;
|
||||
|
||||
}
|
||||
|
||||
static Int
|
||||
p_string_to_list( USES_REGS1 )
|
||||
{ /* name(?Atomic,?String) */
|
||||
char *String; /* alloc temp space on trail */
|
||||
Term t = Deref(ARG1), NewT, NameT = Deref(ARG2);
|
||||
|
||||
restart_aux:
|
||||
if (!IsVarTerm(t)) {
|
||||
Term StringT;
|
||||
|
||||
if (Yap_IsWideStringTerm(t)) {
|
||||
StringT = Yap_WideStringToList(Yap_BlobWideStringOfTerm(t));
|
||||
} else if (Yap_IsStringTerm(t)) {
|
||||
StringT = Yap_StringToList(Yap_BlobStringOfTerm(t));
|
||||
} else if (IsAtomTerm(t)) {
|
||||
Atom at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at))
|
||||
StringT = Yap_WideStringToList(RepAtom(at)->WStrOfAE);
|
||||
else
|
||||
StringT = Yap_StringToList(RepAtom(at)->StrOfAE);
|
||||
} else if (IsIntTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
sprintf(String, Int_FORMAT, IntOfTerm(t));
|
||||
StringT = Yap_StringToList(String);
|
||||
} else if (IsFloatTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, "%f", FloatOfTerm(t));
|
||||
StringT = Yap_StringToList(String);
|
||||
} else if (IsLongIntTerm(t)) {
|
||||
char *String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, Int_FORMAT, LongIntOfTerm(t));
|
||||
StringT = Yap_StringToList(String);
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(t)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (!Yap_gmp_to_string(t, String, ((char *)AuxSp-String)-1024, 10 ))
|
||||
goto expand_auxsp;
|
||||
StringT = Yap_StringToList(String);
|
||||
#endif
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_ATOMIC,NameT,"string_to_list/2");
|
||||
return FALSE;
|
||||
}
|
||||
return Yap_unify_constant(ARG2, StringT);
|
||||
}
|
||||
if (!IsVarTerm(NameT)) {
|
||||
if (IsAtomTerm(NameT)) {
|
||||
Atom at = AtomOfTerm(NameT);
|
||||
if (IsWideAtom(at)) {
|
||||
wchar_t *s = RepAtom(at)->WStrOfAE;
|
||||
NewT = Yap_MkBlobWideStringTerm(s, wcslen(s));
|
||||
return Yap_unify(NewT, ARG1);
|
||||
} else
|
||||
String = RepAtom(at)->StrOfAE;
|
||||
} else if (IsIntTerm(NameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
sprintf(String, Int_FORMAT, IntOfTerm(NameT));
|
||||
} else if (IsFloatTerm(NameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, "%f", FloatOfTerm(NameT));
|
||||
} else if (IsLongIntTerm(NameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (String + 1024 > (char *)AuxSp)
|
||||
goto expand_auxsp;
|
||||
|
||||
sprintf(String, Int_FORMAT, LongIntOfTerm(NameT));
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(NameT)) {
|
||||
String = Yap_PreAllocCodeSpace();
|
||||
if (!Yap_gmp_to_string(NameT, String, ((char *)AuxSp-String)-1024, 10 ))
|
||||
goto expand_auxsp;
|
||||
#endif
|
||||
} else {
|
||||
wchar_t *WString = (wchar_t *)Yap_PreAllocCodeSpace();
|
||||
wchar_t *ws = WString;
|
||||
while (IsPairTerm(NameT)) {
|
||||
Term Head = HeadOfTerm(NameT);
|
||||
Int i;
|
||||
|
||||
if (IsVarTerm(Head)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,Head,"string_codes/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsIntegerTerm(Head)) {
|
||||
Yap_Error(TYPE_ERROR_INTEGER,Head,"string_codes/2");
|
||||
return FALSE;
|
||||
}
|
||||
i = IntegerOfTerm(Head);
|
||||
if (i < 0) {
|
||||
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,Head,"string_codes/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (ws > (wchar_t *)AuxSp-1024) {
|
||||
goto expand_auxsp;
|
||||
}
|
||||
*ws++ = i;
|
||||
NameT = TailOfTerm(NameT);
|
||||
}
|
||||
if (IsVarTerm(NameT)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,ARG2,"string_codes/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (NameT != TermNil) {
|
||||
Yap_Error(TYPE_ERROR_LIST,ARG2,"string_codes/2");
|
||||
return FALSE;
|
||||
}
|
||||
*ws++ = '\0';
|
||||
NewT = Yap_MkBlobWideStringTerm(WString, wcslen(WString));
|
||||
return Yap_unify(NewT, ARG1);
|
||||
/* **** */
|
||||
}
|
||||
NewT = Yap_MkBlobStringTerm(String, sizeof(String));
|
||||
return Yap_unify(NewT, ARG1);
|
||||
}
|
||||
Yap_Error(INSTANTIATION_ERROR, ARG1, "string_to_list/2");
|
||||
return(FALSE);
|
||||
|
||||
/* error handling */
|
||||
expand_auxsp:
|
||||
String = Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE);
|
||||
if (String + 1024 > (char *)AuxSp) {
|
||||
/* crash in flames */
|
||||
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "allocating temp space in string_to_list/2");
|
||||
return FALSE;
|
||||
}
|
||||
NameT = Deref(ARG1);
|
||||
t = Deref(ARG2);
|
||||
goto restart_aux;
|
||||
|
||||
}
|
||||
|
||||
static Int
|
||||
p_atom_chars( USES_REGS1 )
|
||||
{
|
||||
@@ -4126,6 +4383,8 @@ Yap_InitCPreds(void)
|
||||
/* general purpose */
|
||||
Yap_InitCPred("$opdec", 4, p_opdec, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("name", 2, p_name, 0);
|
||||
Yap_InitCPred("string_to_atom", 2, p_string_to_atom, 0);
|
||||
Yap_InitCPred("string_to_list", 2, p_string_to_list, 0);
|
||||
Yap_InitCPred("char_code", 2, p_char_code, SafePredFlag);
|
||||
Yap_InitCPred("atom_chars", 2, p_atom_chars, 0);
|
||||
Yap_InitCPred("atom_codes", 2, p_atom_codes, 0);
|
||||
@@ -4294,5 +4553,3 @@ Yap_InitCPreds(void)
|
||||
CurrentModule = cm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user