2008-12-22 12:02:22 +00:00
|
|
|
#ifndef PL_YAP_H
|
|
|
|
#define PL_YAP_H
|
|
|
|
|
|
|
|
#ifdef __YAP_PROLOG__
|
|
|
|
|
2013-11-16 00:27:02 +00:00
|
|
|
#include "Yatom.h"
|
|
|
|
|
2015-03-28 19:38:54 +00:00
|
|
|
#include <libgen.h>
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
/* depends on tag schema, but 4 should always do */
|
|
|
|
#define LMASK_BITS 4 /* total # mask bits */
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#if HAVE_CTYPE_H
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#define SIZE_VOIDP SIZEOF_INT_P
|
|
|
|
|
|
|
|
|
|
|
|
#if SIZEOF_LONG_INT==4
|
|
|
|
#define INT64_FORMAT "%lld"
|
|
|
|
#else
|
|
|
|
#define INT64_FORMAT "%ld"
|
|
|
|
#endif
|
2011-02-10 00:01:19 +00:00
|
|
|
#define INTBITSIZE (sizeof(int)*8)
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-03-26 15:17:17 +00:00
|
|
|
typedef module_t Module;
|
2013-11-16 00:27:02 +00:00
|
|
|
typedef Term (*Func)(term_t); /* foreign functions */
|
2011-02-10 00:01:19 +00:00
|
|
|
|
2011-02-12 18:42:44 +00:00
|
|
|
extern const char *Yap_GetCurrentPredName(void);
|
2013-11-16 00:27:02 +00:00
|
|
|
extern Int Yap_GetCurrentPredArity(void);
|
|
|
|
extern term_t Yap_fetch_module_for_format(term_t args, Term *modp);
|
2014-01-07 01:10:48 +00:00
|
|
|
extern void Yap_setCurrentSourceLocation( void *rd );
|
2012-02-18 11:01:06 +00:00
|
|
|
extern void *Yap_GetStreamHandle(Atom at);
|
2014-02-20 10:38:18 +00:00
|
|
|
extern void Yap_WriteAtom(IOSTREAM *s, Atom atom);
|
2012-02-18 11:01:06 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
extern atom_t codeToAtom(int chrcode);
|
|
|
|
|
2015-02-03 02:36:51 +00:00
|
|
|
#define valTermRef(t) ((Word)Yap_AddressFromSlot(t))
|
2011-02-10 00:01:19 +00:00
|
|
|
|
|
|
|
#include "pl-codelist.h"
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
//move this to SWI
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
#define GP_CREATE 2 /* create (in this module) */
|
|
|
|
|
|
|
|
#ifndef HAVE_MBSCOLL
|
|
|
|
COMMON(int) mbscoll(const char *s1, const char *s2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_MBSCASECOLL
|
|
|
|
COMMON(int) mbscasecoll(const char *s1, const char *s2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
COMMON(atom_t) TemporaryFile(const char *id, int *fdp);
|
|
|
|
COMMON(char *) Getenv(const char *, char *buf, size_t buflen);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
|
|
|
/*** memory allocation stuff: SWI wraps around malloc */
|
|
|
|
|
|
|
|
#define stopItimer()
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
COMMON(word) pl_print(term_t term);
|
|
|
|
COMMON(word) pl_write(term_t term);
|
|
|
|
COMMON(word) pl_write_canonical(term_t term);
|
|
|
|
COMMON(word) pl_write_term(term_t term, term_t options);
|
|
|
|
COMMON(word) pl_writeq(term_t term);
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
get_procedure(term_t descr, predicate_t *proc, term_t he, int f) {
|
2013-11-16 00:27:02 +00:00
|
|
|
CACHE_REGS
|
2015-04-13 13:28:17 +01:00
|
|
|
Term t = Yap_GetFromSlot(descr );
|
2013-11-16 00:27:02 +00:00
|
|
|
|
|
|
|
if (IsVarTerm(t)) return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
if (IsAtomTerm(t))
|
2013-11-16 00:27:02 +00:00
|
|
|
*proc = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t),CurrentModule));
|
|
|
|
else if (IsApplTerm(t)) {
|
|
|
|
Functor f = FunctorOfTerm(t);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
2013-11-16 00:27:02 +00:00
|
|
|
*proc = RepPredProp(Yap_GetPredPropByFunc(f, CurrentModule));
|
2011-02-10 00:01:19 +00:00
|
|
|
}
|
2013-11-16 00:27:02 +00:00
|
|
|
return TRUE;
|
2011-02-10 00:01:19 +00:00
|
|
|
}
|
2008-12-22 13:49:44 +00:00
|
|
|
|
2013-11-13 10:38:20 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
/* TBD */
|
2008-12-22 13:49:44 +00:00
|
|
|
|
2010-06-23 11:44:44 +01:00
|
|
|
extern word globalString(size_t size, char *s);
|
|
|
|
extern word globalWString(size_t size, wchar_t *s);
|
|
|
|
|
2011-03-03 11:41:21 +00:00
|
|
|
#define allocHeap(n) allocHeap__LD(n PASS_LD)
|
|
|
|
|
|
|
|
#define valHandle(r) valHandle__LD(r PASS_LD)
|
2010-07-28 17:14:18 +01:00
|
|
|
|
2013-11-16 00:27:02 +00:00
|
|
|
Int YAP_PLArityOfSWIFunctor(functor_t f);
|
|
|
|
struct PL_blob_t* YAP_find_blob_type(Atom at);
|
2011-02-10 00:01:19 +00:00
|
|
|
|
2011-02-16 00:23:58 +00:00
|
|
|
void PL_license(const char *license, const char *module);
|
2010-07-28 17:14:18 +01:00
|
|
|
|
2013-11-13 10:38:20 +00:00
|
|
|
|
2010-07-28 17:14:18 +01:00
|
|
|
#define arityFunctor(f) YAP_PLArityOfSWIFunctor(f)
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2013-11-20 22:27:46 +00:00
|
|
|
#define stringAtom(w) (YAP_AtomFromSWIAtom(w)->StrOfAE)
|
2013-11-16 00:27:02 +00:00
|
|
|
#define isInteger(A) (!IsVarTerm(A) && ( IsIntegerTerm((A)) || YAP_IsBigNumTerm((A)) ))
|
2013-12-02 14:49:41 +00:00
|
|
|
#define isString(A) (!IsVarTerm(A) && IsStringTerm(A) )
|
2013-11-16 00:27:02 +00:00
|
|
|
#define isAtom(A) (!IsVarTerm(A) && IsAtomTerm((A)) )
|
|
|
|
#define isList(A) (!IsVarTerm(A) && IsPairTerm((A)) )
|
|
|
|
#define isNil(A) ((A) == TermNil)
|
|
|
|
#define isReal(A) (!IsVarTerm(A) && IsFloatTerm((A)) )
|
|
|
|
#define isFloat(A) (!IsVarTerm(A) && IsFloatTerm((A)) )
|
|
|
|
#define isVar(A) IsVarTerm((A))
|
|
|
|
#define valReal(w) FloatOfTerm((w))
|
|
|
|
#define valFloat(w) FloatOfTerm((w))
|
2013-12-05 21:26:46 +00:00
|
|
|
#define atomValue(atom) AtomOfTerm(atom)
|
2013-11-16 00:27:02 +00:00
|
|
|
#define atomFromTerm(term) YAP_SWIAtomFromAtom(AtomOfTerm(term))
|
2011-09-02 23:22:35 +01:00
|
|
|
|
2013-11-16 00:27:02 +00:00
|
|
|
inline static char *
|
|
|
|
atomName(Atom atom)
|
2011-09-02 23:22:35 +01:00
|
|
|
{
|
2015-04-13 13:28:17 +01:00
|
|
|
if (IsWideAtom(atom))
|
2013-11-16 00:27:02 +00:00
|
|
|
return (char *)(atom->WStrOfAE);
|
|
|
|
return atom->StrOfAE;
|
2011-09-02 23:22:35 +01:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:27:02 +00:00
|
|
|
#define nameOfAtom(atom) nameOfAtom(atom)
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
#define atomBlobType(at) YAP_find_blob_type(at)
|
2008-12-22 12:02:22 +00:00
|
|
|
#define argTermP(w,i) ((Word)((YAP_ArgsOfTerm(w)+(i))))
|
2011-03-14 21:03:28 +00:00
|
|
|
#define deRef(t) while (IsVarTerm(*(t)) && !IsUnboundVar(t)) { t = (CELL *)(*(t)); }
|
2011-02-10 00:01:19 +00:00
|
|
|
#define canBind(t) FALSE // VSC: to implement
|
|
|
|
#define _PL_predicate(A,B,C,D) PL_predicate(A,B,C)
|
2013-11-16 00:27:02 +00:00
|
|
|
#define predicateHasClauses(pe) ((pe)->cs.p_code.NOfClauses != 0)
|
2013-11-13 10:38:20 +00:00
|
|
|
#define lookupModule(A) Yap_GetModuleEntry(MkAtomTerm(YAP_AtomFromSWIAtom(A)))
|
2013-01-15 16:51:55 +00:00
|
|
|
|
2013-11-18 12:57:09 +00:00
|
|
|
Procedure resolveProcedure(functor_t f, Module module);
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
#define charEscapeWriteOption(A) FALSE // VSC: to implement
|
2015-04-13 13:28:17 +01:00
|
|
|
#define wordToTermRef(A) Yap_InitSlot(*(A))
|
2011-03-14 21:03:28 +00:00
|
|
|
#define isTaggedInt(A) IsIntegerTerm(A)
|
|
|
|
#define valInt(A) IntegerOfTerm(A)
|
2013-11-13 10:38:20 +00:00
|
|
|
|
2013-11-13 23:48:54 +00:00
|
|
|
#define MODULE_user Yap_GetModuleEntry(MkAtomTerm(Yap_LookupAtom("user")))
|
|
|
|
#define MODULE_system Yap_GetModuleEntry(MkAtomTerm(Yap_LookupAtom("system")))
|
2013-11-13 10:38:20 +00:00
|
|
|
#define MODULE_parse Yap_GetModuleEntry(LOCAL_SourceModule)
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-27 11:40:27 +00:00
|
|
|
extern term_t Yap_CvtTerm(term_t ts);
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#define clearNumber(n)
|
|
|
|
|
2011-08-12 15:52:47 +01:00
|
|
|
wchar_t *nameOfWideAtom(atom_t atom);
|
|
|
|
int isWideAtom(atom_t atom);
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
inline static int
|
2011-03-01 10:26:25 +00:00
|
|
|
charCode(Term w)
|
|
|
|
{ if ( IsAtomTerm(w) )
|
2015-04-13 13:28:17 +01:00
|
|
|
{
|
2013-11-16 00:27:02 +00:00
|
|
|
Atom a = atomValue(w);
|
2011-02-10 00:01:19 +00:00
|
|
|
|
2013-11-16 00:27:02 +00:00
|
|
|
if (IsWideAtom(a)) {
|
|
|
|
if (wcslen(a->WStrOfAE) == 1)
|
|
|
|
return a->WStrOfAE[0];
|
|
|
|
return -1;
|
2011-02-10 00:01:19 +00:00
|
|
|
}
|
2013-11-16 00:27:02 +00:00
|
|
|
if (strlen(a->StrOfAE) == 1)
|
2013-12-05 21:26:46 +00:00
|
|
|
return ((unsigned char *)(a->StrOfAE))[0];
|
2013-11-16 00:27:02 +00:00
|
|
|
return -1;
|
2011-02-10 00:01:19 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-03 11:41:21 +00:00
|
|
|
#define PL_get_atom(t, a) PL_get_atom__LD(t, a PASS_LD)
|
|
|
|
#define PL_get_atom_ex(t, a) PL_get_atom_ex__LD(t, a PASS_LD)
|
|
|
|
#define PL_get_text(l, t, f) PL_get_text__LD(l, t, f PASS_LD)
|
2013-11-16 00:27:02 +00:00
|
|
|
#define PL_is_atom(t) PL_is_atom__LD(t PASS_LD)
|
2011-03-03 11:41:21 +00:00
|
|
|
#define PL_is_variable(t) PL_is_variable__LD(t PASS_LD)
|
|
|
|
#define PL_new_term_ref() PL_new_term_ref__LD(PASS_LD1)
|
2013-11-15 15:45:55 +00:00
|
|
|
#define PL_put_atom(t, a) PL_put_atom__LD(t, a PASS_LD)
|
2011-03-03 11:41:21 +00:00
|
|
|
#define PL_put_term(t1, t2) PL_put_term__LD(t1, t2 PASS_LD)
|
|
|
|
#define PL_unify_atom(t, a) PL_unify_atom__LD(t, a PASS_LD)
|
|
|
|
#define PL_unify_integer(t, i) PL_unify_integer__LD(t, i PASS_LD)
|
2011-02-10 00:01:19 +00:00
|
|
|
|
2013-11-15 15:45:55 +00:00
|
|
|
#define _PL_get_arg(i, t, a) _PL_get_arg__LD(i, t, a PASS_LD);
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#endif /* __YAP_PROLOG__ */
|
|
|
|
|
2013-11-13 10:38:20 +00:00
|
|
|
unsigned int getUnknownModule(module_t m);
|
|
|
|
|
2009-06-01 22:56:00 +01:00
|
|
|
#if IN_PL_OS_C
|
2009-05-29 20:36:49 +01:00
|
|
|
static int
|
|
|
|
stripostfix(const char *s, const char *e)
|
|
|
|
{ size_t ls = strlen(s);
|
|
|
|
size_t le = strlen(e);
|
|
|
|
|
|
|
|
if ( ls >= le )
|
|
|
|
return strcasecmp(&s[ls-le], e) == 0;
|
|
|
|
|
|
|
|
return FALSE;
|
2015-04-13 13:28:17 +01:00
|
|
|
}
|
2009-06-01 22:56:00 +01:00
|
|
|
#endif
|
2009-03-13 19:37:52 +00:00
|
|
|
|
2011-02-15 23:45:47 +00:00
|
|
|
#if HAVE_SIGPROCMASK
|
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
unblockSignal(int sig)
|
|
|
|
{ sigset_t set;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, sig);
|
|
|
|
|
|
|
|
sigprocmask(SIG_UNBLOCK, &set, NULL);
|
|
|
|
// DEBUG(1, Sdprintf("Unblocked signal %d\n", sig));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void
|
|
|
|
unblockSignal(int sig)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-02 00:01:30 +01:00
|
|
|
|
2013-01-15 16:51:55 +00:00
|
|
|
#define suspendTrace(x)
|
|
|
|
|
|
|
|
atom_t ATOM_;
|
2011-02-16 00:23:58 +00:00
|
|
|
|
2013-11-13 10:38:20 +00:00
|
|
|
#if THREADS
|
2015-06-17 23:49:02 +01:00
|
|
|
intptr_t system_thread_id(void);
|
2013-11-13 10:38:20 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-17 23:49:02 +01:00
|
|
|
extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio,Term *bindingsp);
|
2014-06-04 22:08:37 +01:00
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#endif /* PL_YAP_H */
|