]> Repositorios git - scryer-prolog.git/commitdiff
use occurs check when enabled in UnifyValue (#885)
authorMark Thom <[email protected]>
Tue, 23 Mar 2021 04:05:03 +0000 (22:05 -0600)
committerMark Thom <[email protected]>
Tue, 23 Mar 2021 04:05:03 +0000 (22:05 -0600)
src/clause_types.rs
src/machine/machine_state_impl.rs
src/machine/system_calls.rs
src/toplevel.pl

index 51894bed506cd23d5d73fb03a2b17092be218ea6..cf327707773e6d7b025f233fafcac06b5eb3e6ee 100644 (file)
@@ -306,6 +306,7 @@ pub(crate) enum SystemClauseType {
     SetNSTOAsUnify,
     SetSTOWithErrorAsUnify,
     HomeDirectory,
+    DebugHook,
 }
 
 impl SystemClauseType {
@@ -592,6 +593,7 @@ impl SystemClauseType {
             &SystemClauseType::SetNSTOAsUnify => clause_name!("$set_nsto_as_unify"),
             &SystemClauseType::HomeDirectory => clause_name!("$home_directory"),
             &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_sto_with_error_as_unify", 0) => Some(SystemClauseType::SetSTOWithErrorAsUnify),
             ("$home_directory", 1) => Some(SystemClauseType::HomeDirectory),
+            ("$debug_hook", 0) => Some(SystemClauseType::DebugHook),
             _ => None,
         }
     }
index 593523087ede37506fd099707ef55c33f889afeb..a6539ee2e20951f7f584cb1dc27f30c5bcd0560b 100644 (file)
@@ -1327,8 +1327,21 @@ impl MachineState {
                         self.increment_s_ptr(1);
                     }
                     MachineMode::Write => {
-                        let heap_val = self.store(self[reg]);
-                        self.heap.push(HeapCellValue::Addr(heap_val));
+                        let h = self.heap.h();
+                        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.
                     }
                 };
             }
index 33cff953211854987bfbdd6f43ea9daa39281ccb..082a3e163aa2d3704d753377fd84e7e445111300 100644 (file)
@@ -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 => {
                 self.attr_var_init.reset();
             }
@@ -3658,22 +3602,6 @@ impl MachineState {
             &SystemClauseType::REPL(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 => {
                 let e = self.e;
                 let frame_len = self.stack.index_and_frame(e).prelude.univ_prelude.num_cells;
@@ -5483,6 +5411,9 @@ impl MachineState {
 
                 self.fail = true;
             }
+            &SystemClauseType::DebugHook => {
+                self.fail = false;
+            }
         };
 
         return_from_clause!(self.last_call, self)
index 27c76d208830d8693e0f4f2d5e2c536184dacd08..a41af81940c3e3fc48e5511e45a62a1f859b2757 100644 (file)
@@ -163,7 +163,7 @@ instruction_match(Term, VarList) :-
 
 submit_query_and_print_results_(Term, VarList) :-
     '$get_b_value'(B),
-    call(Term),
+    '$call'(Term),
     write_eqs_and_read_input(B, VarList),
     !.
 submit_query_and_print_results_(_, _) :-
@@ -174,7 +174,7 @@ submit_query_and_print_results_(_, _) :-
 
 
 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),
                        submit_query_and_print_results_(Term, VarList),