cleanup restore: use same code for check_saved_state and for actual

restore, tell exact path of file, try several files even if first one is
corrupt.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@664 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-10-30 17:27:19 +00:00
parent 6d8c592775
commit 8ac94c1d88
7 changed files with 280 additions and 238 deletions

View File

@ -847,13 +847,14 @@ X_API Int
YAP_Init(YAP_init_args *yap_init) YAP_Init(YAP_init_args *yap_init)
{ {
int restore_result; int restore_result;
int Trail = 0, Stack = 0, Heap = 0; CELL Trail = 0, Stack = 0, Heap = 0;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
yap_args = yap_init->Argv; yap_args = yap_init->Argv;
yap_argc = yap_init->Argc; yap_argc = yap_init->Argc;
if (yap_init->SavedState != NULL) { if (yap_init->SavedState != NULL ||
if (SavedInfo (yap_init->SavedState, &Trail, &Stack, &Heap, yap_init->YapLibDir) != 1) { yap_init->YapPrologBootFile == NULL) {
if (SavedInfo (yap_init->SavedState, yap_init->YapLibDir, &Trail, &Stack, &Heap) != 1) {
return(YAP_BOOT_FROM_SAVED_ERROR); return(YAP_BOOT_FROM_SAVED_ERROR);
} }
} }
@ -889,15 +890,16 @@ YAP_Init(YAP_init_args *yap_init)
InitMPE (); InitMPE ();
#endif #endif
if (yap_init->YapPrologBootFile != NULL) { if (yap_init->YapPrologRCFile != NULL) {
/* /*
This must be done before restore, otherwise This must be done before restore, otherwise
restore will print out messages .... restore will print out messages ....
*/ */
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult; yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
} }
if (yap_init->SavedState != NULL) { if (yap_init->SavedState != NULL ||
restore_result = Restore(yap_init->SavedState); yap_init->YapPrologBootFile == NULL) {
restore_result = Restore(yap_init->SavedState, yap_init->YapLibDir);
} else { } else {
restore_result = FAIL_RESTORE; restore_result = FAIL_RESTORE;
} }
@ -927,7 +929,7 @@ YAP_Init(YAP_init_args *yap_init)
#endif /* YAPOR || TABLING */ #endif /* YAPOR || TABLING */
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
if (yap_init->YapPrologBootFile != NULL) { if (yap_init->YapPrologRCFile != NULL) {
PutValue(FullLookupAtom("$consult_on_boot"), MkAtomTerm(LookupAtom(yap_init->YapPrologBootFile))); PutValue(FullLookupAtom("$consult_on_boot"), MkAtomTerm(LookupAtom(yap_init->YapPrologBootFile)));
/* /*
This must be done again after restore, as yap_flags This must be done again after restore, as yap_flags
@ -935,8 +937,8 @@ YAP_Init(YAP_init_args *yap_init)
*/ */
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult; yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
} }
if (yap_init->SavedState != NULL) { if (yap_init->SavedState != NULL ||
yap_init->YapPrologBootFile == NULL) {
if (restore_result == FAIL_RESTORE) if (restore_result == FAIL_RESTORE)
return(YAP_BOOT_FROM_SAVED_ERROR); return(YAP_BOOT_FROM_SAVED_ERROR);
if (restore_result == DO_ONLY_CODE) { if (restore_result == DO_ONLY_CODE) {
@ -959,6 +961,7 @@ YAP_FastInit(char saved_state[])
init_args.TrailSize = 0; init_args.TrailSize = 0;
init_args.YapLibDir = NULL; init_args.YapLibDir = NULL;
init_args.YapPrologBootFile = NULL; init_args.YapPrologBootFile = NULL;
init_args.YapPrologRCFile = NULL;
init_args.HaltAfterConsult = FALSE; init_args.HaltAfterConsult = FALSE;
init_args.FastBoot = FALSE; init_args.FastBoot = FALSE;
init_args.NumberWorkers = 1; init_args.NumberWorkers = 1;

View File

@ -311,18 +311,22 @@ dump_stack(void)
} else if (HeapTop > (ADDR)GlobalBase) { } else if (HeapTop > (ADDR)GlobalBase) {
fprintf(stderr,"[ YAP ERROR: Code Space Collided against Global ]\n"); fprintf(stderr,"[ YAP ERROR: Code Space Collided against Global ]\n");
} else { } else {
fprintf(stderr," [ Goals with alternatives open:\n"); if (b_ptr != NULL) {
while (b_ptr != NULL) { fprintf(stderr," [ Goals with alternatives open:\n");
cl_position(b_ptr->cp_ap); while (b_ptr != NULL) {
b_ptr = b_ptr->cp_b; cl_position(b_ptr->cp_ap);
b_ptr = b_ptr->cp_b;
}
fprintf(stderr," ]\n");
} }
fprintf(stderr," ]\n"); if (env_ptr != NULL) {
fprintf(stderr," [ Goals left to continue:\n"); fprintf(stderr," [ Goals left to continue:\n");
while (env_ptr != NULL) { while (env_ptr != NULL) {
cl_position((yamop *)(env_ptr[E_CP])); cl_position((yamop *)(env_ptr[E_CP]));
env_ptr = (CELL *)(env_ptr[E_E]); env_ptr = (CELL *)(env_ptr[E_E]);
}
fprintf(stderr," ]\n");
} }
fprintf(stderr," ]\n");
} }
} }
@ -330,7 +334,8 @@ dump_stack(void)
static void static void
error_exit_yap (int value) error_exit_yap (int value)
{ {
dump_stack(); if (!PrologMode & BootMode)
dump_stack();
exit_yap(value); exit_yap(value);
} }
@ -387,7 +392,7 @@ Error (yap_error_number type, Term where, char *format,...)
exit(1); exit(1);
} }
/* must do this here */ /* must do this here */
if (type == FATAL_ERROR) { if (type == FATAL_ERROR || HeapBase == NULL) {
va_start (ap, format); va_start (ap, format);
/* now build the error string */ /* now build the error string */
if (format != NULL) { if (format != NULL) {

350
C/save.c
View File

@ -54,7 +54,7 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
/********* hack for accesing several kinds of terms. Should be cleaned **/ /********* hack for accesing several kinds of terms. Should be cleaned **/
extern char StartUpFile[]; static char StartUpFile[] = "startup";
static char end_msg[256] ="*** End of YAP saved state *****"; static char end_msg[256] ="*** End of YAP saved state *****";
@ -97,7 +97,7 @@ STATIC_PROTO(void save_crc, (void));
STATIC_PROTO(Int do_save, (int)); STATIC_PROTO(Int do_save, (int));
STATIC_PROTO(Int p_save, (void)); STATIC_PROTO(Int p_save, (void));
STATIC_PROTO(Int p_save_program, (void)); STATIC_PROTO(Int p_save_program, (void));
STATIC_PROTO(int check_header, (void)); STATIC_PROTO(int check_header, (CELL *, CELL *, CELL *, CELL *));
STATIC_PROTO(void get_heap_info, (void)); STATIC_PROTO(void get_heap_info, (void));
STATIC_PROTO(void get_regs, (int)); STATIC_PROTO(void get_regs, (int));
STATIC_PROTO(void get_insts, (OPCODE [])); STATIC_PROTO(void get_insts, (OPCODE []));
@ -121,7 +121,7 @@ STATIC_PROTO(void restore_heap, (void));
STATIC_PROTO(void ShowAtoms, (void)); STATIC_PROTO(void ShowAtoms, (void));
STATIC_PROTO(void ShowEntries, (PropEntry *)); STATIC_PROTO(void ShowEntries, (PropEntry *));
#endif #endif
STATIC_PROTO(int OpenRestore, (char *)); STATIC_PROTO(int OpenRestore, (char *, char *, CELL *, CELL *, CELL *, CELL *));
STATIC_PROTO(void CloseRestore, (void)); STATIC_PROTO(void CloseRestore, (void));
STATIC_PROTO(int check_opcodes, (OPCODE [])); STATIC_PROTO(int check_opcodes, (OPCODE []));
STATIC_PROTO(void RestoreHeap, (OPCODE [], int)); STATIC_PROTO(void RestoreHeap, (OPCODE [], int));
@ -276,6 +276,8 @@ open_file(char *ss, int flag)
static void static void
close_file(void) close_file(void)
{ {
if (splfild == 0)
return;
close(splfild); close(splfild);
splfild = 0; splfild = 0;
} }
@ -284,32 +286,49 @@ close_file(void)
static void static void
putout(CELL l) putout(CELL l)
{ {
mywrite(splfild, (char *) &l, sizeof(CELL)); mywrite(splfild, (char *) &l, sizeof(CELL));
} }
/* stores a pointer to a cell in a file */ /* stores a pointer to a cell in a file */
static void static void
putcellptr(CELL *l) putcellptr(CELL *l)
{ {
mywrite(splfild, (char *) &l, sizeof(CELLPOINTER)); mywrite(splfild, (char *) &l, sizeof(CELLPOINTER));
} }
/* gets a cell from a file */ /* gets a cell from a file */
static CELL static CELL
get_cell(void) get_cell(void)
{ {
CELL l; CELL l;
myread(splfild, (char *) &l, Unsigned(sizeof(CELL))); myread(splfild, (char *) &l, Unsigned(sizeof(CELL)));
return (l); return (l);
}
/* gets a cell from a file */
static CELL
get_header_cell(void)
{
CELL l;
int count = 0, n;
while (count < sizeof(CELL)) {
if ((n = read(splfild, &l, sizeof(CELL)-count)) < 0) {
ErrorMessage = "corrupt saved state";
return(0L);
}
count += n;
}
return(l);
} }
/* gets a pointer to cell from a file */ /* gets a pointer to cell from a file */
static CELL * static CELL *
get_cellptr(void) get_cellptr(void)
{ {
CELL *l; CELL *l;
myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER)));
return (l); myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER)));
return (l);
} }
/* /*
@ -326,6 +345,10 @@ put_info(int info, int mode)
putout(Unsigned(info)); putout(Unsigned(info));
/* say whether we just saved the heap or everything */ /* say whether we just saved the heap or everything */
putout(mode); putout(mode);
/* c-predicates in system */
putout(NUMBER_OF_CPREDS);
/* comparison predicates in system */
putout(NUMBER_OF_CMPFUNCS);
/* current state of stacks, to be used by SavedInfo */ /* current state of stacks, to be used by SavedInfo */
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
/* space available in heap area */ /* space available in heap area */
@ -589,58 +612,110 @@ p_save_program(void)
/* First check out if we are dealing with a valid file */ /* First check out if we are dealing with a valid file */
static int static int
check_header(void) check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
{ {
char pp[80]; char pp[80];
char msg[256]; char msg[256];
CELL hp_size, gb_size, lc_size, tr_size, mode; CELL hp_size, gb_size, lc_size, tr_size, mode, c_preds, cmp_funcs;
/* make sure we always check if there are enough bytes */
/* skip the first line */ /* skip the first line */
do { do {
myread(splfild, pp, 1); if (read(splfild, pp, 1) < 0) {
ErrorMessage = "corrupt saved state";
return(FAIL_RESTORE);
}
} while (pp[0] != 1); } while (pp[0] != 1);
/* now check the version */ /* now check the version */
sprintf(msg, "YAPV%s", version_number); sprintf(msg, "YAPV%s", version_number);
myread(splfild, pp, Unsigned(strlen(msg) + 1)); {
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
while (count < to_read) {
if ((n = read(splfild, pp, to_read-count)) < 0) {
ErrorMessage = "corrupt saved state";
return(FAIL_RESTORE);
}
count += n;
}
}
if (pp[0] != 'Y' && pp[1] != 'A' && pp[0] != 'P') {
ErrorMessage = "corrupt saved state";
return(FAIL_RESTORE);
}
if (strcmp(pp, msg) != 0) { if (strcmp(pp, msg) != 0) {
Error(SYSTEM_ERROR,TermNil,"not a saved Prolog state"); ErrorMessage = "saved state for different version of YAP";
return(FAIL_RESTORE); return(FAIL_RESTORE);
} }
/* check info on header */ /* check info on header */
/* ignore info on saved state */ /* ignore info on saved state */
get_cell(); *info = get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
/* check the restore mode */ /* check the restore mode */
if ((mode = get_cell()) != DO_EVERYTHING && mode != DO_ONLY_CODE) { mode = get_header_cell();
Error(SYSTEM_ERROR,TermNil,"corrupted saved state"); if (ErrorMessage)
return(FAIL_RESTORE);
/* check the number of c-predicates */
c_preds = get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
if (HeapBase != NULL && c_preds != NUMBER_OF_CPREDS) {
ErrorMessage = "saved state with different built-ins";
return(FAIL_RESTORE);
}
cmp_funcs = get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
if (HeapBase != NULL && cmp_funcs != NUMBER_OF_CMPFUNCS) {
ErrorMessage = "saved state with different built-ins";
return(FAIL_RESTORE);
}
if (mode != DO_EVERYTHING && mode != DO_ONLY_CODE) {
ErrorMessage = "corrupt saved state";
return(FAIL_RESTORE); return(FAIL_RESTORE);
} }
/* ignore info on stacks size */ /* ignore info on stacks size */
get_cell(); *AHeap = get_header_cell();
get_cell(); *AStack = get_header_cell();
get_cell(); *ATrail = get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
/* now, check whether we got enough enough space to load the /* now, check whether we got enough enough space to load the
saved space */ saved space */
hp_size = get_cell(); hp_size = get_cell();
while (hp_size > Unsigned(AuxTop) - Unsigned(HeapBase)) { if (ErrorMessage)
return(FAIL_RESTORE);
while (HeapBase != NULL && hp_size > Unsigned(AuxTop) - Unsigned(HeapBase)) {
if(!growheap(FALSE)) { if(!growheap(FALSE)) {
Error(SYSTEM_ERROR,TermNil,ErrorMessage); return(FAIL_RESTORE);
return(FALSE);
} }
} }
if (mode == DO_EVERYTHING) { if (mode == DO_EVERYTHING) {
if ((lc_size = get_cell())+(gb_size=get_cell()) > Unsigned(LocalBase) - Unsigned(GlobalBase)) { lc_size = get_cell();
Error(SYSTEM_ERROR,TermNil,"out of stack space, Yap needs %d", lc_size+gb_size); if (ErrorMessage)
return(FALSE); return(FAIL_RESTORE);
gb_size=get_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
if (HeapBase != NULL && lc_size+gb_size > Unsigned(LocalBase) - Unsigned(GlobalBase)) {
ErrorMessage = "not enough stack space for restore";
return(FAIL_RESTORE);
} }
if ((tr_size = get_cell()) > Unsigned(TrailTop) - Unsigned(TrailBase)) { if (HeapBase != NULL && (tr_size = get_cell()) > Unsigned(TrailTop) - Unsigned(TrailBase)) {
Error(SYSTEM_ERROR,TermNil,"out of trail space, Yap needs %d", tr_size); ErrorMessage = "not enough trail space for restore";
return(FAIL_RESTORE); return(FAIL_RESTORE);
} }
} else { } else {
/* skip cell size */ /* skip cell size */
get_cell(); get_header_cell();
get_cell(); if (ErrorMessage)
get_cell(); return(FAIL_RESTORE);
get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
get_header_cell();
if (ErrorMessage)
return(FAIL_RESTORE);
} }
return(mode); return(mode);
} }
@ -1225,57 +1300,19 @@ ShowAtoms()
#include <stdio.h> #include <stdio.h>
static int static int
OpenRestore(char *s) commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap) {
{
int mode; int mode;
/* if (strcmp(s, StartUpFile) == 0) if ((mode = check_header(Astate,ATrail,AStack,AHeap)) == FAIL_RESTORE)
YP_fprintf(YP_stderr, "[ YAP version %s ]\n\n", version_number);*/
CloseStreams(TRUE);
if ((splfild = open_file(s, O_RDONLY)) < 0) {
if (!dir_separator(s[0]) && !volume_header(s)) {
/*
we have a relative path for the file, try to do somewhat better
using YAPLIBDIR or friends.
*/
if (Yap_LibDir != NULL) {
strncpy(FileNameBuf, Yap_LibDir, YAP_FILENAME_MAX);
#if HAVE_GETENV
} else {
char *yap_env = getenv("YAPLIBDIR");
if (yap_env != NULL) {
strncpy(FileNameBuf, yap_env, YAP_FILENAME_MAX);
#endif
} else {
strncpy(FileNameBuf, LIB_DIR, YAP_FILENAME_MAX);
}
#if HAVE_GETENV
}
#endif
#if _MSC_VER || defined(__MINGW32__)
strncat(FileNameBuf,"\\", YAP_FILENAME_MAX);
#else
strncat(FileNameBuf,"/", YAP_FILENAME_MAX);
#endif
strncat(FileNameBuf,s, YAP_FILENAME_MAX);
if ((splfild = open_file(FileNameBuf, O_RDONLY)) < 0) {
if (PrologMode != BootMode) {
Error(SYSTEM_ERROR,MkAtomTerm(LookupAtom(s)),
"save/1, open(%s)", strerror(errno));
}
return(FAIL_RESTORE);
}
} else {
return(FAIL_RESTORE);
}
}
PrologMode = BootMode;
if ((mode = check_header()) == FAIL_RESTORE)
return(FAIL_RESTORE); return(FAIL_RESTORE);
if (!yap_flags[HALT_AFTER_CONSULT_FLAG]) { PrologMode = BootMode;
YP_fprintf(YP_stderr, "[ Restoring file %s ]\n", s); if (HeapBase) {
if (!yap_flags[HALT_AFTER_CONSULT_FLAG]) {
TrueFileName(s,FileNameBuf2, YAP_FILENAME_MAX);
YP_fprintf(YP_stderr, "[ Restoring file %s ]\n", FileNameBuf2);
}
CloseStreams(TRUE);
} }
#ifdef DEBUG_RESTORE4 #ifdef DEBUG_RESTORE4
/* /*
@ -1286,6 +1323,67 @@ OpenRestore(char *s)
return(mode); return(mode);
} }
static void
cat_file_name(char *s, char *prefix, char *name, unsigned int max_length)
{
strncpy(s, prefix, max_length);
#if _MSC_VER || defined(__MINGW32__)
strncat(s,"\\", max_length);
#else
strncat(s,"/", max_length);
#endif
strncat(s, name, max_length);
}
static int
OpenRestore(char *s, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap)
{
int mode = FAIL_RESTORE;
ErrorMessage = NULL;
if (s == NULL)
s = StartUpFile;
if (s != NULL && (splfild = open_file(s, O_RDONLY)) > 0) {
if ((mode = commit_to_saved_state(s,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
return(mode);
}
if (!dir_separator(s[0]) && !volume_header(s)) {
/*
we have a relative path for the file, try to do somewhat better
using YAPLIBDIR or friends.
*/
if (YapLibDir != NULL) {
cat_file_name(FileNameBuf, Yap_LibDir, s, YAP_FILENAME_MAX);
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
return(mode);
}
}
#if HAVE_GETENV
{
char *yap_env = getenv("YAPLIBDIR");
if (yap_env != NULL) {
cat_file_name(FileNameBuf, yap_env, s, YAP_FILENAME_MAX);
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
return(mode);
}
}
}
#endif
if (LIB_DIR != NULL) {
cat_file_name(FileNameBuf, LIB_DIR, s, YAP_FILENAME_MAX);
if ((splfild = open_file(FileNameBuf, O_RDONLY)) > 0) {
if ((mode = commit_to_saved_state(FileNameBuf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE)
return(mode);
}
}
}
Error(SYSTEM_ERROR, TermNil, ErrorMessage);
ErrorMessage = NULL;
return(FAIL_RESTORE);
}
static void static void
CloseRestore(void) CloseRestore(void)
{ {
@ -1341,77 +1439,24 @@ RestoreHeap(OPCODE old_ops[], int functions_moved)
* state * state
*/ */
int int
SavedInfo(char *FileName, int *ATrail, int *AStack, int *AHeap, char *YapLibDir) SavedInfo(char *FileName, char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
{ {
char pp[80]; CELL MyTrail, MyStack, MyHeap, MyState;
char msg[256]; int mode;
char NameBuf[YAP_FILENAME_MAX];
int result, mode;
if ((splfild = open_file(FileName, O_RDONLY)) < 0) { mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap);
if (!dir_separator(FileName[0]) && !volume_header(FileName)) {
/* we have a relative path for the file, try to do somewhat better */
if (YapLibDir != NULL) {
strncpy(FileNameBuf, YapLibDir, YAP_FILENAME_MAX);
#if HAVE_GETENV
} else {
char* my_env=getenv("YAPLIBDIR");
if (my_env != NULL) {
strncpy(NameBuf, my_env, YAP_FILENAME_MAX);
#endif
} else {
strncpy(NameBuf, LIB_DIR, YAP_FILENAME_MAX);
}
#if HAVE_GETENV
}
#endif
#if _MSC_VER || defined(__MINGW32__)
strncat(NameBuf,"\\", YAP_FILENAME_MAX);
#else
strncat(NameBuf,"/", YAP_FILENAME_MAX);
#endif
strncat(NameBuf,FileName, YAP_FILENAME_MAX);
if ((splfild = open_file(NameBuf, O_RDONLY)) < 0) {
return(FALSE);
}
} else {
return(FALSE);
}
}
/* skip the first line */
do {
myread(splfild, pp, 1);
} while (pp[0] != 1);
sprintf(msg, "YAPV%s", version_number);
myread(splfild, pp, Unsigned(strlen(msg) + 1));
if (strcmp(pp, msg) != 0) {
if (PrologMode != BootMode)
Error(SYSTEM_ERROR, TermNil,
"file %s is not a saved Prolog state", FileName);
return(0);
}
result = get_cell();
mode = get_cell();
if (mode != DO_ONLY_CODE && mode != DO_EVERYTHING) {
Error(SYSTEM_ERROR, TermNil,
"file %s is not a saved Prolog state", FileName);
return(0);
}
if (*AHeap)
get_cell();
else
*AHeap = get_cell() / 1024;
if (mode == DO_ONLY_CODE || *AStack)
get_cell();
else
*AStack = get_cell() / 1024;
if (mode == DO_ONLY_CODE || *ATrail)
get_cell();
else
*ATrail = get_cell() / 1024;
close_file(); close_file();
return (result); if (mode == FAIL_RESTORE) {
ErrorMessage = NULL;
return(0);
}
if (! *AHeap)
*AHeap = MyHeap / 1024;
if (mode != DO_ONLY_CODE && *AStack)
*AStack = MyStack / 1024;
if (mode != DO_ONLY_CODE && *ATrail)
*ATrail = MyTrail / 1024;
return (MyState);
} }
static void static void
@ -1455,14 +1500,15 @@ int in_limbo = FALSE;
* associated registers * associated registers
*/ */
int int
Restore(char *s) Restore(char *s, char *lib_dir)
{ {
int restore_mode; int restore_mode;
int funcs_moved; int funcs_moved;
OPCODE old_ops[_std_top+1]; OPCODE old_ops[_std_top+1];
if ((restore_mode = OpenRestore(s)) == FAIL_RESTORE) CELL MyTrail, MyStack, MyHeap, MyState;
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap)) == FAIL_RESTORE)
return(FALSE); return(FALSE);
ShutdownLoadForeign(); ShutdownLoadForeign();
in_limbo = TRUE; in_limbo = TRUE;
@ -1521,7 +1567,7 @@ p_restore(void)
Error(TYPE_ERROR_LIST,t1,"restore/1"); Error(TYPE_ERROR_LIST,t1,"restore/1");
return(FALSE); return(FALSE);
} }
if ((mode = Restore(FileNameBuf)) == DO_ONLY_CODE) { if ((mode = Restore(FileNameBuf, NULL)) == DO_ONLY_CODE) {
#if PUSH_REGS #if PUSH_REGS
restore_absmi_regs(&standard_regs); restore_absmi_regs(&standard_regs);
#endif #endif

View File

@ -10,7 +10,7 @@
* File: Yap.proto * * File: Yap.proto *
* mods: * * mods: *
* comments: Function declarations for YAP * * comments: Function declarations for YAP *
* version: $Id: Yapproto.h,v 1.26 2002-10-29 17:23:32 vsc Exp $ * * version: $Id: Yapproto.h,v 1.27 2002-10-30 17:27:17 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* prototype file for Yap */ /* prototype file for Yap */
@ -243,8 +243,8 @@ int STD_PROTO(IsPosfixOp,(Prop,int *,int *));
Term STD_PROTO(Parse,(void)); Term STD_PROTO(Parse,(void));
/* save.c */ /* save.c */
int STD_PROTO(SavedInfo,(char *,int *,int *,int *,char *)); int STD_PROTO(SavedInfo,(char *,char *,CELL *,CELL *,CELL *));
int STD_PROTO(Restore,(char *)); int STD_PROTO(Restore,(char *, char *));
void STD_PROTO(InitSavePreds,(void)); void STD_PROTO(InitSavePreds,(void));
/* scanner.c */ /* scanner.c */

View File

@ -67,7 +67,7 @@
static int PROTO(mygetc, (void)); static int PROTO(mygetc, (void));
static void PROTO(do_bootfile, (char *)); static void PROTO(do_bootfile, (char *));
static void PROTO(do_top_goal,(YAP_Term)); static void PROTO(do_top_goal,(YAP_Term));
static void PROTO(exec_top_level,(int, char *)); static void PROTO(exec_top_level,(int, YAP_init_args *));
#ifndef LIGHT #ifndef LIGHT
void PROTO (exit, (int)); void PROTO (exit, (int));
@ -86,7 +86,6 @@ static int output_msg;
#endif #endif
static char BootFile[] = "boot.yap"; static char BootFile[] = "boot.yap";
static char StartUpFile[] = "startup";
#ifdef lint #ifdef lint
/* VARARGS1 */ /* VARARGS1 */
@ -211,15 +210,12 @@ do_bootfile (char *bootfilename)
#endif #endif
} }
static char *filename;
static void static void
print_usage(const YAP_init_args *init_args) print_usage(const YAP_init_args *init_args)
{ {
fprintf(stderr,"\n[ Valid switches for command line arguments: ]\n"); fprintf(stderr,"\n[ Valid switches for command line arguments: ]\n");
fprintf(stderr," -? Shows this screen\n"); fprintf(stderr," -? Shows this screen\n");
fprintf(stderr," -b Boot file (%s)\n", StartUpFile); fprintf(stderr," -b Boot file \n");
fprintf(stderr," -l Prolog file\n"); fprintf(stderr," -l Prolog file\n");
fprintf(stderr," -h Heap area in Kbytes (default: %d, minimum: %d)\n", fprintf(stderr," -h Heap area in Kbytes (default: %d, minimum: %d)\n",
DefHeapSpace, MinHeapSpace); DefHeapSpace, MinHeapSpace);
@ -246,7 +242,7 @@ print_usage(const YAP_init_args *init_args)
*/ */
static int static int
parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args) 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_BOOT_FROM_SAVED_CODE;
@ -260,15 +256,17 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
{ {
case 'b': case 'b':
BootMode = YAP_BOOT_FROM_PROLOG; BootMode = YAP_BOOT_FROM_PROLOG;
iap->YapPrologBootFile = *++argv;
argc--;
break; break;
case '?': case '?':
print_usage(init_args); print_usage(iap);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'w': case 'w':
ssize = &(init_args->NumberWorkers); ssize = &(iap->NumberWorkers);
goto GetSize; goto GetSize;
case 'd': case 'd':
ssize = &(init_args->DelayedReleaseLoad); ssize = &(iap->DelayedReleaseLoad);
goto GetSize; goto GetSize;
#ifdef USE_SOCKET #ifdef USE_SOCKET
case 'c': /* running as client */ case 'c': /* running as client */
@ -313,7 +311,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
break; break;
#endif /* EMACS */ #endif /* EMACS */
case 'f': case 'f':
init_args->FastBoot = TRUE; iap->FastBoot = TRUE;
break; break;
#ifdef MPWSHELL #ifdef MPWSHELL
case 'm': case 'm':
@ -323,19 +321,19 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
#endif #endif
case 's': case 's':
case 'S': case 'S':
ssize = &(init_args->StackSize); ssize = &(iap->StackSize);
if (p[1] == 'l') { if (p[1] == 'l') {
p++; p++;
ssize = &(init_args->SchedulerLoop); ssize = &(iap->SchedulerLoop);
} }
goto GetSize; goto GetSize;
case 'h': case 'h':
case 'H': case 'H':
ssize = &(init_args->HeapSize); ssize = &(iap->HeapSize);
goto GetSize; goto GetSize;
case 't': case 't':
case 'T': case 'T':
ssize = &(init_args->TrailSize); ssize = &(iap->TrailSize);
GetSize: GetSize:
if (*++p == '\0') if (*++p == '\0')
{ {
@ -344,7 +342,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
else else
{ {
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]); fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
print_usage(init_args); print_usage(iap);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -381,13 +379,13 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
/* we're done here */ /* we're done here */
argc = 1; argc = 1;
} }
init_args->YapPrologBootFile = *argv; iap->YapPrologRCFile = *argv;
argv++; argv++;
init_args->HaltAfterConsult = TRUE; iap->HaltAfterConsult = TRUE;
break; break;
case 'l': case 'l':
if ((*argv)[0] == '\0') if ((*argv)[0] == '\0')
init_args->YapPrologBootFile = *argv; iap->YapPrologRCFile = *argv;
else { else {
argc--; argc--;
if (argc == 0) { if (argc == 0) {
@ -395,7 +393,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
argv++; argv++;
init_args->YapPrologBootFile = *argv; iap->YapPrologRCFile = *argv;
} }
break; break;
case '-': case '-':
@ -405,64 +403,51 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *init_args)
default: default:
{ {
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p); fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p);
print_usage(init_args); print_usage(iap);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
else { else {
filename = p; iap->SavedState = p;
} }
} }
return(BootMode); return(BootMode);
} }
static int static int
init_standard_system(int argc, char *argv[]) init_standard_system(int argc, char *argv[], YAP_init_args *iap)
{ {
int BootMode; int BootMode;
YAP_init_args init_args;
init_args.SavedState = NULL; iap->SavedState = NULL;
init_args.HeapSize = 0; iap->HeapSize = 0;
init_args.StackSize = 0; iap->StackSize = 0;
init_args.TrailSize = 0; iap->TrailSize = 0;
init_args.YapLibDir = NULL; iap->YapLibDir = NULL;
init_args.YapPrologBootFile = NULL; iap->YapPrologBootFile = NULL;
init_args.HaltAfterConsult = FALSE; iap->YapPrologRCFile = NULL;
init_args.FastBoot = FALSE; iap->HaltAfterConsult = FALSE;
init_args.NumberWorkers = 1; iap->FastBoot = FALSE;
init_args.SchedulerLoop = 10; iap->NumberWorkers = 1;
init_args.DelayedReleaseLoad = 3; iap->SchedulerLoop = 10;
init_args.Argc = argc; iap->DelayedReleaseLoad = 3;
init_args.Argv = argv; iap->Argc = argc;
iap->Argv = argv;
BootMode = parse_yap_arguments(argc,argv,&init_args); BootMode = parse_yap_arguments(argc,argv,iap);
/* init memory */ /* init memory */
if (BootMode == YAP_BOOT_FROM_PROLOG) if (BootMode == YAP_BOOT_FROM_PROLOG) {
{ YAP_Init(iap);
} else {
YAP_Init(&init_args); BootMode = YAP_Init(iap);
}
}
else
{
if (filename == NULL)
init_args.SavedState = StartUpFile;
else
init_args.SavedState = filename;
BootMode = YAP_Init(&init_args);
}
return(BootMode); return(BootMode);
} }
static void static void
exec_top_level(int BootMode, char *filename) exec_top_level(int BootMode, YAP_init_args *iap)
{ {
YAP_Term atomfalse; YAP_Term atomfalse;
YAP_Atom livegoal; YAP_Atom livegoal;
@ -476,7 +461,7 @@ exec_top_level(int BootMode, char *filename)
{ {
YAP_Atom livegoal; YAP_Atom livegoal;
/* read the bootfile */ /* read the bootfile */
do_bootfile (filename ? filename : BootFile); do_bootfile (iap->YapPrologBootFile ? iap->YapPrologBootFile : BootFile);
livegoal = YAP_FullLookupAtom("$live"); livegoal = YAP_FullLookupAtom("$live");
/* initialise the top-level */ /* initialise the top-level */
YAP_PutValue(livegoal, YAP_MkAtomTerm (YAP_LookupAtom("true"))); YAP_PutValue(livegoal, YAP_MkAtomTerm (YAP_LookupAtom("true")));
@ -504,11 +489,12 @@ main (int argc, char **argv)
#endif #endif
{ {
int BootMode; int BootMode;
YAP_init_args init_args;
#ifdef SIMICS #ifdef SIMICS
fprintf(stdout,"Entering YAP\n"); fprintf(stdout,"Entering YAP\n");
#endif /* SIMICS */ #endif /* SIMICS */
BootMode = init_standard_system(argc, argv); BootMode = init_standard_system(argc, argv, &init_args);
if (BootMode == YAP_BOOT_FROM_SAVED_ERROR) { if (BootMode == YAP_BOOT_FROM_SAVED_ERROR) {
fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n"); fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n");
exit(1); exit(1);
@ -516,7 +502,7 @@ main (int argc, char **argv)
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
start_workers(); start_workers();
#endif /* YAPOR || TABLING */ #endif /* YAPOR || TABLING */
exec_top_level(BootMode, filename); exec_top_level(BootMode, &init_args);
return(0); return(0);
} }

View File

@ -70,8 +70,10 @@ typedef struct {
int TrailSize; int TrailSize;
/* if NON-NULL, value for YAPLIBDIR */ /* if NON-NULL, value for YAPLIBDIR */
char *YapLibDir; char *YapLibDir;
/* if NON-NULL, name for a Prolog file to consult before entering top-level */ /* if NON-NULL, name for a Prolog file to use when booting */
char *YapPrologBootFile; char *YapPrologBootFile;
/* if NON-NULL, name for a Prolog file to consult before entering top-level */
char *YapPrologRCFile;
/* if previous NON-NULL and TRUE, halt after consulting that file */ /* if previous NON-NULL and TRUE, halt after consulting that file */
int HaltAfterConsult; int HaltAfterConsult;
/* ignore .yaprc, .prolog.ini, etc. files. */ /* ignore .yaprc, .prolog.ini, etc. files. */

View File

@ -21,7 +21,7 @@
% throws an exception if called outside of any cleanup-context. % throws an exception if called outside of any cleanup-context.
% %
% cleanup_all. % cleanup_all.
% calls all pending CleanUpGoals and resets the cleanup-system to an initial state. % calls all pending CleanUpGoals and resets the cleanup-system to an initial state.
% should only be used as one of the last calls in the main program. % should only be used as one of the last calls in the main program.
% %
% hidden predicates: % hidden predicates: