use setup_cal_n_init_goal_info in dynamic_module_resolution
This commit is contained in:
@@ -690,6 +690,26 @@ expand_goal(UnexpandedGoals, Module, ExpandedGoals) :-
|
|||||||
'$call'(UnexpandedGoals = 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.
|
:- non_counted_backtracking expand_goal_cases/4.
|
||||||
|
|
||||||
expand_goal_cases((Goal0, Goals0), Module, ExpandedGoals, HeadVars) :-
|
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),
|
expand_goal(Goals0, Module, Goals1, HeadVars),
|
||||||
ExpandedGoals = (Module:Goals1).
|
ExpandedGoals = (Module:Goals1).
|
||||||
|
|
||||||
:- non_counted_backtracking expand_goal/4.
|
|
||||||
|
|
||||||
expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars) :-
|
:- non_counted_backtracking thread_goals/3.
|
||||||
( var(UnexpandedGoals) ->
|
|
||||||
expand_module_names(call(UnexpandedGoals), [0], Module, ExpandedGoals, HeadVars)
|
thread_goals(Goals0, Goals1, Functor) :-
|
||||||
; goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1),
|
( var(Goals0) ->
|
||||||
( Module \== user ->
|
Goals0 = Goals1
|
||||||
goal_expansion(UnexpandedGoals1, user, Goals)
|
; Goals0 = [G | Gs] ->
|
||||||
; Goals = UnexpandedGoals1
|
( Gs = [] ->
|
||||||
),
|
Goals1 = G
|
||||||
( expand_goal_cases(Goals, Module, ExpandedGoals, HeadVars) ->
|
; Goals1 =.. [Functor, G, Goals2],
|
||||||
true
|
thread_goals(Gs, Goals2, Functor)
|
||||||
; predicate_property(Module:Goals, meta_predicate(MetaSpecs0)),
|
|
||||||
MetaSpecs0 =.. [_ | MetaSpecs] ->
|
|
||||||
expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars)
|
|
||||||
; thread_goals(Goals, ExpandedGoals, (','))
|
|
||||||
; Goals = ExpandedGoals
|
|
||||||
)
|
)
|
||||||
|
; Goals1 = Goals0
|
||||||
).
|
).
|
||||||
|
|
||||||
:- non_counted_backtracking thread_goals/4.
|
:- non_counted_backtracking thread_goals/4.
|
||||||
@@ -748,20 +763,6 @@ thread_goals(Goals0, Goals1, Hole, Functor) :-
|
|||||||
; Goals1 =.. [Functor, Goals0, Hole]
|
; 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.
|
% call/{1-64} with dynamic goal expansion.
|
||||||
|
|||||||
@@ -3014,47 +3014,22 @@ impl Machine {
|
|||||||
self.machine_st.registers[1 + narity]
|
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]
|
self.machine_st.registers[2 + narity]
|
||||||
));
|
));
|
||||||
|
|
||||||
read_heap_cell!(addr,
|
let (name, arity, s) = self.machine_st.setup_call_n_init_goal_info(goal, narity)?;
|
||||||
(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() {
|
for i in (arity + 1..arity + narity + 1).rev() {
|
||||||
self.machine_st.registers[i] = self.machine_st.registers[i - arity];
|
self.machine_st.registers[i] = self.machine_st.registers[i - arity];
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 1..arity + 1 {
|
for i in 1..arity + 1 {
|
||||||
self.machine_st.registers[i] = self.machine_st.heap[a + i];
|
self.machine_st.registers[i] = self.machine_st.heap[s + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((module_name, (name, arity + narity)))
|
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();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
Err(self.machine_st.error_form(err, stub))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn enqueue_attributed_var(&mut self) {
|
pub(crate) fn enqueue_attributed_var(&mut self) {
|
||||||
|
|||||||
Reference in New Issue
Block a user