2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
2004-05-14 17:33:47 +01:00
|
|
|
* YAP Prolog *
|
2001-04-09 20:54:03 +01:00
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
2004-05-14 17:33:47 +01:00
|
|
|
* Copyright L.Damas, V.Santos Costa and Universidade do Porto 1985-- *
|
2001-04-09 20:54:03 +01:00
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: c_interface.c *
|
|
|
|
* comments: c_interface primitives definition *
|
|
|
|
* *
|
2007-11-16 14:58:41 +00:00
|
|
|
* Last rev: $Date: 2007-11-16 14:58:40 $,$Author: vsc $ *
|
2004-05-14 18:11:32 +01:00
|
|
|
* $Log: not supported by cvs2svn $
|
2007-11-16 14:58:41 +00:00
|
|
|
* Revision 1.102 2007/11/01 20:50:31 vsc
|
|
|
|
* fix YAP_LeaveGoal (again)
|
|
|
|
*
|
2007-11-01 20:50:31 +00:00
|
|
|
* Revision 1.101 2007/10/29 22:48:54 vsc
|
|
|
|
* small fixes
|
|
|
|
*
|
2007-10-29 22:48:54 +00:00
|
|
|
* Revision 1.100 2007/10/28 00:54:09 vsc
|
|
|
|
* new version of viterbi implementation
|
|
|
|
* fix all:atvars reporting bad info
|
|
|
|
* fix bad S info in x86_64
|
|
|
|
*
|
2007-10-28 01:54:09 +01:00
|
|
|
* Revision 1.99 2007/10/16 18:57:17 vsc
|
|
|
|
* get rid of debug statement.
|
|
|
|
*
|
2007-10-16 19:57:17 +01:00
|
|
|
* Revision 1.98 2007/10/15 23:48:46 vsc
|
|
|
|
* unset var
|
|
|
|
*
|
2007-10-16 00:48:46 +01:00
|
|
|
* Revision 1.97 2007/10/05 18:24:30 vsc
|
|
|
|
* fix garbage collector and fix LeaveGoal
|
|
|
|
*
|
2007-10-05 19:24:30 +01:00
|
|
|
* Revision 1.96 2007/09/04 10:34:54 vsc
|
|
|
|
* Improve SWI interface emulation.
|
|
|
|
*
|
2007-09-04 11:34:55 +01:00
|
|
|
* Revision 1.95 2007/06/04 12:28:01 vsc
|
|
|
|
* interface speedups
|
|
|
|
* bad error message in X is foo>>2.
|
|
|
|
*
|
2007-06-04 13:28:02 +01:00
|
|
|
* Revision 1.94 2007/05/15 11:33:51 vsc
|
|
|
|
* fix min list
|
|
|
|
*
|
2007-05-15 12:33:51 +01:00
|
|
|
* Revision 1.93 2007/05/14 16:44:11 vsc
|
|
|
|
* improve external interface
|
|
|
|
*
|
2007-05-14 17:44:12 +01:00
|
|
|
* Revision 1.92 2007/04/18 23:01:16 vsc
|
|
|
|
* fix deadlock when trying to create a module with the same name as a
|
|
|
|
* predicate (for now, just don't lock modules). obs Paulo Moura.
|
|
|
|
*
|
2007-04-19 00:01:16 +01:00
|
|
|
* Revision 1.91 2007/03/30 16:47:22 vsc
|
|
|
|
* fix gmpless blob handling
|
|
|
|
*
|
2007-03-30 17:47:22 +01:00
|
|
|
* Revision 1.90 2007/03/22 11:12:20 vsc
|
|
|
|
* make sure that YAP_Restart does not restart a failed goal.
|
|
|
|
*
|
2007-03-22 11:12:22 +00:00
|
|
|
* Revision 1.89 2007/01/28 14:26:36 vsc
|
|
|
|
* WIN32 support
|
|
|
|
*
|
2007-01-28 14:26:37 +00:00
|
|
|
* Revision 1.88 2007/01/08 08:27:19 vsc
|
|
|
|
* fix restore (Trevor)
|
|
|
|
* make indexing a bit faster on IDB
|
|
|
|
*
|
2007-01-08 08:27:19 +00:00
|
|
|
* Revision 1.87 2006/12/13 16:10:14 vsc
|
|
|
|
* several debugger and CLP(BN) improvements.
|
|
|
|
*
|
2006-12-13 16:10:26 +00:00
|
|
|
* Revision 1.86 2006/11/27 17:42:02 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
2006-11-27 17:42:03 +00:00
|
|
|
* Revision 1.85 2006/05/16 18:37:30 vsc
|
|
|
|
* WIN32 fixes
|
|
|
|
* compiler bug fixes
|
|
|
|
* extend interface
|
|
|
|
*
|
2006-05-16 19:37:31 +01:00
|
|
|
* Revision 1.84 2006/03/09 15:52:04 tiagosoares
|
|
|
|
* CUT_C and MYDDAS support for 64 bits architectures
|
|
|
|
*
|
2006-03-09 15:52:06 +00:00
|
|
|
* Revision 1.83 2006/02/08 17:29:54 tiagosoares
|
|
|
|
* MYDDAS: Myddas Top Level for MySQL and Datalog
|
|
|
|
*
|
2006-02-08 17:29:55 +00:00
|
|
|
* Revision 1.82 2006/01/18 15:34:53 vsc
|
|
|
|
* avoid sideffects from MkBigInt
|
|
|
|
*
|
2006-01-18 15:34:54 +00:00
|
|
|
* Revision 1.81 2006/01/16 02:57:51 vsc
|
|
|
|
* fix bug with very large integers
|
|
|
|
* fix bug where indexing code was looking at code after a cut.
|
|
|
|
*
|
2006-01-16 02:57:52 +00:00
|
|
|
* Revision 1.80 2006/01/02 03:35:44 vsc
|
|
|
|
* fix interface and docs
|
|
|
|
*
|
2006-01-02 03:35:45 +00:00
|
|
|
* Revision 1.79 2006/01/02 02:25:44 vsc
|
|
|
|
* cannot release space from external GMPs.
|
|
|
|
*
|
2006-01-02 02:25:45 +00:00
|
|
|
* Revision 1.78 2006/01/02 02:16:18 vsc
|
|
|
|
* support new interface between YAP and GMP, so that we don't rely on our own
|
|
|
|
* allocation routines.
|
|
|
|
* Several big fixes.
|
|
|
|
*
|
2006-01-02 02:16:19 +00:00
|
|
|
* Revision 1.77 2005/11/18 18:48:51 tiagosoares
|
|
|
|
* support for executing c code when a cut occurs
|
|
|
|
*
|
2005-11-18 18:52:41 +00:00
|
|
|
* Revision 1.76 2005/11/03 18:49:26 vsc
|
|
|
|
* fix bignum conversion
|
|
|
|
*
|
2005-11-03 18:49:26 +00:00
|
|
|
* Revision 1.75 2005/10/28 17:38:49 vsc
|
|
|
|
* sveral updates
|
|
|
|
*
|
2005-10-28 18:38:50 +01:00
|
|
|
* Revision 1.74 2005/10/21 16:07:07 vsc
|
|
|
|
* fix tabling
|
|
|
|
*
|
2005-10-21 17:07:07 +01:00
|
|
|
* Revision 1.73 2005/10/18 17:04:43 vsc
|
|
|
|
* 5.1:
|
|
|
|
* - improvements to GC
|
|
|
|
* 2 generations
|
|
|
|
* generic speedups
|
|
|
|
* - new scheme for attvars
|
|
|
|
* - hProlog like interface also supported
|
|
|
|
* - SWI compatibility layer
|
|
|
|
* - extra predicates
|
|
|
|
* - global variables
|
|
|
|
* - moved to Prolog module
|
|
|
|
* - CLP(R) by Leslie De Koninck, Tom Schrijvers, Cristian Holzbaur, Bart
|
|
|
|
* Demoen and Jan Wielemacker
|
|
|
|
* - load_files/2
|
|
|
|
*
|
|
|
|
* from 5.0.1
|
|
|
|
*
|
|
|
|
* - WIN32 missing include files (untested)
|
|
|
|
* - -L trouble (my thanks to Takeyuchi Shiramoto-san)!
|
|
|
|
* - debugging of backtrable user-C preds would core dump.
|
|
|
|
* - redeclaring a C-predicate as Prolog core dumps.
|
|
|
|
* - badly protected YapInterface.h.
|
|
|
|
* - break/0 was failing at exit.
|
|
|
|
* - YAP_cut_fail and YAP_cut_succeed were different from manual.
|
|
|
|
* - tracing through data-bases could core dump.
|
|
|
|
* - cut could break on very large computations.
|
|
|
|
* - first pass at BigNum issues (reported by Roberto).
|
|
|
|
* - debugger could get go awol after fail port.
|
|
|
|
* - weird message on wrong debugger option.
|
|
|
|
*
|
2005-10-18 18:04:43 +01:00
|
|
|
* Revision 1.72 2005/10/15 02:42:57 vsc
|
|
|
|
* fix interface
|
|
|
|
*
|
2005-10-15 03:42:57 +01:00
|
|
|
* Revision 1.71 2005/08/17 13:35:51 vsc
|
|
|
|
* YPP would leave exceptions on the system, disabling Yap-4.5.7
|
|
|
|
* message.
|
|
|
|
*
|
2005-08-17 14:35:52 +01:00
|
|
|
* Revision 1.70 2005/08/04 15:45:51 ricroc
|
|
|
|
* TABLING NEW: support to limit the table space size
|
|
|
|
*
|
2005-08-04 16:45:56 +01:00
|
|
|
* Revision 1.69 2005/07/19 17:12:18 rslopes
|
|
|
|
* fix for older compilers that do not support declaration of vars
|
|
|
|
* in the middle of the function code.
|
|
|
|
*
|
2005-07-19 18:12:18 +01:00
|
|
|
* Revision 1.68 2005/05/31 00:23:47 ricroc
|
|
|
|
* remove abort_yapor function
|
|
|
|
*
|
2005-05-31 01:23:47 +01:00
|
|
|
* Revision 1.67 2005/04/10 04:35:19 vsc
|
|
|
|
* AllocMemoryFromYap should now handle large requests the right way.
|
|
|
|
*
|
2005-04-10 05:35:19 +01:00
|
|
|
* Revision 1.66 2005/04/10 04:01:10 vsc
|
|
|
|
* bug fixes, I hope!
|
|
|
|
*
|
2005-04-10 05:01:15 +01:00
|
|
|
* Revision 1.65 2005/03/15 18:29:23 vsc
|
|
|
|
* fix GPL
|
|
|
|
* fix idb: stuff in coroutines.
|
|
|
|
*
|
2005-03-15 18:29:25 +00:00
|
|
|
* Revision 1.64 2005/03/13 06:26:10 vsc
|
|
|
|
* fix excessive pruning in meta-calls
|
|
|
|
* fix Term->int breakage in compiler
|
|
|
|
* improve JPL (at least it does something now for amd64).
|
|
|
|
*
|
2005-03-13 06:26:13 +00:00
|
|
|
* Revision 1.63 2005/03/04 20:30:10 ricroc
|
|
|
|
* bug fixes for YapTab support
|
|
|
|
*
|
2005-03-04 20:30:14 +00:00
|
|
|
* Revision 1.62 2005/03/02 18:35:44 vsc
|
|
|
|
* try to make initialisation process more robust
|
|
|
|
* try to make name more robust (in case Lookup new atom fails)
|
|
|
|
*
|
2005-03-02 18:35:49 +00:00
|
|
|
* Revision 1.61 2005/03/01 22:25:08 vsc
|
|
|
|
* fix pruning bug
|
|
|
|
* make DL_MALLOC less enthusiastic about walking through buckets.
|
|
|
|
*
|
2005-03-01 22:25:09 +00:00
|
|
|
* Revision 1.60 2005/02/08 18:04:47 vsc
|
|
|
|
* library_directory may not be deterministic (usually it isn't).
|
|
|
|
*
|
2005-02-08 18:05:21 +00:00
|
|
|
* Revision 1.59 2004/12/08 00:56:35 vsc
|
|
|
|
* missing ;
|
|
|
|
*
|
2004-12-08 00:56:35 +00:00
|
|
|
* Revision 1.58 2004/11/19 22:08:41 vsc
|
|
|
|
* replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate.
|
|
|
|
*
|
2004-11-19 22:08:43 +00:00
|
|
|
* Revision 1.57 2004/11/18 22:32:31 vsc
|
|
|
|
* fix situation where we might assume nonextsing double initialisation of C predicates (use
|
|
|
|
* Hidden Pred Flag).
|
|
|
|
* $host_type was double initialised.
|
|
|
|
*
|
2004-11-18 22:32:40 +00:00
|
|
|
* Revision 1.56 2004/10/31 02:18:03 vsc
|
|
|
|
* fix bug in handling Yap heap overflow while adding new clause.
|
|
|
|
*
|
2004-10-31 02:18:04 +00:00
|
|
|
* Revision 1.55 2004/10/28 20:12:20 vsc
|
|
|
|
* Use Doug Lea's malloc as an alternative to YAP's standard malloc
|
|
|
|
* don't use TR directly in scanner/parser, this avoids trouble with ^C while
|
|
|
|
* consulting large files.
|
|
|
|
* pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should
|
|
|
|
* compile out of the box now).
|
|
|
|
*
|
2004-10-28 21:12:23 +01:00
|
|
|
* Revision 1.54 2004/10/06 16:55:46 vsc
|
|
|
|
* change configure to support big mem configs
|
|
|
|
* get rid of extra globals
|
|
|
|
* fix trouble with multifile preds
|
|
|
|
*
|
2004-10-06 17:55:48 +01:00
|
|
|
* Revision 1.53 2004/08/11 16:14:51 vsc
|
|
|
|
* whole lot of fixes:
|
|
|
|
* - memory leak in indexing
|
|
|
|
* - memory management in WIN32 now supports holes
|
|
|
|
* - extend Yap interface, more support for SWI-Interface
|
|
|
|
* - new predicate mktime in system
|
|
|
|
* - buffer console I/O in WIN32
|
|
|
|
*
|
2004-08-11 17:14:55 +01:00
|
|
|
* Revision 1.52 2004/07/23 03:37:16 vsc
|
|
|
|
* fix heap overflow in YAP_LookupAtom
|
|
|
|
*
|
2004-07-23 04:37:17 +01:00
|
|
|
* Revision 1.51 2004/07/22 21:32:20 vsc
|
|
|
|
* debugger fixes
|
|
|
|
* initial support for JPL
|
|
|
|
* bad calls to garbage collector and gc
|
|
|
|
* debugger fixes
|
|
|
|
*
|
2004-07-22 22:32:23 +01:00
|
|
|
* Revision 1.50 2004/06/29 19:04:41 vsc
|
|
|
|
* fix multithreaded version
|
|
|
|
* include new version of Ricardo's profiler
|
|
|
|
* new predicat atomic_concat
|
|
|
|
* allow multithreaded-debugging
|
|
|
|
* small fixes
|
|
|
|
*
|
2004-06-29 20:04:46 +01:00
|
|
|
* Revision 1.49 2004/06/09 03:32:02 vsc
|
|
|
|
* fix bugs
|
|
|
|
*
|
2004-06-09 04:32:03 +01:00
|
|
|
* Revision 1.48 2004/06/05 03:36:59 vsc
|
|
|
|
* coroutining is now a part of attvars.
|
|
|
|
* some more fixes.
|
|
|
|
*
|
2004-06-05 04:37:01 +01:00
|
|
|
* Revision 1.47 2004/05/17 21:42:08 vsc
|
|
|
|
* misc fixes
|
|
|
|
*
|
2004-05-17 22:42:12 +01:00
|
|
|
* Revision 1.46 2004/05/14 17:56:45 vsc
|
|
|
|
* Yap_WriteBuffer
|
|
|
|
*
|
2004-05-14 18:56:47 +01:00
|
|
|
* Revision 1.45 2004/05/14 17:11:30 vsc
|
|
|
|
* support BigNums in interface
|
|
|
|
*
|
2004-05-14 18:11:32 +01:00
|
|
|
* Revision 1.44 2004/05/14 16:33:44 vsc
|
|
|
|
* add Yap_ReadBuffer
|
|
|
|
* *
|
2004-05-14 17:33:47 +01:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#define Bool int
|
|
|
|
#define flt double
|
2004-08-11 17:14:55 +01:00
|
|
|
#define YAP_Term Term
|
2001-04-09 20:54:03 +01:00
|
|
|
#define C_INTERFACE
|
|
|
|
|
|
|
|
#include "Yap.h"
|
2002-12-27 16:53:09 +00:00
|
|
|
#include "clause.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "yapio.h"
|
2005-03-02 18:35:49 +00:00
|
|
|
#if HAVE_STDARG_H
|
|
|
|
#include <stdarg.h>
|
|
|
|
#endif
|
2007-09-04 11:34:55 +01:00
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2003-02-24 14:11:54 +00:00
|
|
|
#if _MSC_VER || defined(__MINGW32__)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2003-01-08 16:45:35 +00:00
|
|
|
#include "iopreds.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#define HAS_YAP_H 1
|
|
|
|
#include "yap_structs.h"
|
2005-10-21 17:07:07 +01:00
|
|
|
#ifdef TABLING
|
|
|
|
#include "tab.macros.h"
|
|
|
|
#endif /* TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
|
|
|
#endif /* YAPOR */
|
2004-07-22 22:32:23 +01:00
|
|
|
#include "threads.h"
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
#include "cut_c.h"
|
|
|
|
#endif /* CUT_C */
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define YAP_BOOT_FROM_PROLOG 0
|
|
|
|
#define YAP_BOOT_FROM_SAVED_CODE 1
|
|
|
|
#define YAP_BOOT_FROM_SAVED_STACKS 2
|
|
|
|
#define YAP_BOOT_FROM_SAVED_ERROR -1
|
|
|
|
|
2002-02-04 16:12:54 +00:00
|
|
|
#if defined(_MSC_VER) && defined(YAP_EXPORTS)
|
2001-04-09 20:54:03 +01:00
|
|
|
#define X_API __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define X_API
|
|
|
|
#endif
|
|
|
|
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_A,(int));
|
2002-09-17 00:25:09 +01:00
|
|
|
X_API Term STD_PROTO(YAP_Deref,(Term));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_MkVarTerm,(void));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsVarTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsNonVarTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsIntTerm,(Term));
|
2004-05-14 18:11:32 +01:00
|
|
|
X_API Bool STD_PROTO(YAP_IsBigNumTerm,(Term));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Bool STD_PROTO(YAP_IsFloatTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsDbRefTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsAtomTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsPairTerm,(Term));
|
|
|
|
X_API Bool STD_PROTO(YAP_IsApplTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_MkIntTerm,(Int));
|
2004-05-14 18:11:32 +01:00
|
|
|
X_API Term STD_PROTO(YAP_MkBigNumTerm,(void *));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Int STD_PROTO(YAP_IntOfTerm,(Term));
|
2006-01-02 02:16:19 +00:00
|
|
|
X_API void STD_PROTO(YAP_BigNumOfTerm,(Term, void *));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_MkFloatTerm,(flt));
|
|
|
|
X_API flt STD_PROTO(YAP_FloatOfTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_MkAtomTerm,(Atom));
|
|
|
|
X_API Atom STD_PROTO(YAP_AtomOfTerm,(Term));
|
|
|
|
X_API Atom STD_PROTO(YAP_LookupAtom,(char *));
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API Atom STD_PROTO(YAP_LookupWideAtom,(wchar_t *));
|
|
|
|
X_API int STD_PROTO(YAP_AtomNameLength,(Atom));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Atom STD_PROTO(YAP_FullLookupAtom,(char *));
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API int STD_PROTO(YAP_IsWideAtom,(Atom));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API char *STD_PROTO(YAP_AtomName,(Atom));
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API wchar_t *STD_PROTO(YAP_WideAtomName,(Atom));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_MkPairTerm,(Term,Term));
|
|
|
|
X_API Term STD_PROTO(YAP_MkNewPairTerm,(void));
|
|
|
|
X_API Term STD_PROTO(YAP_HeadOfTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_TailOfTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_MkApplTerm,(Functor,unsigned long int,Term *));
|
|
|
|
X_API Term STD_PROTO(YAP_MkNewApplTerm,(Functor,unsigned long int));
|
|
|
|
X_API Functor STD_PROTO(YAP_FunctorOfTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_ArgOfTerm,(Int,Term));
|
2007-06-04 13:28:02 +01:00
|
|
|
X_API Term *STD_PROTO(YAP_ArgsOfTerm,(Term));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Functor STD_PROTO(YAP_MkFunctor,(Atom,Int));
|
|
|
|
X_API Atom STD_PROTO(YAP_NameOfFunctor,(Functor));
|
|
|
|
X_API Int STD_PROTO(YAP_ArityOfFunctor,(Functor));
|
|
|
|
X_API void *STD_PROTO(YAP_ExtraSpace,(void));
|
2005-10-18 18:04:43 +01:00
|
|
|
X_API void STD_PROTO(YAP_cut_up,(void));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Int STD_PROTO(YAP_Unify,(Term,Term));
|
|
|
|
X_API int STD_PROTO(YAP_Reset,(void));
|
|
|
|
X_API Int STD_PROTO(YAP_Init,(YAP_init_args *));
|
|
|
|
X_API Int STD_PROTO(YAP_FastInit,(char *));
|
2007-06-04 13:28:02 +01:00
|
|
|
X_API PredEntry *STD_PROTO(YAP_FunctorToPred,(Functor));
|
|
|
|
X_API PredEntry *STD_PROTO(YAP_AtomToPred,(Atom));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Int STD_PROTO(YAP_CallProlog,(Term));
|
|
|
|
X_API void *STD_PROTO(YAP_AllocSpaceFromYap,(unsigned int));
|
|
|
|
X_API void STD_PROTO(YAP_FreeSpaceFromYap,(void *));
|
|
|
|
X_API int STD_PROTO(YAP_StringToBuffer, (Term, char *, unsigned int));
|
2004-05-14 17:33:47 +01:00
|
|
|
X_API Term STD_PROTO(YAP_ReadBuffer, (char *,Term *));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_BufferToString, (char *));
|
|
|
|
X_API Term STD_PROTO(YAP_BufferToAtomList, (char *));
|
2005-03-02 18:35:49 +00:00
|
|
|
X_API void STD_PROTO(YAP_Error,(int, Term, char *, ...));
|
2004-06-05 04:37:01 +01:00
|
|
|
X_API Term STD_PROTO(YAP_RunGoal,(Term));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API int STD_PROTO(YAP_RestartGoal,(void));
|
2007-05-15 12:33:51 +01:00
|
|
|
X_API int STD_PROTO(YAP_ShutdownGoal,(int));
|
2007-06-04 13:28:02 +01:00
|
|
|
X_API int STD_PROTO(YAP_EnterGoal,(PredEntry *, Term *, YAP_dogoalinfo *));
|
|
|
|
X_API int STD_PROTO(YAP_RetryGoal,(YAP_dogoalinfo *));
|
|
|
|
X_API int STD_PROTO(YAP_LeaveGoal,(int, YAP_dogoalinfo *));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API int STD_PROTO(YAP_GoalHasException,(Term *));
|
2005-08-17 14:35:52 +01:00
|
|
|
X_API void STD_PROTO(YAP_ClearExceptions,(void));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API int STD_PROTO(YAP_ContinueGoal,(void));
|
|
|
|
X_API void STD_PROTO(YAP_PruneGoal,(void));
|
|
|
|
X_API void STD_PROTO(YAP_InitConsult,(int, char *));
|
|
|
|
X_API void STD_PROTO(YAP_EndConsult,(void));
|
|
|
|
X_API Term STD_PROTO(YAP_Read, (int (*)(void)));
|
2007-01-28 14:26:37 +00:00
|
|
|
X_API void STD_PROTO(YAP_Write, (Term, int (*)(wchar_t), int));
|
2007-05-14 17:44:12 +01:00
|
|
|
X_API Term STD_PROTO(YAP_CopyTerm, (Term));
|
2004-05-14 18:56:47 +01:00
|
|
|
X_API Term STD_PROTO(YAP_WriteBuffer, (Term, char *, unsigned int, int));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API char *STD_PROTO(YAP_CompileClause, (Term));
|
|
|
|
X_API void STD_PROTO(YAP_PutValue, (Atom,Term));
|
|
|
|
X_API Term STD_PROTO(YAP_GetValue, (Atom));
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API int STD_PROTO(YAP_CompareTerms, (Term,Term));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API void STD_PROTO(YAP_Exit, (int));
|
|
|
|
X_API void STD_PROTO(YAP_InitSocks, (char *, long));
|
|
|
|
X_API void STD_PROTO(YAP_SetOutputMessage, (void));
|
|
|
|
X_API int STD_PROTO(YAP_StreamToFileNo, (Term));
|
|
|
|
X_API void STD_PROTO(YAP_CloseAllOpenStreams,(void));
|
|
|
|
X_API Term STD_PROTO(YAP_OpenStream,(void *, char *, Term, int));
|
2007-05-14 17:44:12 +01:00
|
|
|
X_API long STD_PROTO(YAP_CurrentSlot,(void));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API long STD_PROTO(YAP_NewSlots,(int));
|
|
|
|
X_API long STD_PROTO(YAP_InitSlot,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_GetFromSlot,(long));
|
|
|
|
X_API Term *STD_PROTO(YAP_AddressFromSlot,(long));
|
|
|
|
X_API void STD_PROTO(YAP_PutInSlot,(long, Term));
|
|
|
|
X_API void STD_PROTO(YAP_RecoverSlots,(int));
|
|
|
|
X_API void STD_PROTO(YAP_Throw,(Term));
|
|
|
|
X_API void STD_PROTO(YAP_Halt,(int));
|
|
|
|
X_API Term *STD_PROTO(YAP_TopOfLocalStack,(void));
|
|
|
|
X_API void *STD_PROTO(YAP_Predicate,(Atom,unsigned long int,int));
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API void STD_PROTO(YAP_PredicateInfo,(void *,Atom *,unsigned long int *,Term *));
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API void STD_PROTO(YAP_UserCPredicate,(char *,CPredicate,unsigned long int));
|
|
|
|
X_API void STD_PROTO(YAP_UserBackCPredicate,(char *,CPredicate,CPredicate,unsigned long int,unsigned int));
|
2004-02-12 12:37:12 +00:00
|
|
|
X_API void STD_PROTO(YAP_UserCPredicateWithArgs,(char *,CPredicate,unsigned long int,Term));
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
X_API void STD_PROTO(YAP_UserBackCutCPredicate,(char *,CPredicate,CPredicate,CPredicate,unsigned long int,unsigned int));
|
|
|
|
X_API void *STD_PROTO(YAP_ExtraSpaceCut,(void));
|
|
|
|
#endif
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API Term STD_PROTO(YAP_CurrentModule,(void));
|
|
|
|
X_API Term STD_PROTO(YAP_CreateModule,(Atom));
|
2006-05-16 19:37:31 +01:00
|
|
|
X_API int STD_PROTO(YAP_ThreadSelf,(void));
|
|
|
|
X_API int STD_PROTO(YAP_GetThreadRefCount,(int));
|
|
|
|
X_API void STD_PROTO(YAP_SetThreadRefCount,(int,int));
|
2005-03-13 06:26:13 +00:00
|
|
|
X_API CELL STD_PROTO(YAP_ThreadCreateEngine,(thread_attr *));
|
2006-05-16 19:37:31 +01:00
|
|
|
X_API int STD_PROTO(YAP_ThreadAttachEngine,(int));
|
|
|
|
X_API int STD_PROTO(YAP_ThreadDetachEngine,(int));
|
|
|
|
X_API int STD_PROTO(YAP_ThreadDestroyEngine,(int));
|
2006-12-13 16:10:26 +00:00
|
|
|
X_API Term STD_PROTO(YAP_MkBlobTerm,(unsigned int));
|
|
|
|
X_API void *STD_PROTO(YAP_BlobOfTerm,(Term));
|
|
|
|
X_API Term STD_PROTO(YAP_TermNil,(void));
|
2002-05-14 19:24:34 +01:00
|
|
|
|
|
|
|
static int (*do_getf)(void);
|
|
|
|
|
|
|
|
static int do_yap_getc(int streamno) {
|
|
|
|
return(do_getf());
|
|
|
|
}
|
|
|
|
|
2007-01-28 14:26:37 +00:00
|
|
|
static int (*do_putcf)(wchar_t);
|
2002-05-14 19:24:34 +01:00
|
|
|
|
2007-01-28 14:26:37 +00:00
|
|
|
static int do_yap_putc(int streamno,wchar_t ch) {
|
2002-05-14 19:24:34 +01:00
|
|
|
do_putcf(ch);
|
|
|
|
return(ch);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2007-10-28 01:54:09 +01:00
|
|
|
static int
|
|
|
|
dogc(void)
|
|
|
|
{
|
|
|
|
UInt arity;
|
|
|
|
|
|
|
|
if (P && PREVOP(P,sla)->opc == Yap_opcode(_call_usercpred)) {
|
|
|
|
arity = PREVOP(P,sla)->u.sla.sla_u.p->ArityOfPE;
|
|
|
|
} else {
|
|
|
|
arity = 0;
|
|
|
|
}
|
|
|
|
if (!Yap_gc(arity, ENV, CP)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
doexpand(UInt sz)
|
|
|
|
{
|
|
|
|
UInt arity;
|
|
|
|
|
|
|
|
if (P && PREVOP(P,sla)->opc == Yap_opcode(_call_usercpred)) {
|
|
|
|
arity = PREVOP(P,sla)->u.sla.sla_u.p->ArityOfPE;
|
|
|
|
} else {
|
|
|
|
arity = 0;
|
|
|
|
}
|
|
|
|
if (!Yap_gcl(sz, arity, ENV, CP)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_A(int i)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return(Deref(XREGS[i]));
|
|
|
|
}
|
|
|
|
|
2002-09-17 00:25:09 +01:00
|
|
|
X_API Term
|
|
|
|
YAP_Deref(Term t)
|
|
|
|
{
|
|
|
|
return(Deref(t));
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsIntTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-05-14 18:11:32 +01:00
|
|
|
return IsIntegerTerm(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
|
|
|
YAP_IsBigNumTerm(Term t)
|
|
|
|
{
|
|
|
|
#if USE_GMP
|
2005-10-18 18:04:43 +01:00
|
|
|
return IsBigIntTerm(t);
|
2004-05-14 18:11:32 +01:00
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsVarTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsVarTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsNonVarTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsNonVarTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsFloatTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsFloatTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsDbRefTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsDBRefTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsAtomTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsAtomTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsPairTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsPairTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Bool
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IsApplTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (IsApplTerm(t) && !IsExtensionFunctor(FunctorOfTerm(t)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkIntTerm(Int n)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term I;
|
|
|
|
BACKUP_H();
|
|
|
|
|
|
|
|
I = MkIntegerTerm(n);
|
|
|
|
RECOVER_H();
|
2006-01-16 02:57:52 +00:00
|
|
|
return I;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_IntOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
if (!IsApplTerm(t))
|
2004-05-14 18:11:32 +01:00
|
|
|
return IntOfTerm(t);
|
|
|
|
else {
|
|
|
|
return LongIntOfTerm(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
|
|
|
YAP_MkBigNumTerm(void *big)
|
|
|
|
{
|
|
|
|
#if USE_GMP
|
|
|
|
Term I;
|
|
|
|
BACKUP_H();
|
2006-01-18 15:34:54 +00:00
|
|
|
I = Yap_MkBigIntTerm((MP_INT *)big);
|
2004-05-14 18:11:32 +01:00
|
|
|
RECOVER_H();
|
|
|
|
return I;
|
|
|
|
#else
|
|
|
|
return TermNil;
|
|
|
|
#endif /* USE_GMP */
|
|
|
|
}
|
|
|
|
|
2006-01-02 02:16:19 +00:00
|
|
|
X_API void
|
|
|
|
YAP_BigNumOfTerm(Term t, void *b)
|
2004-05-14 18:11:32 +01:00
|
|
|
{
|
|
|
|
#if USE_GMP
|
2006-01-02 02:16:19 +00:00
|
|
|
MP_INT *bz = (MP_INT *)b;
|
2004-05-14 18:11:32 +01:00
|
|
|
if (IsVarTerm(t))
|
2006-01-02 02:16:19 +00:00
|
|
|
return;
|
2004-05-14 18:11:32 +01:00
|
|
|
if (!IsBigIntTerm(t))
|
2006-01-02 02:16:19 +00:00
|
|
|
return;
|
2006-01-02 03:35:45 +00:00
|
|
|
mpz_set(bz,Yap_BigIntOfTerm(t));
|
2004-05-14 18:11:32 +01:00
|
|
|
#endif /* USE_GMP */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
X_API Term
|
|
|
|
YAP_MkBlobTerm(unsigned int sz)
|
|
|
|
{
|
|
|
|
Term I;
|
|
|
|
MP_INT *dst;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-10-28 01:54:09 +01:00
|
|
|
while (H+(sz+sizeof(MP_INT)/sizeof(CELL)+2) > ASP-1024) {
|
|
|
|
if (!doexpand((sz+sizeof(MP_INT)/sizeof(CELL)+2)*sizeof(CELL)))
|
|
|
|
return TermNil;
|
|
|
|
}
|
2007-11-16 14:58:41 +00:00
|
|
|
I = AbsAppl(H);
|
2006-12-13 16:10:26 +00:00
|
|
|
H[0] = (CELL)FunctorBigInt;
|
|
|
|
dst = (MP_INT *)(H+1);
|
|
|
|
dst->_mp_size = 0L;
|
|
|
|
dst->_mp_alloc = sz;
|
|
|
|
H += (1+sizeof(MP_INT)/sizeof(CELL));
|
|
|
|
H[sz] = EndSpecials;
|
|
|
|
H += sz+1;
|
|
|
|
RECOVER_H();
|
|
|
|
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void *
|
|
|
|
YAP_BlobOfTerm(Term t)
|
|
|
|
{
|
|
|
|
MP_INT *src;
|
2007-03-30 17:47:22 +01:00
|
|
|
|
2006-12-13 16:10:26 +00:00
|
|
|
if (IsVarTerm(t))
|
|
|
|
return NULL;
|
|
|
|
if (!IsBigIntTerm(t))
|
|
|
|
return NULL;
|
|
|
|
src = (MP_INT *)(RepAppl(t)+1);
|
|
|
|
return (void *)(src+1);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkFloatTerm(double n)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
|
|
|
t = MkFloatTerm(n);
|
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API flt
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_FloatOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (FloatOfTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkAtomTerm(Atom n)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = MkAtomTerm(n);
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Atom
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_AtomOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (AtomOfTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API int
|
|
|
|
YAP_IsWideAtom(Atom a)
|
|
|
|
{
|
|
|
|
return IsWideAtom(a);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API char *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_AtomName(Atom a)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
char *o;
|
|
|
|
|
|
|
|
o = AtomName(a);
|
|
|
|
return(o);
|
|
|
|
}
|
|
|
|
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API wchar_t *
|
|
|
|
YAP_WideAtomName(Atom a)
|
|
|
|
{
|
|
|
|
return RepAtom(a)->WStrOfAE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Atom
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_LookupAtom(char *c)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2005-03-01 22:25:09 +00:00
|
|
|
Atom a;
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
a = Yap_LookupAtom(c);
|
|
|
|
if (a == NIL || (ActiveSignals & YAP_CDOVF_SIGNAL)) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return a;
|
2004-07-23 04:37:17 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API Atom
|
|
|
|
YAP_LookupWideAtom(wchar_t *c)
|
|
|
|
{
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
a = Yap_LookupWideAtom(c);
|
|
|
|
if (a == NIL || (ActiveSignals & YAP_CDOVF_SIGNAL)) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Atom
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_FullLookupAtom(char *c)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Atom at;
|
|
|
|
|
2005-03-01 22:25:09 +00:00
|
|
|
while (TRUE) {
|
|
|
|
at = Yap_FullLookupAtom(c);
|
|
|
|
if (at == NIL || (ActiveSignals & YAP_CDOVF_SIGNAL)) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return at;
|
2004-07-23 04:37:17 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-09-04 11:34:55 +01:00
|
|
|
X_API int
|
|
|
|
YAP_AtomNameLength(Atom at)
|
|
|
|
{
|
|
|
|
if (IsWideAtom(at)) {
|
|
|
|
wchar_t *c = RepAtom(at)->WStrOfAE;
|
|
|
|
|
|
|
|
return wcslen(c);
|
|
|
|
} else {
|
|
|
|
char *c = RepAtom(at)->StrOfAE;
|
|
|
|
|
|
|
|
return strlen(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkVarTerm(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
CELL t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
|
|
|
t = MkVarTerm();
|
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkPairTerm(Term t1, Term t2)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-11-16 14:58:41 +00:00
|
|
|
if (H > ASP-1024)
|
|
|
|
t = TermNil;
|
|
|
|
else
|
|
|
|
t = MkPairTerm(t1, t2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-05-14 19:24:34 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkNewPairTerm()
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-11-16 14:58:41 +00:00
|
|
|
if (H > ASP-1024)
|
|
|
|
t = TermNil;
|
|
|
|
else
|
|
|
|
t = Yap_MkNewPairTerm();
|
2002-05-14 19:24:34 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_HeadOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (HeadOfTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_TailOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (TailOfTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkApplTerm(Functor f,unsigned long int arity, Term args[])
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-11-16 14:58:41 +00:00
|
|
|
if (H+arity > ASP-1024)
|
|
|
|
t = TermNil;
|
|
|
|
else
|
|
|
|
t = Yap_MkApplTerm(f, arity, args);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-05-06 16:33:05 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkNewApplTerm(Functor f,unsigned long int arity)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-11-16 14:58:41 +00:00
|
|
|
if (H+arity > ASP-1024)
|
|
|
|
t = TermNil;
|
|
|
|
else
|
|
|
|
t = Yap_MkNewApplTerm(f, arity);
|
2002-05-06 16:33:05 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2002-05-06 16:33:05 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API Functor
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_FunctorOfTerm(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (FunctorOfTerm(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_ArgOfTerm(Int n, Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (ArgOfTerm(n, t));
|
|
|
|
}
|
|
|
|
|
2007-06-04 13:28:02 +01:00
|
|
|
X_API Term *
|
|
|
|
YAP_ArgsOfTerm(Term t)
|
|
|
|
{
|
|
|
|
if (IsApplTerm(t))
|
|
|
|
return RepAppl(t)+1;
|
|
|
|
else if (IsPairTerm(t))
|
|
|
|
return RepPair(t);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
X_API Functor
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_MkFunctor(Atom a, Int n)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_MkFunctor(a, n));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Atom
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_NameOfFunctor(Functor f)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (NameOfFunctor(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_ArityOfFunctor(Functor f)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return (ArityOfFunctor(f));
|
|
|
|
}
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
X_API void *
|
|
|
|
YAP_ExtraSpaceCut(void)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
BACKUP_B();
|
|
|
|
|
2006-03-09 15:52:06 +00:00
|
|
|
ptr = (void *)(((CELL *)(Yap_REGS.CUT_C_TOP))-(((yamop *)Yap_REGS.CUT_C_TOP->try_userc_cut_yamop)->u.lds.extra));
|
2005-11-18 18:52:41 +00:00
|
|
|
|
|
|
|
RECOVER_B();
|
|
|
|
return(ptr);
|
|
|
|
}
|
|
|
|
#endif /*CUT_C*/
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API void *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_ExtraSpace(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
BACKUP_B();
|
|
|
|
|
|
|
|
/* find a pointer to extra space allocable */
|
|
|
|
ptr = (void *)((CELL *)(B+1)+P->u.lds.s);
|
|
|
|
|
|
|
|
RECOVER_B();
|
|
|
|
return(ptr);
|
|
|
|
}
|
|
|
|
|
2005-10-18 18:04:43 +01:00
|
|
|
X_API void
|
|
|
|
YAP_cut_up(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
BACKUP_B();
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
{
|
|
|
|
while (POP_CHOICE_POINT(B->cp_b))
|
|
|
|
{
|
|
|
|
POP_EXECUTE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CUT_C */
|
2005-10-18 18:04:43 +01:00
|
|
|
#ifdef YAPOR
|
2005-10-21 17:07:07 +01:00
|
|
|
{
|
|
|
|
choiceptr cut_pt;
|
|
|
|
|
|
|
|
cut_pt = B->cp_b;
|
|
|
|
CUT_prune_to(cut_pt);
|
|
|
|
B = cut_pt;
|
|
|
|
}
|
|
|
|
#else /* YAPOR */
|
2002-01-14 22:26:53 +00:00
|
|
|
B = B->cp_b; /* cut_fail */
|
2005-10-21 17:07:07 +01:00
|
|
|
#endif
|
2002-01-14 22:26:53 +00:00
|
|
|
HB = B->cp_h; /* cut_fail */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_B();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Unify(Term t1, Term t2)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int out;
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_unify(t1, t2);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
2007-01-08 08:27:19 +00:00
|
|
|
return out;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-05-14 17:44:12 +01:00
|
|
|
X_API long
|
|
|
|
YAP_CurrentSlot(void)
|
|
|
|
{
|
|
|
|
return Yap_CurrentSlot();
|
|
|
|
}
|
|
|
|
|
2002-05-18 05:01:53 +01:00
|
|
|
X_API long
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_NewSlots(int n)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return Yap_NewSlots(n);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API long
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_InitSlot(Term t)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return Yap_InitSlot(t);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_RecoverSlots(int n)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_RecoverSlots(n);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_GetFromSlot(long slot)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return Yap_GetFromSlot(slot);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_AddressFromSlot(long slot)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return Yap_AddressFromSlot(slot);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_PutInSlot(long slot, Term t)
|
2002-05-18 05:01:53 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutInSlot(slot, t);
|
2002-05-18 05:01:53 +01:00
|
|
|
}
|
|
|
|
|
2002-05-16 21:33:00 +01:00
|
|
|
|
2002-05-18 05:01:53 +01:00
|
|
|
typedef Int (*CPredicate1)(long);
|
|
|
|
typedef Int (*CPredicate2)(long,long);
|
|
|
|
typedef Int (*CPredicate3)(long,long,long);
|
|
|
|
typedef Int (*CPredicate4)(long,long,long,long);
|
|
|
|
typedef Int (*CPredicate5)(long,long,long,long,long);
|
|
|
|
typedef Int (*CPredicate6)(long,long,long,long,long,long);
|
|
|
|
typedef Int (*CPredicate7)(long,long,long,long,long,long,long);
|
|
|
|
typedef Int (*CPredicate8)(long,long,long,long,long,long,long,long);
|
2002-05-16 21:33:00 +01:00
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Execute(PredEntry *pe, CPredicate exec_code)
|
2002-05-16 21:33:00 +01:00
|
|
|
{
|
|
|
|
if (pe->PredFlags & CArgsPredFlag) {
|
|
|
|
switch (pe->ArityOfPE) {
|
|
|
|
case 0:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate code0 = exec_code;
|
2002-05-16 21:33:00 +01:00
|
|
|
return ((code0)());
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate1 code1 = (CPredicate1)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code1)(YAP_InitSlot(Deref(ARG1))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate2 code2 = (CPredicate2)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code2)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate3 code3 = (CPredicate3)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code3)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate4 code4 = (CPredicate4)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code4)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3)),
|
|
|
|
YAP_InitSlot(Deref(ARG4))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate5 code5 = (CPredicate5)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code5)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3)),
|
|
|
|
YAP_InitSlot(Deref(ARG4)),
|
|
|
|
YAP_InitSlot(Deref(ARG5))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate6 code6 = (CPredicate6)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code6)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3)),
|
|
|
|
YAP_InitSlot(Deref(ARG4)),
|
|
|
|
YAP_InitSlot(Deref(ARG5)),
|
|
|
|
YAP_InitSlot(Deref(ARG6))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate7 code7 = (CPredicate7)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code7)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3)),
|
|
|
|
YAP_InitSlot(Deref(ARG4)),
|
|
|
|
YAP_InitSlot(Deref(ARG5)),
|
|
|
|
YAP_InitSlot(Deref(ARG6)),
|
|
|
|
YAP_InitSlot(Deref(ARG7))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
2002-06-11 06:43:01 +01:00
|
|
|
CPredicate8 code8 = (CPredicate8)exec_code;
|
2002-09-09 18:40:12 +01:00
|
|
|
return ((code8)(YAP_InitSlot(Deref(ARG1)),
|
|
|
|
YAP_InitSlot(Deref(ARG2)),
|
|
|
|
YAP_InitSlot(Deref(ARG3)),
|
|
|
|
YAP_InitSlot(Deref(ARG4)),
|
|
|
|
YAP_InitSlot(Deref(ARG5)),
|
|
|
|
YAP_InitSlot(Deref(ARG6)),
|
|
|
|
YAP_InitSlot(Deref(ARG7)),
|
|
|
|
YAP_InitSlot(Deref(ARG8))));
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
2002-06-11 06:43:01 +01:00
|
|
|
return((exec_code)());
|
2002-05-16 21:33:00 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_CallProlog(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int out;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = CurrentModule;
|
2001-04-09 20:54:03 +01:00
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2002-05-14 19:24:34 +01:00
|
|
|
while (!IsVarTerm(t) &&
|
|
|
|
IsApplTerm(t) &&
|
|
|
|
FunctorOfTerm(t) == FunctorModule) {
|
|
|
|
Term tmod = ArgOfTerm(1,t);
|
|
|
|
if (IsVarTerm(tmod)) return(FALSE);
|
|
|
|
if (!IsAtomTerm(tmod)) return(FALSE);
|
2004-02-12 12:37:12 +00:00
|
|
|
mod = tmod;
|
2002-05-14 19:24:34 +01:00
|
|
|
t = ArgOfTerm(2,t);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_execute_goal(t, 0, mod);
|
2001-04-09 20:54:03 +01:00
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
X_API void *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_AllocSpaceFromYap(unsigned int size)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2005-04-10 05:35:19 +01:00
|
|
|
while ((ptr = Yap_AllocCodeSpace(size)) == NULL) {
|
2004-01-23 02:23:51 +00:00
|
|
|
if (!Yap_growheap(FALSE, size, NULL)) {
|
2004-11-19 22:08:43 +00:00
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
2005-04-10 05:35:19 +01:00
|
|
|
return NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
2005-04-10 05:35:19 +01:00
|
|
|
return ptr;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_FreeSpaceFromYap(void *ptr)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace(ptr);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a string to a buffer */
|
2001-05-21 21:00:05 +01:00
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
unsigned int j = 0;
|
|
|
|
|
|
|
|
while (t != TermNil) {
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (IsVarTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,Head,"user defined procedure");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsIntTerm(Head)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
if (i < 0 || i > 255) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
buf[j++] = i;
|
2001-05-21 21:00:05 +01:00
|
|
|
if (j > bufsize) {
|
|
|
|
buf[j-1] = '\0';
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
t = TailOfTerm(t);
|
|
|
|
if (IsVarTerm(t)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(INSTANTIATION_ERROR,t,"user defined procedure");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
} else if (!IsPairTerm(t) && t != TermNil) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST, t, "user defined procedure");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf[j] = '\0';
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
/* copy a string to a buffer */
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_BufferToString(char *s)
|
2001-05-21 21:00:05 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
t = Yap_StringToList(s);
|
2001-05-21 21:00:05 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a string to a buffer */
|
|
|
|
X_API Term
|
|
|
|
YAP_ReadBuffer(char *s, Term *tp)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2007-06-04 13:28:02 +01:00
|
|
|
while ((t = Yap_StringToTerm(s,tp)) == 0L) {
|
|
|
|
if (!dogc())
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-14 17:33:47 +01:00
|
|
|
RECOVER_H();
|
|
|
|
return t;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a string to a buffer */
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_BufferToAtomList(char *s)
|
2001-05-21 21:00:05 +01:00
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
BACKUP_H();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
t = Yap_StringToListOfAtoms(s);
|
2001-05-21 21:00:05 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API void
|
2005-03-02 18:35:49 +00:00
|
|
|
YAP_Error(int myerrno, Term t, char *buf,...)
|
|
|
|
{
|
|
|
|
#define YAP_BUF_SIZE 512
|
|
|
|
va_list ap;
|
|
|
|
char tmpbuf[YAP_BUF_SIZE];
|
|
|
|
|
|
|
|
if (!myerrno)
|
|
|
|
myerrno = SYSTEM_ERROR;
|
|
|
|
if (t == 0L)
|
|
|
|
t = TermNil;
|
|
|
|
if (buf != NULL) {
|
|
|
|
va_start (ap, buf);
|
|
|
|
#if HAVE_VSNPRINTF
|
|
|
|
(void) vsnprintf(tmpbuf, YAP_BUF_SIZE, buf, ap);
|
|
|
|
#else
|
|
|
|
(void) vsprintf(tmpbuf, buf, ap);
|
|
|
|
#endif
|
|
|
|
va_end (ap);
|
|
|
|
} else {
|
|
|
|
tmpbuf[0] = '\0';
|
|
|
|
}
|
|
|
|
Yap_Error(myerrno,t,tmpbuf);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-01-28 14:26:37 +00:00
|
|
|
static int myputc (wchar_t ch)
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
putc(ch,stderr);
|
2006-11-27 17:42:03 +00:00
|
|
|
return ch;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2007-06-04 13:28:02 +01:00
|
|
|
X_API PredEntry *
|
|
|
|
YAP_FunctorToPred(Functor func)
|
|
|
|
{
|
|
|
|
return RepPredProp(PredPropByFunc(func, CurrentModule));
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API PredEntry *
|
|
|
|
YAP_AtomToPred(Atom at)
|
|
|
|
{
|
|
|
|
return RepPredProp(PredPropByAtom(at, CurrentModule));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
run_emulator(YAP_dogoalinfo *dgi)
|
|
|
|
{
|
|
|
|
choiceptr myB;
|
|
|
|
int out;
|
|
|
|
|
|
|
|
Yap_PrologMode = UserMode;
|
|
|
|
out = Yap_absmi(0);
|
|
|
|
Yap_PrologMode = UserCCallMode;
|
|
|
|
myB = (choiceptr)(LCL0-dgi->b);
|
|
|
|
CP = myB->cp_cp;
|
|
|
|
if (!out ) {
|
|
|
|
/* recover stack */
|
|
|
|
/* on failed computations */
|
|
|
|
TR = B->cp_tr;
|
|
|
|
H = B->cp_h;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH = B->cp_depth = DEPTH;
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
YENV = ENV = B->cp_env;
|
|
|
|
ASP = (CELL *)(B+1);
|
|
|
|
B = B->cp_b;
|
|
|
|
HB = B->cp_h;
|
|
|
|
}
|
|
|
|
P = dgi->p;
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_EnterGoal(PredEntry *pe, Term *ptr, YAP_dogoalinfo *dgi)
|
|
|
|
{
|
|
|
|
UInt i;
|
|
|
|
choiceptr myB;
|
2007-10-16 00:48:46 +01:00
|
|
|
int out;
|
2007-06-04 13:28:02 +01:00
|
|
|
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
dgi->p = P;
|
|
|
|
ptr--;
|
|
|
|
i = pe->ArityOfPE;
|
|
|
|
while (i>0) {
|
|
|
|
XREGS[i] = ptr[i];
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
P = pe->CodeOfPred;
|
|
|
|
/* create a choice-point to be tag new goal */
|
|
|
|
myB = (choiceptr)ASP;
|
|
|
|
myB--;
|
|
|
|
dgi->b = LCL0-(CELL *)myB;
|
|
|
|
myB->cp_tr = TR;
|
|
|
|
myB->cp_h = HB = H;
|
|
|
|
myB->cp_b = B;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
myB->cp_depth = DEPTH;
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
myB->cp_cp = CP;
|
|
|
|
myB->cp_ap = NOCODE;
|
|
|
|
myB->cp_env = ENV;
|
|
|
|
CP = YESCODE;
|
|
|
|
B = myB;
|
|
|
|
HB = H;
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
WPP = NULL;
|
|
|
|
#endif
|
|
|
|
ASP = YENV = (CELL *)B;
|
2007-10-16 00:48:46 +01:00
|
|
|
YENV[E_CB] = Unsigned (B);
|
|
|
|
out = run_emulator(dgi);
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return out;
|
2007-06-04 13:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_RetryGoal(YAP_dogoalinfo *dgi)
|
|
|
|
{
|
|
|
|
choiceptr myB;
|
|
|
|
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
myB = (choiceptr)(LCL0-dgi->b);
|
|
|
|
CP = myB->cp_cp;
|
|
|
|
/* sanity check */
|
|
|
|
if (B >= myB) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
P = FAILCODE;
|
|
|
|
return run_emulator(dgi);
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_LeaveGoal(int backtrack, YAP_dogoalinfo *dgi)
|
|
|
|
{
|
|
|
|
choiceptr myB;
|
|
|
|
|
|
|
|
myB = (choiceptr)(LCL0-dgi->b);
|
2007-11-01 20:50:31 +00:00
|
|
|
if (B > myB) {
|
|
|
|
/* someone cut us */
|
2007-06-04 13:28:02 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-01 20:50:31 +00:00
|
|
|
/* prune away choicepoints */
|
|
|
|
if (B != myB) {
|
2007-06-04 13:28:02 +01:00
|
|
|
#ifdef YAPOR
|
2007-11-01 20:50:31 +00:00
|
|
|
CUT_prune_to(myB);
|
2007-06-04 13:28:02 +01:00
|
|
|
#endif
|
2007-11-01 20:50:31 +00:00
|
|
|
B = myB;
|
|
|
|
}
|
|
|
|
/* if backtracking asked for, recover space and bindings */
|
2007-06-04 13:28:02 +01:00
|
|
|
if (backtrack) {
|
|
|
|
P = FAILCODE;
|
|
|
|
Yap_exec_absmi(TRUE);
|
|
|
|
/* recover stack space */
|
|
|
|
H = B->cp_h;
|
|
|
|
TR = B->cp_tr;
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH = B->cp_depth;
|
|
|
|
#endif /* DEPTH_LIMIT */
|
|
|
|
YENV = ENV = B->cp_env;
|
|
|
|
}
|
|
|
|
/* recover local stack */
|
|
|
|
ASP = (CELL *)(B+1);
|
|
|
|
B = B->cp_b;
|
|
|
|
HB = B->cp_h;
|
|
|
|
P = dgi->p;
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-05 04:37:01 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_RunGoal(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-06-05 04:37:01 +01:00
|
|
|
Term out;
|
2002-06-18 03:27:53 +01:00
|
|
|
yamop *old_CP = CP;
|
2001-04-09 20:54:03 +01:00
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2007-03-22 11:12:22 +00:00
|
|
|
Yap_AllowRestart = FALSE;
|
2005-02-08 18:05:21 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_RunTopGoal(t);
|
2005-02-08 18:05:21 +00:00
|
|
|
Yap_PrologMode = UserCCallMode;
|
2002-06-18 03:27:53 +01:00
|
|
|
if (out) {
|
|
|
|
P = (yamop *)ENV[E_CP];
|
|
|
|
ENV = (CELL *)ENV[E_E];
|
|
|
|
CP = old_CP;
|
2007-03-22 11:12:22 +00:00
|
|
|
Yap_AllowRestart = TRUE;
|
2002-06-18 03:27:53 +01:00
|
|
|
} else {
|
2002-09-09 18:40:12 +01:00
|
|
|
if (B != NULL) /* restore might have destroyed B */
|
|
|
|
B = B->cp_b;
|
2007-03-22 11:12:22 +00:00
|
|
|
Yap_AllowRestart = FALSE;
|
2002-06-18 03:27:53 +01:00
|
|
|
}
|
2007-03-22 11:12:22 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_RestartGoal(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int out;
|
|
|
|
BACKUP_MACHINE_REGS();
|
2007-03-22 11:12:22 +00:00
|
|
|
|
|
|
|
if (Yap_AllowRestart) {
|
|
|
|
P = (yamop *)FAILCODE;
|
|
|
|
do_putcf = myputc;
|
|
|
|
Yap_PrologMode = UserMode;
|
|
|
|
out = Yap_exec_absmi(TRUE);
|
|
|
|
Yap_PrologMode = UserCCallMode;
|
|
|
|
if (out == FALSE) {
|
|
|
|
/* cleanup */
|
|
|
|
Yap_trust_last();
|
|
|
|
Yap_AllowRestart = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out = FALSE;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2007-05-14 17:44:12 +01:00
|
|
|
X_API int
|
2007-05-15 12:33:51 +01:00
|
|
|
YAP_ShutdownGoal(int backtrack)
|
2007-05-14 17:44:12 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
|
|
|
if (Yap_AllowRestart) {
|
|
|
|
choiceptr cut_pt;
|
|
|
|
yamop *my_p = P;
|
|
|
|
|
|
|
|
cut_pt = B;
|
|
|
|
while (cut_pt-> cp_ap != NOCODE) {
|
|
|
|
cut_pt = cut_pt->cp_b;
|
|
|
|
}
|
|
|
|
#ifdef YAPOR
|
|
|
|
CUT_prune_to(cut_pt);
|
|
|
|
#endif
|
|
|
|
/* just force backtrack */
|
|
|
|
B = cut_pt;
|
2007-05-15 12:33:51 +01:00
|
|
|
if (backtrack) {
|
|
|
|
P = FAILCODE;
|
|
|
|
Yap_exec_absmi(TRUE);
|
|
|
|
/* recover stack space */
|
|
|
|
H = cut_pt->cp_h;
|
|
|
|
TR = cut_pt->cp_tr;
|
|
|
|
}
|
|
|
|
/* we can always recover the stack */
|
2007-05-14 17:44:12 +01:00
|
|
|
ENV = cut_pt->cp_env;
|
|
|
|
ASP = (CELL *)(cut_pt+1);
|
|
|
|
ASP += EnvSizeInCells;
|
|
|
|
P = my_p;
|
|
|
|
ENV = (CELL *)ASP[E_E];
|
|
|
|
B = (choiceptr)ASP[E_CB];
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH = ASP[E_DEPTH];
|
|
|
|
#endif
|
|
|
|
Yap_AllowRestart = FALSE;
|
|
|
|
}
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_ContinueGoal(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int out;
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2005-02-08 18:05:21 +00:00
|
|
|
Yap_PrologMode = UserMode;
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_exec_absmi(TRUE);
|
2005-02-08 18:05:21 +00:00
|
|
|
Yap_PrologMode = UserCCallMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return(out);
|
|
|
|
}
|
|
|
|
|
2002-05-14 19:24:34 +01:00
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_PruneGoal(void)
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
BACKUP_B();
|
|
|
|
|
|
|
|
while (B->cp_ap != NOCODE) {
|
|
|
|
B = B->cp_b;
|
|
|
|
}
|
2002-06-18 03:27:53 +01:00
|
|
|
B = B->cp_b;
|
2002-05-14 19:24:34 +01:00
|
|
|
|
|
|
|
RECOVER_B();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_GoalHasException(Term *t)
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
int out = FALSE;
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
if (EX) {
|
|
|
|
*t = EX;
|
|
|
|
out = TRUE;
|
|
|
|
}
|
|
|
|
RECOVER_MACHINE_REGS();
|
2005-08-17 14:35:52 +01:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
|
|
|
YAP_ClearExceptions(void)
|
|
|
|
{
|
|
|
|
EX = 0L;
|
|
|
|
UncaughtThrow = FALSE;
|
2002-05-14 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_InitConsult(int mode, char *filename)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
|
|
|
if (mode == YAP_CONSULT_MODE)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_consult(FALSE, filename);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_consult(TRUE, filename);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_EndConsult(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_end_consult();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Read(int (*mygetc)(void))
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Term t;
|
2003-01-08 16:45:35 +00:00
|
|
|
int sno;
|
2004-02-05 16:57:02 +00:00
|
|
|
TokEntry *tokstart;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
|
|
|
do_getf = mygetc;
|
2006-11-27 17:42:03 +00:00
|
|
|
sno = Yap_GetFreeStreamDForReading();
|
2004-06-09 04:32:03 +01:00
|
|
|
if (sno < 0) {
|
2003-01-08 16:45:35 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil, "new stream not available for YAP_Read");
|
|
|
|
return TermNil;
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
Stream[sno].stream_getc = do_yap_getc;
|
2004-02-05 16:57:02 +00:00
|
|
|
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(sno);
|
2003-01-08 16:45:35 +00:00
|
|
|
Stream[sno].status = Free_Stream_f;
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_ErrorMessage)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2005-04-10 05:01:15 +01:00
|
|
|
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
t = Yap_Parse();
|
2004-02-05 16:57:02 +00:00
|
|
|
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
2004-05-14 17:33:47 +01:00
|
|
|
return t;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2007-01-28 14:26:37 +00:00
|
|
|
YAP_Write(Term t, int (*myputc)(wchar_t), int flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2007-01-28 14:26:37 +00:00
|
|
|
do_putcf = myputc; /* */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (t, do_yap_putc, flags);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
}
|
|
|
|
|
2007-05-14 17:44:12 +01:00
|
|
|
|
|
|
|
X_API Term
|
|
|
|
YAP_CopyTerm(Term t)
|
|
|
|
{
|
|
|
|
Term tn;
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
|
|
|
tn = Yap_CopyTerm(t);
|
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
|
|
|
|
return tn;
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:56:47 +01:00
|
|
|
X_API Term
|
|
|
|
YAP_WriteBuffer(Term t, char *buf, unsigned int sze, int flags)
|
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
t = Yap_TermToString(t, buf, sze, flags);
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API char *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_CompileClause(Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *codeaddr;
|
2001-11-15 00:01:43 +00:00
|
|
|
int mod = CurrentModule;
|
2004-12-08 00:56:35 +00:00
|
|
|
Term tn = TermNil;
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ErrorMessage = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
ARG1 = t;
|
2004-06-29 20:04:46 +01:00
|
|
|
YAPEnterCriticalSection();
|
2003-11-21 16:56:20 +00:00
|
|
|
codeaddr = Yap_cclause (t,0, mod, t);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (codeaddr != NULL) {
|
|
|
|
t = Deref(ARG1); /* just in case there was an heap overflow */
|
2004-11-18 22:32:40 +00:00
|
|
|
if (!Yap_addclause (t, codeaddr, TRUE, mod, &tn)) {
|
|
|
|
YAPLeaveCriticalSection();
|
|
|
|
return Yap_ErrorMessage;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-06-29 20:04:46 +01:00
|
|
|
YAPLeaveCriticalSection();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-07-23 04:37:17 +01:00
|
|
|
if (ActiveSignals & YAP_CDOVF_SIGNAL) {
|
|
|
|
if (!Yap_growheap(FALSE, 0, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "YAP failed to grow heap: %s", Yap_ErrorMessage);
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
RECOVER_MACHINE_REGS();
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_ErrorMessage);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this routine is supposed to be called from an external program
|
|
|
|
that wants to control Yap */
|
|
|
|
|
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Init(YAP_init_args *yap_init)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int restore_result;
|
2002-10-30 17:27:19 +00:00
|
|
|
CELL Trail = 0, Stack = 0, Heap = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_argv = yap_init->Argv;
|
|
|
|
Yap_argc = yap_init->Argc;
|
2007-10-29 22:48:54 +00:00
|
|
|
if (yap_init->SavedState != NULL &&
|
2002-10-30 17:27:19 +00:00
|
|
|
yap_init->YapPrologBootFile == NULL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap) != 1) {
|
2005-03-02 18:35:49 +00:00
|
|
|
yap_init->ErrorNo = Yap_Error_TYPE;
|
|
|
|
yap_init->ErrorCause = Yap_ErrorMessage;
|
|
|
|
return YAP_BOOT_FROM_SAVED_ERROR;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (yap_init->TrailSize == 0) {
|
|
|
|
if (Trail == 0)
|
|
|
|
Trail = DefTrailSpace;
|
|
|
|
} else {
|
|
|
|
Trail = yap_init->TrailSize;
|
|
|
|
}
|
|
|
|
if (yap_init->StackSize == 0) {
|
|
|
|
if (Stack == 0)
|
|
|
|
Stack = DefStackSpace;
|
|
|
|
} else {
|
|
|
|
Stack = yap_init->StackSize;
|
|
|
|
}
|
|
|
|
if (yap_init->HeapSize == 0) {
|
|
|
|
if (Heap == 0)
|
|
|
|
Heap = DefHeapSpace;
|
|
|
|
} else {
|
|
|
|
Heap = yap_init->HeapSize;
|
|
|
|
}
|
2004-11-18 22:32:40 +00:00
|
|
|
/* tell the system who should cope with interruptions */
|
|
|
|
Yap_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts;
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_InitWorkspace(Heap, Stack, Trail,
|
2005-08-04 16:45:56 +01:00
|
|
|
yap_init->MaxTableSpaceSize,
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_init->NumberWorkers,
|
|
|
|
yap_init->SchedulerLoop,
|
|
|
|
yap_init->DelayedReleaseLoad
|
|
|
|
);
|
2004-02-05 16:57:02 +00:00
|
|
|
Yap_InitExStacks (Trail, Stack);
|
2005-07-19 18:12:18 +01:00
|
|
|
|
|
|
|
{ BACKUP_MACHINE_REGS();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitYaamRegs();
|
2002-02-11 20:46:41 +00:00
|
|
|
|
|
|
|
#if HAVE_MPI
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitMPI ();
|
2002-02-11 20:46:41 +00:00
|
|
|
#endif
|
2002-02-22 14:31:45 +00:00
|
|
|
#if HAVE_MPE
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitMPE ();
|
2002-02-22 14:31:45 +00:00
|
|
|
#endif
|
2002-02-11 20:46:41 +00:00
|
|
|
|
2002-10-30 17:27:19 +00:00
|
|
|
if (yap_init->YapPrologRCFile != NULL) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
|
|
|
This must be done before restore, otherwise
|
|
|
|
restore will print out messages ....
|
|
|
|
*/
|
|
|
|
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
|
|
|
|
}
|
2002-10-30 17:27:19 +00:00
|
|
|
if (yap_init->SavedState != NULL ||
|
|
|
|
yap_init->YapPrologBootFile == NULL) {
|
2005-03-15 18:29:25 +00:00
|
|
|
#if SUPPORT_CONDOR || SUPPORT_THREADS
|
|
|
|
restore_result = YAP_FULL_BOOT_FROM_PROLOG;
|
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
restore_result = Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
|
2005-03-02 18:35:49 +00:00
|
|
|
if (restore_result == FAIL_RESTORE) {
|
|
|
|
yap_init->ErrorNo = Yap_Error_TYPE;
|
|
|
|
yap_init->ErrorCause = Yap_ErrorMessage;
|
2005-07-19 18:12:18 +01:00
|
|
|
/* shouldn't RECOVER_MACHINE_REGS(); be here ??? */
|
2005-03-02 18:35:49 +00:00
|
|
|
return YAP_BOOT_FROM_SAVED_ERROR;
|
|
|
|
}
|
2005-03-15 18:29:25 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
|
|
|
restore_result = FAIL_RESTORE;
|
|
|
|
}
|
2002-01-27 20:40:10 +00:00
|
|
|
yap_flags[FAST_BOOT_FLAG] = yap_init->FastBoot;
|
2001-04-09 20:54:03 +01:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
|
|
|
make_root_frames();
|
|
|
|
#ifdef YAPOR
|
|
|
|
init_workers();
|
|
|
|
#endif /* YAPOR */
|
|
|
|
init_local();
|
|
|
|
#ifdef YAPOR
|
|
|
|
if (worker_id != 0) {
|
|
|
|
#if SBA
|
|
|
|
/*
|
|
|
|
In the SBA we cannot just happily inherit registers
|
|
|
|
from the other workers
|
|
|
|
*/
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitYaamRegs();
|
2003-11-07 16:31:08 +00:00
|
|
|
#endif /* SBA */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* slaves, waiting for work */
|
2004-05-13 21:54:58 +01:00
|
|
|
CurrentModule = USER_MODULE;
|
2001-04-09 20:54:03 +01:00
|
|
|
P = GETWORK_FIRST_TIME;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exec_absmi(FALSE);
|
2005-05-31 01:23:47 +01:00
|
|
|
Yap_Error(INTERNAL_ERROR, TermNil, "abstract machine unexpected exit (YAP_Init)");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#endif /* YAPOR || TABLING */
|
|
|
|
RECOVER_MACHINE_REGS();
|
2005-07-19 18:12:18 +01:00
|
|
|
}
|
2005-10-21 17:07:07 +01:00
|
|
|
if (yap_init->YapPrologRCFile) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$consult_on_boot"), MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologRCFile)));
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
|
|
|
This must be done again after restore, as yap_flags
|
|
|
|
has been overwritten ....
|
|
|
|
*/
|
|
|
|
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
|
|
|
|
}
|
2006-02-08 17:29:55 +00:00
|
|
|
#ifdef MYDDAS_MYSQL
|
|
|
|
if (yap_init->myddas) {
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_goal"),MkIntegerTerm(yap_init->myddas));
|
|
|
|
|
|
|
|
/* Mandatory Fields */
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_user"),MkAtomTerm(Yap_LookupAtom(yap_init->myddas_user)));
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_db"),MkAtomTerm(Yap_LookupAtom(yap_init->myddas_db)));
|
|
|
|
|
|
|
|
/* Non-Mandatory Fields */
|
|
|
|
if (yap_init->myddas_pass != NULL)
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_pass"),MkAtomTerm(Yap_LookupAtom(yap_init->myddas_pass)));
|
|
|
|
if (yap_init->myddas_host != NULL)
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_host"),MkAtomTerm(Yap_LookupAtom(yap_init->myddas_host)));
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-21 17:07:07 +01:00
|
|
|
if (yap_init->YapPrologTopLevelGoal) {
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$top_level_goal"), MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologTopLevelGoal)));
|
|
|
|
}
|
|
|
|
if (yap_init->YapPrologGoal) {
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$init_goal"), MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologGoal)));
|
|
|
|
}
|
2005-10-28 18:38:50 +01:00
|
|
|
if (yap_init->YapPrologAddPath) {
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$extend_file_search_path"), MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologAddPath)));
|
|
|
|
}
|
2002-10-30 17:27:19 +00:00
|
|
|
if (yap_init->SavedState != NULL ||
|
|
|
|
yap_init->YapPrologBootFile == NULL) {
|
2005-03-02 18:35:49 +00:00
|
|
|
if (restore_result == FAIL_RESTORE) {
|
|
|
|
yap_init->ErrorNo = Yap_Error_TYPE;
|
|
|
|
yap_init->ErrorCause = Yap_ErrorMessage;
|
|
|
|
return YAP_BOOT_FROM_SAVED_ERROR;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (restore_result == DO_ONLY_CODE) {
|
2005-03-02 18:35:49 +00:00
|
|
|
return YAP_BOOT_FROM_SAVED_CODE;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2005-03-02 18:35:49 +00:00
|
|
|
return YAP_BOOT_FROM_SAVED_STACKS;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return YAP_BOOT_FROM_PROLOG;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_FastInit(char saved_state[])
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_init_args init_args;
|
2005-03-02 18:35:49 +00:00
|
|
|
Int out;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
init_args.SavedState = saved_state;
|
|
|
|
init_args.HeapSize = 0;
|
|
|
|
init_args.StackSize = 0;
|
|
|
|
init_args.TrailSize = 0;
|
|
|
|
init_args.YapLibDir = NULL;
|
|
|
|
init_args.YapPrologBootFile = NULL;
|
2004-01-23 02:23:51 +00:00
|
|
|
init_args.YapPrologInitFile = NULL;
|
2002-10-30 17:27:19 +00:00
|
|
|
init_args.YapPrologRCFile = NULL;
|
2005-10-21 17:07:07 +01:00
|
|
|
init_args.YapPrologGoal = NULL;
|
|
|
|
init_args.YapPrologTopLevelGoal = NULL;
|
2005-10-28 18:38:50 +01:00
|
|
|
init_args.YapPrologAddPath = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
init_args.HaltAfterConsult = FALSE;
|
2002-01-27 20:40:10 +00:00
|
|
|
init_args.FastBoot = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
init_args.NumberWorkers = 1;
|
|
|
|
init_args.SchedulerLoop = 10;
|
|
|
|
init_args.DelayedReleaseLoad = 3;
|
2004-11-18 22:32:40 +00:00
|
|
|
init_args.PrologShouldHandleInterrupts = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
init_args.Argc = 0;
|
|
|
|
init_args.Argv = NULL;
|
2005-03-02 18:35:49 +00:00
|
|
|
init_args.ErrorNo = 0;
|
|
|
|
init_args.ErrorCause = NULL;
|
|
|
|
out = YAP_Init(&init_args);
|
|
|
|
if (out == YAP_BOOT_FROM_SAVED_ERROR) {
|
|
|
|
Yap_Error(init_args.ErrorNo,TermNil,init_args.ErrorCause);
|
|
|
|
}
|
|
|
|
return out;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_PutValue(Atom at, Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(at, t);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_GetValue(Atom at)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_GetValue(at));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API int
|
|
|
|
YAP_CompareTerms(Term t1, Term t2)
|
|
|
|
{
|
|
|
|
return Yap_compare_terms(t1, t2);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Reset(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
|
|
|
|
|
|
|
/* first, backtrack to the root */
|
|
|
|
if (B != NULL) {
|
|
|
|
while (B->cp_b != NULL)
|
|
|
|
B = B->cp_b;
|
|
|
|
P = (yamop *)FAILCODE;
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_exec_absmi(0) != 0)
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
/* reinitialise the engine */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitYaamRegs();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Exit(int retval)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exit(retval);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_InitSocks(char *host, long port)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#if USE_SOCKET
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_init_socks(host, port);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_SetOutputMessage(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#if DEBUG
|
2002-11-19 17:10:45 +00:00
|
|
|
Yap_output_msg = TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
X_API int
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_StreamToFileNo(Term t)
|
2001-05-21 21:00:05 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
return(Yap_StreamToFileNo(t));
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_CloseAllOpenStreams(void)
|
2001-05-21 21:00:05 +01:00
|
|
|
{
|
|
|
|
BACKUP_H();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_CloseStreams(FALSE);
|
2001-05-21 21:00:05 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_OpenStream(void *fh, char *name, Term nm, int flags)
|
2001-05-21 21:00:05 +01:00
|
|
|
{
|
2001-06-13 18:18:38 +01:00
|
|
|
Term retv;
|
|
|
|
|
2001-05-21 21:00:05 +01:00
|
|
|
BACKUP_H();
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
retv = Yap_OpenStream((FILE *)fh, name, nm, flags);
|
2001-05-21 21:00:05 +01:00
|
|
|
|
|
|
|
RECOVER_H();
|
2001-06-13 18:18:38 +01:00
|
|
|
return retv;
|
2001-05-21 21:00:05 +01:00
|
|
|
}
|
|
|
|
|
2002-05-06 16:33:05 +01:00
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Throw(Term t)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
|
|
|
BACKUP_MACHINE_REGS();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_JumpToEnv(t);
|
2002-05-06 16:33:05 +01:00
|
|
|
RECOVER_MACHINE_REGS();
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Halt(int i)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exit(i);
|
2002-05-06 16:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API CELL *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_TopOfLocalStack(void)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
|
|
|
return(ASP);
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void *
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_Predicate(Atom a, unsigned long int arity, int m)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
|
|
|
if (arity == 0) {
|
|
|
|
return((void *)RepPredProp(PredPropByAtom(a,m)));
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Functor f = Yap_MkFunctor(a, arity);
|
2002-05-06 16:33:05 +01:00
|
|
|
return((void *)RepPredProp(PredPropByFunc(f,m)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
2004-08-11 17:14:55 +01:00
|
|
|
YAP_PredicateInfo(void *p, Atom* a, unsigned long int* arity, Term* m)
|
2002-05-06 16:33:05 +01:00
|
|
|
{
|
|
|
|
PredEntry *pd = (PredEntry *)p;
|
|
|
|
if (pd->ArityOfPE) {
|
|
|
|
*arity = pd->ArityOfPE;
|
|
|
|
*a = NameOfFunctor(pd->FunctorOfPred);
|
|
|
|
} else {
|
|
|
|
*arity = 0;
|
|
|
|
*a = (Atom)(pd->FunctorOfPred);
|
|
|
|
}
|
2004-02-12 12:37:12 +00:00
|
|
|
if (pd->ModuleOfPred)
|
|
|
|
*m = pd->ModuleOfPred;
|
|
|
|
else
|
|
|
|
*m = TermProlog;
|
2002-05-06 16:33:05 +01:00
|
|
|
}
|
2002-05-14 19:24:34 +01:00
|
|
|
|
2002-09-09 18:40:12 +01:00
|
|
|
X_API void
|
|
|
|
YAP_UserCPredicate(char *name, CPredicate def, unsigned long int arity)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred(name, arity, def, UserCPredFlag);
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
X_API void
|
|
|
|
YAP_UserBackCPredicate(char *name, CPredicate init, CPredicate cont,
|
|
|
|
unsigned long int arity, unsigned int extra)
|
|
|
|
{
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
Yap_InitCPredBackCut(name, arity, extra, init, cont, NULL ,UserCPredFlag);
|
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPredBack(name, arity, extra, init, cont, UserCPredFlag);
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-09 18:40:12 +01:00
|
|
|
}
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
X_API void
|
|
|
|
YAP_UserBackCutCPredicate(char *name, CPredicate init, CPredicate cont, CPredicate cut,
|
|
|
|
unsigned long int arity, unsigned int extra)
|
|
|
|
{
|
|
|
|
Yap_InitCPredBackCut(name, arity, extra, init, cont, cut, UserCPredFlag);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-05-16 21:33:00 +01:00
|
|
|
X_API void
|
2004-02-12 12:37:12 +00:00
|
|
|
YAP_UserCPredicateWithArgs(char *a, CPredicate f, unsigned long int arity, Term mod)
|
2002-05-16 21:33:00 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term cm = CurrentModule;
|
2002-05-16 21:33:00 +01:00
|
|
|
CurrentModule = mod;
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_UserCPredicate(a,f,arity);
|
2002-05-16 21:33:00 +01:00
|
|
|
if (arity == 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByAtom(Yap_LookupAtom(a),mod));
|
2002-05-16 21:33:00 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Functor f = Yap_MkFunctor(Yap_LookupAtom(a), arity);
|
2002-05-16 21:33:00 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(f,mod));
|
|
|
|
}
|
|
|
|
pe->PredFlags |= CArgsPredFlag;
|
|
|
|
CurrentModule = cm;
|
|
|
|
}
|
|
|
|
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API Term
|
2002-09-09 18:40:12 +01:00
|
|
|
YAP_CurrentModule(void)
|
2002-05-14 19:24:34 +01:00
|
|
|
{
|
|
|
|
return(CurrentModule);
|
|
|
|
}
|
2002-09-09 18:40:12 +01:00
|
|
|
|
2004-08-11 17:14:55 +01:00
|
|
|
X_API Term
|
|
|
|
YAP_CreateModule(Atom at)
|
|
|
|
{
|
2007-04-19 00:01:16 +01:00
|
|
|
Term t;
|
|
|
|
WRITE_LOCK(RepAtom(at)->ARWLock);
|
|
|
|
t = Yap_Module(MkAtomTerm(at));
|
|
|
|
WRITE_UNLOCK(RepAtom(at)->ARWLock);
|
|
|
|
return t;
|
|
|
|
|
2004-08-11 17:14:55 +01:00
|
|
|
}
|
|
|
|
|
2004-07-22 22:32:23 +01:00
|
|
|
X_API int
|
|
|
|
YAP_ThreadSelf(void)
|
|
|
|
{
|
|
|
|
#if USE_THREADS
|
|
|
|
return Yap_thread_self();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-03-13 06:26:13 +00:00
|
|
|
X_API CELL
|
2004-07-22 22:32:23 +01:00
|
|
|
YAP_ThreadCreateEngine(thread_attr *attr)
|
|
|
|
{
|
|
|
|
#if USE_THREADS
|
|
|
|
return Yap_thread_create_engine(attr);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_ThreadAttachEngine(int wid)
|
|
|
|
{
|
|
|
|
#if USE_THREADS
|
|
|
|
return Yap_thread_attach_engine(wid);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_ThreadDetachEngine(int wid)
|
|
|
|
{
|
|
|
|
#if USE_THREADS
|
|
|
|
return Yap_thread_detach_engine(wid);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
X_API int
|
|
|
|
YAP_ThreadDestroyEngine(int wid)
|
|
|
|
{
|
|
|
|
#if USE_THREADS
|
|
|
|
return Yap_thread_destroy_engine(wid);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-05-16 19:37:31 +01:00
|
|
|
X_API Term
|
2006-12-13 16:10:26 +00:00
|
|
|
YAP_TermNil(void)
|
2006-05-16 19:37:31 +01:00
|
|
|
{
|
2006-12-13 16:10:26 +00:00
|
|
|
return TermNil;
|
2006-05-16 19:37:31 +01:00
|
|
|
}
|
|
|
|
|