]> Repositorios git - scryer-prolog.git/commitdiff
scan registers of instructions leading to verify_attributes interrupt to find the...
authorMark <[email protected]>
Fri, 26 Jan 2024 06:59:54 +0000 (23:59 -0700)
committerMark <[email protected]>
Fri, 26 Jan 2024 06:59:54 +0000 (23:59 -0700)
build/instructions_template.rs
src/machine/dispatch.rs
src/machine/mod.rs
src/machine/system_calls.rs

index cf6a63f310df6b057e06c6e1c2016168be950d77..1840341b1644ca2c1a07405b163d7c0ef98255e7 100644 (file)
@@ -792,8 +792,8 @@ enum InstructionTemplate {
     #[strum_discriminants(strum(props(Arity = "0", Name = "install_verify_attr")))]
     InstallVerifyAttr,
     // call verify_attrs.
-    #[strum_discriminants(strum(props(Arity = "0", Name = "verify_attr_interrupt")))]
-    VerifyAttrInterrupt,
+    #[strum_discriminants(strum(props(Arity = "1", Name = "verify_attr_interrupt")))]
+    VerifyAttrInterrupt(usize),
     // procedures
     CallClause(ClauseType, usize, usize, bool, bool), // ClauseType,
                                                       // arity,
@@ -1153,6 +1153,33 @@ fn generate_instruction_preface() -> TokenStream {
         pub type CodeDeque = VecDeque<Instruction>;
 
         impl Instruction {
+            #[inline]
+            pub fn registers(&self) -> Vec<RegType> {
+                match self {
+                    &Instruction::GetConstant(_, _, r) => vec![r],
+                    &Instruction::GetList(_, r) => vec![r],
+                    &Instruction::GetPartialString(_, _, r, _) => vec![r],
+                    &Instruction::GetStructure(_, _, _, r) => vec![r],
+                    &Instruction::GetVariable(r, t) => vec![r, temp_v!(t)],
+                    &Instruction::GetValue(r, t) => vec![r, temp_v!(t)],
+                    &Instruction::UnifyLocalValue(r) => vec![r],
+                    &Instruction::UnifyVariable(r) => vec![r],
+                    &Instruction::PutConstant(_, _, r) => vec![r],
+                    &Instruction::PutList(_, r) => vec![r],
+                    &Instruction::PutPartialString(_, _, r, _) => vec![r],
+                    &Instruction::PutStructure(_, _, r) => vec![r],
+                    &Instruction::PutValue(r, t) => vec![r, temp_v!(t)],
+                    &Instruction::PutVariable(r, t) => vec![r, temp_v!(t)],
+                    &Instruction::SetLocalValue(r) => vec![r],
+                    &Instruction::SetVariable(r) => vec![r],
+                    &Instruction::SetValue(r) => vec![r],
+                    &Instruction::GetLevel(r) => vec![r],
+                    &Instruction::GetPrevLevel(r) => vec![r],
+                    &Instruction::GetCutPoint(r) => vec![r],
+                    _ => vec![],
+                }
+            }
+
             #[inline]
             pub fn to_indexing_line_mut(&mut self) -> Option<&mut Vec<IndexingLine>> {
                 match self {
@@ -1243,8 +1270,8 @@ fn generate_instruction_preface() -> TokenStream {
                     &Instruction::InstallVerifyAttr => {
                         functor!(atom!("install_verify_attr"))
                     }
-                    &Instruction::VerifyAttrInterrupt => {
-                        functor!(atom!("verify_attr_interrupt"))
+                    &Instruction::VerifyAttrInterrupt(arity) => {
+                        functor!(atom!("verify_attr_interrupt"), [fixnum(arity)])
                     }
                     &Instruction::DynamicElse(birth, death, next_or_fail) => {
                         match (death, next_or_fail) {
index b83b6d520e6939d00922e61ede01e4fa13339604..f3a73e6ced07d9050e398e413e219e164c765f4f 100644 (file)
@@ -557,20 +557,29 @@ impl Machine {
                         }
 
                         let mut p = self.machine_st.p;
+                        let mut arity = 0;
 
                         while self.code[p].is_head_instr() {
+                            for r in self.code[p].registers() {
+                                if let RegType::Temp(t) = r {
+                                    arity = std::cmp::max(arity, t);
+                                }
+                            }
+
                             p += 1;
                         }
 
-                        let instr =
-                            std::mem::replace(&mut self.code[p], Instruction::VerifyAttrInterrupt);
+                        let instr = std::mem::replace(
+                            &mut self.code[p],
+                            Instruction::VerifyAttrInterrupt(arity),
+                        );
 
                         self.code[VERIFY_ATTR_INTERRUPT_LOC] = instr;
                         self.machine_st.attr_var_init.cp = p;
                     }
-                    &Instruction::VerifyAttrInterrupt => {
-                        let (_, arity) = self.code[VERIFY_ATTR_INTERRUPT_LOC].to_name_and_arity();
-                        let arity = std::cmp::max(arity, self.machine_st.num_of_args);
+                    &Instruction::VerifyAttrInterrupt(arity) => {
+                        // let (_, arity) = self.code[VERIFY_ATTR_INTERRUPT_LOC].to_name_and_arity();
+                        // let arity = std::cmp::max(arity, self.machine_st.num_of_args);
                         self.run_verify_attr_interrupt(arity);
                     }
                     &Instruction::Add(ref a1, ref a2, t) => {
index f8f3797182b502c066cc0274893dd59d597419ae..5326c83cf5d8579e1fadd1dc3648fa940bdb4a8a 100644 (file)
@@ -391,7 +391,7 @@ impl Machine {
         self.code.extend(vec![
             Instruction::BreakFromDispatchLoop,
             Instruction::InstallVerifyAttr,
-            Instruction::VerifyAttrInterrupt,
+            Instruction::VerifyAttrInterrupt(0),
             Instruction::BreakFromDispatchLoop, // the location of LIB_QUERY_SUCCESS
             Instruction::ExecuteTermGreaterThan,
             Instruction::ExecuteTermLessThan,
index dbcbacd06366d15fdeabc56d39a2f94642a3eb59..5a10358d8882e75f6e51c8f19e28c94cb918113f 100644 (file)
@@ -5739,11 +5739,11 @@ impl Machine {
     #[inline(always)]
     pub(super) fn restore_instr_at_verify_attr_interrupt(&mut self) {
         match &self.code[VERIFY_ATTR_INTERRUPT_LOC] {
-            &Instruction::VerifyAttrInterrupt => {}
+            &Instruction::VerifyAttrInterrupt(_) => {}
             _ => {
                 let instr = mem::replace(
                     &mut self.code[VERIFY_ATTR_INTERRUPT_LOC],
-                    Instruction::VerifyAttrInterrupt,
+                    Instruction::VerifyAttrInterrupt(0),
                 );
 
                 self.code[self.machine_st.attr_var_init.cp] = instr;