gather initialization goals and call them once load succeeds (#792)
This commit is contained in:
@@ -387,8 +387,6 @@ impl SystemClauseType {
|
|||||||
clause_name!("$cpp_multifile_property"),
|
clause_name!("$cpp_multifile_property"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty) =>
|
&SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty) =>
|
||||||
clause_name!("$cpp_discontiguous_property"),
|
clause_name!("$cpp_discontiguous_property"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates) =>
|
|
||||||
clause_name!("$compile_pending_predicates"),
|
|
||||||
&SystemClauseType::REPL(REPLCodePtr::AbolishClause) =>
|
&SystemClauseType::REPL(REPLCodePtr::AbolishClause) =>
|
||||||
clause_name!("$abolish_clause"),
|
clause_name!("$abolish_clause"),
|
||||||
&SystemClauseType::Close => clause_name!("$close"),
|
&SystemClauseType::Close => clause_name!("$close"),
|
||||||
@@ -756,7 +754,6 @@ impl SystemClauseType {
|
|||||||
("$cpp_dynamic_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DynamicProperty)),
|
("$cpp_dynamic_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DynamicProperty)),
|
||||||
("$cpp_multifile_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::MultifileProperty)),
|
("$cpp_multifile_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::MultifileProperty)),
|
||||||
("$cpp_discontiguous_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty)),
|
("$cpp_discontiguous_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty)),
|
||||||
("$compile_pending_predicates", 1) => Some(SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates)),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ unload_evacuable(Evacuable) :-
|
|||||||
'$pop_load_state_payload'(Evacuable),
|
'$pop_load_state_payload'(Evacuable),
|
||||||
'$pop_load_context'.
|
'$pop_load_context'.
|
||||||
|
|
||||||
|
run_initialization_goals :-
|
||||||
|
prolog_load_context(module, Module),
|
||||||
|
( predicate_property(Module:'$initialization_goals'(_), dynamic) ->
|
||||||
|
findall(Goal, '$call'(builtins:retract(Module:'$initialization_goals'(Goal))), Goals),
|
||||||
|
( maplist(Module:call, Goals) ->
|
||||||
|
true
|
||||||
|
; true %% initialization goals can fail without thwarting the load.
|
||||||
|
)
|
||||||
|
; true
|
||||||
|
).
|
||||||
|
|
||||||
file_load(Stream, Path) :-
|
file_load(Stream, Path) :-
|
||||||
file_load(Stream, Path, _).
|
file_load(Stream, Path, _).
|
||||||
@@ -83,6 +93,7 @@ file_load(Stream, Path, Evacuable) :-
|
|||||||
catch(loader:load_loop(Stream, Evacuable),
|
catch(loader:load_loop(Stream, Evacuable),
|
||||||
E,
|
E,
|
||||||
(loader:unload_evacuable(Evacuable), throw(E))),
|
(loader:unload_evacuable(Evacuable), throw(E))),
|
||||||
|
run_initialization_goals,
|
||||||
'$pop_load_context'.
|
'$pop_load_context'.
|
||||||
|
|
||||||
|
|
||||||
@@ -91,6 +102,7 @@ load(Stream) :-
|
|||||||
catch(loader:load_loop(Stream, Evacuable),
|
catch(loader:load_loop(Stream, Evacuable),
|
||||||
E,
|
E,
|
||||||
(loader:unload_evacuable(Evacuable), throw(E))),
|
(loader:unload_evacuable(Evacuable), throw(E))),
|
||||||
|
run_initialization_goals,
|
||||||
'$pop_load_context'.
|
'$pop_load_context'.
|
||||||
|
|
||||||
load_loop(Stream, Evacuable) :-
|
load_loop(Stream, Evacuable) :-
|
||||||
@@ -237,9 +249,8 @@ compile_declaration(dynamic(Name/Arity), Evacuable) :-
|
|||||||
'$add_dynamic_predicate'(Name, Arity, Evacuable).
|
'$add_dynamic_predicate'(Name, Arity, Evacuable).
|
||||||
compile_declaration(initialization(Goal), Evacuable) :-
|
compile_declaration(initialization(Goal), Evacuable) :-
|
||||||
prolog_load_context(module, Module),
|
prolog_load_context(module, Module),
|
||||||
'$compile_pending_predicates'(Evacuable),
|
assertz(Module:'$initialization_goals'(Goal)).
|
||||||
expand_goal(call(Goal), Module, call(ExpandedGoal)),
|
|
||||||
call(ExpandedGoal).
|
|
||||||
|
|
||||||
|
|
||||||
compile_clause(Clause, Evacuable, VNs) :-
|
compile_clause(Clause, Evacuable, VNs) :-
|
||||||
|
|||||||
@@ -1789,22 +1789,6 @@ impl Machine {
|
|||||||
|
|
||||||
self.machine_st.fail = true;
|
self.machine_st.fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate)
|
|
||||||
fn compile_pending_predicates(&mut self) {
|
|
||||||
let (mut loader, evacuable_h) = self.loader_from_heap_evacuable(temp_v!(1));
|
|
||||||
|
|
||||||
let compile_pending_predicates = || {
|
|
||||||
if !loader.predicates.is_empty() {
|
|
||||||
loader.compile_and_submit()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveTermStream::evacuate(loader)
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = compile_pending_predicates();
|
|
||||||
self.restore_load_state_payload(result, evacuable_h);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Loader<'a, LiveTermStream> {
|
impl<'a> Loader<'a, LiveTermStream> {
|
||||||
|
|||||||
@@ -524,7 +524,6 @@ pub enum REPLCodePtr {
|
|||||||
MultifileProperty,
|
MultifileProperty,
|
||||||
DiscontiguousProperty,
|
DiscontiguousProperty,
|
||||||
DynamicProperty,
|
DynamicProperty,
|
||||||
CompilePendingPredicates,
|
|
||||||
AbolishClause,
|
AbolishClause,
|
||||||
Asserta,
|
Asserta,
|
||||||
Assertz,
|
Assertz,
|
||||||
|
|||||||
@@ -491,9 +491,6 @@ impl Machine {
|
|||||||
REPLCodePtr::DynamicProperty => {
|
REPLCodePtr::DynamicProperty => {
|
||||||
self.dynamic_property();
|
self.dynamic_property();
|
||||||
}
|
}
|
||||||
REPLCodePtr::CompilePendingPredicates => {
|
|
||||||
self.compile_pending_predicates();
|
|
||||||
}
|
|
||||||
REPLCodePtr::Assertz => {
|
REPLCodePtr::Assertz => {
|
||||||
self.compile_assert(AppendOrPrepend::Append);
|
self.compile_assert(AppendOrPrepend::Append);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,6 @@ impl fmt::Display for REPLCodePtr {
|
|||||||
write!(f, "REPLCodePtr::MultifileProperty"),
|
write!(f, "REPLCodePtr::MultifileProperty"),
|
||||||
REPLCodePtr::DiscontiguousProperty =>
|
REPLCodePtr::DiscontiguousProperty =>
|
||||||
write!(f, "REPLCodePtr::DiscontiguousProperty"),
|
write!(f, "REPLCodePtr::DiscontiguousProperty"),
|
||||||
REPLCodePtr::CompilePendingPredicates =>
|
|
||||||
write!(f, "REPLCodePtr::CompilePendingPredicates"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user