]> Repositorios git - scryer-prolog.git/commitdiff
gather initialization goals and call them once load succeeds (#792)
authorMark Thom <[email protected]>
Sat, 6 Feb 2021 01:40:13 +0000 (18:40 -0700)
committerMark Thom <[email protected]>
Sat, 6 Feb 2021 01:42:30 +0000 (18:42 -0700)
src/clause_types.rs
src/loader.pl
src/machine/loader.rs
src/machine/machine_indices.rs
src/machine/mod.rs
src/write.rs

index 76c70e7449dcadbacd10fa3a7e73beb02258cbc8..6f412b78ec6a55c4a197752d348dca6b9102db8a 100644 (file)
@@ -387,8 +387,6 @@ impl SystemClauseType {
                 clause_name!("$cpp_multifile_property"),
             &SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty) =>
                 clause_name!("$cpp_discontiguous_property"),
-            &SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates) =>
-                clause_name!("$compile_pending_predicates"),
             &SystemClauseType::REPL(REPLCodePtr::AbolishClause) =>
                 clause_name!("$abolish_clause"),
             &SystemClauseType::Close => clause_name!("$close"),
@@ -756,7 +754,6 @@ impl SystemClauseType {
             ("$cpp_dynamic_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DynamicProperty)),
             ("$cpp_multifile_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::MultifileProperty)),
             ("$cpp_discontiguous_property", 3) => Some(SystemClauseType::REPL(REPLCodePtr::DiscontiguousProperty)),
-            ("$compile_pending_predicates", 1) => Some(SystemClauseType::REPL(REPLCodePtr::CompilePendingPredicates)),
             _ => None,
         }
     }
index 5f499c7d8ce36ce87767704d19000c1c6a18b430..fb9d68403e3e015b8e2a74995b9abef4ccf98882 100644 (file)
@@ -74,6 +74,16 @@ unload_evacuable(Evacuable) :-
     '$pop_load_state_payload'(Evacuable),
     '$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, _).
@@ -83,6 +93,7 @@ file_load(Stream, Path, Evacuable) :-
     catch(loader:load_loop(Stream, Evacuable),
           E,
           (loader:unload_evacuable(Evacuable), throw(E))),
+    run_initialization_goals,
     '$pop_load_context'.
 
 
@@ -91,6 +102,7 @@ load(Stream) :-
     catch(loader:load_loop(Stream, Evacuable),
           E,
           (loader:unload_evacuable(Evacuable), throw(E))),
+    run_initialization_goals,
     '$pop_load_context'.
 
 load_loop(Stream, Evacuable) :-
@@ -237,9 +249,8 @@ compile_declaration(dynamic(Name/Arity), Evacuable) :-
     '$add_dynamic_predicate'(Name, Arity, Evacuable).
 compile_declaration(initialization(Goal), Evacuable) :-
     prolog_load_context(module, Module),
-    '$compile_pending_predicates'(Evacuable),
-    expand_goal(call(Goal), Module, call(ExpandedGoal)),
-    call(ExpandedGoal).
+    assertz(Module:'$initialization_goals'(Goal)).
+
 
 
 compile_clause(Clause, Evacuable, VNs) :-
index eae4ab5764d4f2a70c25ef4eb5951836b0c6b33b..e7eb1165e940db7ac8595670b26b18f759fbd2e7 100644 (file)
@@ -1789,22 +1789,6 @@ impl Machine {
 
         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> {
index 7a183ecd825becf10238dd9e78bd38d08307a03e..b6883e7798d4ec80f7958b7ae946b3f8e410752c 100644 (file)
@@ -524,7 +524,6 @@ pub enum REPLCodePtr {
     MultifileProperty,
     DiscontiguousProperty,
     DynamicProperty,
-    CompilePendingPredicates,
     AbolishClause,
     Asserta,
     Assertz,
index 0b0439cd69663a078eca330f51d91475441853d9..6a73369eb25299cd9389c30f5f510dce93a7a47b 100644 (file)
@@ -491,9 +491,6 @@ impl Machine {
             REPLCodePtr::DynamicProperty => {
                 self.dynamic_property();
             }
-            REPLCodePtr::CompilePendingPredicates => {
-                self.compile_pending_predicates();
-            }
             REPLCodePtr::Assertz => {
                 self.compile_assert(AppendOrPrepend::Append);
             }
index 17944e9d1db260c5edf935686d3be8a01329c62b..00538abb9fca80f155db7b4f19837c14204acfa0 100644 (file)
@@ -72,8 +72,6 @@ impl fmt::Display for REPLCodePtr {
                 write!(f, "REPLCodePtr::MultifileProperty"),
             REPLCodePtr::DiscontiguousProperty =>
                 write!(f, "REPLCodePtr::DiscontiguousProperty"),
-            REPLCodePtr::CompilePendingPredicates =>
-                write!(f, "REPLCodePtr::CompilePendingPredicates"),
         }
     }
 }