YAP 7.1.0
c_interface.c File Reference
#include <stdlib.h>
#include <string.h>
#include "Yap.h"
#include "YapHeap.h"
#include "YapSignals.h"
#include "YapInterface.h"
#include "YapText.h"
#include "attvar.h"
#include "clause.h"
#include "yapio.h"
#include "cut_c.h"
#include "iopreds.h"
#include <libgen.h>
#include <Yatom.h>
#include <heapgc.h>

Go to the source code of this file.

Macros

#define C_INTERFACE_C   1
 
#define _EXPORT_KERNEL   1
 
#define strncpy(X, Y, Z)   strcpy(X, Y)
 
#define strncat(X, Y, Z)   strcat(X, Y)
 
#define SOURCEBOOTPath   NULL
 
#define FRG_REDO_MASK   0x00000003L
 
#define FRG_REDO_BITS   2
 
#define REDO_INT   0x02 /* Returned an integer */
 
#define REDO_PTR   0x03 /* returned a pointer */
 
#define YAP_BUF_SIZE   512
 

Typedefs

typedef void * atom_t
 
typedef void * functor_t
 
typedef Int(* CPredicate0) (void)
 
typedef Int(* CPredicate1) (yhandle_t)
 
typedef Int(* CPredicate2) (yhandle_t, yhandle_t)
 
typedef Int(* CPredicate3) (yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate4) (yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate5) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate6) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate7) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate8) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate9) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicate10) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t)
 
typedef Int(* CPredicateV) (yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate0) (struct foreign_context *)
 
typedef uintptr_t(* CBPredicate1) (yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate2) (yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate3) (yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate4) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate5) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate6) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate7) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate8) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate9) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 
typedef uintptr_t(* CBPredicate10) (yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, struct foreign_context *)
 

Enumerations

enum  frg_code {
  FRG_FIRST_CALL = 0 , FRG_CUTTED = 1 , FRG_REDO = 2 , FRG_FIRST_CALL = 0 ,
  FRG_CUTTED = 1 , FRG_REDO = 2
}
 

Functions

X_API int YAP_Reset (yap_reset_t mode, bool reset_global)
 
X_API void YAP_StartSlots (void)
 initialize the slot data-structure: all existing slots will be discarded More...
 
X_API void YAP_EndSlots (void)
 discard all existing slots: operates as More...
 
X_API yhandle_t YAP_CurrentSlot (void)
 report the current position of the slots, assuming that they occupy the top of the stack More...
 
X_API yhandle_t YAP_InitSlot (YAP_Term t)
 allocate n empty new slots More...
 
X_API YAP_Term YAP_GetFromSlot (YAP_handle_t slot)
 read from a slot More...
 
X_API YAP_Term * YAP_AddressFromSlot (YAP_handle_t)
 get the memory address of a slot More...
 
X_API YAP_Term * YAP_AddressOfTermInSlot (YAP_handle_t)
 get the memory address of the term actually stored in a slot More...
 
X_API void YAP_PutInSlot (YAP_handle_t slot, YAP_Term t)
 store term in a slot
 
X_API int YAP_RecoverSlots (int, YAP_handle_t topSlot)
 Succeeds if it recovers the space allocated for $n$ contiguous slots starting at topSlot. More...
 
X_API YAP_handle_t YAP_ArgsToSlots (int HowMany)
 copies the first new n YAAM registers to slots More...
 
X_API void YAP_SlotsToArgs (int HowMany, YAP_handle_t slot)
 copies n slots such that sl is copied to the last abstract ,achine register More...
 
X_API YAP_Term YAP_A (int i)
 
X_API YAP_Term YAP_SetA (int i, YAP_Term t)
 
X_API YAP_Bool YAP_IsIntTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsNumberTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsLongIntTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsBigNumTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsRationalTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsStringTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsVarTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsNonVarTerm (YAP_Term t)
 
X_API YAP_Bool YAP_IsFloatTerm (Term t)
 
X_API YAP_Bool YAP_IsDbRefTerm (Term t)
 
X_API YAP_Bool YAP_IsAtomTerm (Term t)
 
