change bootstrap sequence to support -B and to allow booting from pl files

This commit is contained in:
Vitor Santos Costa 2016-05-10 08:33:44 +01:00
parent d7318266fe
commit 83a1269553
21 changed files with 245 additions and 223 deletions

4
.gitignore vendored
View File

@ -159,9 +159,9 @@ yPQ
YAP.sublime* YAP.sublime*
yap32 yap32
Eclipse Eclipse
codeblocks
yap-6.3.tags yap-6.3.tags
android
yap.prj yap.prj
yap.VITORs-MBP.vsc.pui yap.VITORs-MBP.vsc.pui

View File

@ -1407,7 +1407,7 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
return 0L; return 0L;
} }
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
continue; return 0;
} else { } else {
break; break;
} }
@ -1989,6 +1989,7 @@ X_API void YAP_PruneGoal(YAP_dogoalinfo *gi) {
break; break;
B = B->cp_b; B = B->cp_b;
} }
Yap_TrimTrail(); Yap_TrimTrail();
RECOVER_B(); RECOVER_B();
@ -2008,35 +2009,37 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id); Yap_ResetException(worker_id);
} }
X_API int YAP_InitConsult(int mode, const char *filename, int *osnop) { X_API int YAP_InitConsult(int mode, const char *filename, char *full,
int *osnop) {
CACHE_REGS CACHE_REGS
FILE *f; FILE *f = NULL;
int sno; int sno;
char full[FILENAME_MAX] BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (mode == YAP_BOOT_MODE) { if (mode == YAP_BOOT_MODE) {
mode = YAP_CONSULT_MODE; mode = YAP_CONSULT_MODE;
} }
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 = Yap_AbsoluteFile(filename, full, true); const char *fl =
Yap_findFile(filename, NULL, NULL, full, true, YAP_BOOT_PL, true, true);
if (!fl) if (!fl)
return -1; return -1;
f = fopen(fl, "r"); f = fopen(fl, "r");
if (!f) if (!f)
return -1; return -1;
else if (fl != filename && fl != full && fl != LOCAL_FileNameBuf && if (!f) {
fl != LOCAL_FileNameBuf2) return -1;
free((void *)fl); }
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f); sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
*osnop = Yap_CheckAlias(AtomLoopStream); *osnop = Yap_CheckAlias(AtomLoopStream);
if (!Yap_AddAlias(AtomLoopStream, sno)) { if (!Yap_AddAlias(AtomLoopStream, sno)) {
Yap_CloseStream(sno); Yap_CloseStream(sno);
sno = -1; sno = -1;
} }
GLOBAL_Stream[sno].name = Yap_LookupAtom(filename); GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(filename)); GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(filename));
GLOBAL_Stream[sno].encoding = ENC_ISO_LATIN1; GLOBAL_Stream[sno].encoding = ENC_ISO_UTF8;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;
@ -2180,19 +2183,16 @@ X_API char *YAP_CompileClause(Term t) {
static int yap_lineno = 0; static int yap_lineno = 0;
/* do initial boot by consulting the file boot.yap */ /* do initial boot by consulting the file boot.yap */
static void do_bootfile(char *bootfilename USES_REGS) { static void do_bootfile(const char *bootfilename USES_REGS) {
Term t; Term t;
int bootfile, osno; int bootfile, osno;
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
char full[YAP_FILENAME_MAX + 1];
/* consult boot.pl */ /* consult boot.pl */
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
/* bootfile = YAP_InitConsult(YAP_BOOT_MODE, bootfilename, full, &osno);
To be honest, YAP_InitConsult does not really do much,
it's here for the future. It also makes what we want to do clearer.
*/
bootfile = YAP_InitConsult(YAP_BOOT_MODE, bootfilename, &osno);
if (bootfile < 0) { if (bootfile < 0) {
fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n", fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n",
bootfilename); bootfilename);
@ -2243,58 +2243,27 @@ static void do_bootfile(char *bootfilename USES_REGS) {
#endif #endif
} }
/* trust YAPSHAREDIR over YAP_PL_SRCDIR, and notice that the code is
* dependent. */
static bool construct_init_file(char *boot_file, char *BootFile) {
#if HAVE_GETENV
if (getenv("YAPSHAREDIR")) {
strncpy(boot_file, getenv("YAPSHAREDIR"), 256);
strncat(boot_file, "/pl/", 255);
if (Yap_Exists(boot_file)) {
return true;
}
}
#endif
#if __ANDROID__
strncpy(boot_file, "/assets/share/pl/", 256);
if (Yap_Exists(boot_file)) {
return true;
}
#endif
strncpy(boot_file, YAP_SHAREDIR "/pl/", 256);
strncat(boot_file, BootFile, 255);
if (Yap_Exists(boot_file)) {
return true;
}
strncpy(boot_file, YAP_PL_SRCDIR "/", 256);
strncat(boot_file, BootFile, 255);
if (Yap_Exists(boot_file)) {
return true;
}
return false;
}
/* 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 #define BOOT_FROM_SAVED_STATE TRUE
static char BootFile[] = "boot.yap"; static char BootFile[] = "boot.yap";
static char InitFile[] = "init.yap";
Int YAP_Init(YAP_init_args *yap_init) { Int YAP_Init(YAP_init_args *yap_init) {
int restore_result; YAP_file_type_t restore_result = yap_init->initial_file_type;
bool do_bootstrap = (yap_init->YapPrologBootFile != NULL); 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; static int initialized = FALSE;
Int rc;
/* ignore repeated calls to YAP_Init */ /* ignore repeated calls to YAP_Init */
if (initialized) if (initialized)
return YAP_BOOT_DONE_BEFOREHAND; return YAP_BOOT_ERROR;
initialized = TRUE; initialized = TRUE;
Yap_InitPageSize(); /* init memory page size, required by later functions */ Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
later functions */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
Yap_init_yapor_global_local_memory(); Yap_init_yapor_global_local_memory();
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
@ -2303,13 +2272,19 @@ 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 BOOT_FROM_SAVED_STATE if (restore_result == YAP_QLY) {
if (!yap_init->SavedState) { yap_init->SavedState = Yap_findFile(yap_init->SavedState, YAP_STARTUP, NULL,
yap_init->SavedState = boot_file, true, YAP_QLY, true, true);
Yap_locateFile(YAP_STARTUP, boot_file, sizeof(boot_file) - 1); if (yap_init->SavedState == NULL)
restore_result = YAP_BOOT_PL;
}
if (restore_result == YAP_BOOT_PL) {
yap_init->YapPrologBootFile =
Yap_findFile(yap_init->YapPrologBootFile, BootFile, NULL, boot_file, true,
YAP_BOOT_PL, true, true);
} }
#else #if 0
if (yap_init->SavedState) { if (yap_init->SavedState) {
fprintf(stderr, "[ WARNING: YAP will ignore saved state %s ]\n", fprintf(stderr, "[ WARNING: YAP will ignore saved state %s ]\n",
yap_init->SavedState); yap_init->SavedState);
@ -2366,26 +2341,24 @@ Int YAP_Init(YAP_init_args *yap_init) {
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
yap_init->HaltAfterConsult); yap_init->HaltAfterConsult);
} }
/* tell the scystem 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_FROM_PROLOG;
} else { // try always to boot from the saved state. } else { // try always to boot from the saved state.
if (restore_result != YAP_BOOT_FROM_PROLOG) { 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_FROM_PROLOG;
yap_init->ErrorNo = LOCAL_Error_TYPE; } else {
yap_init->ErrorCause = LOCAL_ErrorMessage; restore_result =
return YAP_BOOT_ERROR; Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
}
if (restore_result == FAIL_RESTORE) {
restore_result = YAP_BOOT_PL;
} }
} }
restore_result = Yap_Restore(yap_init->SavedState, yap_init->YapLibDir);
if (restore_result == FAIL_RESTORE) {
restore_result = YAP_BOOT_FROM_PROLOG;
}
} }
GLOBAL_FAST_BOOT_FLAG = yap_init->FastBoot; GLOBAL_FAST_BOOT_FLAG = yap_init->FastBoot;
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
Yap_init_root_frames(); Yap_init_root_frames();
@ -2459,48 +2432,25 @@ Int YAP_Init(YAP_init_args *yap_init) {
setVerbosity(TermSilent); setVerbosity(TermSilent);
} }
if (restore_result == DO_EVERYTHING || restore_result == DO_ONLY_CODE) { if (restore_result == DO_EVERYTHING || restore_result == DO_ONLY_CODE) {
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(yap_init->SavedState)));
LOCAL_PrologMode &= ~BootMode; LOCAL_PrologMode &= ~BootMode;
if (restore_result == DO_ONLY_CODE) { if (restore_result == DO_ONLY_CODE) {
/* first, initialize the saved state */ /* first, initialize the saved state */
Term t_goal = MkAtomTerm(AtomInitProlog); rc = YAP_BOOT_FROM_SAVED_CODE;
YAP_RunGoalOnce(t_goal);
return YAP_BOOT_FROM_SAVED_CODE;
} else { } else {
CurrentModule = LOCAL_SourceModule = USER_MODULE; CurrentModule = LOCAL_SourceModule = USER_MODULE;
return YAP_BOOT_FROM_SAVED_STACKS; rc = YAP_BOOT_FROM_SAVED_STACKS;
} }
} else {
if (!yap_init->YapPrologBootFile)
yap_init->YapPrologBootFile = BootFile;
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile)));
do_bootfile(yap_init->YapPrologBootFile);
rc = YAP_BOOT_FROM_PROLOG;
} }
/* read the bootfile */ return rc;
if (!do_bootstrap) {
construct_init_file(boot_file, BootFile);
yap_init->YapPrologBootFile = boot_file;
}
do_bootfile(yap_init->YapPrologBootFile ? yap_init->YapPrologBootFile
: BootFile PASS_REGS);
/* initialize the top-level */
if (!do_bootstrap) {
char init_file[256];
Atom atfile;
Functor fgoal;
YAP_Term goal, as[2];
if (!construct_init_file(init_file, InitFile))
Yap_exit(1);
/* consult init file */
atfile = Yap_LookupAtom(init_file);
as[0] = MkAtomTerm(atfile);
fgoal = Yap_MkFunctor(Yap_FullLookupAtom("$silent_bootstrap"), 1);
goal = Yap_MkApplTerm(fgoal, 1, as);
/* launch consult */
YAP_RunGoalOnce(goal);
/* set default module to user */
as[0] = MkAtomTerm(AtomUser);
fgoal = Yap_MkFunctor(Yap_LookupAtom("module"), 1);
goal = Yap_MkApplTerm(fgoal, 1, as);
YAP_RunGoalOnce(goal);
}
Yap_PutValue(Yap_FullLookupAtom("$live"),
MkAtomTerm(Yap_FullLookupAtom("$true")));
return YAP_BOOT_FROM_PROLOG;
} }
Int Yap_InitDefaults(YAP_init_args *init_args, char saved_state[]) { Int Yap_InitDefaults(YAP_init_args *init_args, char saved_state[]) {
@ -2515,13 +2465,8 @@ Int Yap_InitDefaults(YAP_init_args *init_args, char saved_state[]) {
init_args->MaxGlobalSize = 0; init_args->MaxGlobalSize = 0;
init_args->MaxTrailSize = 0; init_args->MaxTrailSize = 0;
init_args->YapLibDir = NULL; init_args->YapLibDir = NULL;
#if __ANDROID__
init_args->YapPrologBootFile = "boot.yap"; init_args->YapPrologBootFile = "boot.yap";
init_args->YapPrologInitGoal = "bootstrap"; init_args->YapPrologInitGoal = "bootstrap";
#else
init_args->YapPrologBootFile = NULL;
init_args->YapPrologInitGoal = NULL;
#endif
init_args->YapPrologRCFile = NULL; init_args->YapPrologRCFile = NULL;
init_args->YapPrologGoal = NULL; init_args->YapPrologGoal = NULL;
init_args->YapPrologTopLevelGoal = NULL; init_args->YapPrologTopLevelGoal = NULL;

View File

@ -131,7 +131,7 @@ void *Yap_LoadForeignFile(char *file, int flags) {
else else
dlflag |= RTLD_LOCAL; dlflag |= RTLD_LOCAL;
#endif #endif
if (!Yap_locateFile(file, LOCAL_FileNameBuf, true)) { if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true)) {
/* use LD_LIBRARY_PATH */ /* use LD_LIBRARY_PATH */
strncpy(LOCAL_FileNameBuf, file, YAP_FILENAME_MAX - 1); strncpy(LOCAL_FileNameBuf, file, YAP_FILENAME_MAX - 1);
strncat(LOCAL_FileNameBuf, ".", YAP_FILENAME_MAX - 1); strncat(LOCAL_FileNameBuf, ".", YAP_FILENAME_MAX - 1);
@ -177,8 +177,8 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
CACHE_REGS CACHE_REGS
while (libs) { while (libs) {
if (!Yap_locateFile((char *)AtomName(libs->name), LOCAL_FileNameBuf, const char *file = AtomName(libs->name);
true)) { if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true)) {
/* use LD_LIBRARY_PATH */ /* use LD_LIBRARY_PATH */
strncpy(LOCAL_FileNameBuf, (char *)AtomName(libs->name), strncpy(LOCAL_FileNameBuf, (char *)AtomName(libs->name),
YAP_FILENAME_MAX); YAP_FILENAME_MAX);
@ -204,8 +204,8 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
other routines */ other routines */
/* dlopen wants to follow the LD_CONFIG_PATH */ /* dlopen wants to follow the LD_CONFIG_PATH */
if (!Yap_locateFile((char *)AtomName(ofiles->name), LOCAL_FileNameBuf, const char *file = AtomName(ofiles->name);
TRUE)) { if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true)) {
strcpy(LOCAL_ErrorSay, strcpy(LOCAL_ErrorSay,
"%% Trying to open unexisting file in LoadForeign"); "%% Trying to open unexisting file in LoadForeign");
return LOAD_FAILLED; return LOAD_FAILLED;

View File

@ -82,7 +82,8 @@ LoadForeign(StringList ofiles, StringList libs,
while (ofiles) { while (ofiles) {
HINSTANCE handle; HINSTANCE handle;
if (Yap_locateFile(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE) && const char *file = AtomName(ofiles->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true) &&
(handle=LoadLibrary(LOCAL_FileNameBuf)) != 0) (handle=LoadLibrary(LOCAL_FileNameBuf)) != 0)
{ {
LOCAL_ErrorSay[0]=~'\0'; LOCAL_ErrorSay[0]=~'\0';

View File

@ -158,7 +158,8 @@ LoadForeign(StringList ofiles, StringList libs,
void *handle; void *handle;
/* mydlopen wants to follow the LD_CONFIG_PATH */ /* mydlopen wants to follow the LD_CONFIG_PATH */
if (!Yap_locateFile(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) { iconst char *file = AtomName(ofiles->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true) ) {
strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign"); strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign");
return LOAD_FAILLED; return LOAD_FAILLED;
} }

View File

@ -61,7 +61,8 @@ LoadForeign( StringList ofiles, StringList libs,
int valid_fname; int valid_fname;
/* shl_load wants to follow the LD_CONFIG_PATH */ /* shl_load wants to follow the LD_CONFIG_PATH */
valid_fname = Yap_locateFile( AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE ); const char *file = AtomName(ofiles->name);
valid_fname = Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true);
if( !valid_fname ) { if( !valid_fname ) {
strcpy( LOCAL_ErrorSay, "%% Trying to open non-existing file in LoadForeign" ); strcpy( LOCAL_ErrorSay, "%% Trying to open non-existing file in LoadForeign" );

View File

@ -1062,7 +1062,7 @@ static Int qload_program(USES_REGS1) {
return true; return true;
} }
int Yap_Restore(const char *s, char *lib_dir) { int Yap_Restore(const char *s, const char *lib_dir) {
CACHE_REGS CACHE_REGS
FILE *stream = Yap_OpenRestore(s, lib_dir); FILE *stream = Yap_OpenRestore(s, lib_dir);
@ -1072,6 +1072,7 @@ int Yap_Restore(const char *s, char *lib_dir) {
if (do_header(stream) == NIL) if (do_header(stream) == NIL)
return FALSE; return FALSE;
read_module(stream); read_module(stream);
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
fclose(stream); fclose(stream);
GLOBAL_RestoreFile = NULL; GLOBAL_RestoreFile = NULL;
LOCAL_SourceModule = CurrentModule = USER_MODULE; LOCAL_SourceModule = CurrentModule = USER_MODULE;
@ -1085,7 +1086,7 @@ void Yap_InitQLYR(void) {
SyncPredFlag | HiddenPredFlag); SyncPredFlag | HiddenPredFlag);
Yap_InitCPred("$qload_program", 1, qload_program, Yap_InitCPred("$qload_program", 1, qload_program,
SyncPredFlag | HiddenPredFlag); SyncPredFlag | HiddenPredFlag);
Yap_InitCPred("$q_header", 2, get_header, SyncPredFlag | HiddenPredFlag); Yap_InitCPred("$q_header", 2, get_header, SyncPredFlag | HiddenPredFlag);
if (FALSE) { if (FALSE) {
restore_codes(); restore_codes();
} }

View File

@ -125,7 +125,7 @@ static void restore_heap(void);
static void ShowAtoms(void); static void ShowAtoms(void);
static void ShowEntries(PropEntry *); static void ShowEntries(PropEntry *);
#endif #endif
static int OpenRestore(const char *, char *, CELL *, CELL *, CELL *, CELL *, FILE **); static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *, CELL *, FILE **);
static void CloseRestore(void); static void CloseRestore(void);
#ifndef _WIN32 #ifndef _WIN32
static int check_opcodes(OPCODE []); static int check_opcodes(OPCODE []);
@ -1385,7 +1385,7 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A
LOCAL_PrologMode = BootMode; LOCAL_PrologMode = BootMode;
if (Yap_HeapBase) { if (Yap_HeapBase) {
if (falseGlobalPrologFlag( HALT_AFTER_CONSULT_FLAG ) && !silentMode( )) { if (falseGlobalPrologFlag( HALT_AFTER_CONSULT_FLAG ) && !silentMode( )) {
Yap_locateFile(s,LOCAL_FileNameBuf2, YAP_FILENAME_MAX); Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true, true);
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2); fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
} }
Yap_CloseStreams(TRUE); Yap_CloseStreams(TRUE);
@ -1420,7 +1420,7 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
} }
static int static int
OpenRestore(const char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp) OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp)
{ {
CACHE_REGS CACHE_REGS
@ -1445,7 +1445,7 @@ OpenRestore(const char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL
} }
FILE * FILE *
Yap_OpenRestore(const char *inpf, char *YapLibDir) Yap_OpenRestore(const char *inpf, const char *YapLibDir)
{ {
FILE *stream = NULL; FILE *stream = NULL;
@ -1535,7 +1535,7 @@ RestoreHeap(OPCODE old_ops[] USES_REGS)
* state * state
*/ */
int int
Yap_SavedInfo(const char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap) Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
{ {
return DO_ONLY_CODE; return DO_ONLY_CODE;

View File

@ -1338,7 +1338,7 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
static Int p_executable(USES_REGS1) { static Int p_executable(USES_REGS1) {
if (GLOBAL_argv && GLOBAL_argv[0]) if (GLOBAL_argv && GLOBAL_argv[0])
Yap_locateFile(GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE); Yap_findFile(GLOBAL_argv[0], NULL, NULL, LOCAL_FileNameBuf, true, YAP_EXE, true, true);
else else
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1); strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);

View File

@ -155,12 +155,14 @@ static int dump_runtime_variables(void) {
return 1; return 1;
} }
X_API int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) { X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
char *p; char *p;
int BootMode = YAP_BOOT_FROM_SAVED_CODE; int BootMode = YAP_QLY;
unsigned long int *ssize; unsigned long int *ssize;
iap->SavedState = NULL; iap->SavedState = NULL;
iap->initial_file_type = YAP_QLY;
iap->HeapSize = 0; iap->HeapSize = 0;
iap->StackSize = 0; iap->StackSize = 0;
iap->TrailSize = 0; iap->TrailSize = 0;
@ -178,7 +180,7 @@ X_API int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
iap->YapPrologTopLevelGoal = NULL; iap->YapPrologTopLevelGoal = NULL;
iap->YapPrologAddPath = NULL; iap->YapPrologAddPath = NULL;
iap->HaltAfterConsult = FALSE; iap->HaltAfterConsult = FALSE;
iap->FastBoot = FALSE; iap->FastBoot = false;
iap->MaxTableSpaceSize = 0; iap->MaxTableSpaceSize = 0;
iap->NumberWorkers = DEFAULT_NUMBERWORKERS; iap->NumberWorkers = DEFAULT_NUMBERWORKERS;
iap->SchedulerLoop = DEFAULT_SCHEDULERLOOP; iap->SchedulerLoop = DEFAULT_SCHEDULERLOOP;
@ -197,9 +199,26 @@ X_API int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
if (*p == '-') if (*p == '-')
switch (*++p) { switch (*++p) {
case 'b': case 'b':
BootMode = YAP_BOOT_FROM_PROLOG; iap->initial_file_type = BootMode = YAP_PL;
iap->YapPrologBootFile = *++argv; if (p[1])
argc--; iap->YapPrologBootFile = p+1;
else if (argv[1] && *argv[1] != '-') {
iap->YapPrologBootFile = *++argv;
argc--;
} else {
iap->YapPrologBootFile = "boot.yap";
}
break;
case 'B':
iap->initial_file_type = BootMode = YAP_BOOT_PL;
if (p[1])
iap->YapPrologBootFile = p+1;
else if (argv[1] && *argv[1] != '-') {
iap->YapPrologBootFile = *++argv;
argc--;
} else {
iap->YapPrologBootFile = "boot.yap";
}
break; break;
case '?': case '?':
print_usage(); print_usage();

View File

@ -338,6 +338,15 @@ goal succeeded while leaving choicepoints. */
enable the use of the readline library for console interactions, true by default if readline was found. */ enable the use of the readline library for console interactions, true by default if readline was found. */
YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true", NULL), YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true", NULL),
YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom, "boot.yap", NULL),
/**<`resource_database`
Name of the resource file (saved-state or Prolog file) used to construct the YAP
run-time environment.
*/
YAP_FLAG(SAVED_PROGRAM_FLAG, "saved_program", false, booleanFlag, "false", NULL),
/**<`saved_program`
if `true` YAP booted from a `yss` file, usually `startup.yss'. If `false`, YAP booted from a Prolog file, by default `boot.yap`.
*/
YAP_FLAG(SHARED_OBJECT_EXTENSION_FLAG, "shared_object_extension", false, YAP_FLAG(SHARED_OBJECT_EXTENSION_FLAG, "shared_object_extension", false,
isatom, SO_EXT, NULL), /**< `shared_object_extension ` isatom, SO_EXT, NULL), /**< `shared_object_extension `

View File

@ -355,16 +355,16 @@ void Yap_InitReadUtil(void);
/* qly.c */ /* qly.c */
void Yap_InitQLY(void); void Yap_InitQLY(void);
int Yap_Restore(const char *, char *); int Yap_Restore(const char *, const char *);
void Yap_InitQLYR(void); void Yap_InitQLYR(void);
/* range.c */ /* range.c */
void Yap_InitRange(void); void Yap_InitRange(void);
/* save.c */ /* save.c */
int Yap_SavedInfo(const char *, char *, CELL *, CELL *, CELL *); int Yap_SavedInfo(const char *, const char *, CELL *, CELL *, CELL *);
int Yap_SavedStateRestore(char *, char *); int Yap_SavedStateRestore(char *, char *);
FILE *Yap_OpenRestore(const char *, char *); FILE *Yap_OpenRestore(const char *, const char *);
void Yap_InitSavePreds(void); void Yap_InitSavePreds(void);
/* scanner.c */ /* scanner.c */
@ -396,7 +396,7 @@ void Yap_show_statistics(void);
int Yap_IsOpMaxPrio(Atom); int Yap_IsOpMaxPrio(Atom);
/* sysbits.c */ /* sysbits.c */
void Yap_InitPageSize(void); size_t Yap_InitPageSize(void);
bool Yap_set_fpu_exceptions(Term); bool Yap_set_fpu_exceptions(Term);
UInt Yap_cputime(void); UInt Yap_cputime(void);
uint64_t Yap_walltime(void); uint64_t Yap_walltime(void);
@ -420,21 +420,18 @@ void Yap_InitSysbits(int wid);
void Yap_InitSysPreds(void); void Yap_InitSysPreds(void);
void Yap_InitcTime(int); void Yap_InitcTime(int);
void Yap_InitTime(int); void Yap_InitTime(int);
const char *Yap_locateFile(const char *, char *, bool);
double Yap_random(void); double Yap_random(void);
#ifdef _WIN32 #ifdef _WIN32
char *Yap_RegistryGetString(char *); char *Yap_RegistryGetString(char *);
void Yap_WinError(char *); void Yap_WinError(char *);
#endif #endif
typedef enum { YAP_STD, YAP_SAVED_STATE, YAP_OBJ, YAP_PL, YAP_QLY } file_type_t;
const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok); const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz, const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
bool ok); bool ok);
const char *Yap_findFile(const char *isource, const char *idef, const char *Yap_findFile(const char *isource, const char *idef,
const char *root, char *result, bool access, const char *root, char *result, bool access,
file_type_t ftype, bool expand_root, bool in_lib); YAP_file_type_t ftype, bool expand_root, bool in_lib);
/* threads.c */ /* threads.c */
void Yap_InitThreadPreds(void); void Yap_InitThreadPreds(void);
void Yap_InitFirstWorkerThreadHandle(void); void Yap_InitFirstWorkerThreadHandle(void);

View File

@ -73,10 +73,11 @@ static void do_top_goal(YAP_Term Goal) { YAP_RunGoalOnce(Goal); }
static int init_standard_system(int argc, char *argv[], YAP_init_args *iap) { static int init_standard_system(int argc, char *argv[], YAP_init_args *iap) {
int BootMode = YAP_parse_yap_arguments(argc, argv, iap); YAP_file_type_t BootMode = YAP_parse_yap_arguments(argc, argv, iap);
/* init memory */ /* init memory */
BootMode = YAP_Init(iap); iap->initial_file_type =
BootMode = YAP_Init(iap);
if (iap->ErrorNo) { if (iap->ErrorNo) {
/* boot failed */ /* boot failed */
YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause); YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause);
@ -91,10 +92,8 @@ static void exec_top_level(int BootMode, YAP_init_args *iap) {
if (BootMode == YAP_BOOT_FROM_SAVED_STACKS) { if (BootMode == YAP_BOOT_FROM_SAVED_STACKS) {
/* continue executing from the frozen stacks */ /* continue executing from the frozen stacks */
YAP_ContinueGoal(); YAP_ContinueGoal();
livegoal = YAP_FullLookupAtom("$live");
} else {
livegoal = YAP_FullLookupAtom("$bootstrap");
} }
livegoal = YAP_FullLookupAtom("$live");
/* the top-level is now ready */ /* the top-level is now ready */
/* read it before case someone, that is, Ashwin, hides /* read it before case someone, that is, Ashwin, hides

View File

@ -166,6 +166,18 @@ typedef struct YAP_thread_attr_struct {
#include <threads.h> #include <threads.h>
#endif #endif
typedef enum { YAP_BIN = 0x0001,
YAP_TEXT = 0x0002,
YAP_SAVED_STATE = 0x0004,
YAP_OBJ = 0x0008,
YAP_PL = 0x0010,
YAP_BOOT_PL = 0x0030,
YAP_QLY = 0x0040,
YAP_EXE = 0x0080
} YAP_file_type_t;
#define YAP_ANY_FILE (0x00ff)
typedef enum { typedef enum {
YAP_TAG_ATT = 0x1, YAP_TAG_ATT = 0x1,
YAP_TAG_UNBOUND = 0x2, YAP_TAG_UNBOUND = 0x2,
@ -179,13 +191,13 @@ typedef enum {
YAP_TAG_FLOAT = 0x200, YAP_TAG_FLOAT = 0x200,
YAP_TAG_OPAQUE = 0x400, YAP_TAG_OPAQUE = 0x400,
YAP_TAG_APPL = 0x800, YAP_TAG_APPL = 0x800,
YAP_TAG_DBREF = 0x1000 YAP_TAG_DBREF = 0x1000,
YAP_TAG_STRING = 0x2000,
YAP_TAG_ARRAY = 0x4000
} YAP_tag_t; } YAP_tag_t;
#define YAP_BOOT_FROM_SAVED_CODE 1 #define YAP_BOOT_FROM_SAVED_CODE 1
#define YAP_BOOT_FROM_SAVED_STACKS 2 #define YAP_BOOT_FROM_SAVED_STACKS 2
#define YAP_FULL_BOOT_FROM_PROLOG 4
#define YAP_BOOT_DONE_BEFOREHAND 8
#define YAP_BOOT_ERROR -1 #define YAP_BOOT_ERROR -1
#define YAP_WRITE_QUOTED 1 #define YAP_WRITE_QUOTED 1
@ -204,6 +216,8 @@ typedef enum {
#define YAP_BOOT_MODE 2 #define YAP_BOOT_MODE 2
typedef struct yap_boot_params { typedef struct yap_boot_params {
/* boot type as suggested by the user */
YAP_file_type_t initial_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 */
@ -219,25 +233,24 @@ typedef struct yap_boot_params {
unsigned long int TrailSize; unsigned long int TrailSize;
/* if NON-0, maximal size for Trail */ /* if NON-0, maximal size for Trail */
unsigned long int MaxTrailSize; unsigned long int MaxTrailSize;
/* if NON-0, minimal size for AttributeVarStack */ /* if NON-0, minimal size for AttributeVarStack */
unsigned long int AttsSize; unsigned long int AttsSize;
/* if NON-0, maximal size for AttributeVarStack */ /* if NON-0, maximal size for AttributeVarStack */
unsigned long int MaxAttsSize; unsigned long int MaxAttsSize;
/* if NON-NULL, value for YAPLIBDIR */ /* if NON-NULL, value for YAPLIBDIR */
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 */
char *YapPrologBootFile; const char *YapPrologBootFile;
/* if NON-NULL, name for a Prolog file to use when initializing */ /* if NON-NULL, name for a Prolog file to use when initializing */
char *YapPrologInitGoal; const char *YapPrologInitGoal;
/* if NON-NULL, name for a Prolog file to consult before entering top-level */ /* if NON-NULL, name for a Prolog file to consult before entering top-level */
char *YapPrologRCFile; const char *YapPrologRCFile;
/* if NON-NULL, a goal to run before top-level */ /* if NON-NULL, a goal to run before top-level */
char *YapPrologGoal; const char *YapPrologGoal;
/* if NON-NULL, a goal to run as top-level */ /* if NON-NULL, a goal to run as top-level */
char *YapPrologTopLevelGoal; const char *YapPrologTopLevelGoal;
/* if NON-NULL, a path to extend file-search-path */ /* if NON-NULL, a path to extend file-search-path */
char *YapPrologAddPath; const char *YapPrologAddPath;
/* if previous NON-NULL and TRUE, halt after consulting that file */ /* if previous NON-NULL and TRUE, halt after consulting that file */
bool HaltAfterConsult; bool HaltAfterConsult;
/* ignore .yaprc, .prolog.ini, etc. files. */ /* ignore .yaprc, .prolog.ini, etc. files. */

View File

@ -1947,7 +1947,7 @@ extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
extern X_API FILE *YAP_TermToStream(YAP_Term t); extern X_API FILE *YAP_TermToStream(YAP_Term t);
extern X_API int YAP_InitConsult(int mode, const char *filename, extern X_API int YAP_InitConsult(int mode, const char *filename, char *buf,
int *previous_sno); int *previous_sno);
extern X_API void YAP_EndConsult(int s, int *previous_sno); extern X_API void YAP_EndConsult(int s, int *previous_sno);
@ -2212,7 +2212,7 @@ extern X_API int YAP_RequiresExtraStack(size_t);
* reserved memory for alloc IF DEBUG * reserved memory for alloc IF DEBUG
* -P only in development versions * -P only in development versions
*/ */
extern X_API int YAP_parse_yap_arguments(int argc, char *argv[], extern X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
YAP_init_args *iap); YAP_init_args *iap);
extern X_API YAP_Int YAP_AtomToInt(YAP_Atom At); extern X_API YAP_Int YAP_AtomToInt(YAP_Atom At);

View File

@ -92,8 +92,14 @@ Term Yap_StringToNumberTerm(char *s, encoding_t *encp) {
GLOBAL_Stream[sno].encoding = *encp; GLOBAL_Stream[sno].encoding = *encp;
else else
GLOBAL_Stream[sno].encoding = LOCAL_encoding; GLOBAL_Stream[sno].encoding = LOCAL_encoding;
#ifdef __ANDROID__
while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS)
s++
;
#else
while (*s && iswblank(*s++)) while (*s && iswblank(*s++))
; ;
#endif
t = Yap_scan_num(GLOBAL_Stream + sno); t = Yap_scan_num(GLOBAL_Stream + sno);
if (LOCAL_Error_TYPE == SYNTAX_ERROR) if (LOCAL_Error_TYPE == SYNTAX_ERROR)
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;

View File

@ -1431,8 +1431,7 @@ static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3"); PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
return (FALSE); return (FALSE);
} }
if (!Yap_locateFile(RepAtom(AtomOfTerm(file_name))->StrOfAE, if (!Yap_findFile(RepAtom(AtomOfTerm(file_name))->StrOfAE, NULL, NULL, LOCAL_FileNameBuf, true, YAP_ANY_FILE, true, false))
LOCAL_FileNameBuf, false))
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
"absolute_file_name/3")); "absolute_file_name/3"));
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)))); return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));

View File

@ -759,6 +759,7 @@ static Int real_path(USES_REGS1) {
} }
#if _WIN32 #if _WIN32
char cmd2[YAP_FILENAME_MAX + 1]; char cmd2[YAP_FILENAME_MAX + 1];
char *rc;
if ((rc = unix2win(cmd, cmd2, YAP_FILENAME_MAX)) == NULL) { if ((rc = unix2win(cmd, cmd2, YAP_FILENAME_MAX)) == NULL) {
return false; return false;
@ -1150,20 +1151,20 @@ static Int p_dir_sp(USES_REGS1) {
return Yap_unify_constant(ARG1, t) || Yap_unify_constant(ARG1, t2); return Yap_unify_constant(ARG1, t) || Yap_unify_constant(ARG1, t2);
} }
void Yap_InitPageSize(void) { size_t Yap_InitPageSize(void) {
#ifdef _WIN32 #ifdef _WIN32
SYSTEM_INFO si; SYSTEM_INFO si;
GetSystemInfo(&si); GetSystemInfo(&si);
Yap_page_size = si.dwPageSize; return si.dwPageSize;
#elif HAVE_UNISTD_H #elif HAVE_UNISTD_H
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
Yap_page_size = getpagesize(); return getpagesize();
#elif defined(_AIX) #elif defined(_AIX)
Yap_page_size = sysconf(_SC_PAGE_SIZE); return sysconf(_SC_PAGE_SIZE);
#elif !defined(_SC_PAGESIZE) #elif !defined(_SC_PAGESIZE)
Yap_page_size = getpagesize(); return getpagesize();
#else #else
Yap_page_size = sysconf(_SC_PAGESIZE); return sysconf(_SC_PAGESIZE);
#endif #endif
#else #else
bla bla bla bla
@ -1247,7 +1248,7 @@ static Int working_directory(USES_REGS1) {
*/ */
const char *Yap_findFile(const char *isource, const char *idef, const char *Yap_findFile(const char *isource, const char *idef,
const char *iroot, char *result, bool access, const char *iroot, char *result, bool access,
file_type_t ftype, bool expand_root, bool in_lib) { YAP_file_type_t ftype, bool expand_root, bool in_lib) {
char save_buffer[YAP_FILENAME_MAX + 1]; char save_buffer[YAP_FILENAME_MAX + 1];
const char *root, *source = isource; const char *root, *source = isource;
int rc = FAIL_RESTORE; int rc = FAIL_RESTORE;
@ -1261,40 +1262,47 @@ const char *Yap_findFile(const char *isource, const char *idef,
switch (try ++) { switch (try ++) {
case 0: // path or file name is given; case 0: // path or file name is given;
root = iroot; root = iroot;
if (iroot || isource) { if (!root && ftype == YAP_BOOT_PL) {
root = YAP_PL_SRCDIR;
}
if (idef || isource) {
source = (isource ? isource : idef); source = (isource ? isource : idef);
} else {
done = true;
} }
break; break;
case 1: // library directory is given in command line case 1: // library directory is given in command line
if (in_lib && ftype == YAP_SAVED_STATE) { if (in_lib && ftype == YAP_SAVED_STATE) {
root = iroot; root = iroot;
source = (isource ? isource : idef); source = (isource ? isource : idef);
} else } else {
done = true; done = true;
}
break; break;
case 2: // use environment variable YAPLIBDIR case 2: // use environment variable YAPLIBDIR
#if HAVE_GETENV #if HAVE_GETENV
if (in_lib) { if (in_lib) {
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) { if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
root = getenv("YAPLIBDIR"); root = getenv("YAPLIBDIR");
} else { } else if (ftype == YAP_BOOT_PL) {
root = getenv("YAPSHAREDIR"); root = getenv("YAPSHAREDIR");
if (root == NULL) {
continue;
} else {
strncpy(save_buffer, root, YAP_FILENAME_MAX);
strncat(save_buffer, "/pl", YAP_FILENAME_MAX);
}
} }
source = (isource ? isource : idef); source = (isource ? isource : idef);
} else } else
done = true;
break;
#else
done = true;
#endif #endif
done = true;
break; break;
case 3: // use compilation variable YAPLIBDIR case 3: // use compilation variable YAPLIBDIR
if (in_lib) { if (in_lib) {
source = (isource ? isource : idef); source = (isource ? isource : idef);
if (ftype == YAP_PL || ftype == YAP_QLY) { if (ftype == YAP_PL) {
root = YAP_SHAREDIR; root = YAP_SHAREDIR;
} else if (ftype == YAP_BOOT_PL) {
root = YAP_SHAREDIR "/pl";
} else { } else {
root = YAP_LIBDIR; root = YAP_LIBDIR;
} }
@ -1314,7 +1322,6 @@ const char *Yap_findFile(const char *isource, const char *idef,
break; break;
case 5: // search from the binary case 5: // search from the binary
{
#ifndef __ANDROID__ #ifndef __ANDROID__
done = true; done = true;
break; break;
@ -1322,10 +1329,16 @@ const char *Yap_findFile(const char *isource, const char *idef,
const char *pt = Yap_FindExecutable(); const char *pt = Yap_FindExecutable();
if (pt) { if (pt) {
source = if (ftype == YAP_BOOT_PL) {
(ftype == YAP_SAVED_STATE || ftype == YAP_OBJ ? "../../lib/Yap" root = "../../share/Yap/pl";
: "../../share/Yap"); } else {
if (Yap_findFile(source, NULL, pt, save_buffer, access, ftype, root =
(ftype == YAP_SAVED_STATE
|| ftype == YAP_OBJ
? "../../lib/Yap"
: "../../share/Yap");
}
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
expand_root, in_lib)) expand_root, in_lib))
root = save_buffer; root = save_buffer;
else else
@ -1334,7 +1347,7 @@ const char *Yap_findFile(const char *isource, const char *idef,
done = true; done = true;
} }
source = (isource ? isource : idef); source = (isource ? isource : idef);
} break; break;
case 6: // default, try current directory case 6: // default, try current directory
if (!isource && ftype == YAP_SAVED_STATE) if (!isource && ftype == YAP_SAVED_STATE)
source = idef; source = idef;
@ -1352,16 +1365,13 @@ const char *Yap_findFile(const char *isource, const char *idef,
// expand names in case you have // expand names in case you have
// to add a prefix // to add a prefix
if (!access || Yap_Exists(work)) if (!access || Yap_Exists(work)) {
return work; // done return work; // done
}
} }
return NULL; return NULL;
} }
const char *Yap_locateFile(const char *source, char *result, bool in_lib) {
return Yap_findFile(source, NULL, NULL, result, true, YAP_PL, true, in_lib);
}
static Int true_file_name(USES_REGS1) { static Int true_file_name(USES_REGS1) {
Term t = Deref(ARG1); Term t = Deref(ARG1);
const char *s; const char *s;

View File

@ -60,7 +60,7 @@ add_custom_target (${YAP_STARTUP} ALL SOURCES ${PL_SOURCES} WORKING_DIRECTORY ${
# Create a startup.yss on the top directory. # Create a startup.yss on the top directory.
add_custom_command (TARGET ${YAP_STARTUP} add_custom_command (TARGET ${YAP_STARTUP}
COMMAND yap-bin -b ${CMAKE_SOURCE_DIR}/pl/boot.yap -L ${CMAKE_SOURCE_DIR}/pl/init.yap -z qend_program COMMAND yap-bin -B
VERBATIM VERBATIM
WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR}
DEPENDS yap-bin ${PL_SOURCES} DEPENDS yap-bin ${PL_SOURCES}

View File

@ -25,16 +25,16 @@
* @addtogroup Predicates_on_Atoms * @addtogroup Predicates_on_Atoms
* @ingroup YAPChars * @ingroup YAPChars
* *
*/ */
/** @pred atom_concat(+ _As_,? _A_) /** @pred atom_concat(+ _As_,? _A_)
The predicate holds when the first argument is a list of atoms, and the The predicate holds when the first argument is a list of atoms, and the
second unifies with the atom obtained by concatenating all the atoms in second unifies with the atom obtained by concatenating all the atoms in
the first list. the first list.
*/ */
atom_concat(Xs,At) :- atom_concat(Xs,At) :-
( var(At) -> ( var(At) ->
@ -75,8 +75,8 @@ atom_concat(Xs,At) :-
Follow is Next+Sz, Follow is Next+Sz,
'$process_atom_holes'(Unbound). '$process_atom_holes'(Unbound).
/** @pred atomic_list_concat(+ _As_,? _A_) /** @pred atomic_list_concat(+ _As_,? _A_)
The predicate holds when the first argument is a list of atomic terms, and The predicate holds when the first argument is a list of atomic terms, and
@ -84,11 +84,11 @@ the second unifies with the atom obtained by concatenating all the
atomic terms in the first list. The first argument thus may contain atomic terms in the first list. The first argument thus may contain
atoms or numbers. atoms or numbers.
*/ */
atomic_list_concat(L,At) :- atomic_list_concat(L,At) :-
atomic_concat(L, At). atomic_concat(L, At).
/** @pred atomic_list_concat(? _As_,+ _Separator_,? _A_) /** @pred atomic_list_concat(? _As_,+ _Separator_,? _A_)
Creates an atom just like atomic_list_concat/2, but inserts Creates an atom just like atomic_list_concat/2, but inserts
@ -110,7 +110,7 @@ shown below.
L = [gnu, gnat] L = [gnu, gnat]
~~~~~ ~~~~~
*/ */
atomic_list_concat(L, El, At) :- atomic_list_concat(L, El, At) :-
var(El), !, var(El), !,
@ -133,7 +133,7 @@ atomic_list_concat(L, El, At) :-
'$add_els'([A,B|L],El,[A,El|NL]) :- !, '$add_els'([A,B|L],El,[A,El|NL]) :- !,
'$add_els'([B|L],El,NL). '$add_els'([B|L],El,NL).
'$add_els'(L,_,L). '$add_els'(L,_,L).
% %
% small compatibility hack % small compatibility hack
@ -142,7 +142,7 @@ atomic_list_concat(L, El, At) :-
'$variables_in_term'(T,[],V10), '$variables_in_term'(T,[],V10),
'$sort'(V10, V1), '$sort'(V10, V1),
'$non_singletons_in_term'(T,[],V20), '$non_singletons_in_term'(T,[],V20),
'$sort'(V20, V2), '$sort'(V20, V2),
'$subtract_lists_of_variables'(V2,V1,VL). '$subtract_lists_of_variables'(V2,V1,VL).
'$subtract_lists_of_variables'([],VL,VL). '$subtract_lists_of_variables'([],VL,VL).
@ -153,13 +153,13 @@ atomic_list_concat(L, El, At) :-
'$subtract_lists_of_variables'([V1|VL1],[V2|VL2],[V2|VL]) :- '$subtract_lists_of_variables'([V1|VL1],[V2|VL2],[V2|VL]) :-
'$subtract_lists_of_variables'([V1|VL1],VL2,VL). '$subtract_lists_of_variables'([V1|VL1],VL2,VL).
/** @pred current_atom( _A_) /** @pred current_atom( _A_)
Checks whether _A_ is a currently defined atom. It is used to find all Checks whether _A_ is a currently defined atom. It is used to find all
currently defined atoms by backtracking. currently defined atoms by backtracking.
*/ */
current_atom(A) :- % check current_atom(A) :- % check
atom(A), !. atom(A), !.

View File

@ -415,28 +415,49 @@ true :- true.
% simple trick to find out if this is we are booting from Prolog. % simple trick to find out if this is we are booting from Prolog.
% boot from a saved state % boot from a saved state
( (
'$undefined'('$init_preds',prolog) current_prolog_flag(saved_program, False),
writeln(False),
current_prolog_flag(saved_program, false)
->
current_prolog_flag(resource_database, RootPath),
writeln(RootPath),
file_directory_name( RootPath, Dir ),
atom_concat( Dir, '/init.yap' , Init),
bootstrap(Init),
module( user ),
'$make_saved_state',
get_value('$consult_on_boot',X),
(
X \= []
->
qsave_program( 'startup.yss'),
halt
;
true
)
;
'$init_state'
),
'$db_clean_queues'(0),
% this must be executed from C-code.
% '$startup_saved_state',
set_input(user_input),
set_output(user_output),
'$init_or_threads',
'$run_at_thread_start'.
'$make_saved_state' :-
current_prolog_flag(os_argv, Args),
(
member( Arg, Args ),
atom_concat( '-B', _, Arg )
-> ->
get_value('$consult_on_boot',X), qsave_program( 'startup.yss'),
( halt(0)
X \= []
->
bootstrap(X),
module( user ),
qsave_program( 'startup.yss')
; ;
true true
) ).
;
'$init_state'
),
'$db_clean_queues'(0),
% this must be executed from C-code.
% '$startup_saved_state',
set_input(user_input),
set_output(user_output),
'$init_or_threads',
'$run_at_thread_start'.
'$init_globals' :- '$init_globals' :-
% set_prolog_flag(break_level, 0), % set_prolog_flag(break_level, 0),