Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3
This commit is contained in:
commit
f2782cc274
@ -958,9 +958,9 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
|||||||
p0 = AbsPredProp(p);
|
p0 = AbsPredProp(p);
|
||||||
p->FunctorOfPred = (Functor)AbsAtom(ae);
|
p->FunctorOfPred = (Functor)AbsAtom(ae);
|
||||||
WRITE_UNLOCK(ae->ARWLock);
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
Yap_inform_profiler_of_clause((yamop *)&(p->OpcodeOfPred), (yamop *)(&(p->OpcodeOfPred)+1), p, GPROF_NEW_PRED_ATOM);
|
Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred)+1, p, GPROF_NEW_PRED_ATOM);
|
||||||
if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) {
|
if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) {
|
||||||
Yap_inform_profiler_of_clause((yamop *)&(p->cs.p_code.ExpandCode), (yamop *)(&(p->cs.p_code.ExpandCode)+1), p, GPROF_NEW_PRED_ATOM);
|
Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode), &(p->cs.p_code.ExpandCode)+1, p, GPROF_NEW_PRED_ATOM);
|
||||||
}
|
}
|
||||||
return p0;
|
return p0;
|
||||||
}
|
}
|
||||||
|
104
C/c_interface.c
104
C/c_interface.c
@ -442,6 +442,9 @@ X_API void STD_PROTO(YAP_FreeSpaceFromYap,(void *));
|
|||||||
X_API int STD_PROTO(YAP_StringToBuffer, (Term, char *, unsigned int));
|
X_API int STD_PROTO(YAP_StringToBuffer, (Term, char *, unsigned int));
|
||||||
X_API Term STD_PROTO(YAP_ReadBuffer, (char *,Term *));
|
X_API Term STD_PROTO(YAP_ReadBuffer, (char *,Term *));
|
||||||
X_API Term STD_PROTO(YAP_FloatsToList, (double *, size_t));
|
X_API Term STD_PROTO(YAP_FloatsToList, (double *, size_t));
|
||||||
|
X_API Int STD_PROTO(YAP_ListToFloats, (Term, double *, size_t));
|
||||||
|
X_API Term STD_PROTO(YAP_IntsToList, (Int *, size_t));
|
||||||
|
X_API Int STD_PROTO(YAP_ListToInts, (Term, Int *, size_t));
|
||||||
X_API Term STD_PROTO(YAP_BufferToString, (char *));
|
X_API Term STD_PROTO(YAP_BufferToString, (char *));
|
||||||
X_API Term STD_PROTO(YAP_NBufferToString, (char *, size_t));
|
X_API Term STD_PROTO(YAP_NBufferToString, (char *, size_t));
|
||||||
X_API Term STD_PROTO(YAP_WideBufferToString, (wchar_t *));
|
X_API Term STD_PROTO(YAP_WideBufferToString, (wchar_t *));
|
||||||
@ -3594,6 +3597,89 @@ YAP_FloatsToList(double *dblp, size_t sz)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X_API Int
|
||||||
|
YAP_ListToFloats(Term t, double *dblp, size_t sz)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
t = Deref(t);
|
||||||
|
do {
|
||||||
|
Term hd;
|
||||||
|
if (IsVarTerm(t))
|
||||||
|
return -1;
|
||||||
|
if (t == TermNil)
|
||||||
|
return i;
|
||||||
|
if (!IsPairTerm(t))
|
||||||
|
return -1;
|
||||||
|
hd = HeadOfTerm(t);
|
||||||
|
if (!IsFloatTerm(hd))
|
||||||
|
return -1;
|
||||||
|
dblp[i++] = FloatOfTerm(hd);
|
||||||
|
if (i == sz)
|
||||||
|
return sz;
|
||||||
|
t = TailOfTerm(t);
|
||||||
|
} while (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
X_API Term
|
||||||
|
YAP_IntsToList(Int *dblp, size_t sz)
|
||||||
|
{
|
||||||
|
CACHE_REGS
|
||||||
|
Term t;
|
||||||
|
CELL *oldH;
|
||||||
|
BACKUP_H();
|
||||||
|
|
||||||
|
if (!sz)
|
||||||
|
return TermNil;
|
||||||
|
while (ASP-1024 < H + sz*3) {
|
||||||
|
if ((CELL *)dblp > H0 && (CELL *)dblp < H) {
|
||||||
|
/* we are in trouble */
|
||||||
|
LOCAL_OpenArray = (CELL *)dblp;
|
||||||
|
}
|
||||||
|
if (!dogc( 0, NULL PASS_REGS )) {
|
||||||
|
RECOVER_H();
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
dblp = (Int *)LOCAL_OpenArray;
|
||||||
|
LOCAL_OpenArray = NULL;
|
||||||
|
}
|
||||||
|
t = AbsPair(H);
|
||||||
|
while (sz) {
|
||||||
|
oldH = H;
|
||||||
|
H +=2;
|
||||||
|
oldH[0] = MkIntegerTerm(*dblp++);
|
||||||
|
oldH[1] = AbsPair(H);
|
||||||
|
sz--;
|
||||||
|
}
|
||||||
|
oldH[1] = TermNil;
|
||||||
|
RECOVER_H();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
X_API Int
|
||||||
|
YAP_ListToInts(Term t, Int *dblp, size_t sz)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
t = Deref(t);
|
||||||
|
do {
|
||||||
|
Term hd;
|
||||||
|
if (IsVarTerm(t))
|
||||||
|
return -1;
|
||||||
|
if (t == TermNil)
|
||||||
|
return i;
|
||||||
|
if (!IsPairTerm(t))
|
||||||
|
return -1;
|
||||||
|
hd = HeadOfTerm(t);
|
||||||
|
if (!IsIntTerm(hd))
|
||||||
|
return -1;
|
||||||
|
dblp[i++] = IntOfTerm(hd);
|
||||||
|
if (i == sz)
|
||||||
|
return sz;
|
||||||
|
t = TailOfTerm(t);
|
||||||
|
} while (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
X_API Term
|
X_API Term
|
||||||
YAP_OpenList(int n)
|
YAP_OpenList(int n)
|
||||||
{
|
{
|
||||||
@ -3975,16 +4061,14 @@ Term YAP_BPROLOG_curr_toam_status;
|
|||||||
|
|
||||||
Int
|
Int
|
||||||
YAP_ListLength(Term t) {
|
YAP_ListLength(Term t) {
|
||||||
Int l = 0;
|
Term *aux;
|
||||||
while (TRUE) {
|
|
||||||
if (IsVarTerm(t)) return -1;
|
Int n = Yap_SkipList(&t, &aux);
|
||||||
if (t == TermNil)
|
if (IsVarTerm(*aux))
|
||||||
return l;
|
return -1;
|
||||||
if (!IsPairTerm(t))
|
if (*aux == TermNil)
|
||||||
return -1;
|
return n;
|
||||||
l++;
|
return -1;
|
||||||
t = TailOfTerm(t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Int
|
Int
|
||||||
|
16
docs/yap.tex
16
docs/yap.tex
@ -16536,13 +16536,27 @@ The user-provided string must include a terminating null
|
|||||||
character. Syntax errors will cause returning @code{FALSE} and binding
|
character. Syntax errors will cause returning @code{FALSE} and binding
|
||||||
@var{error} to a Prolog term.
|
@var{error} to a Prolog term.
|
||||||
|
|
||||||
|
@findex YAP_IntsToList (C-Interface function)
|
||||||
@findex YAP_FloatsToList (C-Interface function)
|
@findex YAP_FloatsToList (C-Interface function)
|
||||||
These C-interface functions are useful when converting chunks of data to Prolog:
|
These C-interface functions are useful when converting chunks of data to Prolog:
|
||||||
@example
|
@example
|
||||||
YAP_Term YAP_FloatsToList(double *@var{buf},size_t @var{sz})
|
YAP_Term YAP_FloatsToList(double *@var{buf},size_t @var{sz})
|
||||||
|
YAP_Term YAP_IntsToList(YAP_Int *@var{buf},size_t @var{sz})
|
||||||
@end example
|
@end example
|
||||||
@noindent
|
@noindent
|
||||||
Notice that they are unsafe, and may call the garbage collector.
|
Notice that they are unsafe, and may call the garbage collector. They
|
||||||
|
return 0 on error.
|
||||||
|
|
||||||
|
@findex YAP_ListToInts (C-Interface function)
|
||||||
|
@findex YAP_ToListFloats (C-Interface function)
|
||||||
|
These C-interface functions are useful when converting Prolog lists to arrays:
|
||||||
|
@example
|
||||||
|
YAP_Int YAP_IntsToList(YAP_Term t, YAP_Int *@var{buf},size_t @var{sz})
|
||||||
|
YAP_Int YAP_FloatsToList(YAP_Term t, double *@var{buf},size_t @var{sz})
|
||||||
|
@end example
|
||||||
|
@noindent
|
||||||
|
They return the number of integers scanned, up to a maximum of @t{sz},
|
||||||
|
and @t{-1} on error.
|
||||||
|
|
||||||
@node Memory Allocation, Controlling Streams, Manipulating Strings, C-Interface
|
@node Memory Allocation, Controlling Streams, Manipulating Strings, C-Interface
|
||||||
@section Memory Allocation
|
@section Memory Allocation
|
||||||
|
@ -357,6 +357,10 @@ extern X_API void PROTO(YAP_PutValue,(YAP_Atom, YAP_Term));
|
|||||||
extern X_API YAP_Term PROTO(YAP_GetValue,(YAP_Atom));
|
extern X_API YAP_Term PROTO(YAP_GetValue,(YAP_Atom));
|
||||||
|
|
||||||
extern X_API YAP_Term PROTO(YAP_FloatsToList,(YAP_Float *, size_t));
|
extern X_API YAP_Term PROTO(YAP_FloatsToList,(YAP_Float *, size_t));
|
||||||
|
extern X_API YAP_Int PROTO(YAP_ListToFloats,(YAP_Term, YAP_Float *, size_t));
|
||||||
|
|
||||||
|
extern X_API YAP_Term PROTO(YAP_IntsToList,(YAP_Int *, size_t));
|
||||||
|
extern X_API YAP_Int PROTO(YAP_ListToInts,(YAP_Term, YAP_Int *, size_t));
|
||||||
|
|
||||||
/* int StringToBuffer(YAP_Term,char *,unsigned int) */
|
/* int StringToBuffer(YAP_Term,char *,unsigned int) */
|
||||||
extern X_API int PROTO(YAP_StringToBuffer,(YAP_Term,char *,unsigned int));
|
extern X_API int PROTO(YAP_StringToBuffer,(YAP_Term,char *,unsigned int));
|
||||||
|
Reference in New Issue
Block a user