X_API YAP_Bool YAP_IsPairTerm (Term t)
 
X_API YAP_Bool YAP_IsApplTerm (Term t)
 
X_API YAP_Bool YAP_IsCompoundTerm (Term t)
 
X_API Term YAP_MkIntTerm (Int n)
 
X_API Term YAP_MkStringTerm (const char *n)
 
X_API Term YAP_MkCharPTerm (char *n)
 
X_API Term YAP_MkUnsignedStringTerm (const unsigned char *n)
 
X_API const char * YAP_StringOfTerm (Term t)
 
X_API const unsigned char * YAP_UnsignedStringOfTerm (Term t)
 
X_API Int YAP_IntOfTerm (Term t)
 
X_API Term YAP_MkBigNumTerm (void *big)
 
X_API YAP_Bool YAP_BigNumOfTerm (Term t, void *b)
 
X_API Term YAP_MkRationalTerm (void *big)
 
X_API YAP_Bool YAP_RationalOfTerm (Term t, void *b)
 
X_API Term YAP_MkBlobTerm (unsigned int sz)
 
X_API void * YAP_BlobOfTerm (Term t)
 
X_API Term YAP_MkFloatTerm (double n)
 
X_API YAP_Float YAP_FloatOfTerm (YAP_Term t)
 
X_API Term YAP_MkAtomTerm (YAP_Atom n)
 
X_API YAP_Atom YAP_AtomOfTerm (Term t)
 
X_API bool YAP_IsWideAtom (YAP_Atom a)
 
X_API const char * YAP_AtomName (YAP_Atom a)
 
X_API const wchar_t * YAP_WideAtomName (YAP_Atom a)
 
X_API YAP_Atom YAP_LookupAtom (const char *c)
 
X_API YAP_Atom YAP_LookupWideAtom (const wchar_t *c)
 
X_API YAP_Atom YAP_FullLookupAtom (const char *c)
 
X_API size_t YAP_AtomNameLength (YAP_Atom at)
 
X_API Term YAP_MkVarTerm (void)
 
X_API Term YAP_MkPairTerm (Term t1, Term t2)
 
X_API Term YAP_MkListFromTerms (Term *ta, Int sz)
 
X_API Term YAP_MkNewPairTerm ()
 
X_API Term YAP_HeadOfTerm (Term t)
 
X_API Term YAP_TailOfTerm (Term t)
 
X_API Int YAP_SkipList (Term *l, Term **tailp)
 
X_API Term YAP_MkApplTerm (YAP_Functor f, UInt arity, Term args[])
 
X_API Term YAP_MkNewApplTerm (YAP_Functor f, UInt arity)
 
X_API YAP_Functor YAP_FunctorOfTerm (Term t)
 
X_API Term YAP_ArgOfTerm (UInt n, Term t)
 
X_API Term * YAP_ArgsOfTerm (Term t)
 
X_API YAP_Functor YAP_MkFunctor (YAP_Atom a, UInt n)
 
X_API YAP_Atom YAP_NameOfFunctor (YAP_Functor f)
 
X_API UInt YAP_ArityOfFunctor (YAP_Functor f)
 
X_API void * YAP_ExtraSpaceCut (void)
 
X_API void * YAP_ExtraSpace (void)
 
X_API void YAP_cut_up (void)
 
X_API bool YAP_Unify (Term t1, Term t2)
 
X_API int YAP_Unifiable (Term t1, Term t2)
 
X_API int YAP_ExactlyEqual (Term t1, Term t2)
 
X_API int YAP_Variant (Term t1, Term t2)
 
X_API Int YAP_TermHash (Term t, Int sz, Int depth, int variant)
 
X_API Int YAP_NewSlots (int n)
 
X_API Int YAP_InitSlot (Term t)
 
X_API void YAP_PutInSlot (Int slot, Term t)
 
X_API Int YAP_Execute (PredEntry *pe, CPredicate exec_code)
 
X_API Int YAP_ExecuteFirst (PredEntry *pe, CPredicate exec_code)
 
X_API Int YAP_ExecuteOnCut (PredEntry *pe, CPredicate exec_code, struct cut_c_str *top)
 
