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/library/dialect/swi/fli/swi.h

102 lines
2.2 KiB
C
Raw Normal View History

2014-05-12 17:49:11 +01:00
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2014 *
* *
*************************************************************************/
/**
@file swi.h
@defgroup swi-c-interface SWI-Prolog Foreign Language Interface
2014-05-14 10:01:11 +01:00
*
* @tableofcontents
*
* A reimplementation of Jan Wielemaker's SWI-Prolog C-language interface, it supports
* most of the functionality in the original implementation. It allows for:
*
* - Term Construction, Access, and Unification
* - Manipulation of Atoms, Strings, Lists of Codes and Lists of Atoms
* - Query evaluation
* - Thread and Prolog engine management
* - Data-Base Access
*
* In this interface, all Prolog data known by C is referenced through term references (term_t), hence
* Prolog has all the information necessary to perform its memory management without special precautions
* from the C programmer.
2014-05-12 17:49:11 +01:00
@{
*/
2010-11-30 21:59:45 +00:00
void Yap_swi_install(void);
void Yap_install_blobs(void);
typedef struct open_query_struct {
2014-03-13 12:54:06 +00:00
int q_open;
int q_state;
YAP_Term *q_g;
PredEntry *q_pe;
yamop *q_p, *q_cp;
jmp_buf q_env;
int q_flags;
YAP_dogoalinfo q_h;
2014-03-20 13:33:17 +00:00
struct open_query_struct *oq;
2010-11-30 21:59:45 +00:00
} open_query;
#define addr_hash(V) (((CELL) (V)) >> 4 & (N_SWI_HASH-1))
static inline void
add_to_hash(Int i, ADDR key)
{
2013-10-04 13:22:00 +01:00
2010-11-30 21:59:45 +00:00
UInt h = addr_hash(key);
while (SWI_ReverseHash[h].key) {
h = (h+1)%N_SWI_HASH;
}
SWI_ReverseHash[h].key = key;
SWI_ReverseHash[h].pos = i;
}
static atom_t
in_hash(ADDR key)
{
UInt h = addr_hash(key);
while (SWI_ReverseHash[h].key) {
if (SWI_ReverseHash[h].key == key)
return SWI_ReverseHash[h].pos;
h = (h+1)%N_SWI_HASH;
}
return 0;
}
static inline Term
SWIModuleToModule(module_t m)
{
CACHE_REGS
2010-11-30 21:59:45 +00:00
if (m)
return MkAtomTerm(m->AtomOfME);
2010-11-30 21:59:45 +00:00
if (CurrentModule)
return CurrentModule;
return USER_MODULE;
}
static inline functor_t
FunctorToSWIFunctor(Functor at)
{
atom_t ats;
if ((ats = in_hash((ADDR)at)))
return (functor_t)((CELL)ats*4+2);
2010-11-30 21:59:45 +00:00
return (functor_t)at;
}
2013-11-21 00:22:03 +00:00
#define isDefinedProcedure(pred) TRUE // TBD
2014-05-14 10:01:11 +01:00
/**
@}
*/