mostly reindenting.

This commit is contained in:
Vítor Santos Costa 2016-01-03 01:34:09 +00:00
parent 811808fc34
commit 5ca49ae202

350
C/init.c
View File

@ -23,6 +23,8 @@ static char SccsId[] = "%W% %G%";
* *
*/ */
#define __INIT_C__ 1
#include <stdlib.h> #include <stdlib.h>
#include "Yap.h" #include "Yap.h"
#include "clause.h" #include "clause.h"
@ -74,15 +76,13 @@ static void InitVersion(void);
void exit(int); void exit(int);
static void InitWorker(int wid); static void InitWorker(int wid);
/************** YAP PROLOG GLOBAL VARIABLES *************************/ /************** YAP PROLOG GLOBAL VARIABLES *************************/
/************* variables related to memory allocation ***************/ /************* variables related to memory allocation ***************/
ADDR Yap_HeapBase; ADDR Yap_HeapBase;
/************** declarations local to init.c ************************/ /************** declarations local to init.c ************************/
static char *optypes[] = static char *optypes[] = {"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
{"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
/* OS page size for memory allocation */ /* OS page size for memory allocation */
size_t Yap_page_size; size_t Yap_page_size;
@ -93,7 +93,6 @@ int Yap_Portray_delays = FALSE;
#endif #endif
#endif #endif
/** /**
@defgroup Operators Summary of YAP Predefined Operators @defgroup Operators Summary of YAP Predefined Operators
@ -188,9 +187,7 @@ The following is the list of the declarations of the predefined operators:
#define fx 6 #define fx 6
#define fy 7 #define fy 7
int int Yap_IsOpType(char *type) {
Yap_IsOpType(char *type)
{
int i; int i;
for (i = 1; i <= 7; ++i) for (i = 1; i <= 7; ++i)
@ -199,9 +196,7 @@ Yap_IsOpType(char *type)
return (i <= 7); return (i <= 7);
} }
static int static int OpDec(int p, const char *type, Atom a, Term m) {
OpDec(int p, const char *type, Atom a, Term m)
{
int i; int i;
AtomEntry *ae = RepAtom(a); AtomEntry *ae = RepAtom(a);
OpEntry *info; OpEntry *info;
@ -214,7 +209,8 @@ OpDec(int p, const char *type, Atom a, Term m)
if (strcmp(type, optypes[i]) == 0) if (strcmp(type, optypes[i]) == 0)
break; break;
if (i > 7) { if (i > 7) {
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,MkAtomTerm(Yap_LookupAtom(type)),"op/3"); Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER, MkAtomTerm(Yap_LookupAtom(type)),
"op/3");
return (FALSE); return (FALSE);
} }
if (p) { if (p) {
@ -269,15 +265,11 @@ OpDec(int p, const char *type, Atom a, Term m)
return (TRUE); return (TRUE);
} }
int int Yap_OpDec(int p, char *type, Atom a, Term m) {
Yap_OpDec(int p, char *type, Atom a, Term m)
{
return (OpDec(p, type, a, m)); return (OpDec(p, type, a, m));
} }
static void static void SetOp(int p, int type, char *at, Term m) {
SetOp(int p, int type, char *at, Term m)
{
#if DEBUG #if DEBUG
if (GLOBAL_Option[5]) if (GLOBAL_Option[5])
fprintf(stderr, "[setop %d %s %s]\n", p, optypes[type], at); fprintf(stderr, "[setop %d %s %s]\n", p, optypes[type], at);
@ -286,9 +278,7 @@ SetOp(int p, int type, char *at, Term m)
} }
/* Gets the info about an operator in a prop */ /* Gets the info about an operator in a prop */
Atom Atom Yap_GetOp(OpEntry *pp, int *prio, int fix) {
Yap_GetOp(OpEntry *pp, int *prio, int fix)
{
int n; int n;
SMALLUNSGN p; SMALLUNSGN p;
@ -323,8 +313,7 @@ typedef struct OPSTRUCT {
short int opType, opPrio; short int opType, opPrio;
} Opdef; } Opdef;
static Opdef Ops[] = { static Opdef Ops[] = {{":-", xfx, 1200},
{":-", xfx, 1200},
{"-->", xfx, 1200}, {"-->", xfx, 1200},
{"?-", fx, 1200}, {"?-", fx, 1200},
{":-", fx, 1200}, {":-", fx, 1200},
@ -397,12 +386,9 @@ static Opdef Ops[] = {
{"\\", fy, 200}, {"\\", fy, 200},
{"//", yfx, 400}, {"//", yfx, 400},
{"**", xfx, 200}, {"**", xfx, 200},
{"^", xfy, 200} {"^", xfy, 200}};
};
static void static void InitOps(void) {
InitOps(void)
{
unsigned int i; unsigned int i;
for (i = 0; i < sizeof(Ops) / sizeof(*Ops); ++i) for (i = 0; i < sizeof(Ops) / sizeof(*Ops); ++i)
SetOp(Ops[i].opPrio, Ops[i].opType, Ops[i].opName, PROLOG_MODULE); SetOp(Ops[i].opPrio, Ops[i].opType, Ops[i].opName, PROLOG_MODULE);
@ -416,9 +402,7 @@ InitOps(void)
#endif #endif
#endif #endif
static void static void InitDebug(void) {
InitDebug(void)
{
Atom At; Atom At;
#if DEBUG #if DEBUG
int i; int i;
@ -462,9 +446,7 @@ InitDebug(void)
Yap_PutValue(At, MkIntTerm(15)); Yap_PutValue(At, MkIntTerm(15));
} }
static UInt static UInt update_flags_from_prolog(UInt flags, PredEntry *pe) {
update_flags_from_prolog(UInt flags, PredEntry *pe)
{
if (pe->PredFlags & MetaPredFlag) if (pe->PredFlags & MetaPredFlag)
flags |= MetaPredFlag; flags |= MetaPredFlag;
if (pe->PredFlags & SourcePredFlag) if (pe->PredFlags & SourcePredFlag)
@ -480,9 +462,8 @@ update_flags_from_prolog(UInt flags, PredEntry *pe)
return flags; return flags;
} }
void void Yap_InitCPred(const char *Name, UInt Arity, CPredicate code,
Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags) pred_flags_t flags) {
{
CACHE_REGS CACHE_REGS
Atom atom = NIL; Atom atom = NIL;
PredEntry *pe = NULL; PredEntry *pe = NULL;
@ -536,7 +517,8 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
if (flags & SafePredFlag) { if (flags & SafePredFlag) {
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(p_code, Osbpp), p), l); sz = (CELL)NEXTOP(NEXTOP(NEXTOP(p_code, Osbpp), p), l);
} else { } else {
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code,e),p),Osbpp),p),l); sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code, e), p), Osbpp), p),
l);
} }
cl = (StaticClause *)Yap_AllocCodeSpace(sz); cl = (StaticClause *)Yap_AllocCodeSpace(sz);
if (!cl) { if (!cl) {
@ -567,9 +549,7 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
p_code->opc = Yap_opcode(_call_cpred); p_code->opc = Yap_opcode(_call_cpred);
p_code->y_u.Osbpp.bmap = NULL; p_code->y_u.Osbpp.bmap = NULL;
p_code->y_u.Osbpp.s = -Signed(RealEnvSize); p_code->y_u.Osbpp.s = -Signed(RealEnvSize);
p_code->y_u.Osbpp.p = p_code->y_u.Osbpp.p = p_code->y_u.Osbpp.p0 = pe;
p_code->y_u.Osbpp.p0 =
pe;
p_code = NEXTOP(p_code, Osbpp); p_code = NEXTOP(p_code, Osbpp);
if (!(flags & SafePredFlag)) { if (!(flags & SafePredFlag)) {
p_code->opc = Yap_opcode(_deallocate); p_code->opc = Yap_opcode(_deallocate);
@ -584,9 +564,7 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
pe->OpcodeOfPred = pe->CodeOfPred->opc; pe->OpcodeOfPred = pe->CodeOfPred->opc;
} }
bool bool Yap_AddCallToFli(PredEntry *pe, CPredicate call) {
Yap_AddCallToFli( PredEntry *pe, CPredicate call )
{
yamop *p_code; yamop *p_code;
if (pe->PredFlags & BackCPredFlag) { if (pe->PredFlags & BackCPredFlag) {
@ -601,9 +579,7 @@ Yap_AddCallToFli( PredEntry *pe, CPredicate call )
} }
} }
bool bool Yap_AddRetryToFli(PredEntry *pe, CPredicate re) {
Yap_AddRetryToFli( PredEntry *pe, CPredicate re )
{
yamop *p_code; yamop *p_code;
if (pe->PredFlags & BackCPredFlag) { if (pe->PredFlags & BackCPredFlag) {
@ -616,9 +592,7 @@ Yap_AddRetryToFli( PredEntry *pe, CPredicate re )
} }
} }
bool bool Yap_AddCutToFli(PredEntry *pe, CPredicate CUT) {
Yap_AddCutToFli( PredEntry *pe, CPredicate CUT )
{
yamop *p_code; yamop *p_code;
if (pe->PredFlags & BackCPredFlag) { if (pe->PredFlags & BackCPredFlag) {
@ -632,9 +606,8 @@ Yap_AddCutToFli( PredEntry *pe, CPredicate CUT )
} }
} }
void void Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code,
Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_t flags) pred_flags_t flags) {
{
CACHE_REGS CACHE_REGS
Atom atom = NIL; Atom atom = NIL;
PredEntry *pe = NULL; PredEntry *pe = NULL;
@ -674,11 +647,13 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
/* already exists */ /* already exists */
} else { } else {
while (!cl) { while (!cl) {
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),plxxs),p),l); UInt sz = sizeof(StaticClause) +
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL), plxxs), p), l);
cl = (StaticClause *)Yap_AllocCodeSpace(sz); cl = (StaticClause *)Yap_AllocCodeSpace(sz);
if (!cl) { if (!cl) {
if (!Yap_growheap(FALSE, sz, NULL)) { if (!Yap_growheap(FALSE, sz, NULL)) {
Yap_Error(RESOURCE_ERROR_HEAP,TermNil,"while initializing %s", Name); Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "while initializing %s",
Name);
return; return;
} }
} else { } else {
@ -710,9 +685,8 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
p_code->y_u.l.l = cl->ClCode; p_code->y_u.l.l = cl->ClCode;
} }
void void Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def,
Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_flags_t flags) pred_flags_t flags) {
{
CACHE_REGS CACHE_REGS
Atom atom = NIL; Atom atom = NIL;
PredEntry *pe = NULL; PredEntry *pe = NULL;
@ -758,15 +732,19 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
if (pe->CodeOfPred == (yamop *)(&(pe->OpcodeOfPred))) { if (pe->CodeOfPred == (yamop *)(&(pe->OpcodeOfPred))) {
if (flags & SafePredFlag) { if (flags & SafePredFlag) {
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l)); cl = (StaticClause *)Yap_AllocCodeSpace(
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), p), l));
} else { } else {
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),p),l)); cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(
NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), e), Osbpp), p), p),
l));
} }
if (!cl) { if (!cl) {
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "No Heap Space in InitAsmPred"); Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "No Heap Space in InitAsmPred");
return; return;
} }
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l); Yap_ClauseSpace +=
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), p), l);
} else { } else {
cl = ClauseCodeToStaticClause(pe->CodeOfPred); cl = ClauseCodeToStaticClause(pe->CodeOfPred);
} }
@ -775,7 +753,8 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
if (flags & SafePredFlag) { if (flags & SafePredFlag) {
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), e), e); cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), e), e);
} else { } else {
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),e),e); cl->ClSize = (CELL)NEXTOP(
NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), e), Osbpp), p), e), e);
} }
cl->usc.ClLine = Yap_source_line_no(); cl->usc.ClLine = Yap_source_line_no();
p_code = cl->ClCode; p_code = cl->ClCode;
@ -806,10 +785,8 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
} }
} }
static void CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont,
static void CPredicate Cut) {
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
{
yamop *code; yamop *code;
if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause || if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause ||
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause || pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause ||
@ -848,25 +825,20 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
code->y_u.OtapFs.f = Cut; code->y_u.OtapFs.f = Cut;
} }
void void Yap_InitCPredBack(const char *Name, UInt Arity, unsigned int Extra,
Yap_InitCPredBack(const char *Name, UInt Arity, CPredicate Start, CPredicate Cont, pred_flags_t flags) {
unsigned int Extra, CPredicate Start,
CPredicate Cont, pred_flags_t flags){
Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, NULL, flags); Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, NULL, flags);
} }
void void Yap_InitCPredBackCut(const char *Name, UInt Arity, unsigned int Extra,
Yap_InitCPredBackCut(const char *Name, UInt Arity, CPredicate Start, CPredicate Cont, CPredicate Cut,
unsigned int Extra, CPredicate Start, pred_flags_t flags) {
CPredicate Cont,CPredicate Cut, pred_flags_t flags){
Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, Cut, flags); Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, Cut, flags);
} }
void void Yap_InitCPredBack_(const char *Name, UInt Arity, unsigned int Extra,
Yap_InitCPredBack_(const char *Name, UInt Arity, CPredicate Start, CPredicate Cont, CPredicate Cut,
unsigned int Extra, CPredicate Start, pred_flags_t flags) {
CPredicate Cont, CPredicate Cut, pred_flags_t flags)
{
CACHE_REGS CACHE_REGS
PredEntry *pe = NULL; PredEntry *pe = NULL;
Atom atom = NIL; Atom atom = NIL;
@ -898,15 +870,14 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
return; return;
} }
} }
if (pe->cs.p_code.FirstClause != NIL) if (pe->cs.p_code.FirstClause != NIL) {
{
flags = update_flags_from_prolog(flags, pe); flags = update_flags_from_prolog(flags, pe);
CleanBack(pe, Start, Cont, Cut); CleanBack(pe, Start, Cont, Cut);
} } else {
else {
StaticClause *cl; StaticClause *cl;
yamop *code = ((StaticClause *)NULL)->ClCode; yamop *code = ((StaticClause *)NULL)->ClCode;
UInt sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l); UInt sz =
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code, OtapFs), OtapFs), OtapFs), l);
if (flags & UserCPredFlag) if (flags & UserCPredFlag)
pe->PredFlags = UserCPredFlag | BackCPredFlag | CompiledPredFlag | flags; pe->PredFlags = UserCPredFlag | BackCPredFlag | CompiledPredFlag | flags;
else else
@ -930,8 +901,8 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
cl->usc.ClLine = Yap_source_line_no(); cl->usc.ClLine = Yap_source_line_no();
code = cl->ClCode; code = cl->ClCode;
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = pe->cs.p_code.FirstClause =
pe->cs.p_code.FirstClause = pe->cs.p_code.LastClause = code; pe->cs.p_code.LastClause = code;
if (flags & UserCPredFlag) if (flags & UserCPredFlag)
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_userc); pe->OpcodeOfPred = code->opc = Yap_opcode(_try_userc);
else else
@ -972,10 +943,7 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
} }
} }
static void InitStdPreds(void) {
static void
InitStdPreds(void)
{
Yap_InitCPreds(); Yap_InitCPreds();
Yap_InitBackCPreds(); Yap_InitBackCPreds();
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
@ -986,16 +954,15 @@ InitStdPreds(void)
#endif #endif
} }
static void InitPredHash(void) {
static void
InitPredHash(void)
{
UInt i; UInt i;
PredHash = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry **) * PredHashInitialSize); PredHash = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry **) *
PredHashInitialSize);
PredHashTableSize = PredHashInitialSize; PredHashTableSize = PredHashInitialSize;
if (PredHash == NULL) { if (PredHash == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL,MkIntTerm(0),"allocating initial predicate hash table"); Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0),
"allocating initial predicate hash table");
} }
for (i = 0; i < PredHashTableSize; ++i) { for (i = 0; i < PredHashTableSize; ++i) {
PredHash[i] = NULL; PredHash[i] = NULL;
@ -1003,9 +970,8 @@ InitPredHash(void)
INIT_RWLOCK(PredHashRWLock); INIT_RWLOCK(PredHashRWLock);
} }
static void static void InitEnvInst(yamop start[2], yamop **instp, op_numbers opc,
InitEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred) PredEntry *pred) {
{
yamop *ipc = start; yamop *ipc = start;
/* make it look like the instruction is preceeded by a call instruction */ /* make it look like the instruction is preceeded by a call instruction */
@ -1019,9 +985,7 @@ InitEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred)
*instp = ipc; *instp = ipc;
} }
static void static void InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe) {
InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
{
yamop *ipc = start; yamop *ipc = start;
/* this is a place holder, it should not really be used */ /* this is a place holder, it should not really be used */
@ -1037,59 +1001,50 @@ InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
#endif /* TABLING */ #endif /* TABLING */
} }
static void static void InitDBErasedMarker(void) {
InitDBErasedMarker(void) DBErasedMarker = (DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
{
Yap_heap_regs->db_erased_marker =
(DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
Yap_LUClauseSpace += sizeof(DBStruct); Yap_LUClauseSpace += sizeof(DBStruct);
Yap_heap_regs->db_erased_marker->id = FunctorDBRef; DBErasedMarker->id = FunctorDBRef;
Yap_heap_regs->db_erased_marker->Flags = ErasedMask; DBErasedMarker->Flags = ErasedMask;
Yap_heap_regs->db_erased_marker->Code = NULL; DBErasedMarker->Code = NULL;
Yap_heap_regs->db_erased_marker->DBT.DBRefs = NULL; DBErasedMarker->DBT.DBRefs = NULL;
Yap_heap_regs->db_erased_marker->Parent = NULL; DBErasedMarker->Parent = NULL;
} }
static void static void InitLogDBErasedMarker(void) {
InitLogDBErasedMarker(void) LogDBErasedMarker = (LogUpdClause *)Yap_AllocCodeSpace(
{ sizeof(LogUpdClause) + (UInt)NEXTOP((yamop *)NULL, e));
Yap_heap_regs->logdb_erased_marker =
(LogUpdClause *)Yap_AllocCodeSpace(sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e));
Yap_LUClauseSpace += sizeof(LogUpdClause) + (UInt)NEXTOP((yamop *)NULL, e); Yap_LUClauseSpace += sizeof(LogUpdClause) + (UInt)NEXTOP((yamop *)NULL, e);
Yap_heap_regs->logdb_erased_marker->Id = FunctorDBRef; LogDBErasedMarker->Id = FunctorDBRef;
Yap_heap_regs->logdb_erased_marker->ClFlags = ErasedMask|LogUpdMask; LogDBErasedMarker->ClFlags = ErasedMask | LogUpdMask;
Yap_heap_regs->logdb_erased_marker->lusl.ClSource = NULL; LogDBErasedMarker->lusl.ClSource = NULL;
Yap_heap_regs->logdb_erased_marker->ClRefCount = 0; LogDBErasedMarker->ClRefCount = 0;
Yap_heap_regs->logdb_erased_marker->ClExt = NULL; LogDBErasedMarker->ClExt = NULL;
Yap_heap_regs->logdb_erased_marker->ClPrev = NULL; LogDBErasedMarker->ClPrev = NULL;
Yap_heap_regs->logdb_erased_marker->ClNext = NULL; LogDBErasedMarker->ClNext = NULL;
Yap_heap_regs->logdb_erased_marker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode,e); LogDBErasedMarker->ClSize =
Yap_heap_regs->logdb_erased_marker->ClCode->opc = Yap_opcode(_op_fail); (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode, e);
LogDBErasedMarker->ClCode->opc = Yap_opcode(_op_fail);
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker); INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
} }
static void static void InitSWIAtoms(void) {
InitSWIAtoms(void)
{
MaxAtomTranslations = N_SWI_ATOMS; MaxAtomTranslations = N_SWI_ATOMS;
MaxFunctorTranslations = N_SWI_FUNCTORS; MaxFunctorTranslations = N_SWI_FUNCTORS;
SWI_Atoms = (Atom *)malloc(sizeof(Atom) * MaxAtomTranslations); SWI_Atoms = (Atom *)malloc(sizeof(Atom) * MaxAtomTranslations);
SWI_Functors = (Functor *)malloc(sizeof(Functor) * 2 * N_SWI_ATOMS); SWI_Functors = (Functor *)malloc(sizeof(Functor) * 2 * N_SWI_ATOMS);
} }
static void static void InitEmptyWakeups(void) {}
InitEmptyWakeups(void)
{
}
static void static void InitAtoms(void) {
InitAtoms(void)
{
int i; int i;
AtomHashTableSize = MaxHash; AtomHashTableSize = MaxHash;
HashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash); HashChain =
(AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
if (HashChain == NULL) { if (HashChain == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL,MkIntTerm(0),"allocating initial atom table"); Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0),
"allocating initial atom table");
} }
for (i = 0; i < MaxHash; ++i) { for (i = 0; i < MaxHash; ++i) {
INIT_RWLOCK(HashChain[i].AERWLock); INIT_RWLOCK(HashChain[i].AERWLock);
@ -1113,13 +1068,12 @@ InitAtoms(void)
#endif #endif
} }
static void static void InitWideAtoms(void) {
InitWideAtoms(void)
{
int i; int i;
WideAtomHashTableSize = MaxWideHash; WideAtomHashTableSize = MaxWideHash;
WideHashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash); WideHashChain =
(AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash);
if (WideHashChain == NULL) { if (WideHashChain == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0), "allocating wide atom table"); Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0), "allocating wide atom table");
} }
@ -1130,15 +1084,12 @@ InitWideAtoms(void)
NOfWideAtoms = 0; NOfWideAtoms = 0;
} }
static void static void InitInvisibleAtoms(void) {
InitInvisibleAtoms(void)
{
/* initialize invisible chain */ /* initialize invisible chain */
Yap_heap_regs->invisiblechain.Entry = NIL; INVISIBLECHAIN.Entry = NIL;
INIT_RWLOCK(Yap_heap_regs->invisiblechain.AERWLock); INIT_RWLOCK(Yap_heap_regs->INVISIBLECHAIN.AERWLock);
} }
#ifdef YAPOR #ifdef YAPOR
void Yap_init_yapor_workers(void) { void Yap_init_yapor_workers(void) {
CACHE_REGS CACHE_REGS
@ -1152,9 +1103,11 @@ void Yap_init_yapor_workers(void) {
int son; int son;
son = fork(); son = fork();
if (son == -1) if (son == -1)
Yap_Error(SYSTEM_ERROR_FATAL, TermNil, "fork error (Yap_init_yapor_workers)"); Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
"fork error (Yap_init_yapor_workers)");
if (son > 0) { if (son > 0) {
/* I am the father, I must stay here and wait for my children to all die */ /* I am the father, I must stay here and wait for my children to all die
*/
struct sigaction sigact; struct sigaction sigact;
sigact.sa_handler = SIG_DFL; sigact.sa_handler = SIG_DFL;
sigemptyset(&sigact.sa_mask); sigemptyset(&sigact.sa_mask);
@ -1170,7 +1123,8 @@ void Yap_init_yapor_workers(void) {
int son; int son;
son = fork(); son = fork();
if (son == -1) if (son == -1)
Yap_Error(SYSTEM_ERROR_FATAL, TermNil, "fork error (Yap_init_yapor_workers)"); Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
"fork error (Yap_init_yapor_workers)");
if (son == 0) { if (son == 0) {
/* new worker */ /* new worker */
worker_id = proc; worker_id = proc;
@ -1185,11 +1139,8 @@ void Yap_init_yapor_workers(void) {
} }
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef THREADS #ifdef THREADS
static void static void InitThreadHandle(int wid) {
InitThreadHandle(int wid)
{
REMOTE_ThreadHandle(wid).in_use = FALSE; REMOTE_ThreadHandle(wid).in_use = FALSE;
REMOTE_ThreadHandle(wid).zombie = FALSE; REMOTE_ThreadHandle(wid).zombie = FALSE;
REMOTE_ThreadHandle(wid).local_preds = NULL; REMOTE_ThreadHandle(wid).local_preds = NULL;
@ -1217,15 +1168,13 @@ InitThreadHandle(int wid)
mboxp->open = true; mboxp->open = true;
Yap_init_tqueue(msgsp); Yap_init_tqueue(msgsp);
} }
} }
int int Yap_InitThread(int new_id) {
Yap_InitThread(int new_id)
{
struct worker_local *new_s; struct worker_local *new_s;
if (new_id) { if (new_id) {
if (!(new_s = (struct worker_local *)calloc(sizeof(struct worker_local), 1))) if (!(new_s =
(struct worker_local *)calloc(sizeof(struct worker_local), 1)))
return FALSE; return FALSE;
Yap_local[new_id] = new_s; Yap_local[new_id] = new_s;
if (!((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))) { if (!((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))) {
@ -1242,16 +1191,13 @@ Yap_InitThread(int new_id)
} }
#endif #endif
static void static void InitScratchPad(int wid) {
InitScratchPad(int wid)
{
REMOTE_ScratchPad(wid).ptr = NULL; REMOTE_ScratchPad(wid).ptr = NULL;
REMOTE_ScratchPad(wid).sz = SCRATCH_START_SIZE; REMOTE_ScratchPad(wid).sz = SCRATCH_START_SIZE;
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE; REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
} }
static CELL * static CELL *InitHandles(int wid) {
InitHandles(int wid) {
size_t initial_slots = 1024; size_t initial_slots = 1024;
CELL *handles; CELL *handles;
@ -1260,31 +1206,29 @@ InitHandles(int wid) {
handles = calloc(initial_slots, sizeof(CELL)); handles = calloc(initial_slots, sizeof(CELL));
if (handles == NULL) { if (handles == NULL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__); Yap_Error(SYSTEM_ERROR_INTERNAL, 0 /* TermNil */,
"No space for handles at " __FILE__ " : %d", __LINE__);
} }
RESET_VARIABLE(handles); RESET_VARIABLE(handles);
return handles; return handles;
} }
void void Yap_CloseScratchPad(void) {
Yap_CloseScratchPad(void)
{
CACHE_REGS CACHE_REGS
Yap_FreeCodeSpace(LOCAL_ScratchPad.ptr); Yap_FreeCodeSpace(LOCAL_ScratchPad.ptr);
LOCAL_ScratchPad.sz = SCRATCH_START_SIZE; LOCAL_ScratchPad.sz = SCRATCH_START_SIZE;
LOCAL_ScratchPad.msz = SCRATCH_START_SIZE; LOCAL_ScratchPad.msz = SCRATCH_START_SIZE;
} }
#include "iglobals.h" #include "heap/iglobals.h"
#include "ilocals.h"
#include "heap/ilocals.h"
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
struct global_data *Yap_global; struct global_data *Yap_global;
long Yap_worker_area_size; long Yap_worker_area_size;
#else
struct global_data Yap_Global;
#endif #endif
#if defined(THREADS) #if defined(THREADS)
@ -1295,9 +1239,7 @@ struct worker_local *Yap_local;
struct worker_local Yap_local; struct worker_local Yap_local;
#endif #endif
static void static void InitCodes(void) {
InitCodes(void)
{
CACHE_REGS CACHE_REGS
#if THREADS #if THREADS
int wid; int wid;
@ -1305,7 +1247,7 @@ InitCodes(void)
Yap_local[wid] = NULL; Yap_local[wid] = NULL;
} }
#endif #endif
#include "ihstruct.h" #include "heap/ihstruct.h"
#if THREADS #if THREADS
Yap_InitThread(0); Yap_InitThread(0);
#endif /* THREADS */ #endif /* THREADS */
@ -1328,30 +1270,27 @@ InitCodes(void)
modp->PredFlags |= MetaPredFlag; modp->PredFlags |= MetaPredFlag;
} }
#ifdef YAPOR #ifdef YAPOR
Yap_heap_regs->getwork_code->y_u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetwork, PROLOG_MODULE)); Yap_heap_regs->getwork_code->y_u.Otapl.p =
Yap_heap_regs->getwork_seq_code->y_u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetworkSeq, PROLOG_MODULE)); RepPredProp(PredPropByAtom(AtomGetwork, PROLOG_MODULE));
Yap_heap_regs->getwork_seq_code->y_u.Otapl.p =
RepPredProp(PredPropByAtom(AtomGetworkSeq, PROLOG_MODULE));
#endif /* YAPOR */ #endif /* YAPOR */
} }
static void InitVersion(void) {
static void Yap_PutValue(AtomVersionNumber, MkAtomTerm(Yap_LookupAtom(YAP_FULL_VERSION)));
InitVersion(void)
{
Yap_PutValue(AtomVersionNumber,
MkAtomTerm(Yap_LookupAtom(YAP_FULL_VERSION)));
} }
void void Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts,
Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_size, UInt max_table_size, int n_workers, int sch_loop,
int n_workers, int sch_loop, int delay_load) int delay_load) {
{
CACHE_REGS CACHE_REGS
/* initialize system stuff */ /* initialize system stuff */
#if PUSH_REGS #if PUSH_REGS
#ifdef THREADS #ifdef THREADS
if (!(Yap_local[0] = (struct worker_local *)calloc(sizeof(struct worker_local), 1))) if (!(Yap_local[0] =
(struct worker_local *)calloc(sizeof(struct worker_local), 1)))
return; return;
pthread_key_create(&Yap_yaamregs_key, NULL); pthread_key_create(&Yap_yaamregs_key, NULL);
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs); pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
@ -1396,13 +1335,17 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
if (n_workers > MAX_WORKERS) if (n_workers > MAX_WORKERS)
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "excessive number of workers"); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "excessive number of workers");
#ifdef YAPOR_COPY #ifdef YAPOR_COPY
INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers, n_workers == 1 ? "":"s"); INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_COW #elif YAPOR_COW
INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers, n_workers == 1 ? "":"s"); INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_SBA #elif YAPOR_SBA
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers, n_workers == 1 ? "":"s"); INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_THREADS #elif YAPOR_THREADS
INFORMATION_MESSAGE("YapOr: threads model with %d worker%s", n_workers, n_workers == 1 ? "":"s"); INFORMATION_MESSAGE("YapOr: threads model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#endif /* YAPOR_COPY - YAPOR_COW - YAPOR_SBA - YAPOR_THREADS */ #endif /* YAPOR_COPY - YAPOR_COW - YAPOR_SBA - YAPOR_THREADS */
#endif /* YAPOR */ #endif /* YAPOR */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
@ -1437,7 +1380,8 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
if (Stack < MinStackSpace) if (Stack < MinStackSpace)
Stack = MinStackSpace; Stack = MinStackSpace;
if (!(LOCAL_GlobalBase = (ADDR)malloc((Trail + Stack) * 1024))) { if (!(LOCAL_GlobalBase = (ADDR)malloc((Trail + Stack) * 1024))) {
Yap_Error(RESOURCE_ERROR_HEAP, 0, "could not allocate stack space for main thread"); Yap_Error(RESOURCE_ERROR_HEAP, 0,
"could not allocate stack space for main thread");
Yap_exit(1); Yap_exit(1);
} }
#if THREADS #if THREADS
@ -1454,14 +1398,10 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
Yap_InitYaamRegs(0); Yap_InitYaamRegs(0);
InitStdPreds(); InitStdPreds();
/* make sure tmp area is available */ /* make sure tmp area is available */
{ { Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace()); }
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
}
} }
int int Yap_HaltRegisterHook(HaltHookFunc f, void *env) {
Yap_HaltRegisterHook (HaltHookFunc f, void * env)
{
struct halt_hook *h; struct halt_hook *h;
if (!(h = (struct halt_hook *)Yap_AllocCodeSpace(sizeof(struct halt_hook)))) if (!(h = (struct halt_hook *)Yap_AllocCodeSpace(sizeof(struct halt_hook))))
@ -1475,9 +1415,7 @@ Yap_HaltRegisterHook (HaltHookFunc f, void * env)
return TRUE; return TRUE;
} }
static void static void run_halt_hooks(int code) {
run_halt_hooks(int code)
{
struct halt_hook *hooke = GLOBAL_HaltHooks; struct halt_hook *hooke = GLOBAL_HaltHooks;
while (hooke) { while (hooke) {
@ -1486,9 +1424,7 @@ run_halt_hooks(int code)
} }
} }
void void Yap_exit(int value) {
Yap_exit (int value)
{
CACHE_REGS CACHE_REGS
void closeFiles(int all); void closeFiles(int all);
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)