X_API Int YAP_ExecuteNext (PredEntry *pe, CPredicate exec_code)
 
X_API void * YAP_ReallocSpaceFromYap (void *ptr, size_t size)
 
X_API void * YAP_AllocSpaceFromYap (size_t size)
 
X_API void YAP_FreeSpaceFromYap (void *ptr)
 
X_API char * YAP_StringToBuffer (Term t, char *buf, unsigned int bufsize)
 copy a string to a buffer, the buffer must have been malloced More...
 
X_API Term YAP_BufferToString (const char *s)
 
X_API Term YAP_NBufferToString (const char *s, size_t len)
 
X_API Term YAP_WideBufferToString (const wchar_t *s)
 
X_API Term YAP_NWideBufferToString (const wchar_t *s, size_t len)
 
X_API Term YAP_ReadBuffer (const char *s, Term *tp)
 
X_API YAP_Term YAP_BufferToAtomList (const char *s)
 
X_API Term YAP_NBufferToAtomList (const char *s, size_t len)
 
X_API Term YAP_WideBufferToAtomList (const wchar_t *s)
 
X_API Term YAP_NWideBufferToAtomList (const wchar_t *s, size_t len)
 
X_API Term YAP_NWideBufferToAtomDiffList (const wchar_t *s, Term t0, size_t len)
 
X_API Term YAP_BufferToDiffList (const char *s, Term t0)
 
X_API Term YAP_NBufferToDiffList (const char *s, Term t0, size_t len)
 
X_API Term YAP_WideBufferToDiffList (const wchar_t *s, Term t0)
 
X_API Term YAP_NWideBufferToDiffList (const wchar_t *s, Term t0, size_t len)
 
X_API void YAP_Error__ (const char *file, const char *function, int lineno, int myerrno, Term t, const char *buf,...)
 
X_API YAP_PredEntryPtr YAP_FunctorToPred (YAP_Functor func)
 
X_API YAP_PredEntryPtr YAP_AtomToPred (YAP_Atom at)
 
X_API YAP_PredEntryPtr YAP_FunctorToPredInModule (YAP_Functor func, Term mod)
 
X_API YAP_PredEntryPtr YAP_AtomToPredInModule (YAP_Atom at, Term mod)
 
X_API bool YAP_EnterGoal (YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi)
 
X_API bool YAP_RetryGoal (YAP_dogoalinfo *dgi)
 
X_API bool YAP_LeaveGoal (bool successful, YAP_dogoalinfo *dgi)
 
X_API Int YAP_RunGoal (Term t)
 
X_API Term YAP_AllocExternalDataInStack (size_t bytes)
 
X_API YAP_Bool YAP_IsExternalDataInStackTerm (Term t)
 
X_API void * YAP_ExternalDataInStackFromTerm (Term t)
 
X_API YAP_opaque_tag_t YAP_NewOpaqueType (struct YAP_opaque_handler_struct *f)
 
X_API Term YAP_NewOpaqueObject (YAP_opaque_tag_t blob_tag, size_t bytes)
 
X_API YAP_Bool YAP_IsOpaqueObjectTerm (Term t, YAP_opaque_tag_t tag)
 
X_API void * YAP_OpaqueObjectFromTerm (Term t)
 
X_API CELL * YAP_HeapStoreOpaqueTerm (Term t)
 
X_API Int YAP_RunGoalOnce (Term t)
 
X_API bool YAP_RestartGoal (void)
 
X_API bool YAP_ShutdownGoal (int backtrack)
 
X_API bool YAP_ContinueGoal (void)
 
X_API void YAP_PruneGoal (YAP_dogoalinfo *gi)
 
X_API bool YAP_GoalHasException (Term *t)
 
X_API void YAP_ClearExceptions (void)
 
X_API int YAP_InitConsult (int mode, const char *fname, char *full, int *osnop)
 
X_API void * YAP_GetStreamFromId (int no)
 given a stream descriptor or stream alias (see open/3 ), return YAP's internal handle More...
 
X_API FILE * YAP_TermToStream (Term t)
 
X_API void YAP_EndConsult (int sno, int *osnop, const char *full)
 
