add support for creating a list of codes or atoms incrementally.
This commit is contained in:
parent
7598b56c38
commit
8efcdf7eaa
@ -501,6 +501,9 @@ X_API int STD_PROTO(YAP_AtomGetHold,(Atom));
|
||||
X_API int STD_PROTO(YAP_AtomReleaseHold,(Atom));
|
||||
X_API Agc_hook STD_PROTO(YAP_AGCRegisterHook,(Agc_hook));
|
||||
X_API char *STD_PROTO(YAP_cwd,(void));
|
||||
X_API Term STD_PROTO(YAP_OpenList,(int));
|
||||
X_API Term STD_PROTO(YAP_ExtendList,(Term, Term));
|
||||
X_API int STD_PROTO(YAP_CloseList,(Term, Term));
|
||||
|
||||
static int (*do_getf)(void);
|
||||
|
||||
@ -2433,3 +2436,45 @@ YAP_cwd(void)
|
||||
strncpy(buf, Yap_FileNameBuf, len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_OpenList(int n)
|
||||
{
|
||||
Term t;
|
||||
BACKUP_H();
|
||||
|
||||
if (H+2*n < ASP-1024) {
|
||||
if (!dogc())
|
||||
return FALSE;
|
||||
}
|
||||
t = AbsPair(H);
|
||||
H += 2*n;
|
||||
|
||||
RECOVER_H();
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API Term
|
||||
YAP_ExtendList(Term t0, Term inp)
|
||||
{
|
||||
Term t;
|
||||
CELL *ptr = RepPair(t0);
|
||||
|
||||
ptr[0] = inp;
|
||||
ptr[1] = AbsPair(ptr+2);
|
||||
t = AbsPair(ptr+2);
|
||||
|
||||
RECOVER_H();
|
||||
return t;
|
||||
}
|
||||
|
||||
X_API int
|
||||
YAP_CloseList(Term t0, Term tail)
|
||||
{
|
||||
CELL *ptr = RepPair(t0);
|
||||
|
||||
RESET_VARIABLE(ptr-1);
|
||||
if (!Yap_unify((Term)(ptr-1), tail))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -218,23 +218,6 @@ mkfunction(iswupper)
|
||||
mkfunction(iswpunct)
|
||||
mkfunction(iswspace)
|
||||
|
||||
#ifdef __SWI_PROLOG__
|
||||
|
||||
#define INIT_DEF(Type, Name, Size) \
|
||||
static void init_ ## Name (void) {} \
|
||||
static const Type Name[] {
|
||||
|
||||
#define ADD_DEF2(Atom, Type) \
|
||||
{ Atom, Type },
|
||||
#define ADD_DEF5(Atom, Type, Reverse, Arity, Ctx) \
|
||||
{ Atom, Type, Reverse, Arity, Ctx },
|
||||
\
|
||||
#define END_DEFS(Atom, F) \
|
||||
{ Atom, F }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
INIT_DEF(char_type, char_types, 26)
|
||||
ADD_DEF2(ATOM_alnum, fiswalnum)
|
||||
ADD_DEF2(ATOM_csym, fiscsym )
|
||||
|
@ -1,6 +1,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <SWI-Prolog.h>
|
||||
/* atom_t macro layer */
|
||||
#define NULL_ATOM ((atom_t)0)
|
||||
#include "atoms.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -262,11 +265,6 @@ PL_local_data_t lds;
|
||||
#define TRY(goal) if ((goal) == FALSE) fail
|
||||
|
||||
|
||||
/* atom_t macro layer */
|
||||
#define NULL_ATOM ((atom_t)0)
|
||||
|
||||
#include "atoms.h"
|
||||
|
||||
atom_t source_file_name; /** source name of the current file that we are
|
||||
consulting */
|
||||
int source_line_no; /** guess.... */
|
||||
@ -489,7 +487,6 @@ extern int writeAtomToStream(IOSTREAM *so, atom_t at);
|
||||
extern int valueExpression(term_t t, Number r ARG_LD);
|
||||
extern word lookupAtom(const char *s, size_t len);
|
||||
extern atom_t lookupUCSAtom(const pl_wchar_t *s, size_t len);
|
||||
extern atom_t codeToAtom(int chrcode);
|
||||
extern int toIntegerNumber(Number n, int flags);
|
||||
extern int get_atom_ptr_text(Atom a, PL_chars_t *text);
|
||||
|
||||
|
@ -417,7 +417,7 @@ setOSFeatures(void)
|
||||
/*******************************
|
||||
* MEMORY *
|
||||
*******************************/
|
||||
#if SWI_PROLOG
|
||||
#if __SWI_PROLOG__
|
||||
uintptr_t
|
||||
UsedMemory(void)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@
|
||||
#undef LD
|
||||
#define LD LOCAL_LD
|
||||
|
||||
#ifdef SWI_PROLOG
|
||||
#ifdef __SWI_PROLOG__
|
||||
static inline word
|
||||
valHandle__LD(term_t r ARG_LD)
|
||||
{ Word p = valTermRef(r);
|
||||
@ -254,7 +254,7 @@ textToAtom(PL_chars_t *text)
|
||||
}
|
||||
|
||||
|
||||
#if SWI_PROLOG
|
||||
#if __SWI_PROLOG__
|
||||
word
|
||||
textToString(PL_chars_t *text)
|
||||
{ PL_canonise_text(text);
|
||||
@ -279,7 +279,7 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
return rval;
|
||||
}
|
||||
case PL_STRING:
|
||||
#if SWI_PROLOG
|
||||
#if __SWI_PROLOG__
|
||||
{ word w = textToString(text);
|
||||
|
||||
return _PL_unify_atomic(term, w);
|
||||
@ -297,7 +297,6 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
}
|
||||
} else
|
||||
{ GET_LD
|
||||
term_t l = PL_new_term_ref();
|
||||
word p0, p;
|
||||
|
||||
switch(text->encoding)
|
||||
@ -305,36 +304,28 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
{ const unsigned char *s = (const unsigned char *)text->text.t;
|
||||
const unsigned char *e = &s[text->length];
|
||||
|
||||
#if SWI_PROLOG
|
||||
p0 = p = allocGlobal(text->length*3);
|
||||
for( ; s < e; s++)
|
||||
{ *p++ = FUNCTOR_dot2;
|
||||
if ( type == PL_CODE_LIST )
|
||||
*p++ = consInt(*s);
|
||||
else
|
||||
*p++ = codeToAtom(*s);
|
||||
*p = consPtr(p+1, TAG_COMPOUND|STG_GLOBAL);
|
||||
p++;
|
||||
p0 = p = INIT_SEQ_CODES(text->length);
|
||||
if ( type == PL_CODE_LIST ) {
|
||||
for( ; s < e; s++)
|
||||
p = EXTEND_SEQ_CODES(p, *s);
|
||||
} else {
|
||||
for( ; s < e; s++)
|
||||
p = EXTEND_SEQ_ATOMS(p, *s);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case ENC_WCHAR:
|
||||
{ const pl_wchar_t *s = (const pl_wchar_t *)text->text.t;
|
||||
const pl_wchar_t *e = &s[text->length];
|
||||
|
||||
#if SWI_PROLOG
|
||||
p0 = p = allocGlobal(text->length*3);
|
||||
for( ; s < e; s++)
|
||||
{ *p++ = FUNCTOR_dot2;
|
||||
if ( type == PL_CODE_LIST )
|
||||
*p++ = consInt(*s);
|
||||
else
|
||||
*p++ = codeToAtom(*s);
|
||||
*p = consPtr(p+1, TAG_COMPOUND|STG_GLOBAL);
|
||||
p++;
|
||||
p0 = p = INIT_SEQ_CODES(text->length);
|
||||
if ( type == PL_CODE_LIST ) {
|
||||
for( ; s < e; s++)
|
||||
p = EXTEND_SEQ_CODES(p, *s);
|
||||
} else {
|
||||
for( ; s < e; s++)
|
||||
p = EXTEND_SEQ_ATOMS(p, *s);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case ENC_UTF8:
|
||||
@ -342,21 +333,22 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
const char *e = &s[text->length];
|
||||
size_t len = utf8_strlen(s, text->length);
|
||||
|
||||
#if SWI_PROLOG
|
||||
p0 = p = allocGlobal(len*3);
|
||||
while(s<e)
|
||||
{ int chr;
|
||||
|
||||
s = utf8_get_char(s, &chr);
|
||||
*p++ = FUNCTOR_dot2;
|
||||
if ( type == PL_CODE_LIST )
|
||||
*p++ = consInt(chr);
|
||||
else
|
||||
*p++ = codeToAtom(chr);
|
||||
*p = consPtr(p+1, TAG_COMPOUND|STG_GLOBAL);
|
||||
p++;
|
||||
p0 = p = INIT_SEQ_CODES(len);
|
||||
if ( type == PL_CODE_LIST ) {
|
||||
while (s < e) {
|
||||
int chr;
|
||||
|
||||
s = utf8_get_char(s, &chr);
|
||||
p = EXTEND_SEQ_CODES(p, chr);
|
||||
}
|
||||
} else {
|
||||
while (s < e) {
|
||||
int chr;
|
||||
|
||||
s = utf8_get_char(s, &chr);
|
||||
p = EXTEND_SEQ_ATOMS(p, chr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case ENC_ANSI:
|
||||
@ -372,27 +364,21 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
n -= rc;
|
||||
s += rc;
|
||||
}
|
||||
|
||||
#if SWI_PROLOG
|
||||
p0 = p = allocGlobal(len*3);
|
||||
p0 = p = INIT_SEQ_CODES(len);
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
n = text->length;
|
||||
|
||||
while(n > 0)
|
||||
{ rc = mbrtowc(&wc, s, n, &mbs);
|
||||
while(n > 0) {
|
||||
rc = mbrtowc(&wc, s, n, &mbs);
|
||||
|
||||
*p++ = FUNCTOR_dot2;
|
||||
if ( type == PL_CODE_LIST )
|
||||
*p++ = consInt(wc);
|
||||
p = EXTEND_SEQ_CODES(p, wc);
|
||||
else
|
||||
*p++ = codeToAtom(wc);
|
||||
*p = consPtr(p+1, TAG_COMPOUND|STG_GLOBAL);
|
||||
p++;
|
||||
p = EXTEND_SEQ_ATOMS(p, wc);
|
||||
|
||||
s += rc;
|
||||
n -= rc;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -402,22 +388,7 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
}
|
||||
}
|
||||
|
||||
#if SWI_PROLOG
|
||||
setHandle(l, consPtr(p0, TAG_COMPOUND|STG_GLOBAL));
|
||||
p--;
|
||||
if ( tail )
|
||||
{ setVar(*p);
|
||||
if ( PL_unify(l, term) )
|
||||
{ setHandle(tail, makeRefG(p));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
} else
|
||||
{ *p = ATOM_nil;
|
||||
return PL_unify(l, term);
|
||||
}
|
||||
#endif
|
||||
return CLOSE_SEQ_OF_CODES(p, p0, tail, term );
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -31,6 +31,25 @@ typedef YAP_Atom Atom;
|
||||
typedef uintptr_t PL_atomic_t; /* same a word */
|
||||
|
||||
|
||||
#ifdef __SWI_PROLOG__
|
||||
|
||||
/* just to make clear how it would look in SWI */
|
||||
|
||||
#define INIT_DEF(Type, Name, Size) \
|
||||
static void init_ ## Name (void) {} \
|
||||
static const Type Name[] {
|
||||
|
||||
#define ADD_DEF2(Atom, Type) \
|
||||
{ Atom, Type },
|
||||
#define ADD_DEF5(Atom, Type, Reverse, Arity, Ctx) \
|
||||
{ Atom, Type, Reverse, Arity, Ctx },
|
||||
\
|
||||
#define END_DEFS(Atom, F) \
|
||||
{ Atom, F }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define INIT_DEF(Type, Name, Size) \
|
||||
static Type Name[Size]; \
|
||||
static void init_ ## Name (void) { \
|
||||
@ -109,20 +128,35 @@ typedef uintptr_t PL_atomic_t; /* same a word */
|
||||
#define stopItimer()
|
||||
|
||||
/* TBD */
|
||||
|
||||
extern atom_t codeToAtom(int chrcode);
|
||||
|
||||
static inline word
|
||||
INIT_SEQ_CODES(size_t n)
|
||||
{
|
||||
return 0L; /* TBD: shift */
|
||||
return (word)YAP_OpenList(n);
|
||||
}
|
||||
|
||||
static inline word
|
||||
EXTEND_SEQ_CODES(word gstore, int c) {
|
||||
return gstore;
|
||||
return (word)YAP_ExtendList((YAP_Term)gstore, YAP_MkIntTerm(c));
|
||||
}
|
||||
|
||||
static inline word
|
||||
EXTEND_SEQ_ATOMS(word gstore, int c) {
|
||||
return (word)YAP_ExtendList((YAP_Term)gstore, codeToAtom(c));
|
||||
}
|
||||
|
||||
static inline int
|
||||
CLOSE_SEQ_OF_CODES(word gstore, word lp, word t1, word t2) {
|
||||
return TRUE;
|
||||
CLOSE_SEQ_OF_CODES(word gstore, word lp, word arg2, word arg3) {
|
||||
if (arg3 == (word)ATOM_nil) {
|
||||
if (!YAP_CloseList((YAP_Term)gstore, YAP_TermNil()))
|
||||
return FALSE;
|
||||
} else {
|
||||
if (!YAP_CloseList((YAP_Term)gstore, YAP_GetFromSlot(arg2)))
|
||||
return FALSE;
|
||||
}
|
||||
return YAP_Unify(YAP_GetFromSlot(arg3), lp);
|
||||
}
|
||||
|
||||
static inline Word
|
||||
|
@ -864,7 +864,7 @@ then
|
||||
YAPLIB="$DYNYAPLIB"
|
||||
DYNLIB_LD="gcc -dynamiclib"
|
||||
PRE_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
|
||||
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
;;
|
||||
*)
|
||||
case "$target_cpu" in
|
||||
@ -878,7 +878,7 @@ then
|
||||
JAVA_TARGET=sparc
|
||||
;;
|
||||
esac
|
||||
EXTEND_DYNLOADER_PATH="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
EXTEND_DYNLOADER_PATH="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
PRE_DYNLOADER_PATH="LD_LIBRARY_PATH=\$(abs_top_builddir)"
|
||||
LDFLAGS="$LDFLAGS -Wl,-R,$prefix/lib -Wl,-R,$JAVA_HOME/jre/lib/$JAVA_TARGET"
|
||||
DYNYAPLIB=libYap"$SHLIB_SUFFIX"
|
||||
@ -888,7 +888,7 @@ then
|
||||
esac
|
||||
else
|
||||
PRE_DYNLOADER_PATH=""
|
||||
EXTEND_DYNLOADER_PATH="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
EXTEND_DYNLOADER_PATH="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||
DYNYAPLIB=libYap.notused
|
||||
fi
|
||||
|
||||
|
@ -471,6 +471,11 @@ extern X_API void *PROTO(YAP_BlobOfTerm,(YAP_Term));
|
||||
/* term comparison */
|
||||
extern X_API int PROTO(YAP_CompareTerms,(YAP_Term, YAP_Term));
|
||||
|
||||
/* list construction */
|
||||
extern X_API YAP_Term PROTO(YAP_OpenList,(int));
|
||||
extern X_API YAP_Term PROTO(YAP_ExtendList,(YAP_Term, YAP_Term));
|
||||
extern X_API int PROTO(YAP_CloseList,(YAP_Term, YAP_Term));
|
||||
|
||||
#define YAP_InitCPred(N,A,F) YAP_UserCPredicate(N,F,A)
|
||||
|
||||
__END_DECLS
|
||||
|
Reference in New Issue
Block a user