]> Repositorios git - scryer-prolog.git/commitdiff
flush loader term queue before compiling declarations, declare '/1' as dynamic before...
authorMark Thom <[email protected]>
Mon, 22 Mar 2021 22:53:23 +0000 (16:53 -0600)
committerMark Thom <[email protected]>
Mon, 22 Mar 2021 22:53:23 +0000 (16:53 -0600)
src/lib/builtins.pl
src/loader.pl
src/machine/system_calls.rs

index 4be599797354e51e27c3fd7bb7b534bc2303d4a9..16d842bbbfa567c3825cad8edd3ebe94445d85b8 100644 (file)
@@ -839,9 +839,9 @@ asserta_clause(Head, Body) :-
             arg(2, Head, F),
             module_asserta_clause(F, Body, Module)
        ; '$head_is_dynamic'(user, Head) ->
-         call_asserta(Head, Body, Name, Arity, user)
+          call_asserta(Head, Body, Name, Arity, user)
        ; '$no_such_predicate'(user, Head) ->
-         call_asserta(Head, Body, Name, Arity, user)
+          call_asserta(Head, Body, Name, Arity, user)
        ;  throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
        )
     ;  throw(error(type_error(callable, Head), asserta/1))
index a748f9810f46894d178c88c327cf537cc4fa43a8..3e2a7b9bbad1ab86cb4c911e2e46490eb9708f9a 100644 (file)
@@ -91,6 +91,7 @@ run_initialization_goals :-
     prolog_load_context(module, Module),
     (  predicate_property(Module:'$initialization_goals'(_), dynamic) ->
        findall(Goal, '$call'(builtins:retract(Module:'$initialization_goals'(Goal))), Goals),
+       abolish(Module:'$initialization_goals'/1),
        (  maplist(Module:call, Goals) ->
           true
        ;  true %% initialization goals can fail without thwarting the load.
@@ -275,7 +276,7 @@ compile_dispatch_or_clause(Term, Evacuable) :-
     (  var(Term) ->
        instantiation_error(load/1)
     ;  compile_dispatch(Term, Evacuable) ->
-       true
+       '$flush_term_queue'(Evacuable)
     ;  compile_clause(Term, Evacuable)
     ).
 
@@ -364,6 +365,7 @@ compile_declaration(discontiguous(Module:Name/Arity), Evacuable) :-
     '$add_discontiguous_predicate'(Module, Name, Arity, Evacuable).
 compile_declaration(initialization(Goal), Evacuable) :-
     prolog_load_context(module, Module),
+    '$add_dynamic_predicate'(Module, '$initialization_goals', 1, Evacuable),
     assertz(Module:'$initialization_goals'(Goal)).
 compile_declaration(set_prolog_flag(Flag, Value), _) :-
     set_prolog_flag(Flag, Value).
index a956577eabf4d406954a44f0d5de48c16a322927..33cff953211854987bfbdd6f43ea9daa39281ccb 100644 (file)
@@ -3471,14 +3471,23 @@ impl MachineState {
                 self.fail = match self.store(self.deref(self[temp_v!(2)])) {
                     Addr::Str(s) => match &self.heap[s] {
                         &HeapCellValue::NamedStr(arity, ref name, ref spec) => {
-                            CLAUSE_TYPE_FORMS.borrow().get(&(name.as_str(), arity)).is_some() ||
-                                indices.get_predicate_code_index(
-                                name.clone(),
-                                arity,
-                                module_name,
-                                spec.clone(),
-                            )
-                            .is_some()
+                            if CLAUSE_TYPE_FORMS.borrow().get(&(name.as_str(), arity)).is_some() {
+                                true
+                            } else {
+                                let index = indices.get_predicate_code_index(
+                                    name.clone(),
+                                    arity,
+                                    module_name,
+                                    spec.clone(),
+                                )
+                                .map(|index| index.get())
+                                .unwrap_or(IndexPtr::DynamicUndefined);
+
+                                match index {
+                                    IndexPtr::DynamicUndefined => false,
+                                    _ => true,
+                                }
+                            }
                         }
                         _ => {
                             unreachable!()
@@ -3489,9 +3498,23 @@ impl MachineState {
                             let spec =
                                 fetch_atom_op_spec(name.clone(), spec.clone(), &indices.op_dir);
 
-                            CLAUSE_TYPE_FORMS.borrow().get(&(name.as_str(), 0)).is_some() ||
-                            indices.get_predicate_code_index(name.clone(), 0, module_name, spec)
-                                .is_some()
+                            if CLAUSE_TYPE_FORMS.borrow().get(&(name.as_str(), 0)).is_some() {
+                                true
+                            } else {
+                                let index = indices.get_predicate_code_index(
+                                    name.clone(),
+                                    0,
+                                    module_name,
+                                    spec.clone(),
+                                )
+                                .map(|index| index.get())
+                                .unwrap_or(IndexPtr::DynamicUndefined);
+
+                                match index {
+                                    IndexPtr::DynamicUndefined => false,
+                                    _ => true,
+                                }
+                            }
                         } else {
                             unreachable!()
                         }