Merge /home/vsc/yap

This commit is contained in:
Vítor Santos Costa 2018-07-13 12:30:26 +01:00
commit 3efb73f35d
12 changed files with 120 additions and 109 deletions

View File

@ -203,13 +203,13 @@ static bool consult(const char *b_file USES_REGS) {
} else { } else {
YAP_CompileClause(t); YAP_CompileClause(t);
} }
} while (true);
yap_error_descriptor_t *errd; yap_error_descriptor_t *errd;
if ((errd = if ((errd =
Yap_GetException(LOCAL_ActiveError))) { Yap_GetException(LOCAL_ActiveError))) {
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText, fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText,
errd->errorAsText); errd->errorAsText);
} }
} while (true);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
YAP_EndConsult(c_stream, &osno, full); YAP_EndConsult(c_stream, &osno, full);
if (!Yap_AddAlias(AtomLoopStream, osno)) { if (!Yap_AddAlias(AtomLoopStream, osno)) {

View File

@ -519,7 +519,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
#if YAP_PYTHON #if YAP_PYTHON
// PyThreadState *_save; // PyThreadState *_save;
std::cerr << "mgoal " << YAPTerm(t).text() << "\n"; //std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
// _save = PyEval_SaveThread(); // _save = PyEval_SaveThread();
#endif #endif
CACHE_REGS CACHE_REGS
@ -553,7 +553,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); //__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q); result = (bool)YAP_EnterGoal(ap, nullptr, &q);
std::cerr << "mgoal " << YAPTerm(t).text() << "\n"; //std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
YAP_LeaveGoal(result && !release, &q); YAP_LeaveGoal(result && !release, &q);
// PyEval_RestoreThread(_save); // PyEval_RestoreThread(_save);

View File

@ -70,13 +70,12 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
#endif #endif
YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**< YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**<
read-only atom, it describes the ISA used in this version of YAP. read-only atom, it describes the ISA used in this version of YAP.
Available from YAP_AEH. Available from YAP_ARCH.
*/ */
YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL), YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL),
YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true, YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true,
booleanFlag, "true", NULL), booleanFlag, "true", NULL),
/**< `arithmetic_exceptions` /**<
Read-write flag telling whether arithmetic exceptions generate Read-write flag telling whether arithmetic exceptions generate
Prolog exceptions. If enabled: Prolog exceptions. If enabled:
@ -97,7 +96,7 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
ProbLog. ProbLog.
*/ */
YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", bqs), YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", bqs),
/**> /**<
If _Value_ is unbound, tell whether a back quoted list of characters If _Value_ is unbound, tell whether a back quoted list of characters
token is converted to a list of atoms, `chars`, to a list of integers, token is converted to a list of atoms, `chars`, to a list of integers,
`codes`, or to a single atom, `atom`. If _Value_ is bound, set to `codes`, or to a single atom, `atom`. If _Value_ is bound, set to

View File

@ -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);

View File

@ -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) {

View File

@ -41,7 +41,6 @@ jupyter_cell( Caller, _, Line ) :-
E=error(A,B), E=error(A,B),
system_error(A,B) system_error(A,B)
). ).
jupyter_cell(_,_,_).
restreams(call) :- restreams(call) :-
streams(true). streams(true).
@ -207,4 +206,4 @@ plot_inline :-
:- endif. :- endif.
:- ( start_low_level_trace ). %:- ( start_low_level_trace ).

View File

@ -121,9 +121,11 @@ print_message(L,E) :-
). ).
'$undefp0'([M|G], _Action) :- '$undefp0'([M|G], _Action) :-
stream_property( loop_stream, file_name(F)), stream_property( loop_stream, [file_name(F), line_number(L)]),
stream_property( loop_stream, line_number(L)), format(user_error,'~a:~d error undefined:',[F,L]),
format(user_error,'~a:~d error undefined: call to ~w~n',[F,L,M:G]), fail
;
format(user_error,' call to ~w~n',[M:G]),
fail. fail.
:- '$undefp_handler'('$undefp0'(_,_),prolog). :- '$undefp_handler'('$undefp0'(_,_),prolog).

View File

@ -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,44 +280,70 @@ 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),
'__NB_getval__'('$lf_status', OldTOpts, fail) '$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),
( '__NB_getval__'('$lf_status', OldTOpts, fail),
nonvar(OldTOpts)
-> ->
'$lf_opt'('$context_module', OldTOpts, Context), '$lf_opt'(autoload, OldTOpts, OldAutoload),
'$lf_opt'(autoload, OldTOpts, OldAutoload) '$lf_opt'('$context_module', OldTOpts, OldContextModule)
; ;
'$lf_option'(last_opt, LastOpt), current_prolog_flag(autoload, OldAutoload),
functor( OldTOpts, opt, LastOpt ) functor( OldTOpts, opt, LastOpt ),
), '$lf_opt'(autoload, OldTOpts, OldAutoload),
'$lf_option'(last_opt, LastOpt), '$lf_opt'('$context_module', OldTOpts, OldContextModule)
functor( TOpts, opt, LastOpt ), ),
( source_location(ParentF, Line) -> true ; ParentF = user_input, Line = -1 ), functor( TOpts, opt, LastOpt ),
'$lf_opt'('$location', TOpts, ParentF:Line), ( source_location(ParentF, Line) -> true ; ParentF = user_input, Line = -1 ),
'$lf_opt'('$files', TOpts, Files), '$lf_opt'('$location', TOpts, ParentF:Line),
'$lf_opt'('$call', TOpts, Call), '$lf_opt'('$files', TOpts, Files),
'$lf_opt'('$options', TOpts, Opts), '$lf_opt'('$call', TOpts, Call),
'$lf_opt'('$parent_topts', TOpts, OldTOpts), '$lf_opt'('$options', TOpts, Opts),
'$process_lf_opts'(Opts,TOpts,Files,Call), '$lf_opt'('$parent_topts', TOpts, OldTOpts),
'$lf_default_opts'(1, LastOpt, TOpts), '$process_lf_opts'(Opts,TOpts,Files,Call),
'$lf_opt'(stream, TOpts, Stream), '$lf_default_opts'(1, LastOpt, TOpts),
( nonvar(Stream) -> '$lf_opt'(stream, TOpts, Stream),
'$set_lf_opt'('$from_stream', TOpts, true ) ( nonvar(Stream) ->
; '$set_lf_opt'('$from_stream', TOpts, true )
'$check_files'(Files,load_files(Files,Opts)) ;
), '$check_files'(Files,load_files(Files,Opts))
'$check_use_module'(Call,UseModule), ),
'$lf_opt'('$use_module', TOpts, UseModule), '$check_use_module'(Call,UseModule),
'$current_module'(M0), '$lf_opt'('$use_module', TOpts, UseModule),
( '$lf_opt'(autoload, TOpts, Autoload), ( '$lf_opt'(autoload, TOpts, Autoload),
var(Autoload) -> var(Autoload) ->
Autoload = OldAutoload Autoload = OldAutoload
; ;
true true
), ),
% 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), !,
@ -432,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),
@ -1103,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.
@ -1264,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), !,
@ -1276,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))
). ).

View File

@ -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]).

View File

@ -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)].

View File

@ -33,17 +33,20 @@
nb_setval('$chr_toplevel_show_store',false). nb_setval('$chr_toplevel_show_store',false).
'$init_consult' :- '$init_consult' :-
set_value('$open_expands_filename',true), set_value('$open_expands_filename',true),
nb_setval('$assert_all',off), nb_setval('$assert_all',off),
nb_setval('$if_level',0), nb_setval('$if_level',0),
nb_setval('$endif',off), nb_setval('$endif',off),
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)
fail. ->
'$init_consult'. true
;
'$init_preds'
).
'$init_win_graphics' :- '$init_win_graphics' :-
'$undefined'(window_title(_,_), system), !. '$undefined'(window_title(_,_), system), !.

View File

@ -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),