X_API Term YAP_Read (FILE *f)
 read a Prolog term from an operating system stream $s$ More...
 
X_API Term YAP_ReadFromStream (int sno)
 read a Prolog term from a Prolog opened stream $s$ More...
 
X_API Term YAP_ReadClauseFromStream (int sno, Term vs, Term pos)
 
X_API void YAP_Write (Term t, FILE *f, int flags)
 
X_API YAP_Term YAP_CopyTerm (Term t)
 
X_API char * YAP_WriteBuffer (Term t, char *buf, size_t sze, int flags)
 
X_API char * YAP_WriteDynamicBuffer (YAP_Term t, encoding_t enc, int flags)
 write a a term to n user-provided buffer: make sure not tp overflow the buffer even if the text is much larger More...
 
X_API bool YAP_CompileClause (Term t)
 
X_API void YAP_PutValue (YAP_Atom at, Term t)
 
X_API Term YAP_GetValue (YAP_Atom at)
 
X_API int YAP_CompareTerms (Term t1, Term t2)
 
X_API void YAP_Exit (int retval)
 
X_API int YAP_InitSocks (const char *host, long port)
 
X_API void YAP_SetOutputMessage (void)
 
X_API int YAP_StreamToFileNo (Term t)
 
X_API void * YAP_RepStreamFromId (int sno)
 Obtain a pointer to the YAP representation of a stream. More...
 
X_API void YAP_CloseAllOpenStreams (void)
 
X_API void YAP_FlushAllStreams (void)
 
X_API void YAP_Throw (Term t)
 
X_API void YAP_AsyncThrow (Term t)
 
X_API void YAP_Halt (int i)
 
X_API CELL * YAP_TopOfLocalStack (void)
 
X_API void * YAP_Predicate (YAP_Atom a, UInt arity, Term m)
 
X_API void YAP_PredicateInfo (void *p, YAP_Atom *a, UInt *arity, Term *m)
 
X_API void YAP_UserCPredicate (const char *name, YAP_UserCPred def, YAP_Arity arity)
 
X_API void YAP_UserBackCPredicate_ (const char *name, YAP_UserCPred init, YAP_UserCPred cont, YAP_Arity arity, YAP_Arity extra)
 
X_API void YAP_UserBackCutCPredicate (const char *name, YAP_UserCPred init, YAP_UserCPred cont, YAP_UserCPred cut, YAP_Arity arity, YAP_Arity extra)
 
X_API void YAP_UserBackCPredicate (const char *name, YAP_UserCPred init, YAP_UserCPred cont, arity_t arity, arity_t extra)
 
X_API void YAP_UserCPredicateWithArgs (const char *a, YAP_UserCPred f, arity_t arity, Term mod)
 
X_API Term YAP_CurrentModule (void)
 
X_API Term YAP_SetCurrentModule (Term new)
 
X_API Term YAP_CreateModule (YAP_Atom at)
 
X_API Term YAP_StripModule (Term t, Term *modp)
 
X_API int YAP_ThreadSelf (void)
 
X_API int YAP_ThreadCreateEngine (struct YAP_thread_attr_struct *attr)
 
X_API int YAP_ThreadAttachEngine (int wid)
 
X_API int YAP_ThreadDetachEngine (int wid)
 
X_API int YAP_ThreadDestroyEngine (int wid)
 
X_API Term YAP_TermNil (void)
 
X_API int YAP_IsTermNil (Term t)
 
X_API int YAP_AtomGetHold (YAP_Atom at)
 
X_API int YAP_AtomReleaseHold (YAP_Atom at)
 
X_API YAP_agc_hook YAP_AGCRegisterHook (YAP_agc_hook hook)
 
X_API int YAP_HaltRegisterHook (HaltHookFunc hook, void *closure)
 
X_API char * YAP_cwd (void)
 
X_API Term YAP_FloatsToList (double *dblp, size_t sz)
 
X_API Int YAP_ListToFloats (Term t, double *dblp, size_t sz)
 
X_API Term YAP_IntsToList (Int *dblp, size_t sz)
 
X_API Int YAP_ListToInts (Term t, Int *dblp, size_t sz)
 
