use occurs check when enabled in UnifyValue (#885)
This commit is contained in:
@@ -306,6 +306,7 @@ pub(crate) enum SystemClauseType {
|
|||||||
SetNSTOAsUnify,
|
SetNSTOAsUnify,
|
||||||
SetSTOWithErrorAsUnify,
|
SetSTOWithErrorAsUnify,
|
||||||
HomeDirectory,
|
HomeDirectory,
|
||||||
|
DebugHook,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemClauseType {
|
impl SystemClauseType {
|
||||||
@@ -592,6 +593,7 @@ impl SystemClauseType {
|
|||||||
&SystemClauseType::SetNSTOAsUnify => clause_name!("$set_nsto_as_unify"),
|
&SystemClauseType::SetNSTOAsUnify => clause_name!("$set_nsto_as_unify"),
|
||||||
&SystemClauseType::HomeDirectory => clause_name!("$home_directory"),
|
&SystemClauseType::HomeDirectory => clause_name!("$home_directory"),
|
||||||
&SystemClauseType::SetSTOWithErrorAsUnify => clause_name!("$set_sto_with_error_as_unify"),
|
&SystemClauseType::SetSTOWithErrorAsUnify => clause_name!("$set_sto_with_error_as_unify"),
|
||||||
|
&SystemClauseType::DebugHook => clause_name!("$debug_hook"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,6 +842,7 @@ impl SystemClauseType {
|
|||||||
("$set_nsto_as_unify", 0) => Some(SystemClauseType::SetNSTOAsUnify),
|
("$set_nsto_as_unify", 0) => Some(SystemClauseType::SetNSTOAsUnify),
|
||||||
("$set_sto_with_error_as_unify", 0) => Some(SystemClauseType::SetSTOWithErrorAsUnify),
|
("$set_sto_with_error_as_unify", 0) => Some(SystemClauseType::SetSTOWithErrorAsUnify),
|
||||||
("$home_directory", 1) => Some(SystemClauseType::HomeDirectory),
|
("$home_directory", 1) => Some(SystemClauseType::HomeDirectory),
|
||||||
|
("$debug_hook", 0) => Some(SystemClauseType::DebugHook),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1327,8 +1327,21 @@ impl MachineState {
|
|||||||
self.increment_s_ptr(1);
|
self.increment_s_ptr(1);
|
||||||
}
|
}
|
||||||
MachineMode::Write => {
|
MachineMode::Write => {
|
||||||
let heap_val = self.store(self[reg]);
|
let h = self.heap.h();
|
||||||
self.heap.push(HeapCellValue::Addr(heap_val));
|
self.heap.push(HeapCellValue::Addr(Addr::HeapCell(h)));
|
||||||
|
|
||||||
|
let addr = self.store(self[reg]);
|
||||||
|
(self.bind_fn)(self, Ref::HeapCell(h), addr);
|
||||||
|
|
||||||
|
// the former code of this match arm was:
|
||||||
|
|
||||||
|
// let addr = self.store(self[reg]);
|
||||||
|
// self.heap.push(HeapCellValue::Addr(addr));
|
||||||
|
|
||||||
|
// the old code didn't perform the occurs
|
||||||
|
// check when enabled and so it was changed to
|
||||||
|
// the above, which is only slightly less
|
||||||
|
// efficient when the occurs_check is disabled.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3541,62 +3541,6 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
&SystemClauseType::ResetGlobalVarAtKey => {
|
|
||||||
let key = self[temp_v!(1)];
|
|
||||||
|
|
||||||
match self.store(self.deref(key)) {
|
|
||||||
Addr::Con(h) if self.heap.atom_at(h) => {
|
|
||||||
if let HeapCellValue::Atom(ref key, _) = &self.heap[h] {
|
|
||||||
indices.global_variables.swap_remove(key);
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&SystemClauseType::ResetGlobalVarAtOffset => {
|
|
||||||
let key = self[temp_v!(1)];
|
|
||||||
|
|
||||||
let key = match self.store(self.deref(key)) {
|
|
||||||
Addr::Con(h) if self.heap.atom_at(h) => {
|
|
||||||
if let HeapCellValue::Atom(ref key, _) = &self.heap[h] {
|
|
||||||
key.clone()
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let value = self[temp_v!(2)];
|
|
||||||
let mut ball = Ball::new();
|
|
||||||
|
|
||||||
ball.boundary = self.heap.h();
|
|
||||||
|
|
||||||
copy_term(
|
|
||||||
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
|
||||||
value,
|
|
||||||
AttrVarPolicy::DeepCopy,
|
|
||||||
);
|
|
||||||
|
|
||||||
let offset = self[temp_v!(3)];
|
|
||||||
|
|
||||||
match self.store(self.deref(offset)) {
|
|
||||||
Addr::Usize(offset) => {
|
|
||||||
indices.global_variables.insert(key, (ball, Some(offset)));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
indices.global_variables.insert(key, (ball, None));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
&SystemClauseType::ResetAttrVarState => {
|
&SystemClauseType::ResetAttrVarState => {
|
||||||
self.attr_var_init.reset();
|
self.attr_var_init.reset();
|
||||||
}
|
}
|
||||||
@@ -3658,22 +3602,6 @@ impl MachineState {
|
|||||||
&SystemClauseType::REPL(repl_code_ptr) => {
|
&SystemClauseType::REPL(repl_code_ptr) => {
|
||||||
return self.repl_redirect(repl_code_ptr);
|
return self.repl_redirect(repl_code_ptr);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
&SystemClauseType::ModuleRetractClause => {
|
|
||||||
let p = self.cp;
|
|
||||||
let trans_type = DynamicTransactionType::ModuleRetract;
|
|
||||||
|
|
||||||
self.p = CodePtr::DynamicTransaction(trans_type, p);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
&SystemClauseType::RetractClause => {
|
|
||||||
let p = self.cp;
|
|
||||||
let trans_type = DynamicTransactionType::Retract;
|
|
||||||
|
|
||||||
self.p = CodePtr::DynamicTransaction(trans_type, p);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
&SystemClauseType::ReturnFromVerifyAttr => {
|
&SystemClauseType::ReturnFromVerifyAttr => {
|
||||||
let e = self.e;
|
let e = self.e;
|
||||||
let frame_len = self.stack.index_and_frame(e).prelude.univ_prelude.num_cells;
|
let frame_len = self.stack.index_and_frame(e).prelude.univ_prelude.num_cells;
|
||||||
@@ -5483,6 +5411,9 @@ impl MachineState {
|
|||||||
|
|
||||||
self.fail = true;
|
self.fail = true;
|
||||||
}
|
}
|
||||||
|
&SystemClauseType::DebugHook => {
|
||||||
|
self.fail = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return_from_clause!(self.last_call, self)
|
return_from_clause!(self.last_call, self)
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ instruction_match(Term, VarList) :-
|
|||||||
|
|
||||||
submit_query_and_print_results_(Term, VarList) :-
|
submit_query_and_print_results_(Term, VarList) :-
|
||||||
'$get_b_value'(B),
|
'$get_b_value'(B),
|
||||||
call(Term),
|
'$call'(Term),
|
||||||
write_eqs_and_read_input(B, VarList),
|
write_eqs_and_read_input(B, VarList),
|
||||||
!.
|
!.
|
||||||
submit_query_and_print_results_(_, _) :-
|
submit_query_and_print_results_(_, _) :-
|
||||||
@@ -174,7 +174,7 @@ submit_query_and_print_results_(_, _) :-
|
|||||||
|
|
||||||
|
|
||||||
submit_query_and_print_results(Term0, VarList) :-
|
submit_query_and_print_results(Term0, VarList) :-
|
||||||
expand_goal(call(Term0), user, Term),
|
expand_goal(call(Term0), user, call(Term)),
|
||||||
!,
|
!,
|
||||||
setup_call_cleanup(bb_put('$first_answer', true),
|
setup_call_cleanup(bb_put('$first_answer', true),
|
||||||
submit_query_and_print_results_(Term, VarList),
|
submit_query_and_print_results_(Term, VarList),
|
||||||
|
|||||||
Reference in New Issue
Block a user