This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/PLStream/pl-yap.h

217 lines
6.1 KiB
C
Raw Normal View History

2008-12-22 12:02:22 +00:00
#ifndef PL_YAP_H
#define PL_YAP_H
#ifdef __YAP_PROLOG__
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;
2011-02-10 00:01:19 +00:00
typedef YAP_Term *Word; /* Anonymous 4 byte object */
typedef YAP_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);
extern YAP_Int Yap_GetCurrentPredArity(void);
2011-02-27 02:34:44 +00:00
extern int Yap_read_term(term_t t, IOSTREAM *st, term_t *exc, term_t vs);
2011-02-13 01:03:08 +00:00
extern int Yap_LookupSWIStream(void *swi_s);
2011-02-15 19:24:15 +00:00
extern term_t Yap_fetch_module_for_format(term_t args, YAP_Term *modp);
2011-02-15 22:44:06 +00:00
extern IOENC Yap_DefaultEncoding(void);
extern void Yap_SetDefaultEncoding(IOENC);
2011-02-10 00:01:19 +00:00
extern atom_t codeToAtom(int chrcode);
#define valTermRef(t) ((Word)YAP_AddressFromSlot(t))
#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) {
YAP_Term t = YAP_GetFromSlot(descr);
if (YAP_IsVarTerm(t)) return 0;
if (YAP_IsAtomTerm(t))
*proc = YAP_Predicate(YAP_AtomOfTerm(t),0,YAP_CurrentModule());
else if (YAP_IsApplTerm(t)) {
YAP_Functor f = YAP_FunctorOfTerm(t);
*proc = YAP_Predicate(YAP_NameOfFunctor(f),YAP_ArityOfFunctor(f),YAP_CurrentModule());
}
return 1;
}
2011-02-10 00:01:19 +00:00
COMMON(intptr_t) lengthList(term_t list, int errors);
COMMON(int) promoteToFloatNumber(Number n);
COMMON(char *) PrologPath(const char *ospath, char *plpath, size_t len);
COMMON(char *) ExpandOneFile(const char *spec, char *file);
COMMON(char *) AbsoluteFile(const char *spec, char *path);
COMMON(char *) BaseName(const char *f);
COMMON(bool) ChDir(const char *path);
COMMON(char *) OsPath(const char *plpath, char *ospath);
COMMON(bool) ChDir(const char *path);
COMMON(int) DeleteTemporaryFile(atom_t name);
COMMON(int) IsAbsolutePath(const char *spec);
/* TBD */
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 freeHeap(p, n) freeHeap__LD(p, n PASS_LD)
#define valHandle(r) valHandle__LD(r PASS_LD)
2010-07-28 17:14:18 +01:00
YAP_Int YAP_PLArityOfSWIFunctor(functor_t f);
YAP_Atom YAP_AtomFromSWIAtom(atom_t at);
2011-03-02 23:19:39 +00:00
atom_t YAP_SWIAtomFromAtom(YAP_Atom at);
2011-02-10 00:01:19 +00:00
PL_blob_t* YAP_find_blob_type(YAP_Atom at);
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
#define arityFunctor(f) YAP_PLArityOfSWIFunctor(f)
2008-12-22 12:02:22 +00:00
2011-03-26 15:17:17 +00:00
#define stringAtom(w) YAP_AtomName(YAP_AtomFromSWIAtom(w))
2011-03-11 19:49:32 +00:00
#define isInteger(A) (YAP_IsIntTerm((A)) || YAP_IsBigNumTerm((A)))
#define isString(A) Yap_IsStringTerm(A)
2008-12-22 12:02:22 +00:00
#define isAtom(A) YAP_IsAtomTerm((A))
#define isList(A) YAP_IsPairTerm((A))
#define isNil(A) ((A) == YAP_TermNil())
#define isReal(A) YAP_IsFloatTerm((A))
#define isFloat(A) YAP_IsFloatTerm((A))
2008-12-22 12:02:22 +00:00
#define isVar(A) YAP_IsVarTerm((A))
#define valReal(w) YAP_FloatOfTerm((w))
#define valFloat(w) YAP_FloatOfTerm((w))
2008-12-22 12:02:22 +00:00
#define AtomLength(w) YAP_AtomNameLength(w)
2011-02-11 01:22:07 +00:00
#define atomValue(atom) YAP_AtomFromSWIAtom(atom)
2011-03-02 23:19:39 +00:00
#define atomFromTerm(term) YAP_SWIAtomFromAtom(YAP_AtomOfTerm(term))
2011-02-10 00:01:19 +00:00
#define atomName(atom) ((char *)YAP_AtomName(atom))
#define nameOfAtom(atom) ((char *)YAP_AtomName(atom))
#define atomLength(atom) YAP_AtomNameLength(atom)
#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 MODULE_user YAP_ModuleUser()
#define _PL_predicate(A,B,C,D) PL_predicate(A,B,C)
#define predicateHasClauses(A) (YAP_NumberOfClausesForPredicate((YAP_PredEntryPtr)A) != 0)
2011-02-15 18:39:50 +00:00
#define lookupModule(A) ((Module)PL_new_module(A))
2011-02-10 00:01:19 +00:00
#define charEscapeWriteOption(A) FALSE // VSC: to implement
#define wordToTermRef(A) YAP_InitSlot(*(A))
2011-03-14 21:03:28 +00:00
#define isTaggedInt(A) IsIntegerTerm(A)
#define valInt(A) IntegerOfTerm(A)
2011-03-26 15:17:17 +00:00
#define MODULE_parse ((Module)CurrentModule)
2008-12-22 12:02:22 +00:00
extern term_t Yap_CvtTerm(term_t ts);
2008-12-22 12:02:22 +00:00
#define clearNumber(n)
2011-02-10 00:01:19 +00:00
inline static int
charCode(Term w)
{ if ( IsAtomTerm(w) )
2011-02-10 00:01:19 +00:00
{
YAP_Atom a = atomValue(w);
2011-02-10 00:01:19 +00:00
if ( YAP_AtomNameLength(a) == 1) {
if (YAP_IsWideAtom(a)) {
return YAP_WideAtomName(a)[0];
}
return YAP_AtomName(a)[0];
}
}
return -1;
}
2011-03-03 11:41:21 +00:00
#define getInputStream(t, s) getInputStream__LD(t, s PASS_LD)
2011-02-10 00:01:19 +00:00
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)
#define PL_is_variable(t) PL_is_variable__LD(t PASS_LD)
#define PL_new_term_ref() PL_new_term_ref__LD(PASS_LD1)
#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
2008-12-22 12:02:22 +00:00
#endif /* __YAP_PROLOG__ */
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;
}
2009-06-01 22:56:00 +01:00
#endif
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
2011-02-16 00:23:58 +00:00
2008-12-22 12:02:22 +00:00
#endif /* PL_YAP_H */