load_file
This commit is contained in:
parent
7b774ef5cd
commit
4de58e0fe4
@ -990,16 +990,11 @@ leaving the current stream position unaltered.
|
|||||||
*/
|
*/
|
||||||
static Int peek_code(USES_REGS1) { /* at_end_of_stream */
|
static Int peek_code(USES_REGS1) { /* at_end_of_stream */
|
||||||
/* the next character is a EOF */
|
/* the next character is a EOF */
|
||||||
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2");
|
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek_code/2");
|
||||||
Int ch;
|
Int ch;
|
||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (GLOBAL_Stream[sno].status & Binary_Stream_f) {
|
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek_code/2");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if ((ch = Yap_peek(sno)) < 0) {
|
if ((ch = Yap_peek(sno)) < 0) {
|
||||||
#ifdef PEEK_EOF
|
#ifdef PEEK_EOF
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
|
13
os/streams.c
13
os/streams.c
@ -683,7 +683,7 @@ static xarg *generate_property(int sno, Term t2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
||||||
bool det;
|
bool det = false;
|
||||||
xarg *args;
|
xarg *args;
|
||||||
int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1));
|
int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1));
|
||||||
stream_property_choices_t p = STREAM_PROPERTY_END;
|
stream_property_choices_t p = STREAM_PROPERTY_END;
|
||||||
@ -705,7 +705,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
|||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
|
||||||
Yap_Error(LOCAL_Error_TYPE, t2, NULL);
|
Yap_ThrowError(LOCAL_Error_TYPE, t2, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cut_fail();
|
cut_fail();
|
||||||
@ -714,16 +714,17 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
|||||||
if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
|
if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
|
||||||
// one solution only
|
// one solution only
|
||||||
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
|
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
|
||||||
free(args) UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) {
|
if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) {
|
||||||
|
free(args);
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
cut_succeed();
|
det = true;
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[i].streamlock);
|
LOCK(GLOBAL_Stream[i].streamlock);
|
||||||
rc = do_stream_property(i, args PASS_REGS);
|
rc = do_stream_property(i, args PASS_REGS);
|
||||||
UNLOCK(GLOBAL_Stream[i].streamlock);
|
UNLOCK(GLOBAL_Stream[i].streamlock);
|
||||||
if (IsVarTerm(t1)) {
|
if (!det && IsVarTerm(t1)) {
|
||||||
if (rc)
|
if (rc)
|
||||||
rc = Yap_unify(ARG1, Yap_MkStream(i));
|
rc = Yap_unify(ARG1, Yap_MkStream(i));
|
||||||
if (p == STREAM_PROPERTY_END) {
|
if (p == STREAM_PROPERTY_END) {
|
||||||
@ -743,7 +744,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// done
|
// done
|
||||||
det = (p == STREAM_PROPERTY_END);
|
det = det || (p == STREAM_PROPERTY_END);
|
||||||
}
|
}
|
||||||
free(args);
|
free(args);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -220,10 +220,10 @@ SWI-compatible option where if _Autoload_ is `true` undefined
|
|||||||
% compilation_mode(compact,source,assert_all) => implemented
|
% compilation_mode(compact,source,assert_all) => implemented
|
||||||
% register(true, false) => implemented
|
% register(true, false) => implemented
|
||||||
%
|
%
|
||||||
load_files(Files,Opts) :-
|
load_files(Files0,Opts) :-
|
||||||
once( '$load_files'(Files,Opts,load_files(Files,Opts)) ),
|
'$yap_strip_module'(Files0,M,Files),
|
||||||
fail.
|
'$load_files'(Files,M,Opts,M:load_files(Files,Opts)).
|
||||||
load_files(_Files,_Opts).
|
|
||||||
|
|
||||||
'$lf_option'(autoload, 1, false).
|
'$lf_option'(autoload, 1, false).
|
||||||
'$lf_option'(derived_from, 2, false).
|
'$lf_option'(derived_from, 2, false).
|
||||||
@ -234,7 +234,14 @@ load_files(_Files,_Opts).
|
|||||||
'$lf_option'(qcompile, 7, Current) :-
|
'$lf_option'(qcompile, 7, Current) :-
|
||||||
'__NB_getval__'('$qcompile', Current, Current = never).
|
'__NB_getval__'('$qcompile', Current, Current = never).
|
||||||
'$lf_option'(silent, 8, _).
|
'$lf_option'(silent, 8, _).
|
||||||
'$lf_option'(skip_unix_header, 9, true).
|
'$lf_option'(skip_unix_header, 9, Skip) :-
|
||||||
|
stream_property(Stream,[alias(loop_stream),tty(TTy),reposition(Rep)]),
|
||||||
|
( Rep == true
|
||||||
|
->
|
||||||
|
(TTy = true -> Skip = false ; Skip = true)
|
||||||
|
;
|
||||||
|
Skip = false
|
||||||
|
).
|
||||||
'$lf_option'(compilation_mode, 10, Flag) :-
|
'$lf_option'(compilation_mode, 10, Flag) :-
|
||||||
current_prolog_flag(source, YFlag),
|
current_prolog_flag(source, YFlag),
|
||||||
( YFlag == false -> Flag = compact ; Flag = source ).
|
( YFlag == false -> Flag = compact ; Flag = source ).
|
||||||
@ -273,17 +280,43 @@ load_files(_Files,_Opts).
|
|||||||
'$lf_option'(Op, Id, _),
|
'$lf_option'(Op, Id, _),
|
||||||
setarg( Id, TOpts, Val ).
|
setarg( Id, TOpts, Val ).
|
||||||
|
|
||||||
'$load_files'(Files, Opts, Call) :-
|
'$load_files'([user], M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user, M, [stream(S)|Opts], Call).
|
||||||
|
'$load_files'(user, M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user, M, [stream(S)|Opts], Call).
|
||||||
|
'$load_files'([-user], M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user, M, [consult(reconsult),stream(S)|Opts], Call).
|
||||||
|
'$load_files'(-user, M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user, M, [consult(reconsult),stream(S)|Opts], Call).
|
||||||
|
'$load_files'([user_input], M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user_input, M, [stream(S)|Opts], Call).
|
||||||
|
'$load_files'(user_input, M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user_input, M, [stream(S)|Opts], Call).
|
||||||
|
'$load_files'([-user_input], M,Opts, Call) :-
|
||||||
|
current_input(S),
|
||||||
|
'$load_files__'(user_input, M, [consult(reconsult),stream(S)|Opts], Call).
|
||||||
|
'$load_files'(-user_input, M,Opts, Call) :-
|
||||||
|
'$load_files__'(user_input, M, [consult(reconsult),stream(S)|Opts], Call).
|
||||||
|
'$load_files'(Files, M, Opts, Call) :-
|
||||||
|
'$load_files__'(Files, M, Opts, Call).
|
||||||
|
'$load_files__'(Files, M, Opts, Call) :-
|
||||||
'$lf_option'(last_opt, LastOpt),
|
'$lf_option'(last_opt, LastOpt),
|
||||||
( '__NB_getval__'('$lf_status', OldTOpts, fail),
|
( '__NB_getval__'('$lf_status', OldTOpts, fail),
|
||||||
nonvar(OldTOpts)
|
nonvar(OldTOpts)
|
||||||
->
|
->
|
||||||
'$lf_opt'(autoload, OldTOpts, OldAutoload)
|
'$lf_opt'(autoload, OldTOpts, OldAutoload),
|
||||||
|
'$lf_opt'('$context_module', OldTOpts, OldContextModule)
|
||||||
;
|
;
|
||||||
current_prolog_flag(autoload, OldAutoload),
|
current_prolog_flag(autoload, OldAutoload),
|
||||||
functor( OldTOpts, opt, LastOpt ),
|
functor( OldTOpts, opt, LastOpt ),
|
||||||
'$lf_opt'(autoload, OldTOpts, OldAutoload),
|
'$lf_opt'(autoload, OldTOpts, OldAutoload),
|
||||||
'$lf_opt'('$context_module', OldTOpts, user)
|
'$lf_opt'('$context_module', OldTOpts, OldContextModule)
|
||||||
),
|
),
|
||||||
functor( TOpts, opt, LastOpt ),
|
functor( TOpts, opt, LastOpt ),
|
||||||
( source_location(ParentF, Line) -> true ; ParentF = user_input, Line = -1 ),
|
( source_location(ParentF, Line) -> true ; ParentF = user_input, Line = -1 ),
|
||||||
@ -302,7 +335,6 @@ load_files(_Files,_Opts).
|
|||||||
),
|
),
|
||||||
'$check_use_module'(Call,UseModule),
|
'$check_use_module'(Call,UseModule),
|
||||||
'$lf_opt'('$use_module', TOpts, UseModule),
|
'$lf_opt'('$use_module', TOpts, UseModule),
|
||||||
'$current_module'(M0),
|
|
||||||
( '$lf_opt'(autoload, TOpts, Autoload),
|
( '$lf_opt'(autoload, TOpts, Autoload),
|
||||||
var(Autoload) ->
|
var(Autoload) ->
|
||||||
Autoload = OldAutoload
|
Autoload = OldAutoload
|
||||||
@ -311,7 +343,7 @@ load_files(_Files,_Opts).
|
|||||||
),
|
),
|
||||||
% make sure we can run consult
|
% make sure we can run consult
|
||||||
'$init_consult',
|
'$init_consult',
|
||||||
'$lf'(Files, M0, Call, TOpts).
|
'$lf'(Files, M, Call, TOpts).
|
||||||
|
|
||||||
'$check_files'(Files, Call) :-
|
'$check_files'(Files, Call) :-
|
||||||
var(Files), !,
|
var(Files), !,
|
||||||
@ -433,32 +465,12 @@ load_files(_Files,_Opts).
|
|||||||
'$lf'(V,_,Call, _ ) :- var(V), !,
|
'$lf'(V,_,Call, _ ) :- var(V), !,
|
||||||
'$do_error'(instantiation_error,Call).
|
'$do_error'(instantiation_error,Call).
|
||||||
'$lf'([], _, _, _) :- !.
|
'$lf'([], _, _, _) :- !.
|
||||||
'$lf'(M:X, _, Call, TOpts) :- !,
|
|
||||||
(
|
|
||||||
atom(M)
|
|
||||||
->
|
|
||||||
'$lf'(X, M, Call, TOpts)
|
|
||||||
;
|
|
||||||
'$do_error'(type_error(atom,M),Call)
|
|
||||||
).
|
|
||||||
'$lf'([F|Fs], Mod, Call, TOpts) :- !,
|
'$lf'([F|Fs], Mod, Call, TOpts) :- !,
|
||||||
% clean up after each consult
|
% clean up after each consult
|
||||||
( '$lf'(F,Mod,Call, TOpts), fail;
|
( '$lf'(F,Mod,Call, TOpts), fail;
|
||||||
'$lf'(Fs, Mod, Call, TOpts), fail;
|
'$lf'(Fs, Mod, Call, TOpts), fail;
|
||||||
true
|
true
|
||||||
).
|
).
|
||||||
'$lf'(user, Mod, Call, TOpts) :-
|
|
||||||
!,
|
|
||||||
stream_property( S, alias( user_input )),
|
|
||||||
'$set_lf_opt'('$from_stream', TOpts, true),
|
|
||||||
'$set_lf_opt'( stream , TOpts, S),
|
|
||||||
'$lf'(S, Mod, Call, TOpts).
|
|
||||||
'$lf'(user_input, Mod, Call, TOpts ) :-
|
|
||||||
!,
|
|
||||||
stream_property( S, alias( user_input )),
|
|
||||||
'$set_lf_opt'('$from_stream', TOpts, true),
|
|
||||||
'$set_lf_opt'( stream , TOpts, S),
|
|
||||||
'$lf'(S, Mod, Call, TOpts).
|
|
||||||
'$lf'(File, Mod, Call, TOpts) :-
|
'$lf'(File, Mod, Call, TOpts) :-
|
||||||
'$lf_opt'(stream, TOpts, Stream),
|
'$lf_opt'(stream, TOpts, Stream),
|
||||||
b_setval('$user_source_file', File),
|
b_setval('$user_source_file', File),
|
||||||
@ -1104,7 +1116,7 @@ just goes through every loaded file and verifies whether reloading is needed.
|
|||||||
|
|
||||||
make :-
|
make :-
|
||||||
recorded('$lf_loaded','$lf_loaded'(F1,_M,reconsult,_,_,_,_),_),
|
recorded('$lf_loaded','$lf_loaded'(F1,_M,reconsult,_,_,_,_),_),
|
||||||
'$load_files'(F1, [if(changed)],make),
|
load_files(F1, [if(changed)]),
|
||||||
fail.
|
fail.
|
||||||
make.
|
make.
|
||||||
|
|
||||||
@ -1265,11 +1277,11 @@ use_module(M,F,Is) :-
|
|||||||
'$use_module'(M,M1,F,Is) :-
|
'$use_module'(M,M1,F,Is) :-
|
||||||
nonvar(F), !,
|
nonvar(F), !,
|
||||||
( var(M) ->
|
( var(M) ->
|
||||||
'$load_files'(M1:F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is)),
|
load_files(M1:F, [if(not_loaded),must_be_module(true),imports(Is)]),
|
||||||
absolute_file_name( F, F1, [expand(true),file_type(prolog)] ),
|
absolute_file_name( F, F1, [expand(true),file_type(prolog)] ),
|
||||||
recorded('$module','$module'(F1,M,_,_,_),_)
|
recorded('$module','$module'(F1,M,_,_,_),_)
|
||||||
;
|
;
|
||||||
'$load_files'(M1:F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
|
load_files(M1:F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
|
||||||
).
|
).
|
||||||
'$use_module'(M,M1,F,Is) :-
|
'$use_module'(M,M1,F,Is) :-
|
||||||
nonvar(M), !,
|
nonvar(M), !,
|
||||||
@ -1277,11 +1289,11 @@ use_module(M,F,Is) :-
|
|||||||
(
|
(
|
||||||
recorded('$module','$module'(F0,M,_,_,_),_)
|
recorded('$module','$module'(F0,M,_,_,_),_)
|
||||||
->
|
->
|
||||||
'$load_files'(M1:F0, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
|
load_files(M1:F0, [if(not_loaded),must_be_module(true),imports(Is)])
|
||||||
;
|
;
|
||||||
nonvar(F0)
|
nonvar(F0)
|
||||||
->
|
->
|
||||||
'$load_files'(M1:F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
|
load_files(M1:F, [if(not_loaded),must_be_module(true),imports(Is)])
|
||||||
;
|
;
|
||||||
'$do_error'(instantiation_error,use_module(M,F,Is))
|
'$do_error'(instantiation_error,use_module(M,F,Is))
|
||||||
).
|
).
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
'$include'/2,
|
'$include'/2,
|
||||||
'$initialization'/1,
|
'$initialization'/1,
|
||||||
'$initialization'/2,
|
'$initialization'/2,
|
||||||
'$load_files'/3,
|
|
||||||
'$require'/2,
|
'$require'/2,
|
||||||
'$set_encoding'/1,
|
'$set_encoding'/1,
|
||||||
'$use_module'/3]).
|
'$use_module'/3]).
|
||||||
|
@ -232,9 +232,9 @@ beautify_hidden_goal('$process_directive'(Gs,_Mode,_VL),prolog) -->
|
|||||||
[(:- Gs)].
|
[(:- Gs)].
|
||||||
beautify_hidden_goal('$loop'(Stream,Option),prolog) -->
|
beautify_hidden_goal('$loop'(Stream,Option),prolog) -->
|
||||||
[execute_load_file(Stream, consult=Option)].
|
[execute_load_file(Stream, consult=Option)].
|
||||||
beautify_hidden_goal('$load_files'(Files,Opts,?),prolog) -->
|
beautify_hidden_goal('$load_files'(Files,M,Opts,?),prolog) -->
|
||||||
[load_files(Files,Opts)].
|
[load_files(M:Files,Opts)].
|
||||||
beautify_hidden_goal('$load_files'(_,_,Name),prolog) -->
|
beautify_hidden_goal('$load_files'(_,_,_,Name),prolog) -->
|
||||||
[Name].
|
[Name].
|
||||||
beautify_hidden_goal('$reconsult'(Files,Mod),prolog) -->
|
beautify_hidden_goal('$reconsult'(Files,Mod),prolog) -->
|
||||||
[reconsult(Mod:Files)].
|
[reconsult(Mod:Files)].
|
||||||
|
@ -40,8 +40,13 @@
|
|||||||
nb_setval('$initialization_goals',off),
|
nb_setval('$initialization_goals',off),
|
||||||
nb_setval('$included_file',[]),
|
nb_setval('$included_file',[]),
|
||||||
nb_setval('$loop_streams',[]),
|
nb_setval('$loop_streams',[]),
|
||||||
\+ '$undefined'('$init_preds',prolog),
|
(
|
||||||
'$init_preds'.
|
'$undefined'('$init_preds',prolog)
|
||||||
|
->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
'$init_preds'
|
||||||
|
).
|
||||||
|
|
||||||
'$init_win_graphics' :-
|
'$init_win_graphics' :-
|
||||||
'$undefined'(window_title(_,_), system), !.
|
'$undefined'(window_title(_,_), system), !.
|
||||||
|
@ -201,8 +201,8 @@ The state of the module system after this error is undefined.
|
|||||||
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
use_module(F) :- '$load_files'(F,
|
use_module(F) :- load_files(F,
|
||||||
[if(not_loaded),must_be_module(true)], use_module(F)).
|
[if(not_loaded),must_be_module(true)]).
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,7 +235,7 @@ Unfortunately it is still not possible to change argument order.
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
use_module(F,Is) :-
|
use_module(F,Is) :-
|
||||||
'$load_files'(F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(F,Is)).
|
load_files(F, [if(not_loaded),must_be_module(true),imports(Is)]).
|
||||||
|
|
||||||
'$module'(O,N,P,Opts) :- !,
|
'$module'(O,N,P,Opts) :- !,
|
||||||
'$module'(O,N,P),
|
'$module'(O,N,P),
|
||||||
|
Reference in New Issue
Block a user