qload/qsave implementation.
This commit is contained in:
parent
ef479f00dc
commit
80faee6824
81
C/qlyr.c
81
C/qlyr.c
@ -44,7 +44,8 @@ typedef enum {
|
|||||||
BAD_ATOM = 8,
|
BAD_ATOM = 8,
|
||||||
MISMATCH = 9,
|
MISMATCH = 9,
|
||||||
INCONSISTENT_CPRED = 10,
|
INCONSISTENT_CPRED = 10,
|
||||||
BAD_READ = 11
|
BAD_READ = 11,
|
||||||
|
BAD_HEADER = 12
|
||||||
} qlfr_err_t;
|
} qlfr_err_t;
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -77,7 +78,7 @@ static void
|
|||||||
QLYR_ERROR(qlfr_err_t my_err)
|
QLYR_ERROR(qlfr_err_t my_err)
|
||||||
{
|
{
|
||||||
Yap_Error(SAVED_STATE_ERROR,TermNil,"error %s in saved state %s",GLOBAL_RestoreFile, qlyr_error[my_err]);
|
Yap_Error(SAVED_STATE_ERROR,TermNil,"error %s in saved state %s",GLOBAL_RestoreFile, qlyr_error[my_err]);
|
||||||
exit(1);
|
Yap_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Atom
|
static Atom
|
||||||
@ -691,11 +692,56 @@ read_tag(IOSTREAM *stream)
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
read_header(IOSTREAM *stream)
|
checkChars(IOSTREAM *stream, char s[])
|
||||||
{
|
{
|
||||||
int ch;
|
int ch, c;
|
||||||
|
char *p = s;
|
||||||
|
|
||||||
|
while ((ch = *p++)) {
|
||||||
|
if ((c = read_byte(stream)) != ch ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Atom
|
||||||
|
get_header(IOSTREAM *stream)
|
||||||
|
{
|
||||||
|
char s[256], *p = s, ch;
|
||||||
|
Atom at;
|
||||||
|
|
||||||
|
if (!checkChars( stream, "#!/bin/sh\nexec_dir=${YAPBINDIR:-" ))
|
||||||
|
return NIL;
|
||||||
|
while ((ch = read_byte(stream)) != '\n');
|
||||||
|
if (!checkChars( stream, "exec $exec_dir/yap $0 \"$@\"\nsaved " ))
|
||||||
|
return NIL;
|
||||||
|
while ((ch = read_byte(stream)) != ',')
|
||||||
|
*p++ = ch;
|
||||||
|
*p++ = '\0';
|
||||||
|
at = Yap_LookupAtom( s );
|
||||||
while ((ch = read_byte(stream)));
|
while ((ch = read_byte(stream)));
|
||||||
|
return at;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_get_header( USES_REGS1 )
|
||||||
|
{
|
||||||
|
IOSTREAM *stream;
|
||||||
|
Term t1 = Deref(ARG1);
|
||||||
|
Atom at;
|
||||||
|
|
||||||
|
if (IsVarTerm(t1)) {
|
||||||
|
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!(stream = Yap_GetInputStream(AtomOfTerm(t1))) ) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if ((at = get_header( stream )) == NIL)
|
||||||
|
return FALSE;
|
||||||
|
return Yap_unify( ARG2, MkAtomTerm( at ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -801,6 +847,7 @@ ReadHash(IOSTREAM *stream)
|
|||||||
pe = RepPredProp(PredPropByAtomAndMod(a,mod));
|
pe = RepPredProp(PredPropByAtomAndMod(a,mod));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
/* IDB */
|
||||||
if (arity == (UInt)-1) {
|
if (arity == (UInt)-1) {
|
||||||
UInt i = read_UInt(stream);
|
UInt i = read_UInt(stream);
|
||||||
pe = Yap_FindLUIntKey(i);
|
pe = Yap_FindLUIntKey(i);
|
||||||
@ -808,12 +855,18 @@ ReadHash(IOSTREAM *stream)
|
|||||||
Atom oa = (Atom)read_UInt(stream);
|
Atom oa = (Atom)read_UInt(stream);
|
||||||
Atom a = LookupAtom(oa);
|
Atom a = LookupAtom(oa);
|
||||||
pe = RepPredProp(PredPropByAtomAndMod(a,mod));
|
pe = RepPredProp(PredPropByAtomAndMod(a,mod));
|
||||||
|
pe->PredFlags |= AtomDBPredFlag;
|
||||||
} else {
|
} else {
|
||||||
Functor of = (Functor)read_UInt(stream);
|
Functor of = (Functor)read_UInt(stream);
|
||||||
Functor f = LookupFunctor(of);
|
Functor f = LookupFunctor(of);
|
||||||
pe = RepPredProp(PredPropByFuncAndMod(f,mod));
|
pe = RepPredProp(PredPropByFuncAndMod(f,mod));
|
||||||
}
|
}
|
||||||
|
pe->PredFlags |= LogUpdatePredFlag;
|
||||||
pe->ArityOfPE = 3;
|
pe->ArityOfPE = 3;
|
||||||
|
if (pe->OpcodeOfPred == UNDEF_OPCODE) {
|
||||||
|
pe->OpcodeOfPred = Yap_opcode(_op_fail);
|
||||||
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = FAILCODE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
InsertPredEntry(ope, pe);
|
InsertPredEntry(ope, pe);
|
||||||
}
|
}
|
||||||
@ -959,7 +1012,10 @@ read_pred(IOSTREAM *stream, Term mod) {
|
|||||||
if (ap->PredFlags & IndexedPredFlag) {
|
if (ap->PredFlags & IndexedPredFlag) {
|
||||||
Yap_RemoveIndexation(ap);
|
Yap_RemoveIndexation(ap);
|
||||||
}
|
}
|
||||||
|
//if (ap->ArityOfPE && ap->ModuleOfPred != IDB_MODULE)
|
||||||
|
// printf(" %s/%ld\n", NameOfFunctor(ap->FunctorOfPred)->StrOfAE, ap->ArityOfPE);
|
||||||
|
//else if (ap->ModuleOfPred != IDB_MODULE)
|
||||||
|
// printf(" %s/%ld\n", ((Atom)(ap->FunctorOfPred))->StrOfAE, ap->ArityOfPE);
|
||||||
#if SIZEOF_INT_P==4
|
#if SIZEOF_INT_P==4
|
||||||
fl1 = flags & ((UInt)STATIC_PRED_FLAGS);
|
fl1 = flags & ((UInt)STATIC_PRED_FLAGS);
|
||||||
ap->PredFlags &= ~((UInt)STATIC_PRED_FLAGS);
|
ap->PredFlags &= ~((UInt)STATIC_PRED_FLAGS);
|
||||||
@ -1013,7 +1069,6 @@ static void
|
|||||||
read_module(IOSTREAM *stream) {
|
read_module(IOSTREAM *stream) {
|
||||||
qlf_tag_t x;
|
qlf_tag_t x;
|
||||||
|
|
||||||
read_header(stream);
|
|
||||||
InitHash();
|
InitHash();
|
||||||
ReadHash(stream);
|
ReadHash(stream);
|
||||||
while ((x = read_tag(stream)) == QLY_START_MODULE) {
|
while ((x = read_tag(stream)) == QLY_START_MODULE) {
|
||||||
@ -1070,14 +1125,12 @@ p_read_program( USES_REGS1 )
|
|||||||
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
|
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!IsAtomTerm(t1)) {
|
if ((stream = Yap_GetInputStream(AtomOfTerm(t1))) ) {
|
||||||
Yap_Error(TYPE_ERROR_ATOM,t1,"read_program/3");
|
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
if (!(stream = Yap_GetInputStream(AtomOfTerm(t1))) ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
YAP_Reset( YAP_RESET_FROM_RESTORE );
|
YAP_Reset( YAP_RESET_FROM_RESTORE );
|
||||||
|
if (get_header( stream ) == NIL)
|
||||||
|
return FALSE;
|
||||||
read_module(stream);
|
read_module(stream);
|
||||||
Sclose( stream );
|
Sclose( stream );
|
||||||
/* back to the top level we go */
|
/* back to the top level we go */
|
||||||
@ -1092,6 +1145,8 @@ Yap_Restore(char *s, char *lib_dir)
|
|||||||
if (!stream)
|
if (!stream)
|
||||||
return -1;
|
return -1;
|
||||||
GLOBAL_RestoreFile = s;
|
GLOBAL_RestoreFile = s;
|
||||||
|
if (get_header( stream ) == NIL)
|
||||||
|
return FALSE;
|
||||||
read_module(stream);
|
read_module(stream);
|
||||||
Sclose( stream );
|
Sclose( stream );
|
||||||
GLOBAL_RestoreFile = NULL;
|
GLOBAL_RestoreFile = NULL;
|
||||||
@ -1102,7 +1157,9 @@ Yap_Restore(char *s, char *lib_dir)
|
|||||||
void Yap_InitQLYR(void)
|
void Yap_InitQLYR(void)
|
||||||
{
|
{
|
||||||
Yap_InitCPred("$qload_module_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qload_module_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag);
|
||||||
|
Yap_InitCPred("$qload_file_preds", 1, p_read_module_preds, SyncPredFlag|UserCPredFlag);
|
||||||
Yap_InitCPred("$qload_program", 1, p_read_program, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qload_program", 1, p_read_program, SyncPredFlag|UserCPredFlag);
|
||||||
|
Yap_InitCPred("$q_header", 2, p_get_header, SyncPredFlag|UserCPredFlag);
|
||||||
if (FALSE) {
|
if (FALSE) {
|
||||||
restore_codes();
|
restore_codes();
|
||||||
}
|
}
|
||||||
|
20
C/qlyw.c
20
C/qlyw.c
@ -771,18 +771,18 @@ save_ops(IOSTREAM *stream, Term mod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
save_header(IOSTREAM *stream)
|
save_header(IOSTREAM *stream, char type[])
|
||||||
{
|
{
|
||||||
char msg[256];
|
char msg[256];
|
||||||
|
|
||||||
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%s", YAP_BINDIR, YAP_FULL_VERSION);
|
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%s %s\n", YAP_BINDIR, type, YAP_FULL_VERSION);
|
||||||
return save_bytes(stream, msg, strlen(msg)+1);
|
return save_bytes(stream, msg, strlen(msg)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
save_module(IOSTREAM *stream, Term mod) {
|
save_module(IOSTREAM *stream, Term mod) {
|
||||||
PredEntry *ap = Yap_ModulePred(mod);
|
PredEntry *ap = Yap_ModulePred(mod);
|
||||||
save_header( stream );
|
save_header( stream, "saved module," );
|
||||||
InitHash();
|
InitHash();
|
||||||
ModuleAdjust(mod);
|
ModuleAdjust(mod);
|
||||||
while (ap) {
|
while (ap) {
|
||||||
@ -813,7 +813,7 @@ save_program(IOSTREAM *stream) {
|
|||||||
ModEntry *me = CurrentModules;
|
ModEntry *me = CurrentModules;
|
||||||
|
|
||||||
InitHash();
|
InitHash();
|
||||||
save_header( stream );
|
save_header( stream, "saved state," );
|
||||||
/* should we allow the user to see hidden predicates? */
|
/* should we allow the user to see hidden predicates? */
|
||||||
while (me) {
|
while (me) {
|
||||||
PredEntry *pp;
|
PredEntry *pp;
|
||||||
@ -855,7 +855,7 @@ save_file(IOSTREAM *stream, Atom FileName) {
|
|||||||
ModEntry *me = CurrentModules;
|
ModEntry *me = CurrentModules;
|
||||||
|
|
||||||
InitHash();
|
InitHash();
|
||||||
save_header( stream );
|
save_header( stream, "saved file," );
|
||||||
/* should we allow the user to see hidden predicates? */
|
/* should we allow the user to see hidden predicates? */
|
||||||
while (me) {
|
while (me) {
|
||||||
PredEntry *pp;
|
PredEntry *pp;
|
||||||
@ -865,6 +865,7 @@ save_file(IOSTREAM *stream, Atom FileName) {
|
|||||||
pp = PredEntryAdjust(pp);
|
pp = PredEntryAdjust(pp);
|
||||||
if (pp &&
|
if (pp &&
|
||||||
!(pp->PredFlags & (MultiFileFlag|NumberDBPredFlag|AtomDBPredFlag|CPredFlag|AsmPredFlag|UserCPredFlag)) &&
|
!(pp->PredFlags & (MultiFileFlag|NumberDBPredFlag|AtomDBPredFlag|CPredFlag|AsmPredFlag|UserCPredFlag)) &&
|
||||||
|
pp->ModuleOfPred != IDB_MODULE &&
|
||||||
pp->src.OwnerFile == FileName) {
|
pp->src.OwnerFile == FileName) {
|
||||||
CHECK(mark_pred(pp));
|
CHECK(mark_pred(pp));
|
||||||
}
|
}
|
||||||
@ -883,8 +884,12 @@ save_file(IOSTREAM *stream, Atom FileName) {
|
|||||||
CHECK(save_tag(stream, QLY_START_MODULE));
|
CHECK(save_tag(stream, QLY_START_MODULE));
|
||||||
CHECK(save_UInt(stream, (UInt)MkAtomTerm(me->AtomOfME)));
|
CHECK(save_UInt(stream, (UInt)MkAtomTerm(me->AtomOfME)));
|
||||||
while (pp != NULL) {
|
while (pp != NULL) {
|
||||||
|
if (pp &&
|
||||||
|
!(pp->PredFlags & (MultiFileFlag|NumberDBPredFlag|AtomDBPredFlag|CPredFlag|AsmPredFlag|UserCPredFlag)) &&
|
||||||
|
pp->src.OwnerFile == FileName) {
|
||||||
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
||||||
CHECK(save_pred(stream, pp));
|
CHECK(save_pred(stream, pp));
|
||||||
|
}
|
||||||
pp = pp->NextPredOfModule;
|
pp = pp->NextPredOfModule;
|
||||||
}
|
}
|
||||||
CHECK(save_tag(stream, QLY_END_PREDICATES));
|
CHECK(save_tag(stream, QLY_END_PREDICATES));
|
||||||
@ -966,9 +971,6 @@ p_save_file( USES_REGS1 )
|
|||||||
if (!(stream = Yap_GetOutputStream(AtomOfTerm(t1))) ) {
|
if (!(stream = Yap_GetOutputStream(AtomOfTerm(t1))) ) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!(stream = Yap_GetOutputStream(AtomOfTerm(t1))) ) {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (IsVarTerm(tfile)) {
|
if (IsVarTerm(tfile)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR,tfile,"save_file/2");
|
Yap_Error(INSTANTIATION_ERROR,tfile,"save_file/2");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -984,7 +986,7 @@ void Yap_InitQLY(void)
|
|||||||
{
|
{
|
||||||
Yap_InitCPred("$qsave_module_preds", 2, p_save_module_preds, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qsave_module_preds", 2, p_save_module_preds, SyncPredFlag|UserCPredFlag);
|
||||||
Yap_InitCPred("$qsave_program", 1, p_save_program, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qsave_program", 1, p_save_program, SyncPredFlag|UserCPredFlag);
|
||||||
Yap_InitCPred("$qsave_file", 2, p_save_file, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qsave_file_preds", 2, p_save_file, SyncPredFlag|UserCPredFlag);
|
||||||
if (FALSE) {
|
if (FALSE) {
|
||||||
restore_codes();
|
restore_codes();
|
||||||
}
|
}
|
||||||
|
185
pl/consult.yap
185
pl/consult.yap
@ -157,6 +157,23 @@ following flags:
|
|||||||
If true, raise an error if the file is not a module file. Used by
|
If true, raise an error if the file is not a module file. Used by
|
||||||
` use_module/1 and use_module/2.
|
` use_module/1 and use_module/2.
|
||||||
|
|
||||||
|
+ qcompile(+ _Value_)
|
||||||
|
|
||||||
|
SWI-Prolog flag that controls whether loaded files should be also
|
||||||
|
compiled into `qly` files. The default value is obtained from the flag
|
||||||
|
`qcompile`:
|
||||||
|
|
||||||
|
`never`, no `qly` file is generated unless the user calls
|
||||||
|
qsave_file/1 and friends, or sets the qcompile option in
|
||||||
|
load_files/2;
|
||||||
|
|
||||||
|
`auto`, all files are qcompiled.
|
||||||
|
|
||||||
|
`large`, files above 100KB are qcompiled.
|
||||||
|
|
||||||
|
`part`, not supported in YAP.
|
||||||
|
|
||||||
|
|
||||||
+ autoload(+ _Autoload_)
|
+ autoload(+ _Autoload_)
|
||||||
|
|
||||||
SWI-compatible option where if _Autoload_ is `true` undefined
|
SWI-compatible option where if _Autoload_ is `true` undefined
|
||||||
@ -175,7 +192,7 @@ following flags:
|
|||||||
% expand(true,false)
|
% expand(true,false)
|
||||||
% if(changed,true,not_loaded) => implemented
|
% if(changed,true,not_loaded) => implemented
|
||||||
% imports(all,List) => implemented
|
% imports(all,List) => implemented
|
||||||
% qcompile(true,false)
|
% qcompile() => implemented
|
||||||
% silent(true,false) => implemented
|
% silent(true,false) => implemented
|
||||||
% stream(Stream) => implemented
|
% stream(Stream) => implemented
|
||||||
% consult(consult,reconsult,exo,db) => implemented
|
% consult(consult,reconsult,exo,db) => implemented
|
||||||
@ -191,7 +208,8 @@ load_files(Files,Opts) :-
|
|||||||
'$lf_option'(expand, 4, false).
|
'$lf_option'(expand, 4, false).
|
||||||
'$lf_option'(if, 5, true).
|
'$lf_option'(if, 5, true).
|
||||||
'$lf_option'(imports, 6, all).
|
'$lf_option'(imports, 6, all).
|
||||||
'$lf_option'(qcompile, 7, never).
|
'$lf_option'(qcompile, 7, Current) :-
|
||||||
|
'$nb_getval'('$qcompile', Current, Current = never).
|
||||||
'$lf_option'(silent, 8, _).
|
'$lf_option'(silent, 8, _).
|
||||||
'$lf_option'(skip_unix_header, 9, false).
|
'$lf_option'(skip_unix_header, 9, false).
|
||||||
'$lf_option'(compilation_mode, 10, source).
|
'$lf_option'(compilation_mode, 10, source).
|
||||||
@ -315,9 +333,11 @@ load_files(Files,Opts) :-
|
|||||||
is_list(Val) -> ( ground(Val) -> true ; '$do_error'(instantiation_error,Call) ) ;
|
is_list(Val) -> ( ground(Val) -> true ; '$do_error'(instantiation_error,Call) ) ;
|
||||||
'$do_error'(domain_error(unimplemented_option,imports(Val)),Call) ).
|
'$do_error'(domain_error(unimplemented_option,imports(Val)),Call) ).
|
||||||
'$process_lf_opt'(qcompile, Val,Call) :-
|
'$process_lf_opt'(qcompile, Val,Call) :-
|
||||||
( Val == true -> '$do_error'(domain_error(unimplemented_option,expand),Call) ;
|
( Val == part -> '$do_error'(domain_error(unimplemented_option,expand),Call) ;
|
||||||
Val == false -> true ;
|
Val == never -> true ;
|
||||||
'$do_error'(domain_error(unimplemented_option,expand(Val)),Call) ).
|
Val == auto -> true ;
|
||||||
|
Val == large -> true ;
|
||||||
|
'$do_error'(domain_error(unknown_option,qcompile(Val)),Call) ).
|
||||||
'$process_lf_opt'(silent, Val, Call) :-
|
'$process_lf_opt'(silent, Val, Call) :-
|
||||||
( Val == false -> true ;
|
( Val == false -> true ;
|
||||||
Val == true -> true ;
|
Val == true -> true ;
|
||||||
@ -395,6 +415,36 @@ load_files(Files,Opts) :-
|
|||||||
'$lf'(user_input, Mod, _, TOpts) :- !,
|
'$lf'(user_input, Mod, _, TOpts) :- !,
|
||||||
b_setval('$source_file', user_input),
|
b_setval('$source_file', user_input),
|
||||||
'$do_lf'(Mod, user_input, user_input, TOpts).
|
'$do_lf'(Mod, user_input, user_input, TOpts).
|
||||||
|
'$lf'(File, Mod, Call, TOpts) :-
|
||||||
|
'$lf_opt'(stream, TOpts, Stream),
|
||||||
|
var( Stream ),
|
||||||
|
H0 is heapused, '$cputime'(T0,_),
|
||||||
|
% check if there is a qly files
|
||||||
|
'$absolute_file_name'(File,[access(read),file_type(qly),file_errors(fail),solutions(first),expand(true)],F,load_files(File)),
|
||||||
|
open( F, read, Stream , [type(binary)] ),
|
||||||
|
( '$q_header'( Stream, Type ),
|
||||||
|
Type == file
|
||||||
|
->
|
||||||
|
time_file64(F, T0F),
|
||||||
|
'$absolute_file_name'(File,[access(read),file_type(prolog),file_errors(fail),solutions(first),expand(true)],FilePl,load_files(File)),
|
||||||
|
time_file64(FilePl, T0Fl),
|
||||||
|
T0F >= T0Fl,
|
||||||
|
!,
|
||||||
|
file_directory_name(F, Dir),
|
||||||
|
working_directory(OldD, Dir),
|
||||||
|
'$msg_level'( TOpts, Verbosity),
|
||||||
|
'$lf_opt'(imports, TOpts, ImportList),
|
||||||
|
'$qload_file'(Stream, Mod, F, FilePl, File, ImportList),
|
||||||
|
close( Stream ),
|
||||||
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
||||||
|
'$current_module'(M, Mod),
|
||||||
|
working_directory( _, OldD),
|
||||||
|
print_message(Verbosity, loaded( loaded, F, M, T, H)),
|
||||||
|
'$exec_initialisation_goals'
|
||||||
|
;
|
||||||
|
close( Stream),
|
||||||
|
fail
|
||||||
|
).
|
||||||
'$lf'(File, Mod, Call, TOpts) :-
|
'$lf'(File, Mod, Call, TOpts) :-
|
||||||
'$lf_opt'(stream, TOpts, Stream),
|
'$lf_opt'(stream, TOpts, Stream),
|
||||||
b_setval('$source_file', File),
|
b_setval('$source_file', File),
|
||||||
@ -403,13 +453,14 @@ load_files(Files,Opts) :-
|
|||||||
'$full_filename'(File, Y, Call),
|
'$full_filename'(File, Y, Call),
|
||||||
open(Y, read, Stream)
|
open(Y, read, Stream)
|
||||||
;
|
;
|
||||||
true
|
stream_property(Stream, file_name(Y))
|
||||||
), !,
|
), !,
|
||||||
'$lf_opt'(reexport, TOpts, Reexport),
|
'$lf_opt'(reexport, TOpts, Reexport),
|
||||||
'$lf_opt'(if, TOpts, If),
|
'$lf_opt'(if, TOpts, If),
|
||||||
( var(If) -> If = true ; true ),
|
( var(If) -> If = true ; true ),
|
||||||
'$lf_opt'(imports, TOpts, Imports),
|
'$lf_opt'(imports, TOpts, Imports),
|
||||||
'$start_lf'(If, Mod, Stream, TOpts, File, Reexport, Imports),
|
'$start_lf'(If, Mod, Stream, TOpts, File, Reexport, Imports),
|
||||||
|
character_count(Stream, Pos),
|
||||||
close(Stream).
|
close(Stream).
|
||||||
'$lf'(X, _, Call, _) :-
|
'$lf'(X, _, Call, _) :-
|
||||||
'$do_error'(permission_error(input,stream,X),Call).
|
'$do_error'(permission_error(input,stream,X),Call).
|
||||||
@ -587,6 +638,9 @@ db_files(Fs) :-
|
|||||||
'$lf_opt'('$context_module', TOpts, ContextModule),
|
'$lf_opt'('$context_module', TOpts, ContextModule),
|
||||||
'$lf_opt'(reexport, TOpts, Reexport),
|
'$lf_opt'(reexport, TOpts, Reexport),
|
||||||
'$msg_level'( TOpts, Verbosity),
|
'$msg_level'( TOpts, Verbosity),
|
||||||
|
'$lf_opt'(qcompile, TOpts, QCompiling),
|
||||||
|
'$nb_getval'('$qcompile', ContextQCompiling, ContextQCompiling = never),
|
||||||
|
nb_setval('$qcompile', QCompiling),
|
||||||
% format( 'I=~w~n', [Verbosity=UserFile] ),
|
% format( 'I=~w~n', [Verbosity=UserFile] ),
|
||||||
'$lf_opt'(encoding, TOpts, Encoding),
|
'$lf_opt'(encoding, TOpts, Encoding),
|
||||||
'$set_encoding'(Stream, Encoding),
|
'$set_encoding'(Stream, Encoding),
|
||||||
@ -618,18 +672,22 @@ db_files(Fs) :-
|
|||||||
StartMsg = consulting,
|
StartMsg = consulting,
|
||||||
EndMsg = consulted
|
EndMsg = consulted
|
||||||
),
|
),
|
||||||
print_message(Verbosity, loading(StartMsg, File)),
|
print_message(Verbosity, loading(StartMsg, UserFile)),
|
||||||
'$lf_opt'(skip_unix_header , TOpts, SkipUnixHeader),
|
'$lf_opt'(skip_unix_header , TOpts, SkipUnixHeader),
|
||||||
( SkipUnixHeader == true->
|
( SkipUnixHeader == true
|
||||||
|
->
|
||||||
'$skip_unix_header'(Stream)
|
'$skip_unix_header'(Stream)
|
||||||
;
|
;
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
'$loop'(Stream,Reconsult),
|
'$loop'(Stream,Reconsult),
|
||||||
|
'$lf_opt'(imports, TOpts, Imports),
|
||||||
|
'$import_to_current_module'(File, ContextModule, Imports, _, TOpts),
|
||||||
|
'$end_consult',
|
||||||
|
'$q_do_save_file'(File, UserFile, ContextModule, TOpts ),
|
||||||
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
||||||
'$current_module'(Mod, SourceModule),
|
'$current_module'(Mod, SourceModule),
|
||||||
print_message(Verbosity, loaded(EndMsg, File, Mod, T, H)),
|
print_message(Verbosity, loaded(EndMsg, File, Mod, T, H)),
|
||||||
'$end_consult',
|
|
||||||
(
|
(
|
||||||
Reconsult = reconsult ->
|
Reconsult = reconsult ->
|
||||||
'$clear_reconsulting'
|
'$clear_reconsulting'
|
||||||
@ -646,14 +704,21 @@ db_files(Fs) :-
|
|||||||
nb_setval('$if_level',OldIfLevel),
|
nb_setval('$if_level',OldIfLevel),
|
||||||
'$lf_opt'('$use_module', TOpts, UseModule),
|
'$lf_opt'('$use_module', TOpts, UseModule),
|
||||||
'$bind_module'(Mod, UseModule),
|
'$bind_module'(Mod, UseModule),
|
||||||
'$lf_opt'(imports, TOpts, Imports),
|
|
||||||
'$import_to_current_module'(File, ContextModule, Imports, _, TOpts),
|
|
||||||
'$reexport'( TOpts, ParentF, Reexport, Imports, File ),
|
'$reexport'( TOpts, ParentF, Reexport, Imports, File ),
|
||||||
|
nb_setval('$qcompile', ContextQCompiling),
|
||||||
( LC == 0 -> prompt(_,' |: ') ; true),
|
( LC == 0 -> prompt(_,' |: ') ; true),
|
||||||
'$exec_initialisation_goals',
|
'$exec_initialisation_goals',
|
||||||
% format( 'O=~w~n', [Mod=UserFile] ),
|
% format( 'O=~w~n', [Mod=UserFile] ),
|
||||||
!.
|
!.
|
||||||
|
|
||||||
|
'$q_do_save_file'(File, UserF, ContextModule, TOpts ) :-
|
||||||
|
'$lf_opt'(qcompile, TOpts, QComp),
|
||||||
|
( QComp == auto ; QComp == large, Pos > 100*1024),
|
||||||
|
'$absolute_file_name'(UserF,[file_type(qly),solutions(first),expand(true)],F,load_files(File)),
|
||||||
|
!,
|
||||||
|
'$qsave_file_'( File, UserF, F ).
|
||||||
|
'$q_do_save_file'(_File, _, _ContextModule, _TOpts ).
|
||||||
|
|
||||||
% are we in autoload and autoload_flag is false?
|
% are we in autoload and autoload_flag is false?
|
||||||
'$msg_level'( TOpts, Verbosity) :-
|
'$msg_level'( TOpts, Verbosity) :-
|
||||||
'$lf_opt'(autoload, TOpts, AutoLoad),
|
'$lf_opt'(autoload, TOpts, AutoLoad),
|
||||||
@ -687,12 +752,11 @@ db_files(Fs) :-
|
|||||||
'$bind_module'(Mod, use_module(Mod)).
|
'$bind_module'(Mod, use_module(Mod)).
|
||||||
|
|
||||||
'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts) :-
|
'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts) :-
|
||||||
\+ recorded('$module','$module'(File, _Module, _, |