]> Repositorios git - scryer-prolog.git/commitdiff
use setup_cal_n_init_goal_info in dynamic_module_resolution
authorMark Thom <[email protected]>
Thu, 16 Jun 2022 04:32:05 +0000 (22:32 -0600)
committerMark Thom <[email protected]>
Thu, 16 Jun 2022 04:33:13 +0000 (22:33 -0600)
src/loader.pl
src/machine/system_calls.rs

index acdd4885d90b2fb9be88e9fa858e50a9eb7cc517..44e05d839d4361d9ea01432b294cf00122eb485c 100644 (file)
@@ -690,6 +690,26 @@ expand_goal(UnexpandedGoals, Module, ExpandedGoals) :-
           '$call'(UnexpandedGoals = ExpandedGoals)),
     !.
 
+:- non_counted_backtracking expand_goal/4.
+
+expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars) :-
+    (  var(UnexpandedGoals) ->
+       expand_module_names(call(UnexpandedGoals), [0], Module, ExpandedGoals, HeadVars)
+    ;  goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1),
+       (  Module \== user ->
+          goal_expansion(UnexpandedGoals1, user, Goals)
+       ;  Goals = UnexpandedGoals1
+       ),
+       (  expand_goal_cases(Goals, Module, ExpandedGoals, HeadVars) ->
+          true
+       ;  predicate_property(Module:Goals, meta_predicate(MetaSpecs0)),
+          MetaSpecs0 =.. [_ | MetaSpecs] ->
+          expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars)
+       ;  thread_goals(Goals, ExpandedGoals, (','))
+       ;  Goals = ExpandedGoals
+       )
+    ).
+
 :- non_counted_backtracking expand_goal_cases/4.
 
 expand_goal_cases((Goal0, Goals0), Module, ExpandedGoals, HeadVars) :-
@@ -714,24 +734,19 @@ expand_goal_cases((Module:Goals0), _, ExpandedGoals, HeadVars) :-
     expand_goal(Goals0, Module, Goals1, HeadVars),
     ExpandedGoals = (Module:Goals1).
 
-:- non_counted_backtracking expand_goal/4.
 
-expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars) :-
-    (  var(UnexpandedGoals) ->
-       expand_module_names(call(UnexpandedGoals), [0], Module, ExpandedGoals, HeadVars)
-    ;  goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1),
-       (  Module \== user ->
-          goal_expansion(UnexpandedGoals1, user, Goals)
-       ;  Goals = UnexpandedGoals1
-       ),
-       (  expand_goal_cases(Goals, Module, ExpandedGoals, HeadVars) ->
-          true
-       ;  predicate_property(Module:Goals, meta_predicate(MetaSpecs0)),
-          MetaSpecs0 =.. [_ | MetaSpecs] ->
-          expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars)
-       ;  thread_goals(Goals, ExpandedGoals, (','))
-       ;  Goals = ExpandedGoals
+:- non_counted_backtracking thread_goals/3.
+
+thread_goals(Goals0, Goals1, Functor) :-
+    (  var(Goals0) ->
+       Goals0 = Goals1
+    ;  Goals0 = [G | Gs] ->
+       (  Gs = [] ->
+          Goals1 = G
+       ;  Goals1 =.. [Functor, G, Goals2],
+          thread_goals(Gs, Goals2, Functor)
        )
+    ;  Goals1 = Goals0
     ).
 
 :- non_counted_backtracking thread_goals/4.
@@ -748,20 +763,6 @@ thread_goals(Goals0, Goals1, Hole, Functor) :-
     ;  Goals1 =.. [Functor, Goals0, Hole]
     ).
 
-:- non_counted_backtracking thread_goals/3.
-
-thread_goals(Goals0, Goals1, Functor) :-
-    (  var(Goals0) ->
-       Goals0 = Goals1
-    ;  Goals0 = [G | Gs] ->
-       (  Gs = [] ->
-          Goals1 = G
-       ;  Goals1 =.. [Functor, G, Goals2],
-          thread_goals(Gs, Goals2, Functor)
-       )
-    ;  Goals1 = Goals0
-    ).
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % call/{1-64} with dynamic goal expansion.
index c39000102528abfdc37192e44a08c57d3386ee6a..46d4801182ec4a6f297794e97cde3523575b32aa 100644 (file)
@@ -3014,46 +3014,21 @@ impl Machine {
             self.machine_st.registers[1 + narity]
         )));
 
-        let addr = self.machine_st.store(self.machine_st.deref(
+        let goal = self.machine_st.store(self.machine_st.deref(
             self.machine_st.registers[2 + narity]
         ));
 
-        read_heap_cell!(addr,
-            (HeapCellValueTag::Str, a) => {
-                let (name, arity) = cell_as_atom_cell!(self.machine_st.heap[a])
-                    .get_name_and_arity();
-
-
-                for i in (arity + 1..arity + narity + 1).rev() {
-                    self.machine_st.registers[i] = self.machine_st.registers[i - arity];
-                }
+        let (name, arity, s) = self.machine_st.setup_call_n_init_goal_info(goal, narity)?;
 
-                for i in 1..arity + 1 {
-                    self.machine_st.registers[i] = self.machine_st.heap[a + i];
-                }
-
-                Ok((module_name, (name, arity + narity)))
-            }
-            (HeapCellValueTag::Atom, (name, _arity)) => {
-                Ok((module_name, (name, narity)))
-            }
-            (HeapCellValueTag::Char, c) => {
-                let key = (self.machine_st.atom_tbl.build_with(&c.to_string()), narity);
-                Ok((module_name, key))
-            }
-            (HeapCellValueTag::AttrVar | HeapCellValueTag::StackVar | HeapCellValueTag::Var) => {
-                let stub = functor_stub(atom!("call"), 1);
-                let err = self.machine_st.instantiation_error();
+        for i in (arity + 1..arity + narity + 1).rev() {
+            self.machine_st.registers[i] = self.machine_st.registers[i - arity];
+        }
 
-                Err(self.machine_st.error_form(err, stub))
-            }
-            _ => {
-                let stub = functor_stub(atom!("call"), narity);
-                let err = self.machine_st.type_error(ValidType::Callable, addr);
+        for i in 1..arity + 1 {
+            self.machine_st.registers[i] = self.machine_st.heap[s + i];
+        }
 
-                Err(self.machine_st.error_form(err, stub))
-            }
-        )
+        Ok((module_name, (name, arity + narity)))
     }
 
     #[inline(always)]