Support for booting when YAP is called from a generic app
- ensure pl boot works - ensure yap is initialed before user code is called - cleanup code to use file status
This commit is contained in:
parent
a7720d42ed
commit
da6d41433f
252
C/c_interface.c
252
C/c_interface.c
@ -57,6 +57,7 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
#include "iopreds.h"
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
typedef void *atom_t;
|
typedef void *atom_t;
|
||||||
typedef void *functor_t;
|
typedef void *functor_t;
|
||||||
@ -86,6 +87,13 @@ X_API int YAP_Reset(yap_reset_t mode);
|
|||||||
#define X_API __declspec(dllexport)
|
#define X_API __declspec(dllexport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BootFilePath NULL
|
||||||
|
#if __ANDROID__
|
||||||
|
#define BOOT_FROM_SAVED_STATE true
|
||||||
|
#endif
|
||||||
|
static char BootFile[] = "boot.yap";
|
||||||
|
static char InitFile[] = "init.yap";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@defgroup slotInterface Term Handles or Slots
|
@defgroup slotInterface Term Handles or Slots
|
||||||
@ingroup ChYInterface
|
@ingroup ChYInterface
|
||||||
@ -1036,7 +1044,6 @@ Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Int ret;
|
Int ret;
|
||||||
Int OASP = LCL0 - (CELL *)B;
|
Int OASP = LCL0 - (CELL *)B;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
|
||||||
// Term omod = CurrentModule;
|
// Term omod = CurrentModule;
|
||||||
// if (pe->PredFlags & CArgsPredFlag) {
|
// if (pe->PredFlags & CArgsPredFlag) {
|
||||||
// CurrentModule = pe->ModuleOfPred;
|
// CurrentModule = pe->ModuleOfPred;
|
||||||
@ -1058,7 +1065,6 @@ Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
|
|||||||
}
|
}
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
// check for junk: open frames, etc */
|
// check for junk: open frames, etc */
|
||||||
Yap_CloseSlots(CurSlot);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
complete_exit(((choiceptr)(LCL0 - OASP)), FALSE, FALSE PASS_REGS);
|
complete_exit(((choiceptr)(LCL0 - OASP)), FALSE, FALSE PASS_REGS);
|
||||||
else
|
else
|
||||||
@ -1176,7 +1182,6 @@ Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
|
|||||||
/* for slots to work */
|
/* for slots to work */
|
||||||
Yap_StartSlots();
|
Yap_StartSlots();
|
||||||
UInt ocp = LCL0 - (CELL *)B;
|
UInt ocp = LCL0 - (CELL *)B;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
|
||||||
if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) {
|
if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) {
|
||||||
Int val;
|
Int val;
|
||||||
CPredicateV codev = (CPredicateV)exec_code;
|
CPredicateV codev = (CPredicateV)exec_code;
|
||||||
@ -1190,7 +1195,6 @@ Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
|
|||||||
} else {
|
} else {
|
||||||
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1), 0, ctx);
|
val = codev(Yap_InitSlots(pe->ArityOfPE, &ARG1), 0, ctx);
|
||||||
}
|
}
|
||||||
Yap_CloseSlots(CurSlot);
|
|
||||||
/* we are below the original choice point ?? */
|
/* we are below the original choice point ?? */
|
||||||
/* make sure we clean up the frames left by the user */
|
/* make sure we clean up the frames left by the user */
|
||||||
PP = NULL;
|
PP = NULL;
|
||||||
@ -1212,7 +1216,6 @@ Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
|
|||||||
return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS);
|
return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS);
|
||||||
} else {
|
} else {
|
||||||
Int ret = (exec_code)(PASS_REGS1);
|
Int ret = (exec_code)(PASS_REGS1);
|
||||||
Yap_CloseSlots(CurSlot);
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Yap_RaiseException();
|
Yap_RaiseException();
|
||||||
}
|
}
|
||||||
@ -1220,26 +1223,6 @@ Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API Int YAP_CallProlog(Term t) {
|
|
||||||
CACHE_REGS
|
|
||||||
Int out;
|
|
||||||
Term mod = CurrentModule;
|
|
||||||
BACKUP_MACHINE_REGS();
|
|
||||||
|
|
||||||
while (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == FunctorModule) {
|
|
||||||
Term tmod = ArgOfTerm(1, t);
|
|
||||||
if (IsVarTerm(tmod))
|
|
||||||
return (FALSE);
|
|
||||||
if (!IsAtomTerm(tmod))
|
|
||||||
return (FALSE);
|
|
||||||
mod = tmod;
|
|
||||||
t = ArgOfTerm(2, t);
|
|
||||||
}
|
|
||||||
out = Yap_execute_goal(t, 0, mod, true);
|
|
||||||
RECOVER_MACHINE_REGS();
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
||||||
X_API void *YAP_ReallocSpaceFromYap(void *ptr, size_t size) {
|
X_API void *YAP_ReallocSpaceFromYap(void *ptr, size_t size) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
void *new_ptr;
|
void *new_ptr;
|
||||||
@ -1280,7 +1263,8 @@ X_API void YAP_FreeSpaceFromYap(void *ptr) { Yap_FreeCodeSpace(ptr); }
|
|||||||
* @param bufsize bu
|
* @param bufsize bu
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/ X_API char *YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
|
*/ X_API char *
|
||||||
|
YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
seq_tv_t inp, out;
|
seq_tv_t inp, out;
|
||||||
inp.val.t = t;
|
inp.val.t = t;
|
||||||
@ -1695,8 +1679,10 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
|||||||
out = run_emulator(PASS_REGS1);
|
out = run_emulator(PASS_REGS1);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
if (out) {
|
if (out) {
|
||||||
LOCAL_CurSlot = dgi->CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
Yap_StartSlots();
|
} else {
|
||||||
|
LOCAL_CurSlot =
|
||||||
|
dgi->CurSlot; // ignore any slots created within the called goal
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -1760,6 +1746,7 @@ X_API Int YAP_RunGoal(Term t) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term out;
|
Term out;
|
||||||
yamop *old_CP = CP;
|
yamop *old_CP = CP;
|
||||||
|
yhandle_t cslot = LOCAL_CurSlot;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
|
||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
@ -1775,7 +1762,6 @@ X_API Int YAP_RunGoal(Term t) {
|
|||||||
CP = old_CP;
|
CP = old_CP;
|
||||||
LOCAL_AllowRestart = TRUE;
|
LOCAL_AllowRestart = TRUE;
|
||||||
// we are back to user code again, need slots */
|
// we are back to user code again, need slots */
|
||||||
Yap_StartSlots();
|
|
||||||
} else {
|
} else {
|
||||||
ENV = B->cp_env;
|
ENV = B->cp_env;
|
||||||
ENV = (CELL *)ENV[E_E];
|
ENV = (CELL *)ENV[E_E];
|
||||||
@ -1788,6 +1774,7 @@ X_API Int YAP_RunGoal(Term t) {
|
|||||||
// make sure the slots are ok.
|
// make sure the slots are ok.
|
||||||
}
|
}
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
|
LOCAL_CurSlot = cslot;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2021,8 +2008,8 @@ X_API int YAP_InitConsult(int mode, const char *filename, char *full,
|
|||||||
}
|
}
|
||||||
bool consulted = (mode == YAP_CONSULT_MODE);
|
bool consulted = (mode == YAP_CONSULT_MODE);
|
||||||
Yap_init_consult(consulted, filename);
|
Yap_init_consult(consulted, filename);
|
||||||
const char *fl =
|
const char *fl = Yap_findFile(filename, NULL, BootFilePath, full, true,
|
||||||
Yap_findFile(filename, NULL, NULL, full, true, YAP_BOOT_PL, true, true);
|
YAP_BOOT_PL, true, true);
|
||||||
if (!fl)
|
if (!fl)
|
||||||
return -1;
|
return -1;
|
||||||
f = fopen(fl, "r");
|
f = fopen(fl, "r");
|
||||||
@ -2203,6 +2190,7 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
|
|||||||
YAP_Reset(YAP_FULL_RESET);
|
YAP_Reset(YAP_FULL_RESET);
|
||||||
Yap_StartSlots();
|
Yap_StartSlots();
|
||||||
t = YAP_ReadClauseFromStream(bootfile);
|
t = YAP_ReadClauseFromStream(bootfile);
|
||||||
|
|
||||||
// Yap_DebugPlWriteln(t);
|
// Yap_DebugPlWriteln(t);
|
||||||
if (t == 0) {
|
if (t == 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -2243,24 +2231,57 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
YAP_DelayInit()
|
||||||
|
|
||||||
|
ensures initialization is done after engine creation.
|
||||||
|
It receives a pointer to function and a string describing
|
||||||
|
the module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static bool initialized = false;
|
||||||
|
static int n_mdelays = 0;
|
||||||
|
static YAP_delaymodule_t *m_delays;
|
||||||
|
|
||||||
|
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
|
||||||
|
if (initialized)
|
||||||
|
return false;
|
||||||
|
if (m_delays) {
|
||||||
|
m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t));
|
||||||
|
} else {
|
||||||
|
m_delays = malloc(sizeof(YAP_delaymodule_t));
|
||||||
|
}
|
||||||
|
m_delays[n_mdelays].f = f;
|
||||||
|
m_delays[n_mdelays].s = s;
|
||||||
|
n_mdelays++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start_modules(void) {
|
||||||
|
Term cm = CurrentModule;
|
||||||
|
for (size_t i = 0; i < n_mdelays; i++) {
|
||||||
|
CurrentModule = MkAtomTerm(YAP_LookupAtom(m_delays[i].s));
|
||||||
|
m_delays[i].f();
|
||||||
|
}
|
||||||
|
CurrentModule = cm;
|
||||||
|
}
|
||||||
|
|
||||||
/* this routine is supposed to be called from an external program
|
/* this routine is supposed to be called from an external program
|
||||||
that wants to control Yap */
|
that wants to control Yap */
|
||||||
|
|
||||||
#define BOOT_FROM_SAVED_STATE TRUE
|
YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||||
static char BootFile[] = "boot.yap";
|
YAP_file_type_t restore_result = yap_init->boot_file_type;
|
||||||
|
|
||||||
Int YAP_Init(YAP_init_args *yap_init) {
|
|
||||||
YAP_file_type_t restore_result = yap_init->initial_file_type;
|
|
||||||
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
|
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
|
||||||
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
|
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
|
||||||
char boot_file[YAP_FILENAME_MAX + 1];
|
char boot_file[YAP_FILENAME_MAX + 1];
|
||||||
static int initialized = FALSE;
|
|
||||||
Int rc;
|
Int rc;
|
||||||
|
const char *yroot;
|
||||||
|
|
||||||
/* ignore repeated calls to YAP_Init */
|
/* ignore repeated calls to YAP_Init */
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return YAP_BOOT_ERROR;
|
return YAP_FOUND_BOOT_ERROR;
|
||||||
initialized = TRUE;
|
initialized = true;
|
||||||
|
|
||||||
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
|
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
|
||||||
later functions */
|
later functions */
|
||||||
@ -2272,56 +2293,58 @@ Int YAP_Init(YAP_init_args *yap_init) {
|
|||||||
functions */
|
functions */
|
||||||
GLOBAL_argv = yap_init->Argv;
|
GLOBAL_argv = yap_init->Argv;
|
||||||
GLOBAL_argc = yap_init->Argc;
|
GLOBAL_argc = yap_init->Argc;
|
||||||
if (restore_result == YAP_QLY) {
|
if (0 && ((YAP_QLY && yap_init->SavedState) ||
|
||||||
yap_init->SavedState = Yap_findFile(yap_init->SavedState, YAP_STARTUP, NULL,
|
(YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) {
|
||||||
boot_file, true, YAP_QLY, true, true);
|
yroot = ".";
|
||||||
if (yap_init->SavedState == NULL)
|
} else {
|
||||||
restore_result = YAP_BOOT_PL;
|
yroot = BootFilePath;
|
||||||
}
|
}
|
||||||
if (restore_result == YAP_BOOT_PL) {
|
if (yap_init->SavedState == NULL) {
|
||||||
yap_init->YapPrologBootFile =
|
yap_init->SavedState = YAP_STARTUP;
|
||||||
Yap_findFile(yap_init->YapPrologBootFile, BootFile, NULL, boot_file, true,
|
|
||||||
YAP_BOOT_PL, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if USE_DL_MALLOC
|
||||||
if (yap_init->SavedState) {
|
if (yap_init->SavedState == NULL)
|
||||||
fprintf(stderr, "[ WARNING: YAP will ignore saved state %s ]\n",
|
yap_init->SavedState = YAP_STARTUP;
|
||||||
yap_init->SavedState);
|
#else
|
||||||
yap_init->SavedState = NULL;
|
yap_init->SavedState = Yap_findFile(yap_init->SavedState, YAP_STARTUP, yroot,
|
||||||
}
|
boot_file, true, YAP_QLY, true, true);
|
||||||
#endif
|
#endif
|
||||||
|
if (yap_init->SavedState == NULL) {
|
||||||
|
restore_result = YAP_BOOT_PL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restore_result == YAP_BOOT_PL) {
|
||||||
|
#if USE_DL_MALLOC
|
||||||
|
if (yap_init->YapPrologBootFile == NULL)
|
||||||
|
yap_init->YapPrologBootFile = BootFile;
|
||||||
|
#else
|
||||||
|
yap_init->YapPrologBootFile =
|
||||||
|
Yap_findFile(yap_init->YapPrologBootFile, BootFile, yroot, boot_file,
|
||||||
|
true, YAP_BOOT_PL, true, true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (yap_init->TrailSize == 0) {
|
if (yap_init->TrailSize == 0) {
|
||||||
if (yap_init->MaxTrailSize) {
|
if (Trail == 0)
|
||||||
Trail = yap_init->MaxTrailSize;
|
|
||||||
} else if (Trail == 0)
|
|
||||||
Trail = DefTrailSpace;
|
Trail = DefTrailSpace;
|
||||||
} else {
|
} else {
|
||||||
Trail = yap_init->TrailSize;
|
Trail = yap_init->TrailSize;
|
||||||
}
|
}
|
||||||
Atts = yap_init->AttsSize;
|
// Atts = yap_init->AttsSize;
|
||||||
if (yap_init->StackSize == 0) {
|
if (yap_init->StackSize == 0) {
|
||||||
if (yap_init->MaxStackSize || yap_init->MaxGlobalSize) {
|
|
||||||
if (yap_init->MaxStackSize) {
|
|
||||||
if (yap_init->MaxGlobalSize) {
|
|
||||||
Stack = yap_init->MaxStackSize + yap_init->MaxGlobalSize;
|
|
||||||
} else {
|
|
||||||
Stack = yap_init->MaxStackSize + DefStackSpace / 2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Stack = yap_init->MaxGlobalSize + DefStackSpace / 2;
|
|
||||||
}
|
|
||||||
} else if (Stack == 0)
|
|
||||||
Stack = DefStackSpace;
|
Stack = DefStackSpace;
|
||||||
} else {
|
} else {
|
||||||
Stack = yap_init->StackSize;
|
Stack = yap_init->StackSize;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_SYSTEM_MALLOC
|
||||||
if (yap_init->HeapSize == 0) {
|
if (yap_init->HeapSize == 0) {
|
||||||
if (Heap == 0)
|
if (Heap == 0)
|
||||||
Heap = DefHeapSpace;
|
Heap = DefHeapSpace;
|
||||||
} else {
|
} else {
|
||||||
Heap = yap_init->HeapSize;
|
Heap = yap_init->HeapSize;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Yap_InitWorkspace(Heap, Stack, Trail, Atts, yap_init->MaxTableSpaceSize,
|
Yap_InitWorkspace(Heap, Stack, Trail, Atts, yap_init->MaxTableSpaceSize,
|
||||||
yap_init->NumberWorkers, yap_init->SchedulerLoop,
|
yap_init->NumberWorkers, yap_init->SchedulerLoop,
|
||||||
@ -2344,17 +2367,17 @@ Int YAP_Init(YAP_init_args *yap_init) {
|
|||||||
/* tell the system who should cope with interrupts */
|
/* tell the system who should cope with interrupts */
|
||||||
Yap_ExecutionMode = yap_init->ExecutionMode;
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
if (do_bootstrap) {
|
if (do_bootstrap) {
|
||||||
restore_result |= YAP_BOOT_FROM_PROLOG;
|
restore_result |= YAP_BOOT_PL;
|
||||||
} else { // try always to boot from the saved state.
|
} else { // try always to boot from the saved state.
|
||||||
if (restore_result == YAP_QLY) {
|
if (restore_result == YAP_QLY) {
|
||||||
if (!Yap_SavedInfo(yap_init->SavedState, yap_init->YapLibDir, &Trail,
|
if (!Yap_SavedInfo(yap_init->SavedState, yap_init->YapLibDir, &Trail,
|
||||||
&Stack, &Heap)) {
|
&Stack, &Heap)) {
|
||||||
restore_result |= YAP_BOOT_FROM_PROLOG;
|
restore_result = YAP_BOOT_PL;
|
||||||
} else {
|
} else {
|
||||||
restore_result =
|
restore_result =
|
||||||
Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
|
Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
|
||||||
}
|
}
|
||||||
if (restore_result == FAIL_RESTORE) {
|
if (restore_result == YAP_FOUND_BOOT_ERROR) {
|
||||||
restore_result = YAP_BOOT_PL;
|
restore_result = YAP_BOOT_PL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2431,74 +2454,53 @@ Int YAP_Init(YAP_init_args *yap_init) {
|
|||||||
if (yap_init->QuietMode) {
|
if (yap_init->QuietMode) {
|
||||||
setVerbosity(TermSilent);
|
setVerbosity(TermSilent);
|
||||||
}
|
}
|
||||||
if (restore_result == DO_EVERYTHING || restore_result == DO_ONLY_CODE) {
|
if (restore_result == YAP_QLY) {
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(yap_init->SavedState)));
|
MkAtomTerm(Yap_LookupAtom(yap_init->SavedState)));
|
||||||
LOCAL_PrologMode &= ~BootMode;
|
LOCAL_PrologMode &= ~BootMode;
|
||||||
if (restore_result == DO_ONLY_CODE) {
|
|
||||||
/* first, initialize the saved state */
|
|
||||||
rc = YAP_BOOT_FROM_SAVED_CODE;
|
|
||||||
} else {
|
|
||||||
CurrentModule = LOCAL_SourceModule = USER_MODULE;
|
CurrentModule = LOCAL_SourceModule = USER_MODULE;
|
||||||
rc = YAP_BOOT_FROM_SAVED_STACKS;
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!yap_init->YapPrologBootFile)
|
if (!yap_init->YapPrologBootFile)
|
||||||
yap_init->YapPrologBootFile = BootFile;
|
yap_init->YapPrologBootFile = BootFile;
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
rc = YAP_BOOT_PL;
|
||||||
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile)));
|
|
||||||
do_bootfile(yap_init->YapPrologBootFile);
|
do_bootfile(yap_init->YapPrologBootFile);
|
||||||
rc = YAP_BOOT_FROM_PROLOG;
|
setAtomicGlobalPrologFlag(
|
||||||
|
RESOURCE_DATABASE_FLAG,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile)));
|
||||||
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
||||||
}
|
}
|
||||||
|
start_modules();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int Yap_InitDefaults(YAP_init_args *init_args, char saved_state[]) {
|
#if (DefTrailSpace < MinTrailSpace)
|
||||||
init_args->SavedState = saved_state;
|
#undef DefTrailSpace
|
||||||
init_args->AttsSize = 0;
|
#define DefTrailSpace MinTrailSpace
|
||||||
init_args->HeapSize = 0;
|
#endif
|
||||||
init_args->StackSize = 0;
|
|
||||||
init_args->TrailSize = 0;
|
|
||||||
init_args->MaxAttsSize = 0;
|
|
||||||
init_args->MaxHeapSize = 0;
|
|
||||||
init_args->MaxStackSize = 0;
|
|
||||||
init_args->MaxGlobalSize = 0;
|
|
||||||
init_args->MaxTrailSize = 0;
|
|
||||||
init_args->YapLibDir = NULL;
|
|
||||||
init_args->YapPrologBootFile = "boot.yap";
|
|
||||||
init_args->YapPrologInitGoal = "bootstrap";
|
|
||||||
init_args->YapPrologRCFile = NULL;
|
|
||||||
init_args->YapPrologGoal = NULL;
|
|
||||||
init_args->YapPrologTopLevelGoal = NULL;
|
|
||||||
init_args->YapPrologAddPath = NULL;
|
|
||||||
init_args->HaltAfterConsult = FALSE;
|
|
||||||
init_args->FastBoot = FALSE;
|
|
||||||
init_args->NumberWorkers = 1;
|
|
||||||
init_args->SchedulerLoop = 10;
|
|
||||||
init_args->DelayedReleaseLoad = 3;
|
|
||||||
init_args->PrologShouldHandleInterrupts = FALSE;
|
|
||||||
init_args->ExecutionMode = INTERPRETED;
|
|
||||||
init_args->Argc = 1;
|
|
||||||
{
|
|
||||||
size_t l1 = 2 * sizeof(char *);
|
|
||||||
if (!(init_args->Argv = (char **)malloc(l1)))
|
|
||||||
return YAP_BOOT_ERROR;
|
|
||||||
init_args->Argv[0] = Yap_FindExecutable();
|
|
||||||
init_args->Argv[1] = NULL;
|
|
||||||
}
|
|
||||||
init_args->ErrorNo = 0;
|
|
||||||
init_args->ErrorCause = NULL;
|
|
||||||
init_args->QuietMode = FALSE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
X_API Int YAP_FastInit(char saved_state[]) {
|
#if (DefStackSpace < MinStackSpace)
|
||||||
|
#undef DefStackSpace
|
||||||
|
#define DefStackSpace MinStackSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DefHeapSpace < MinHeapSpace)
|
||||||
|
#undef DefHeapSpace
|
||||||
|
#define DefHeapSpace MinHeapSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEFAULT_NUMBERWORKERS 1
|
||||||
|
#define DEFAULT_SCHEDULERLOOP 10
|
||||||
|
#define DEFAULT_DELAYEDRELEASELOAD 3
|
||||||
|
|
||||||
|
X_API YAP_file_type_t YAP_FastInit(char saved_state[], int argc, char *argv[]) {
|
||||||
YAP_init_args init_args;
|
YAP_init_args init_args;
|
||||||
Int out;
|
YAP_file_type_t out;
|
||||||
|
|
||||||
if ((out = Yap_InitDefaults(&init_args, saved_state)) != YAP_BOOT_ERROR)
|
if ((out = Yap_InitDefaults(&init_args, saved_state, argc, argv)) !=
|
||||||
|
YAP_FOUND_BOOT_ERROR)
|
||||||
out = YAP_Init(&init_args);
|
out = YAP_Init(&init_args);
|
||||||
if (out == YAP_BOOT_ERROR) {
|
if (out == YAP_FOUND_BOOT_ERROR) {
|
||||||
Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
|
Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
@ -3339,6 +3341,8 @@ X_API Int YAP_FunctorToInt(Functor f) {
|
|||||||
|
|
||||||
X_API Functor YAP_IntToFunctor(Int i) { return TR_Functors[i]; }
|
X_API Functor YAP_IntToFunctor(Int i) { return TR_Functors[i]; }
|
||||||
|
|
||||||
|
void yap_init(void) {}
|
||||||
|
|
||||||
#endif // C_INTERFACE_C
|
#endif // C_INTERFACE_C
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,14 +172,16 @@ typedef struct YAP_thread_attr_struct {
|
|||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum { YAP_BIN = 0x0001,
|
typedef enum {
|
||||||
|
YAP_BIN = 0x0001,
|
||||||
YAP_TEXT = 0x0002,
|
YAP_TEXT = 0x0002,
|
||||||
YAP_SAVED_STATE = 0x0004,
|
YAP_SAVED_STATE = 0x0004,
|
||||||
YAP_OBJ = 0x0008,
|
YAP_OBJ = 0x0008,
|
||||||
YAP_PL = 0x0010,
|
YAP_PL = 0x0010,
|
||||||
YAP_BOOT_PL = 0x0030,
|
YAP_BOOT_PL = 0x0030,
|
||||||
YAP_QLY = 0x0040,
|
YAP_QLY = 0x0040,
|
||||||
YAP_EXE = 0x0080
|
YAP_EXE = 0x0080,
|
||||||
|
YAP_FOUND_BOOT_ERROR = 0x0100
|
||||||
} YAP_file_type_t;
|
} YAP_file_type_t;
|
||||||
|
|
||||||
#define YAP_ANY_FILE (0x00ff)
|
#define YAP_ANY_FILE (0x00ff)
|
||||||
@ -223,26 +225,26 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct yap_boot_params {
|
typedef struct yap_boot_params {
|
||||||
/* boot type as suggested by the user */
|
/* boot type as suggested by the user */
|
||||||
YAP_file_type_t initial_file_type;
|
YAP_file_type_t boot_file_type;
|
||||||
/* if NON-NULL, path where we can find the saved state */
|
/* if NON-NULL, path where we can find the saved state */
|
||||||
const char *SavedState;
|
const char *SavedState;
|
||||||
/* if NON-0, minimal size for Heap or Code Area */
|
/* if NON-0, minimal size for Heap or Code Area */
|
||||||
unsigned long int HeapSize;
|
size_t HeapSize;
|
||||||
/* if NON-0, maximal size for Heap or Code Area */
|
/* if NON-0, maximal size for Heap or Code Area */
|
||||||
unsigned long int MaxHeapSize;
|
size_t MaxHeapSize;
|
||||||
/* if NON-0, minimal size for Local+Global Stack */
|
/* if NON-0, minimal size for Local+Global Stack */
|
||||||
unsigned long int StackSize;
|
size_t StackSize;
|
||||||
/* if NON-0, maximal size for Local+Global Stack */
|
/* if NON-0, maximal size for Local+Global Stack */
|
||||||
unsigned long int MaxStackSize;
|
size_t MaxStackSize;
|
||||||
unsigned long int MaxGlobalSize;
|
size_t MaxGlobalSize;
|
||||||
/* if NON-0, minimal size for Trail */
|
/* if NON-0, minimal size for Trail */
|
||||||
unsigned long int TrailSize;
|
size_t TrailSize;
|
||||||
/* if NON-0, maximal size for Trail */
|
/* if NON-0, maximal size for Trail */
|
||||||
unsigned long int MaxTrailSize;
|
size_t MaxTrailSize;
|
||||||
/* if NON-0, minimal size for AttributeVarStack */
|
/* if NON-0, minimal size for AttributeVarStack */
|
||||||
unsigned long int AttsSize;
|
size_t AttsSize;
|
||||||
/* if NON-0, maximal size for AttributeVarStack */
|
/* if NON-0, maximal size for AttributeVarStack */
|
||||||
unsigned long int MaxAttsSize;
|
size_t MaxAttsSize;
|
||||||
/* if NON-NULL, value for YAPLIBDIR */
|
/* if NON-NULL, value for YAPLIBDIR */
|
||||||
const char *YapLibDir;
|
const char *YapLibDir;
|
||||||
/* if NON-NULL, name for a Prolog file to use when booting */
|
/* if NON-NULL, name for a Prolog file to use when booting */
|
||||||
@ -263,7 +265,7 @@ typedef struct yap_boot_params {
|
|||||||
bool FastBoot;
|
bool FastBoot;
|
||||||
/* the next field only interest YAPTAB */
|
/* the next field only interest YAPTAB */
|
||||||
/* if NON-0, maximum size for Table Space */
|
/* if NON-0, maximum size for Table Space */
|
||||||
unsigned long int MaxTableSpaceSize;
|
size_t MaxTableSpaceSize;
|
||||||
/* the next three fields only interest YAPOR, but we keep them so that
|
/* the next three fields only interest YAPOR, but we keep them so that
|
||||||
users don't need to recompile DLL in order to use YAPOR */
|
users don't need to recompile DLL in order to use YAPOR */
|
||||||
/* if NON-0, number of workers we want to have (default=1) */
|
/* if NON-0, number of workers we want to have (default=1) */
|
||||||
@ -307,7 +309,8 @@ typedef struct yap_boot_params {
|
|||||||
} YAP_init_args;
|
} YAP_init_args;
|
||||||
|
|
||||||
#ifdef YAP_H
|
#ifdef YAP_H
|
||||||
Int Yap_InitDefaults(YAP_init_args *init_args, char saved_state[]);
|
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
|
||||||
|
int Argc, char *Argv[]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* this should be opaque to the user */
|
/* this should be opaque to the user */
|
||||||
@ -414,4 +417,11 @@ typedef enum yap_enum_reset_t {
|
|||||||
YAP_RESET_FROM_RESTORE = 3
|
YAP_RESET_FROM_RESTORE = 3
|
||||||
} yap_reset_t;
|
} yap_reset_t;
|
||||||
|
|
||||||
|
typedef void (*YAP_ModInit_t)(void);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
YAP_ModInit_t f;
|
||||||
|
const char *s;
|
||||||
|
} YAP_delaymodule_t;
|
||||||
|
|
||||||
#endif /* _YAPDEFS_H */
|
#endif /* _YAPDEFS_H */
|
||||||
|
Reference in New Issue
Block a user