X_API Term YAP_OpenList (int n)
 
X_API Term YAP_ExtendList (Term t0, Term inp)
 
X_API int YAP_CloseList (Term t0, Term tail)
 
X_API int YAP_IsAttVar (Term t)
 
X_API Term YAP_AttsOfVar (Term t)
 
X_API int YAP_FileNoFromStream (Term t)
 
X_API void * YAP_FileDescriptorFromStream (Term t)
 
X_API void * YAP_Record (Term t)
 
X_API Term YAP_Recorded (void *handle)
 
X_API int YAP_Erase (void *handle)
 
X_API void YAP_SlotsToArgs (int n, yhandle_t slot)
 
X_API void YAP_signal (int sig)
 
X_API int YAP_SetYAPFlag (Term flag, Term val)
 
X_API yhandle_t YAP_VarSlotToNumber (yhandle_t s)
 
X_API Term YAP_ModuleUser (void)
 
X_API YAP_handle_t YAP_NumberOfClausesForPredicate (YAP_PredEntryPtr ape)
 
X_API int YAP_MaxOpPriority (YAP_Atom at, Term module)
 
X_API int YAP_OpInfo (YAP_Atom at, Term module, int opkind, int *yap_type, int *prio)
 
X_API int YAP_Argv (char ***argvp)
 
X_API YAP_tag_t YAP_TagOfTerm (Term t)
 
X_API void * YAP_PointerOfTerm (Term t)
 
X_API size_t YAP_UTF8_TextLength (Term t)
 Output the number of bytes needed to represent a string in UTF-8 Note that the terminating zero is not included. More...
 
X_API Int YAP_ListLength (Term t)
 
X_API Int YAP_NumberVars (Term t, Int nbv)
 
X_API Term YAP_UnNumberVars (Term t)
 
X_API int YAP_IsNumberedVariable (Term t)
 
X_API size_t YAP_ExportTerm (Term inp, char *buf, size_t len)
 
X_API Term YAP_ImportTerm (char *buf)
 
X_API size_t YAP_SizeOfExportedTerm (char *buf)
 
X_API Term YAP_ImportTfunnumberm (char *buf)
 
X_API int YAP_RequiresExtraStack (size_t sz)
 
X_API Int YAP_AtomToInt (YAP_Atom At)
 
X_API YAP_Atom YAP_IntToAtom (Int i)
 
X_API Int YAP_FunctorToInt (YAP_Functor f)
 
X_API void * YAP_foreign_stream (int sno)
 
X_API YAP_Functor YAP_IntToFunctor (Int i)
 
X_API YAP_PredEntryPtr YAP_TopGoal (void)
 
void yap_init (void)
 

Variables

X_API bool python_in_python
 
int YAP_BPROLOG_exception
 
Term YAP_BPROLOG_curr_toam_status
 
atom_t * TR_Atoms
 
functor_t * TR_Functors
 
size_t AtomTranslations
 
size_t MaxAtomTranslations
 
size_t FunctorTranslations
 
size_t MaxFunctorTranslations
 

Macro Definition Documentation

◆ _EXPORT_KERNEL

#define _EXPORT_KERNEL   1

Definition at line 28 of file c_interface.c.

◆ C_INTERFACE_C

#define C_INTERFACE_C   1

Definition at line 27 of file c_interface.c.

◆ SOURCEBOOTPath

#define SOURCEBOOTPath   NULL

Definition at line 108 of file c_interface.c.

◆ strncat

#define strncat (   X,
  Y,
 
)    strcat(X, Y)

Definition at line 101 of file c_interface.c.

◆ strncpy

#define strncpy (   X,
  Y,
 
)    strcpy(X, Y)

Definition at line 98 of file c_interface.c.

Typedef Documentation

◆ atom_t

typedef void* atom_t

Definition at line 78 of file c_interface.c.

◆ functor_t

typedef void* functor_t

Definition at line 79 of file c_interface.c.

Enumeration Type Documentation

◆ frg_code

enum frg_code

Definition at line 81 of file c_interface.c.

Variable Documentation

◆ python_in_python

X_API bool python_in_python

Definition at line 93 of file c_interface.c.