2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: init.c *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: initializing a prolog session *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code from this file is used to initialize the environment for prolog
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "yapio.h"
|
2004-01-23 02:23:51 +00:00
|
|
|
#include "alloc.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "clause.h"
|
2002-11-11 17:38:10 +00:00
|
|
|
#include "Foreign.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
#include "tracer.h"
|
|
|
|
#endif
|
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
#endif /* YAPOR || TABLING */
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-11-11 17:38:10 +00:00
|
|
|
|
|
|
|
#define LOGFILE "logfile"
|
|
|
|
|
2002-11-19 17:10:45 +00:00
|
|
|
int Yap_output_msg = FALSE;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MACC
|
|
|
|
STATIC_PROTO(void InTTYLine, (char *));
|
|
|
|
#endif
|
|
|
|
#endif
|
2005-10-21 17:09:03 +01:00
|
|
|
STATIC_PROTO(void SetOp, (int, int, char *, Term));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void InitOps, (void));
|
|
|
|
STATIC_PROTO(void InitDebug, (void));
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate, CPredicate));
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate));
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void InitStdPreds,(void));
|
|
|
|
STATIC_PROTO(void InitFlags, (void));
|
|
|
|
STATIC_PROTO(void InitCodes, (void));
|
|
|
|
STATIC_PROTO(void InitVersion, (void));
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
STD_PROTO(void exit, (int));
|
|
|
|
|
|
|
|
/************** YAP PROLOG GLOBAL VARIABLES *************************/
|
|
|
|
|
|
|
|
/************* variables related to memory allocation ***************/
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
ADDR Yap_HeapBase;
|
|
|
|
|
|
|
|
#ifdef THREADS
|
|
|
|
|
2005-01-04 02:50:23 +00:00
|
|
|
struct restore_info rinfo[MAX_WORKERS];
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
struct thread_globs Yap_thread_gl[MAX_WORKERS];
|
|
|
|
|
|
|
|
#else
|
2005-01-04 02:50:23 +00:00
|
|
|
|
|
|
|
struct restore_info rinfo;
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
ADDR Yap_HeapBase,
|
|
|
|
Yap_LocalBase,
|
|
|
|
Yap_GlobalBase,
|
|
|
|
Yap_TrailBase,
|
|
|
|
Yap_TrailTop;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/************ variables concerned with Error Handling *************/
|
2002-11-18 18:18:05 +00:00
|
|
|
char *Yap_ErrorMessage; /* used to pass error messages */
|
|
|
|
Term Yap_Error_Term; /* used to pass error terms */
|
|
|
|
yap_error_number Yap_Error_TYPE; /* used to pass the error */
|
2003-05-19 14:04:09 +01:00
|
|
|
UInt Yap_Error_Size; /* used to pass a size associated with an error */
|
2002-11-11 17:38:10 +00:00
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
/******************* storing error messages ****************************/
|
|
|
|
char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
|
|
|
|
|
|
|
|
/* if we botched in a LongIO operation */
|
|
|
|
jmp_buf Yap_IOBotch;
|
|
|
|
|
|
|
|
/* if we botched in the compiler */
|
|
|
|
jmp_buf Yap_CompilerBotch;
|
|
|
|
|
|
|
|
/************ variables concerned with Error Handling *************/
|
|
|
|
sigjmp_buf Yap_RestartEnv; /* used to restart after an abort execution */
|
|
|
|
|
|
|
|
/********* IO support *****/
|
|
|
|
|
|
|
|
/********* parsing ********************************************/
|
|
|
|
|
|
|
|
TokEntry *Yap_tokptr, *Yap_toktide;
|
|
|
|
VarEntry *Yap_VarTable, *Yap_AnonVarTable;
|
|
|
|
int Yap_eot_before_eof = FALSE;
|
|
|
|
|
|
|
|
/******************* intermediate buffers **********************/
|
|
|
|
|
|
|
|
char Yap_FileNameBuf[YAP_FILENAME_MAX],
|
|
|
|
Yap_FileNameBuf2[YAP_FILENAME_MAX];
|
|
|
|
|
|
|
|
#endif /* THREADS */
|
|
|
|
|
2005-01-28 23:14:41 +00:00
|
|
|
/******** whether Yap is responsible for signal handling******************/
|
|
|
|
int Yap_PrologShouldHandleInterrupts;
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/********* readline support *****/
|
|
|
|
#if HAVE_LIBREADLINE
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
char *_line = (char *) NULL;
|
|
|
|
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef MPWSHELL
|
|
|
|
/********** informing if we are in the MPW shell ********************/
|
|
|
|
|
|
|
|
int mpwshell = FALSE;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EMACS
|
|
|
|
|
|
|
|
int emacs_mode = FALSE;
|
|
|
|
char emacs_tmp[256], emacs_tmp2[256];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/********* Prolog State ********************************************/
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
prolog_exec_mode Yap_PrologMode = BootMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_CritLocks = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/********* streams ********************************************/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_c_input_stream, Yap_c_output_stream, Yap_c_error_stream;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
YP_FILE *Yap_stdin;
|
|
|
|
YP_FILE *Yap_stdout;
|
|
|
|
YP_FILE *Yap_stderr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
/************** Access to yap initial arguments ***************************/
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
char **Yap_argv;
|
|
|
|
int Yap_argc;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/************** Extensions to Terms ***************************************/
|
|
|
|
|
|
|
|
#ifdef COROUTINING
|
|
|
|
/* array with the ops for your favourite extensions */
|
|
|
|
ext_op attas[attvars_ext+1];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************** declarations local to init.c ************************/
|
|
|
|
static char *optypes[] =
|
|
|
|
{"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/* OS page size for memory allocation */
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_page_size;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if USE_THREADED_CODE
|
|
|
|
/* easy access to instruction opcodes */
|
2002-11-18 18:18:05 +00:00
|
|
|
void **Yap_ABSMI_OPCODES;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if USE_SOCKET
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_sockets_io=0;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if DEBUG
|
|
|
|
#if COROUTINING
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_Portray_delays = FALSE;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_do_low_level_trace = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#define xfx 1
|
|
|
|
#define xfy 2
|
|
|
|
#define yfx 3
|
|
|
|
#define xf 4
|
|
|
|
#define yf 5
|
|
|
|
#define fx 6
|
|
|
|
#define fy 7
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_IsOpType(char *type)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i <= 7; ++i)
|
|
|
|
if (strcmp(type, optypes[i]) == 0)
|
|
|
|
break;
|
|
|
|
return (i <= 7);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static int
|
2005-10-21 17:09:03 +01:00
|
|
|
OpDec(int p, char *type, Atom a, Term m)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
OpEntry *info;
|
|
|
|
|
|
|
|
for (i = 1; i <= 7; ++i)
|
|
|
|
if (strcmp(type, optypes[i]) == 0)
|
|
|
|
break;
|
|
|
|
if (i > 7) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,MkAtomTerm(Yap_LookupAtom(type)),"op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
if (i == 1 || i == 2 || i == 4)
|
|
|
|
p |= DcrlpFlag;
|
|
|
|
if (i == 1 || i == 3 || i == 6)
|
|
|
|
p |= DcrrpFlag;
|
|
|
|
}
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
info = RepOpProp(Yap_GetAPropHavingLock(ae, OpProperty));
|
2001-04-09 20:54:03 +01:00
|
|
|
if (EndOfPAEntr(info)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry));
|
2001-04-09 20:54:03 +01:00
|
|
|
info->KindOfPE = Ord(OpProperty);
|
2001-10-30 16:42:05 +00:00
|
|
|
info->NextOfPE = RepAtom(a)->PropsOfAE;
|
2005-10-21 17:09:03 +01:00
|
|
|
info->OpModule = m;
|
2006-04-28 14:23:23 +01:00
|
|
|
info->OpName = a;
|
|
|
|
LOCK(OpListLock);
|
|
|
|
info->OpNext = OpList;
|
|
|
|
OpList = info;
|
|
|
|
UNLOCK(OpListLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
RepAtom(a)->PropsOfAE = AbsOpProp(info);
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_RWLOCK(info->OpRWLock);
|
|
|
|
WRITE_LOCK(info->OpRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
info->Prefix = info->Infix = info->Posfix = 0;
|
|
|
|
} else {
|
|
|
|
WRITE_LOCK(info->OpRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
|
|
|
if (i <= 3) {
|
2007-02-18 00:26:36 +00:00
|
|
|
if (yap_flags[STRICT_ISO_FLAG] &&
|
|
|
|
info->Posfix != 0) /* there is a posfix operator */ {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* ISO dictates */
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR,MkAtomTerm(a),"op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
info->Infix = p;
|
|
|
|
} else if (i <= 5) {
|
2007-02-18 00:26:36 +00:00
|
|
|
if (yap_flags[STRICT_ISO_FLAG] &&
|
|
|
|
info->Infix != 0) /* there is an infix operator */ {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* ISO dictates */
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR,MkAtomTerm(a),"op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
info->Posfix = p;
|
|
|
|
} else {
|
|
|
|
info->Prefix = p;
|
|
|
|
}
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2005-10-21 17:09:03 +01:00
|
|
|
Yap_OpDec(int p, char *type, Atom a, Term m)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2005-10-21 17:09:03 +01:00
|
|
|
return(OpDec(p,type,a,m));
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
2005-10-21 17:09:03 +01:00
|
|
|
SetOp(int p, int type, char *at, Term m)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_Option[5])
|
2002-11-11 17:38:10 +00:00
|
|
|
fprintf(stderr,"[setop %d %s %s]\n", p, optypes[type], at);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2005-10-21 17:09:03 +01:00
|
|
|
OpDec(p, optypes[type], Yap_LookupAtom(at), m);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets the info about an operator in a prop */
|
|
|
|
Atom
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetOp(OpEntry *pp, int *prio, int fix)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
SMALLUNSGN p;
|
|
|
|
|
|
|
|
if (fix == 0) {
|
|
|
|
p = pp->Prefix;
|
|
|
|
if (p & DcrrpFlag)
|
|
|
|
n = 6, *prio = (p ^ DcrrpFlag);
|
|
|
|
else
|
|
|
|
n = 7, *prio = p;
|
|
|
|
} else if (fix == 1) {
|
|
|
|
p = pp->Posfix;
|
|
|
|
if (p & DcrlpFlag)
|
|
|
|
n = 4, *prio = (p ^ DcrlpFlag);
|
|
|
|
else
|
|
|
|
n = 5, *prio = p;
|
|
|
|
} else {
|
|
|
|
p = pp->Infix;
|
|
|
|
if ((p & DcrrpFlag) && (p & DcrlpFlag))
|
|
|
|
n = 1, *prio = (p ^ (DcrrpFlag | DcrlpFlag));
|
|
|
|
else if (p & DcrrpFlag)
|
|
|
|
n = 3, *prio = (p ^ DcrrpFlag);
|
|
|
|
else if (p & DcrlpFlag)
|
|
|
|
n = 2, *prio = (p ^ DcrlpFlag);
|
|
|
|
else
|
|
|
|
n = 4, *prio = p;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
return (Yap_LookupAtom(optypes[n]));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct OPSTRUCT {
|
|
|
|
char *opName;
|
|
|
|
short int opType, opPrio;
|
|
|
|
} Opdef;
|
|
|
|
|
|
|
|
static Opdef Ops[] = {
|
|
|
|
{":-", xfx, 1200},
|
|
|
|
{"-->", xfx, 1200},
|
|
|
|
{"?-", fx, 1200},
|
|
|
|
{":-", fx, 1200},
|
|
|
|
{"dynamic", fx, 1150},
|
|
|
|
{"initialization", fx, 1150},
|
|
|
|
{"mode", fx, 1150},
|
|
|
|
{"public", fx, 1150},
|
|
|
|
{"multifile", fx, 1150},
|
|
|
|
{"meta_predicate", fx, 1150},
|
|
|
|
{"discontiguous", fx, 1150},
|
|
|
|
#ifdef YAPOR
|
|
|
|
{"sequential", fx, 1150},
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
|
|
|
{"table", fx, 1150},
|
|
|
|
#endif /* TABLING */
|
2002-10-03 14:54:35 +01:00
|
|
|
#ifndef UNCUTABLE
|
|
|
|
{"uncutable", fx, 1150},
|
|
|
|
#endif /*UNCUTABLE ceh:*/
|
2001-04-09 20:54:03 +01:00
|
|
|
{";", xfy, 1100},
|
|
|
|
{"|", xfy, 1100},
|
|
|
|
/* {";", yf, 1100}, not allowed in ISO */
|
|
|
|
{"->", xfy, 1050},
|
|
|
|
{",", xfy, 1000},
|
|
|
|
{".", xfy, 999},
|
|
|
|
{"\\+", fy, 900},
|
|
|
|
{"not", fy, 900},
|
|
|
|
{"=", xfx, 700},
|
|
|
|
{"\\=", xfx, 700},
|
|
|
|
{"is", xfx, 700},
|
|
|
|
{"=..", xfx, 700},
|
|
|
|
{"==", xfx, 700},
|
|
|
|
{"\\==", xfx, 700},
|
|
|
|
{"@<", xfx, 700},
|
|
|
|
{"@>", xfx, 700},
|
|
|
|
{"@=<", xfx, 700},
|
|
|
|
{"@>=", xfx, 700},
|
|
|
|
{"=:=", xfx, 700},
|
|
|
|
{"=\\=", xfx, 700},
|
|
|
|
{"<", xfx, 700},
|
|
|
|
{">", xfx, 700},
|
|
|
|
{"=<", xfx, 700},
|
|
|
|
{">=", xfx, 700},
|
|
|
|
{":", xfy, 600},
|
|
|
|
{"+", yfx, 500},
|
|
|
|
{"-", yfx, 500},
|
|
|
|
{"/\\", yfx, 500},
|
|
|
|
{"\\/", yfx, 500},
|
|
|
|
{"#", yfx, 500},
|
|
|
|
{"+", fx, 500},
|
|
|
|
{"-", fx, 500},
|
|
|
|
{"\\", fx, 500},
|
|
|
|
{"*", yfx, 400},
|
|
|
|
{"/", yfx, 400},
|
|
|
|
{"<<", yfx, 400},
|
|
|
|
{">>", yfx, 400},
|
2002-01-02 00:34:44 +00:00
|
|
|
{"mod", yfx, 400},
|
|
|
|
{"rem", yfx, 400},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"//", yfx, 400},
|
|
|
|
{"**", xfx, 200},
|
|
|
|
{"^", xfy, 200}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitOps(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < sizeof(Ops) / sizeof(*Ops); ++i)
|
2005-10-21 17:09:03 +01:00
|
|
|
SetOp(Ops[i].opPrio, Ops[i].opType, Ops[i].opName, PROLOG_MODULE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef HAVE_ISATTY
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
|
|
|
InitDebug(void)
|
|
|
|
{
|
|
|
|
Atom At;
|
|
|
|
#ifdef DEBUG
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < 20; ++i)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Option[i] = 0;
|
2002-11-19 17:10:45 +00:00
|
|
|
if (Yap_output_msg) {
|
2001-04-09 20:54:03 +01:00
|
|
|
char ch;
|
2002-11-11 17:38:10 +00:00
|
|
|
|
|
|
|
#if HAVE_ISATTY
|
|
|
|
if (!isatty (0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(stderr,"absmi address:%p\n", FunAdr(Yap_absmi));
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"Set Trace Options:\n");
|
|
|
|
fprintf(stderr,"a getch\t\tb token\t\tc Lookup\td LookupVar\ti Index\n");
|
|
|
|
fprintf(stderr,"e SetOp\t\tf compile\tg icode\t\th boot\t\tl log\n");
|
2005-11-16 01:55:03 +00:00
|
|
|
fprintf(stderr,"m Machine\t p parser\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
while ((ch = YP_putchar(YP_getchar())) != '\n')
|
|
|
|
if (ch >= 'a' && ch <= 'z')
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Option[ch - 'a' + 1] = 1;
|
|
|
|
if (Yap_Option['l' - 96]) {
|
|
|
|
Yap_logfile = fopen(LOGFILE, "w");
|
|
|
|
if (Yap_logfile == NULL) {
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"can not open %s\n", LOGFILE);
|
|
|
|
getchar();
|
2001-04-09 20:54:03 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"logging session to file 'logfile'\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MAC
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_SetTextFile(LOGFILE);
|
2001-04-09 20:54:03 +01:00
|
|
|
lp = my_line;
|
|
|
|
curfile = Nill;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-18 04:24:10 +00:00
|
|
|
/* Set at full leash */
|
2004-02-06 02:26:23 +00:00
|
|
|
At = Yap_FullLookupAtom("$leash");
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(At, MkIntTerm(15));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-09-27 21:45:04 +01:00
|
|
|
Atom atom = Yap_FullLookupAtom(Name);
|
|
|
|
PredEntry *pe;
|
2004-11-18 22:32:40 +00:00
|
|
|
yamop *p_code;
|
2004-09-27 21:45:04 +01:00
|
|
|
StaticClause *cl = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
if (Arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->PredFlags & CPredFlag) {
|
|
|
|
/* already exists */
|
|
|
|
cl = ClauseCodeToStaticClause(pe->CodeOfPred);
|
2004-11-18 22:32:40 +00:00
|
|
|
if ((flags | StandardPredFlag | CPredFlag) != pe->PredFlags) {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)cl);
|
|
|
|
cl = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 22:32:40 +00:00
|
|
|
p_code = cl->ClCode;
|
2004-09-27 21:45:04 +01:00
|
|
|
while (!cl) {
|
|
|
|
UInt sz;
|
|
|
|
|
|
|
|
if (flags & SafePredFlag) {
|
2005-12-17 03:25:39 +00:00
|
|
|
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(p_code,sla),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2005-12-17 03:25:39 +00:00
|
|
|
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code,e),sla),e),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
|
|
|
if (!cl) {
|
|
|
|
if (!Yap_growheap(FALSE, sz, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += sz;
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-01-28 23:14:41 +00:00
|
|
|
cl->ClSize = sz;
|
2004-09-27 21:45:04 +01:00
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
p_code = cl->ClCode;
|
|
|
|
}
|
2003-11-18 19:16:08 +00:00
|
|
|
}
|
|
|
|
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags = flags | StandardPredFlag | CPredFlag;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.f_code = code;
|
2004-09-27 21:45:04 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_allocate);
|
|
|
|
p_code = NEXTOP(p_code,e);
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
if (flags & UserCPredFlag)
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_call_usercpred);
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_call_cpred);
|
2002-12-27 16:53:09 +00:00
|
|
|
p_code->u.sla.bmap = NULL;
|
2001-10-30 16:42:05 +00:00
|
|
|
p_code->u.sla.s = -Signed(RealEnvSize);
|
2006-12-13 16:10:26 +00:00
|
|
|
p_code->u.sla.sla_u.p =
|
|
|
|
p_code->u.sla.p0 =
|
|
|
|
pe;
|
2001-10-30 16:42:05 +00:00
|
|
|
p_code = NEXTOP(p_code,sla);
|
2004-09-27 21:45:04 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_deallocate);
|
|
|
|
p_code = NEXTOP(p_code,e);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-09-27 21:45:04 +01:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2003-11-18 19:16:08 +00:00
|
|
|
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-01-13 14:02:50 +00:00
|
|
|
Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-09-27 21:45:04 +01:00
|
|
|
Atom atom = Yap_LookupAtom(Name);
|
|
|
|
PredEntry *pe;
|
|
|
|
yamop *p_code = NULL;
|
|
|
|
StaticClause *cl = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
if (Arity) {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2001-11-15 00:01:43 +00:00
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
if (pe->PredFlags & CPredFlag) {
|
|
|
|
p_code = pe->CodeOfPred;
|
|
|
|
/* already exists */
|
|
|
|
} else {
|
|
|
|
while (!cl) {
|
2005-12-17 03:25:39 +00:00
|
|
|
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),llxx),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
|
|
|
if (!cl) {
|
|
|
|
if (!Yap_growheap(FALSE, sz, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += sz;
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-01-28 23:14:41 +00:00
|
|
|
cl->ClSize = sz;
|
2004-09-27 21:45:04 +01:00
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
p_code = cl->ClCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags = flags | StandardPredFlag | CPredFlag;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
|
|
|
pe->cs.d_code = cmp_code;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe->ModuleOfPred = CurrentModule;
|
2003-01-13 14:02:50 +00:00
|
|
|
p_code->opc = pe->OpcodeOfPred = Yap_opcode(_call_bfunc_xx);
|
2003-12-27 00:38:53 +00:00
|
|
|
p_code->u.llxx.p = pe;
|
|
|
|
p_code->u.llxx.f = FAILCODE;
|
|
|
|
p_code->u.llxx.x1 = Yap_emit_x(1);
|
|
|
|
p_code->u.llxx.x2 = Yap_emit_x(2);
|
|
|
|
p_code->u.llxx.flags = Yap_compile_cmp_flags(pe);
|
|
|
|
p_code = NEXTOP(p_code,llxx);
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-09-20 05:16:33 +01:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, int flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-02-06 02:26:23 +00:00
|
|
|
Atom atom = Yap_FullLookupAtom(Name);
|
2001-11-15 00:01:43 +00:00
|
|
|
PredEntry *pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
if (Arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
2002-05-28 17:26:00 +01:00
|
|
|
pe->PredFlags = flags | AsmPredFlag | StandardPredFlag | (code);
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.f_code = def;
|
|
|
|
pe->ModuleOfPred = CurrentModule;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (def != NULL) {
|
2003-04-30 18:46:05 +01:00
|
|
|
yamop *p_code = ((StaticClause *)NULL)->ClCode;
|
2005-12-17 03:25:39 +00:00
|
|
|
StaticClause *cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l));
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2005-11-23 03:01:33 +00:00
|
|
|
if (!cl) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred");
|
|
|
|
return;
|
|
|
|
}
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l);
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),e),e);
|
|
|
|
cl->usc.ClPred = pe;
|
2002-05-28 17:26:00 +01:00
|
|
|
p_code = cl->ClCode;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = pe->OpcodeOfPred = Yap_opcode(_call_cpred);
|
2002-12-27 16:53:09 +00:00
|
|
|
p_code->u.sla.bmap = NULL;
|
2001-10-30 16:42:05 +00:00
|
|
|
p_code->u.sla.s = -Signed(RealEnvSize);
|
2006-12-13 16:10:26 +00:00
|
|
|
p_code->u.sla.sla_u.p = p_code->u.sla.p0 = pe;
|
2001-10-30 16:42:05 +00:00
|
|
|
p_code = NEXTOP(p_code,sla);
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-12-28 22:20:37 +00:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = Yap_opcode(_undef_p);
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
yamop *code;
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause ||
|
|
|
|
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause ||
|
|
|
|
pe->CodeOfPred != pe->cs.p_code.FirstClause) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,
|
2001-04-09 20:54:03 +01:00
|
|
|
"initiating a C Pred with backtracking");
|
|
|
|
return;
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
code = (yamop *)(pe->cs.p_code.FirstClause);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_try_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_try_c);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 2);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2002-12-27 16:53:09 +00:00
|
|
|
code->u.lds.f = Start;
|
2001-04-09 20:54:03 +01:00
|
|
|
code = NEXTOP(code,lds);
|
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_c);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 1);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2002-12-27 16:53:09 +00:00
|
|
|
code->u.lds.f = Cont;
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
code = NEXTOP(code,lds);
|
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
|
|
|
code->opc = Yap_opcode(_cut_c);
|
|
|
|
else
|
|
|
|
code->opc = Yap_opcode(_cut_userc);
|
|
|
|
code->u.lds.f = Cut;
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2005-11-18 18:52:41 +00:00
|
|
|
Yap_InitCPredBack(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
|
|
|
CPredicate Cont,int flags){
|
|
|
|
Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,NULL,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_InitCPredBackCut(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
|
|
|
CPredicate Cont,CPredicate Cut,int flags){
|
|
|
|
Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,Cut,flags);
|
|
|
|
}
|
|
|
|
#endif /* CUT_C */
|
|
|
|
|
|
|
|
void
|
|
|
|
#ifdef CUT_C
|
|
|
|
Yap_InitCPredBack_(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
|
|
|
CPredicate Cont, CPredicate Cut,int flags)
|
|
|
|
#else
|
|
|
|
Yap_InitCPredBack(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
|
|
|
CPredicate Cont, int flags)
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
PredEntry *pe;
|
2004-02-06 02:26:23 +00:00
|
|
|
Atom atom = Yap_FullLookupAtom(Name);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
if (Arity)
|
2002-11-18 18:18:05 +00:00
|
|
|
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
|
2001-11-15 00:01:43 +00:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.FirstClause != NIL)
|
2005-11-18 18:52:41 +00:00
|
|
|
{
|
|
|
|
#ifdef CUT_C
|
|
|
|
CleanBack(pe, Start, Cont, Cut);
|
|
|
|
#else
|
|
|
|
CleanBack(pe, Start, Cont);
|
|
|
|
#endif /*CUT_C*/
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
else {
|
2003-04-30 18:46:05 +01:00
|
|
|
StaticClause *cl;
|
|
|
|
yamop *code = ((StaticClause *)NULL)->ClCode;
|
2005-11-18 18:52:41 +00:00
|
|
|
if (flags & UserCPredFlag)
|
|
|
|
pe->PredFlags = UserCPredFlag | CompiledPredFlag | StandardPredFlag;
|
|
|
|
else
|
|
|
|
pe->PredFlags = CompiledPredFlag | StandardPredFlag;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
pe->PredFlags |= SequentialPredFlag;
|
|
|
|
#endif /* YAPOR */
|
2005-11-18 18:52:41 +00:00
|
|
|
|
|
|
|
#ifdef CUT_C
|
2005-12-17 03:25:39 +00:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,lds),lds),lds),l));
|
2005-11-18 18:52:41 +00:00
|
|
|
#else
|
2005-12-17 03:25:39 +00:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(code,lds),lds),l));
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-19 22:08:43 +00:00
|
|
|
if (cl == NULL) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-12-17 03:25:39 +00:00
|
|
|
#ifdef CUT_C
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,lds),lds),lds),l);
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->ClSize =
|
|
|
|
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,lds),lds),lds),e);
|
|
|
|
#else
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(code,lds),lds),l);
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->ClSize =
|
|
|
|
(CELL)NEXTOP(NEXTOP(NEXTOP(code,lds),lds),e);
|
|
|
|
#endif
|
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
code = cl->ClCode;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred =
|
|
|
|
pe->cs.p_code.FirstClause = pe->cs.p_code.LastClause = code;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_c);
|
2002-12-27 16:53:09 +00:00
|
|
|
code->u.lds.f = Start;
|
2002-05-17 02:01:07 +01:00
|
|
|
code->u.lds.p = pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
code->u.lds.s = Arity;
|
|
|
|
code->u.lds.extra = Extra;
|
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 2);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
code = NEXTOP(code,lds);
|
|
|
|
if (flags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_c);
|
2002-12-27 16:53:09 +00:00
|
|
|
code->u.lds.f = Cont;
|
2002-05-17 02:01:07 +01:00
|
|
|
code->u.lds.p = pe;
|
2001-04-09 20:54:03 +01:00
|
|
|
code->u.lds.s = Arity;
|
|
|
|
code->u.lds.extra = Extra;
|
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 1);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
code = NEXTOP(code,lds);
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
if (flags & UserCPredFlag)
|
|
|
|
code->opc = Yap_opcode(_cut_userc);
|
|
|
|
else
|
|
|
|
code->opc = Yap_opcode(_cut_c);
|
|
|
|
code->u.lds.f = Cut;
|
|
|
|
code->u.lds.p = pe;
|
|
|
|
code->u.lds.s = Arity;
|
|
|
|
code->u.lds.extra = Extra;
|
|
|
|
code = NEXTOP(code,lds);
|
|
|
|
#endif /* CUT_C */
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitStdPreds(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPreds();
|
|
|
|
Yap_InitBackCPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitFlags(void)
|
|
|
|
{
|
2004-12-02 06:06:47 +00:00
|
|
|
/* note that Yap_heap_regs must be set first */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-04-16 17:41:04 +01:00
|
|
|
#if USE_GMP
|
|
|
|
yap_flags[YAP_INT_BOUNDED_FLAG] = 0;
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[YAP_INT_BOUNDED_FLAG] = 1;
|
2001-04-16 17:41:04 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[MAX_ARITY_FLAG] = -1;
|
|
|
|
yap_flags[INTEGER_ROUNDING_FLAG] = 0;
|
|
|
|
yap_flags[YAP_MAX_INTEGER_FLAG] = (Int)(~((CELL)1 << (sizeof(Int)*8-1)));
|
|
|
|
yap_flags[YAP_MIN_INTEGER_FLAG] = (Int)(((CELL)1 << (sizeof(Int)*8-1)));
|
|
|
|
yap_flags[CHAR_CONVERSION_FLAG] = 1;
|
|
|
|
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = 1;
|
|
|
|
yap_flags[YAP_TO_CHARS_FLAG] = QUINTUS_TO_CHARS;
|
|
|
|
yap_flags[LANGUAGE_MODE_FLAG] = 0;
|
|
|
|
yap_flags[STRICT_ISO_FLAG] = FALSE;
|
|
|
|
yap_flags[SOURCE_MODE_FLAG] = FALSE;
|
2003-01-08 16:45:35 +00:00
|
|
|
yap_flags[CHARACTER_ESCAPE_FLAG] = SICSTUS_CHARACTER_ESCAPES;
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
|
2001-10-31 20:16:48 +00:00
|
|
|
#if (defined(YAPOR) || defined(THREADS)) && PUREe_YAPOR
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = FALSE;
|
|
|
|
#else
|
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = TRUE;
|
|
|
|
#endif
|
2007-02-26 10:41:40 +00:00
|
|
|
yap_flags[GENERATE_DEBUG_INFO_FLAG] = TRUE;
|
2003-06-06 12:54:02 +01:00
|
|
|
/* current default */
|
|
|
|
yap_flags[INDEXING_MODE_FLAG] = INDEX_MODE_MULTI;
|
2005-07-06 20:34:12 +01:00
|
|
|
yap_flags[TABLING_MODE_FLAG] = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitCodes(void)
|
|
|
|
{
|
|
|
|
Atom
|
|
|
|
AtomAltNot,
|
|
|
|
#ifdef COROUTINING
|
|
|
|
AtomArrayAccess,
|
|
|
|
#endif
|
|
|
|
AtomArrow,
|
|
|
|
AtomBraces,
|
|
|
|
AtomEq,
|
|
|
|
AtomGVar,
|
|
|
|
AtomNot,
|
|
|
|
AtomQuery,
|
|
|
|
AtomSemic,
|
2004-01-29 13:37:10 +00:00
|
|
|
AtomCreep,
|
2001-04-09 20:54:03 +01:00
|
|
|
AtomStream,
|
|
|
|
AtomStreamPos,
|
|
|
|
AtomVar;
|
2002-01-24 23:55:34 +00:00
|
|
|
Functor
|
|
|
|
FunctorThrow;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->term_prolog = MkAtomTerm(Yap_LookupAtom("prolog"));
|
|
|
|
Yap_heap_regs->user_module = MkAtomTerm(Yap_LookupAtom("user"));
|
|
|
|
Yap_heap_regs->idb_module = MkAtomTerm(Yap_LookupAtom("idb"));
|
|
|
|
Yap_heap_regs->attributes_module = MkAtomTerm(Yap_LookupAtom("attributes"));
|
|
|
|
Yap_heap_regs->charsio_module = MkAtomTerm(Yap_LookupAtom("charsio"));
|
|
|
|
Yap_heap_regs->terms_module = MkAtomTerm(Yap_LookupAtom("terms"));
|
2006-05-17 19:38:11 +01:00
|
|
|
Yap_heap_regs->system_module = MkAtomTerm(Yap_LookupAtom("system"));
|
2006-08-02 19:18:31 +01:00
|
|
|
Yap_heap_regs->readutil_module = MkAtomTerm(Yap_LookupAtom("readutil"));
|
2006-12-27 01:32:38 +00:00
|
|
|
Yap_heap_regs->hacks_module = MkAtomTerm(Yap_LookupAtom("yap_hacks"));
|
2006-09-28 18:24:40 +01:00
|
|
|
Yap_heap_regs->globals_module = MkAtomTerm(Yap_LookupAtom("nb"));
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_InitModules();
|
2006-04-27 15:13:24 +01:00
|
|
|
#ifdef BEAM
|
|
|
|
Yap_heap_regs->beam_retry_code.opc = Yap_opcode(_retry_eam);
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->seq_def = TRUE;
|
2005-07-06 20:34:12 +01:00
|
|
|
Yap_heap_regs->getwork_code.opc = Yap_opcode(_getwork);
|
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->getwork_code), 0);
|
|
|
|
Yap_heap_regs->getwork_seq_code.opc = Yap_opcode(_getwork_seq);
|
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->getwork_seq_code), 0);
|
|
|
|
Yap_heap_regs->getwork_first_time_code.opc = Yap_opcode(_getwork_first_time);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
2005-08-01 16:40:39 +01:00
|
|
|
Yap_heap_regs->table_load_answer_code.opc = Yap_opcode(_table_load_answer);
|
|
|
|
Yap_heap_regs->table_try_answer_code.opc = Yap_opcode(_table_try_answer);
|
2005-07-06 20:34:12 +01:00
|
|
|
Yap_heap_regs->table_completion_code.opc = Yap_opcode(_table_completion);
|
|
|
|
Yap_heap_regs->table_answer_resolution_code.opc = Yap_opcode(_table_answer_resolution);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2005-08-01 16:40:39 +01:00
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->table_load_answer_code), 0);
|
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->table_try_answer_code), 0);
|
2005-07-06 20:34:12 +01:00
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->table_completion_code), 0);
|
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->table_answer_resolution_code), 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#endif /* TABLING */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->expand_op_code = Yap_opcode(_expand_index);
|
|
|
|
Yap_heap_regs->expand_clauses_first = NULL;
|
|
|
|
Yap_heap_regs->expand_clauses_last = NULL;
|
|
|
|
Yap_heap_regs->failcode->opc = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_1 = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_2 = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_3 = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_4 = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_5 = Yap_opcode(_op_fail);
|
|
|
|
Yap_heap_regs->failcode_6 = Yap_opcode(_op_fail);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->env_for_trustfail_code.op = Yap_opcode(_call);
|
|
|
|
Yap_heap_regs->env_for_trustfail_code.s = -Signed(RealEnvSize);
|
|
|
|
Yap_heap_regs->env_for_trustfail_code.l2 = NULL;
|
|
|
|
Yap_heap_regs->trustfailcode->opc = Yap_opcode(_trust_fail);
|
|
|
|
|
|
|
|
Yap_heap_regs->env_for_yes_code.op = Yap_opcode(_call);
|
|
|
|
Yap_heap_regs->env_for_yes_code.s = -Signed(RealEnvSize);
|
|
|
|
Yap_heap_regs->env_for_yes_code.l2 = NULL;
|
|
|
|
Yap_heap_regs->yescode->opc = Yap_opcode(_Ystop);
|
|
|
|
Yap_heap_regs->undef_op = Yap_opcode(_undef_p);
|
|
|
|
Yap_heap_regs->index_op = Yap_opcode(_index_pred);
|
|
|
|
Yap_heap_regs->fail_op = Yap_opcode(_op_fail);
|
|
|
|
|
|
|
|
Yap_heap_regs->nocode->opc = Yap_opcode(_Nstop);
|
|
|
|
|
|
|
|
((yamop *)(&Yap_heap_regs->rtrycode))->opc = Yap_opcode(_retry_and_mark);
|
|
|
|
((yamop *)(&Yap_heap_regs->rtrycode))->u.ld.s = 0;
|
|
|
|
((yamop *)(&Yap_heap_regs->rtrycode))->u.ld.d = NIL;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
2004-12-02 06:06:47 +00:00
|
|
|
INIT_YAMOP_LTT(&(Yap_heap_regs->rtrycode), 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
#ifdef THREADS
|
2004-12-02 06:06:47 +00:00
|
|
|
INIT_LOCK(Yap_heap_regs->thread_handles_lock);
|
2004-01-23 02:23:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i < MAX_WORKERS; i++) {
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->thread_handle[i].in_use = FALSE;
|
|
|
|
Yap_heap_regs->thread_handle[i].local_preds = NULL;
|
2004-01-23 02:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->thread_handle[0].id = 0;
|
|
|
|
Yap_heap_regs->thread_handle[0].in_use = TRUE;
|
|
|
|
Yap_heap_regs->thread_handle[0].default_yaam_regs =
|
2004-01-23 02:23:51 +00:00
|
|
|
&Yap_standard_regs;
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->thread_handle[0].handle = pthread_self();
|
|
|
|
Yap_heap_regs->thread_handle[0].handle = pthread_self();
|
2004-02-21 20:25:45 +00:00
|
|
|
pthread_mutex_init(&ThreadHandle[0].tlock, NULL);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->n_of_threads = 1;
|
|
|
|
Yap_heap_regs->n_of_threads_created = 1;
|
|
|
|
Yap_heap_regs->threads_total_time = 0;
|
2004-01-23 02:23:51 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2004-12-02 06:06:47 +00:00
|
|
|
INIT_LOCK(Yap_heap_regs->bgl);
|
|
|
|
INIT_LOCK(Yap_heap_regs->free_blocks_lock);
|
|
|
|
INIT_LOCK(Yap_heap_regs->heap_used_lock);
|
|
|
|
INIT_LOCK(Yap_heap_regs->heap_top_lock);
|
2006-03-22 20:07:28 +00:00
|
|
|
INIT_LOCK(Yap_heap_regs->dead_static_clauses_lock);
|
|
|
|
INIT_LOCK(Yap_heap_regs->dead_mega_clauses_lock);
|
|
|
|
INIT_LOCK(Yap_heap_regs->dead_static_indices_lock);
|
2006-04-28 14:23:23 +01:00
|
|
|
INIT_LOCK(Yap_heap_regs->op_list_lock);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->heap_top_owner = -1;
|
2004-01-23 02:23:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i < MAX_WORKERS; i++) {
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->wl[i].scratchpad.ptr = NULL;
|
|
|
|
Yap_heap_regs->wl[i].scratchpad.sz = SCRATCH_START_SIZE;
|
|
|
|
Yap_heap_regs->wl[i].scratchpad.msz = SCRATCH_START_SIZE;
|
2005-10-28 18:38:50 +01:00
|
|
|
Yap_heap_regs->wl[i].dynamic_arrays = NULL;
|
|
|
|
Yap_heap_regs->wl[i].static_arrays = NULL;
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_heap_regs->wl[i].global_variables = NULL;
|
|
|
|
Yap_heap_regs->wl[i].global_arena = 0L;
|
|
|
|
Yap_heap_regs->wl[i].global_delay_arena = 0L;
|
2007-03-22 11:12:22 +00:00
|
|
|
Yap_heap_regs->wl[i].allow_restart = FALSE;
|
2006-04-28 16:48:33 +01:00
|
|
|
Yap_heap_regs->wl[i].consultlow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
|
|
|
if (Yap_heap_regs->wl[i].consultlow == NULL) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Yap_heap_regs->wl[i].consultcapacity = InitialConsultCapacity;
|
|
|
|
Yap_heap_regs->wl[i].consultbase = Yap_heap_regs->wl[i].consultsp =
|
|
|
|
Yap_heap_regs->wl[i].consultlow + Yap_heap_regs->wl[i].consultcapacity;
|
2004-01-23 02:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-28 18:38:50 +01:00
|
|
|
#else
|
|
|
|
Yap_heap_regs->wl.dynamic_arrays = NULL;
|
|
|
|
Yap_heap_regs->wl.static_arrays = NULL;
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_heap_regs->wl.global_variables = NULL;
|
|
|
|
Yap_heap_regs->wl.global_arena = 0L;
|
2007-03-22 11:12:22 +00:00
|
|
|
Yap_heap_regs->wl.allow_restart = FALSE;
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_heap_regs->wl.global_delay_arena = 0L;
|
2006-04-28 16:48:33 +01:00
|
|
|
Yap_heap_regs->wl.consultlow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
|
|
|
if (Yap_heap_regs->wl.consultlow == NULL) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Yap_heap_regs->wl.consultcapacity = InitialConsultCapacity;
|
|
|
|
Yap_heap_regs->wl.consultbase = Yap_heap_regs->wl.consultsp =
|
|
|
|
Yap_heap_regs->wl.consultlow + Yap_heap_regs->wl.consultcapacity;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* YAPOR */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->clausecode->arity = 0;
|
|
|
|
Yap_heap_regs->clausecode->clause = NULL;
|
|
|
|
Yap_heap_regs->clausecode->func = NIL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->invisiblechain.Entry = NIL;
|
|
|
|
INIT_RWLOCK(Yap_heap_regs->invisiblechain.AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-02-11 13:59:53 +00:00
|
|
|
{
|
|
|
|
Atom at;
|
|
|
|
PredEntry *pred;
|
|
|
|
|
|
|
|
at = Yap_FullLookupAtom("$creep");
|
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),PROLOG_MODULE));
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->creep_code = pred;
|
2004-02-11 13:59:53 +00:00
|
|
|
at = Yap_FullLookupAtom("$undefp");
|
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),PROLOG_MODULE));
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->undef_code = pred;
|
2004-02-11 13:59:53 +00:00
|
|
|
at = Yap_FullLookupAtom("$spy");
|
|
|
|
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->spy_code = pred;
|
2007-01-24 10:01:40 +00:00
|
|
|
Yap_heap_regs->env_for_trustfail_code.p =
|
|
|
|
Yap_heap_regs->env_for_trustfail_code.p0 =
|
|
|
|
RepPredProp(PredPropByAtom(Yap_FullLookupAtom("fail"),PROLOG_MODULE));
|
2004-02-11 13:59:53 +00:00
|
|
|
}
|
2006-10-11 15:53:57 +01:00
|
|
|
#if DEBUG
|
|
|
|
Yap_heap_regs->new_cps = 0;
|
|
|
|
Yap_heap_regs->live_cps = 0;
|
|
|
|
Yap_heap_regs->dirty_cps = 0;
|
|
|
|
Yap_heap_regs->freed_cps = 0;
|
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->system_profiling = FALSE;
|
|
|
|
Yap_heap_regs->system_call_counting = FALSE;
|
2004-12-05 05:01:45 +00:00
|
|
|
Yap_heap_regs->system_pred_goal_expansion_all = FALSE;
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->system_pred_goal_expansion_on = FALSE;
|
|
|
|
Yap_heap_regs->update_mode = UPDATE_MODE_LOGICAL;
|
|
|
|
Yap_heap_regs->compiler_compile_mode = 0; /* fast will be for native code */
|
2005-07-06 16:10:18 +01:00
|
|
|
Yap_heap_regs->compiler_optimizer_on = TRUE;
|
2007-02-18 00:26:36 +00:00
|
|
|
Yap_heap_regs->compiler_compile_arrays = FALSE;
|
2005-12-05 17:16:12 +00:00
|
|
|
Yap_heap_regs->maxdepth = 0;
|
|
|
|
Yap_heap_regs->maxlist = 0;
|
|
|
|
Yap_heap_regs->maxwriteargs = 0;
|
2004-12-02 06:06:47 +00:00
|
|
|
|
|
|
|
Yap_heap_regs->atprompt = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef COROUTINING
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->num_of_atts = 1; /* initially only coroutining is supported */
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
/* system boots in compile mode */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->static_predicates_marked = TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* use Quintus compatible atom_chars and number_chars, not ISO compatible */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->static_predicates_marked = FALSE;
|
|
|
|
|
|
|
|
Yap_heap_regs->int_keys_size = INT_KEYS_DEFAULT_SIZE;
|
|
|
|
Yap_heap_regs->int_keys_timestamp = 0;
|
|
|
|
Yap_heap_regs->IntKeys = NULL;
|
|
|
|
Yap_heap_regs->int_bb_keys_size = INT_KEYS_DEFAULT_SIZE;
|
|
|
|
Yap_heap_regs->IntBBKeys = NULL;
|
|
|
|
Yap_heap_regs->char_conversion_table = NULL;
|
|
|
|
Yap_heap_regs->char_conversion_table2 = NULL;
|
2002-11-12 00:33:48 +00:00
|
|
|
/*
|
2002-11-18 18:18:05 +00:00
|
|
|
don't initialise this here, this is initialised by Yap_InitModules!!!!
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->no_of_modules = 1;
|
2002-11-12 00:33:48 +00:00
|
|
|
*/
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_abol = Yap_FullLookupAtom("$abol");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomAltNot = Yap_LookupAtom("not");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_append = Yap_LookupAtom ("append");
|
|
|
|
Yap_heap_regs->atom_array = Yap_FullLookupAtom("$array");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef COROUTINING
|
2004-02-06 02:26:23 +00:00
|
|
|
AtomArrayAccess = Yap_FullLookupAtom("$array_arg");
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomArrow = Yap_LookupAtom("->");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_assert = Yap_LookupAtom(":-");
|
|
|
|
Yap_heap_regs->atom_alarm = Yap_FullLookupAtom("$alarm");
|
2002-01-11 15:54:17 +00:00
|
|
|
#if HAVE_SIGACTION
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_sig_pending = Yap_FullLookupAtom("$sig_pending");
|
2002-01-09 17:19:36 +00:00
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomBraces = Yap_LookupAtom("{}");
|
2005-09-09 18:24:39 +01:00
|
|
|
#ifdef COROUTINING
|
|
|
|
Yap_heap_regs->atom_att = Yap_FullLookupAtom("$att");
|
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_b = Yap_FullLookupAtom("$last_choice_pt");
|
|
|
|
Yap_heap_regs->atom_break = Yap_FullLookupAtom("$break");
|
|
|
|
Yap_heap_regs->atom_call = Yap_LookupAtom("call");
|
|
|
|
Yap_heap_regs->atom_catch = Yap_FullLookupAtom("$catch");
|
|
|
|
Yap_heap_regs->atom_comma = Yap_LookupAtom(",");
|
|
|
|
Yap_heap_regs->atom_cpu_time = Yap_LookupAtom("cputime");
|
|
|
|
Yap_heap_regs->atom_csult = Yap_FullLookupAtom("$csult");
|
|
|
|
Yap_heap_regs->atom_cut = Yap_LookupAtom("!");
|
|
|
|
Yap_heap_regs->atom_cut_by = Yap_FullLookupAtom("$cut_by");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef EUROTRA
|
|
|
|
#ifdef SFUNC
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_dollar_undef = MkAtomTerm(Yap_FullLookupAtom("$undef"));
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_dbref = Yap_FullLookupAtom ("$dbref");
|
|
|
|
Yap_heap_regs->atom_e = Yap_LookupAtom("e");
|
|
|
|
Yap_heap_regs->atom_e_q = Yap_LookupAtom("=");
|
|
|
|
Yap_heap_regs->atom_eof = Yap_LookupAtom ("end_of_file");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomEq = Yap_LookupAtom("=");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef EUROTRA
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_f_b = Yap_LookupAtom("fb");
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_fail = Yap_LookupAtom("fail");
|
|
|
|
Yap_heap_regs->atom_false = Yap_LookupAtom("false");
|
|
|
|
Yap_heap_regs->atom_fast = Yap_FullLookupAtom("$fast");
|
|
|
|
Yap_heap_regs->atom_g_t = Yap_LookupAtom(">");
|
|
|
|
Yap_heap_regs->atom_gc = Yap_FullLookupAtom("$gc");
|
|
|
|
Yap_heap_regs->atom_gc_margin = Yap_FullLookupAtom("$gc_margin");
|
|
|
|
Yap_heap_regs->atom_gc_trace = Yap_FullLookupAtom("$gc_trace");
|
|
|
|
Yap_heap_regs->atom_gc_verbose = Yap_FullLookupAtom("$gc_verbose");
|
|
|
|
Yap_heap_regs->atom_gc_very_verbose = Yap_FullLookupAtom("$gc_very_verbose");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomGVar = Yap_LookupAtom("var");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_global = Yap_LookupAtom("global_sp");
|
|
|
|
Yap_heap_regs->atom_heap_used = Yap_LookupAtom("heapused");
|
|
|
|
Yap_heap_regs->atom_inf = Yap_LookupAtom("inf");
|
|
|
|
Yap_heap_regs->atom_l_t = Yap_LookupAtom("<");
|
|
|
|
Yap_heap_regs->atom_local = Yap_LookupAtom("local_sp");
|
|
|
|
Yap_heap_regs->atom_meta_call = Yap_FullLookupAtom("$call");
|
|
|
|
Yap_heap_regs->atom_minus = Yap_LookupAtom("-");
|
|
|
|
Yap_heap_regs->atom_multi_file = Yap_FullLookupAtom("$mf");
|
|
|
|
Yap_heap_regs->atom_nan = Yap_LookupAtom("nan");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomNot = Yap_LookupAtom("\\+");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_otherwise = Yap_LookupAtom("otherwise");
|
|
|
|
Yap_heap_regs->atom_pi = Yap_LookupAtom("pi");
|
|
|
|
Yap_heap_regs->atom_plus = Yap_LookupAtom("+");
|
|
|
|
Yap_heap_regs->atom_portray = Yap_FullLookupAtom("$portray");
|
|
|
|
Yap_heap_regs->atom_profile = Yap_FullLookupAtom("$profile");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomQuery = Yap_LookupAtom("?-");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_random = Yap_LookupAtom("random");
|
|
|
|
Yap_heap_regs->atom_read = Yap_LookupAtom("read");
|
|
|
|
Yap_heap_regs->atom_repeat = Yap_LookupAtom("repeat");
|
|
|
|
Yap_heap_regs->atom_restore_regs = Yap_FullLookupAtom("$restore_regs");
|
2002-11-18 18:18:05 +00:00
|
|
|
AtomSemic = Yap_LookupAtom(";");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_stack_free = Yap_LookupAtom("stackfree");
|
2004-02-06 02:26:23 +00:00
|
|
|
AtomStream = Yap_FullLookupAtom("$stream");
|
|
|
|
AtomStreamPos = Yap_FullLookupAtom("$stream_position");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_true = Yap_LookupAtom("true");
|
2004-01-29 13:37:10 +00:00
|
|
|
AtomCreep = Yap_LookupAtom("$creep");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_user = Yap_LookupAtom ("user");
|
|
|
|
Yap_heap_regs->atom_usr_err = Yap_LookupAtom ("user_error");
|
|
|
|
Yap_heap_regs->atom_usr_in = Yap_LookupAtom ("user_input");
|
|
|
|
Yap_heap_regs->atom_usr_out = Yap_LookupAtom ("user_output");
|
2004-02-06 02:26:23 +00:00
|
|
|
AtomVar = Yap_FullLookupAtom("$VAR");
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->atom_version_number = Yap_FullLookupAtom("$version_name");
|
|
|
|
Yap_heap_regs->atom_write = Yap_LookupAtom ("write");
|
2006-01-02 02:16:19 +00:00
|
|
|
Yap_heap_regs->float_format = Yap_LookupAtom ("\%.15g");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef USE_SOCKET
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_af_inet = Yap_MkFunctor(Yap_LookupAtom("AF_INET"),2);
|
|
|
|
Yap_heap_regs->functor_af_local = Yap_MkFunctor(Yap_LookupAtom("AF_LOCAL"),1);
|
|
|
|
Yap_heap_regs->functor_af_unix = Yap_MkFunctor(Yap_LookupAtom("AF_UNIX"),1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_alt_not = Yap_MkFunctor(AtomAltNot, 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef COROUTINING
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_array_entry = Yap_MkFunctor(AtomArrayAccess, 3);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_arrow = Yap_MkFunctor(AtomArrow, 2);
|
|
|
|
Yap_heap_regs->functor_assert = Yap_MkFunctor(AtomAssert, 2);
|
2005-10-28 18:38:50 +01:00
|
|
|
Yap_heap_regs->functor_at_found_one = Yap_MkFunctor(AtomFoundVar, 2);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef COROUTINING
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_att_goal = Yap_MkFunctor(Yap_FullLookupAtom("$att_do"),2);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_braces = Yap_MkFunctor(AtomBraces, 1);
|
|
|
|
Yap_heap_regs->functor_call = Yap_MkFunctor(AtomCall, 1);
|
|
|
|
Yap_heap_regs->functor_cut_by = Yap_MkFunctor(AtomCutBy, 1);
|
|
|
|
Yap_heap_regs->functor_clist = Yap_MkFunctor(Yap_FullLookupAtom("$when"), 4);
|
|
|
|
Yap_heap_regs->functor_comma = Yap_MkFunctor(AtomComma, 2);
|
|
|
|
Yap_heap_regs->functor_csult = Yap_MkFunctor(AtomCsult, 1);
|
|
|
|
Yap_heap_regs->functor_eq = Yap_MkFunctor(AtomEq, 2);
|
|
|
|
Yap_heap_regs->functor_execute_in_mod = Yap_MkFunctor(Yap_FullLookupAtom("$execute_in_mod"), 2);
|
|
|
|
Yap_heap_regs->functor_execute_within = Yap_MkFunctor(Yap_FullLookupAtom("$execute_within"), 1);
|
|
|
|
Yap_heap_regs->functor_g_atom = Yap_MkFunctor(Yap_LookupAtom("atom"), 1);
|
|
|
|
Yap_heap_regs->functor_g_atomic = Yap_MkFunctor(Yap_LookupAtom("atomic"), 1);
|
|
|
|
Yap_heap_regs->functor_g_compound = Yap_MkFunctor(Yap_LookupAtom("compound"), 1);
|
|
|
|
Yap_heap_regs->functor_g_float = Yap_MkFunctor(Yap_LookupAtom("float"), 1);
|
2005-10-28 18:38:50 +01:00
|
|
|
Yap_heap_regs->functor_g_format_at = Yap_MkFunctor(Yap_LookupAtom("$format@"), 2);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_g_integer = Yap_MkFunctor(Yap_LookupAtom("integer"), 1);
|
|
|
|
Yap_heap_regs->functor_g_number = Yap_MkFunctor(Yap_LookupAtom("number"), 1);
|
|
|
|
Yap_heap_regs->functor_g_primitive = Yap_MkFunctor(Yap_LookupAtom("primitive"), 1);
|
|
|
|
Yap_heap_regs->functor_g_var = Yap_MkFunctor(AtomGVar, 1);
|
|
|
|
Yap_heap_regs->functor_last_execute_within = Yap_MkFunctor(Yap_FullLookupAtom("$last_execute_within"), 1);
|
|
|
|
Yap_heap_regs->functor_list = Yap_MkFunctor(Yap_LookupAtom("."), 2);
|
|
|
|
Yap_heap_regs->functor_mega_clause = Yap_MkFunctor (Yap_FullLookupAtom("$mega_clause"), 2);
|
|
|
|
Yap_heap_regs->functor_module = Yap_MkFunctor(Yap_LookupAtom(":"), 2);
|
|
|
|
Yap_heap_regs->functor_multi_file_clause = Yap_MkFunctor(Yap_FullLookupAtom("$mf_clause"), 5);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_mutable = Yap_MkFunctor(Yap_FullLookupAtom("$mutable_variable"),
|
2001-04-09 20:54:03 +01:00
|
|
|
sizeof(timed_var)/sizeof(CELL));
|
|
|
|
#endif
|
2006-08-22 17:12:46 +01:00
|
|
|
Yap_heap_regs->functor_nb_queue = Yap_MkFunctor(Yap_LookupAtom("queue"), 5);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_not = Yap_MkFunctor(AtomNot, 1);
|
|
|
|
Yap_heap_regs->functor_or = Yap_MkFunctor(AtomSemic, 2);
|
|
|
|
Yap_heap_regs->functor_portray = Yap_MkFunctor(AtomPortray, 1);
|
|
|
|
Yap_heap_regs->functor_query = Yap_MkFunctor(AtomQuery, 1);
|
|
|
|
Yap_heap_regs->functor_creep = Yap_MkFunctor(AtomCreep, 1);
|
2005-04-20 05:02:30 +01:00
|
|
|
Yap_heap_regs->functor_static_clause = Yap_MkFunctor (Yap_FullLookupAtom("$static_clause"), 1);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_stream = Yap_MkFunctor (AtomStream, 1);
|
|
|
|
Yap_heap_regs->functor_stream_pos = Yap_MkFunctor (AtomStreamPos, 3);
|
|
|
|
Yap_heap_regs->functor_stream_eOS = Yap_MkFunctor (Yap_LookupAtom("end_of_stream"), 1);
|
|
|
|
Yap_heap_regs->functor_thread_run = Yap_MkFunctor (Yap_FullLookupAtom("$top_thread_goal"), 2);
|
|
|
|
Yap_heap_regs->functor_change_module = Yap_MkFunctor (Yap_FullLookupAtom("$change_module"), 1);
|
|
|
|
Yap_heap_regs->functor_current_module = Yap_MkFunctor (Yap_FullLookupAtom("$current_module"), 1);
|
2004-02-06 02:26:23 +00:00
|
|
|
FunctorThrow = Yap_MkFunctor( Yap_FullLookupAtom("throw"), 1);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->functor_u_minus = Yap_MkFunctor (Yap_heap_regs->atom_minus, 1);
|
|
|
|
Yap_heap_regs->functor_u_plus = Yap_MkFunctor (Yap_heap_regs->atom_plus, 1);
|
|
|
|
Yap_heap_regs->functor_v_bar = Yap_MkFunctor(Yap_LookupAtom("|"), 2);
|
|
|
|
Yap_heap_regs->functor_var = Yap_MkFunctor(AtomVar, 1);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef EUROTRA
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->term_dollar_u = MkAtomTerm(Yap_FullLookupAtom("$u"));
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->term_refound_var = MkAtomTerm(Yap_FullLookupAtom("$I_FOUND_THE_VARIABLE_AGAIN"));
|
|
|
|
Yap_heap_regs->n_of_file_aliases = 0;
|
|
|
|
Yap_heap_regs->file_aliases = NULL;
|
|
|
|
Yap_heap_regs->foreign_code_loaded = NULL;
|
|
|
|
Yap_heap_regs->yap_lib_dir = NULL;
|
2007-02-18 00:26:36 +00:00
|
|
|
Yap_heap_regs->agc_last_call = 0;
|
2007-07-01 01:14:35 +01:00
|
|
|
Yap_heap_regs->agc_threshold = 10000;
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->agc_hook = NULL;
|
|
|
|
Yap_heap_regs->parser_error_style = EXCEPTION_ON_PARSER_ERROR;
|
|
|
|
Yap_heap_regs->size_of_overflow = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* make sure no one else can use these two atoms */
|
2001-11-15 00:01:43 +00:00
|
|
|
CurrentModule = 0;
|
2006-04-28 14:23:23 +01:00
|
|
|
OpList = NULL;
|
|
|
|
Yap_heap_regs->op_list = NULL;
|
2006-03-22 20:07:28 +00:00
|
|
|
Yap_heap_regs->dead_static_clauses = NULL;
|
|
|
|
Yap_heap_regs->dead_mega_clauses = NULL;
|
|
|
|
Yap_heap_regs->dead_static_indices = NULL;
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_ReleaseAtom(AtomOfTerm(Yap_heap_regs->term_refound_var));
|
2002-03-08 06:31:32 +00:00
|
|
|
/* make sure we have undefp defined */
|
2002-05-10 16:04:03 +01:00
|
|
|
/* predicates can only be defined after this point */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->env_for_yes_code.p =
|
|
|
|
Yap_heap_regs->env_for_yes_code.p0 =
|
|
|
|
RepPredProp(PredPropByAtom(Yap_heap_regs->atom_true,0));
|
|
|
|
Yap_heap_regs->pred_meta_call = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_heap_regs->atom_meta_call,4),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_dollar_catch = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$catch"),3),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_recorded_with_key = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$recorded_with_key"),3),PROLOG_MODULE));
|
2006-10-10 15:08:17 +01:00
|
|
|
Yap_heap_regs->pred_log_upd_clause = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$do_log_upd_clause"),6),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_log_upd_clause0 = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$do_log_upd_clause0"),6),PROLOG_MODULE));
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->pred_static_clause = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$do_static_clause"),5),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_throw = RepPredProp(PredPropByFunc(FunctorThrow,PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_handle_throw = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$handle_throw"),3),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->pred_goal_expansion = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom("goal_expansion"),3),USER_MODULE));
|
|
|
|
Yap_heap_regs->env_for_trustfail_code.p =
|
|
|
|
Yap_heap_regs->env_for_trustfail_code.p0 =
|
|
|
|
RepPredProp(PredPropByAtom(Yap_heap_regs->atom_false,PROLOG_MODULE));
|
2001-11-15 00:01:43 +00:00
|
|
|
{
|
|
|
|
/* make sure we know about the module predicate */
|
2004-12-02 06:06:47 +00:00
|
|
|
PredEntry *modp = RepPredProp(PredPropByFunc(Yap_heap_regs->functor_module,PROLOG_MODULE));
|
2001-11-15 00:01:43 +00:00
|
|
|
modp->PredFlags |= MetaPredFlag;
|
|
|
|
}
|
2002-05-10 16:04:03 +01:00
|
|
|
#ifdef YAPOR
|
2005-07-06 20:34:12 +01:00
|
|
|
Yap_heap_regs->getwork_code.u.ld.p = RepPredProp(PredPropByAtom(Yap_FullLookupAtom("$getwork"), PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->getwork_seq_code.u.ld.p = RepPredProp(PredPropByAtom(Yap_FullLookupAtom("$getwork_seq"), PROLOG_MODULE));
|
|
|
|
#endif /* YAPOR */
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->db_erased_marker =
|
2002-11-18 18:18:05 +00:00
|
|
|
(DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_LUClauseSpace += sizeof(DBStruct);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->db_erased_marker->id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->db_erased_marker->Flags = ErasedMask;
|
|
|
|
Yap_heap_regs->db_erased_marker->Code = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->DBT.DBRefs = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->Parent = NULL;
|
2006-02-24 14:03:42 +00:00
|
|
|
Yap_heap_regs->logdb_erased_marker =
|
|
|
|
(LogUpdClause *)Yap_AllocCodeSpace(sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e));
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_LUClauseSpace += sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e);
|
2006-02-24 14:03:42 +00:00
|
|
|
Yap_heap_regs->logdb_erased_marker->Id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClFlags = ErasedMask|LogUpdMask;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSource = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClRefCount = 0;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPred = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_FullLookupAtom("$do_log_upd_clause"),5),PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClExt = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPrev = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClNext = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode,e);
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClCode->opc = Yap_opcode(_op_fail);
|
|
|
|
INIT_LOCK(Yap_heap_regs->logdb_erased_marker->ClLock);
|
|
|
|
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->yap_streams = NULL;
|
2004-09-03 04:11:09 +01:00
|
|
|
#if DEBUG
|
2004-12-02 06:06:47 +00:00
|
|
|
Yap_heap_regs->expand_clauses_sz = 0L;
|
2004-09-03 04:11:09 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-06-04 01:46:32 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
|
|
|
InitVersion(void)
|
|
|
|
{
|
2004-02-06 02:26:23 +00:00
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$version_name"),
|
2006-05-22 17:23:49 +01:00
|
|
|
MkAtomTerm(Yap_LookupAtom(YAP_VERSION)));
|
|
|
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
|
|
|
Yap_PutValue(Yap_FullLookupAtom("$myddas_version_name"),
|
|
|
|
MkAtomTerm(Yap_LookupAtom(MYDDAS_VERSION)));
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-08-04 16:45:56 +01:00
|
|
|
Yap_InitWorkspace(int Heap, int Stack, int Trail, int max_table_size,
|
|
|
|
int n_workers, int sch_loop, int delay_load)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* initialise system stuff */
|
|
|
|
|
|
|
|
#if PUSH_REGS
|
2004-01-23 02:23:51 +00:00
|
|
|
#ifdef THREADS
|
2004-02-06 17:22:24 +00:00
|
|
|
pthread_key_create(&Yap_yaamregs_key, NULL);
|
|
|
|
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
|
2004-01-23 02:23:51 +00:00
|
|
|
#else
|
|
|
|
/* In this case we need to initialise the abstract registers */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_regp = &Yap_standard_regs;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* the emulator will eventually copy them to its own local
|
|
|
|
register array, but for now they exist */
|
2004-01-23 02:23:51 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* PUSH_REGS */
|
|
|
|
|
2002-10-21 23:14:29 +01:00
|
|
|
#ifdef THREADS
|
2003-12-18 17:23:22 +00:00
|
|
|
Yap_regp->worker_id_ = 0;
|
2002-10-21 23:14:29 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Init signal handling and time */
|
|
|
|
/* also init memory page size, required by later functions */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSysbits ();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2005-03-04 20:30:14 +00:00
|
|
|
#ifdef YAPOR
|
|
|
|
worker_id = 0;
|
2005-08-04 16:45:56 +01:00
|
|
|
if (n_workers > MAX_WORKERS)
|
2005-05-31 01:32:02 +01:00
|
|
|
Yap_Error(INTERNAL_ERROR, TermNil, "excessive number of workers (Yap_InitWorkspace)");
|
2005-03-04 20:30:14 +00:00
|
|
|
#ifdef ENV_COPY
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#elif ACOW
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#else /* SBA */
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#endif /* ENV_COPY - ACOW - SBA */
|
2005-08-04 16:45:56 +01:00
|
|
|
map_memory(Heap, Stack, Trail, n_workers);
|
2005-03-04 20:30:14 +00:00
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitMemory (Trail, Heap, Stack);
|
2005-03-04 20:30:14 +00:00
|
|
|
#endif /* YAPOR */
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace = 0;
|
|
|
|
Yap_IndexSpace_Tree = 0;
|
|
|
|
Yap_IndexSpace_EXT = 0;
|
|
|
|
Yap_IndexSpace_SW = 0;
|
|
|
|
Yap_LUClauseSpace = 0;
|
|
|
|
Yap_LUIndexSpace_Tree = 0;
|
|
|
|
Yap_LUIndexSpace_CP = 0;
|
|
|
|
Yap_LUIndexSpace_EXT = 0;
|
|
|
|
Yap_LUIndexSpace_SW = 0;
|
2007-02-18 00:26:36 +00:00
|
|
|
#if USE_THREADED_CODE
|
|
|
|
Yap_heap_regs->op_rtable = NULL;
|
|
|
|
#endif
|
2005-03-04 20:30:14 +00:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
2005-11-04 01:17:17 +00:00
|
|
|
Yap_init_global(max_table_size, n_workers, sch_loop, delay_load);
|
2003-12-18 16:38:40 +00:00
|
|
|
#endif /* YAPOR || TABLING */
|
2004-03-02 16:44:58 +00:00
|
|
|
|
2005-03-04 20:30:14 +00:00
|
|
|
Yap_InitTime ();
|
2003-10-28 01:16:03 +00:00
|
|
|
AtomHashTableSize = MaxHash;
|
2006-11-27 17:42:03 +00:00
|
|
|
WideAtomHashTableSize = MaxWideHash;
|
2003-10-28 01:16:03 +00:00
|
|
|
HashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
|
2003-12-18 16:38:40 +00:00
|
|
|
if (HashChain == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"allocating initial atom table");
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
for (i = 0; i < MaxHash; ++i) {
|
|
|
|
INIT_RWLOCK(HashChain[i].AERWLock);
|
|
|
|
HashChain[i].Entry = NIL;
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
WideHashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash);
|
|
|
|
if (WideHashChain == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"allocating initial atom table");
|
|
|
|
}
|
|
|
|
for (i = 0; i < MaxWideHash; ++i) {
|
|
|
|
INIT_RWLOCK(WideHashChain[i].AERWLock);
|
|
|
|
WideHashChain[i].Entry = NIL;
|
|
|
|
}
|
2005-10-28 18:38:50 +01:00
|
|
|
NOfAtoms = 0;
|
2006-11-27 17:42:03 +00:00
|
|
|
NOfWideAtoms = 0;
|
2005-11-23 03:01:33 +00:00
|
|
|
#if THREADS
|
|
|
|
SF_STORE->AtFoundVar = Yap_LookupAtom(".");
|
|
|
|
Yap_ReleaseAtom(AtomFoundVar);
|
|
|
|
SF_STORE->AtFreeTerm = Yap_LookupAtom("?");
|
|
|
|
Yap_ReleaseAtom(AtomFreeTerm);
|
|
|
|
SF_STORE->AtNil = Yap_LookupAtom("[]");
|
|
|
|
SF_STORE->AtDot = Yap_LookupAtom(".");
|
|
|
|
#else
|
2005-09-09 18:24:39 +01:00
|
|
|
Yap_LookupAtomWithAddress(".",&(SF_STORE->AtFoundVar));
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleaseAtom(AtomFoundVar);
|
2005-09-09 18:24:39 +01:00
|
|
|
Yap_LookupAtomWithAddress("?",&(SF_STORE->AtFreeTerm));
|
|
|
|
Yap_ReleaseAtom(AtomFreeTerm);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_LookupAtomWithAddress("[]",&(SF_STORE->AtNil));
|
|
|
|
Yap_LookupAtomWithAddress(".",&(SF_STORE->AtDot));
|
2005-11-23 03:01:33 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* InitAbsmi must be done before InitCodes */
|
2007-02-18 00:26:36 +00:00
|
|
|
/* This must be done before initialising predicates */
|
|
|
|
Yap_heap_regs->system_pred_goal_expansion_func = FALSE;
|
2007-02-26 10:41:40 +00:00
|
|
|
for (i = 0; i <= LAST_FLAG; i++) {
|
2007-02-18 00:26:36 +00:00
|
|
|
yap_flags[i] = 0;
|
|
|
|
}
|
|
|
|
GcCalls = 0;
|
|
|
|
#ifdef LOW_PROF
|
|
|
|
ProfilerOn = FALSE;
|
2007-02-18 10:20:31 +00:00
|
|
|
FPreds = NULL;
|
2007-02-18 00:26:36 +00:00
|
|
|
#endif
|
|
|
|
ActiveSignals = 0;
|
|
|
|
DoingUndefp = FALSE;
|
|
|
|
DBErasedList = NULL;
|
|
|
|
DBErasedIList = NULL;
|
|
|
|
Yap_heap_regs->IntLUKeys = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MPW
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAbsmi(REGS, FunctorList);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAbsmi();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
InitCodes();
|
|
|
|
InitOps();
|
|
|
|
InitDebug();
|
|
|
|
InitVersion();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSysPath();
|
2001-04-09 20:54:03 +01:00
|
|
|
InitFlags();
|
|
|
|
InitStdPreds();
|
2004-01-23 02:23:51 +00:00
|
|
|
/* make sure tmp area is available */
|
|
|
|
{
|
|
|
|
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exit (int value)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
|
|
|
#if defined(YAPOR)
|
|
|
|
unmap_memory();
|
2003-11-07 16:31:08 +00:00
|
|
|
#endif /* YAPOR */
|
2004-02-25 19:06:31 +00:00
|
|
|
|
|
|
|
#ifdef LOW_PROF
|
|
|
|
remove("PROFPREDS");
|
|
|
|
remove("PROFILING");
|
|
|
|
#endif
|
2005-12-19 13:52:35 +00:00
|
|
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
2006-06-06 15:11:36 +01:00
|
|
|
Yap_MYDDAS_delete_all_myddas_structs();
|
2005-12-19 13:52:35 +00:00
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
if (! (Yap_PrologMode & BootMode) )
|
|
|
|
Yap_ShutdownLoadForeign();
|
2002-11-11 17:38:10 +00:00
|
|
|
exit(value);
|
|
|
|
}
|
|
|
|
|