]> Repositorios git - scryer-prolog.git/commitdiff
remove IsClause
authorMark Thom <[email protected]>
Mon, 14 May 2018 22:43:49 +0000 (16:43 -0600)
committerMark Thom <[email protected]>
Mon, 14 May 2018 22:43:49 +0000 (16:43 -0600)
src/prolog/ast.rs
src/prolog/codegen.rs
src/prolog/io.rs
src/prolog/machine/machine_state.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/mod.rs
src/prolog/macros.rs

index 26a238dca51b9bafc9df1f0b30871546b4ddc19d..04b93f28227fbc8dc9e21ac8e1c1ca3fffb257c0 100644 (file)
@@ -784,7 +784,7 @@ impl SystemClauseType {
     }
 }
 
-#[derive(Copy, Clone, PartialEq)]
+#[derive(Clone, PartialEq)]
 pub enum BuiltInClauseType {
     AcyclicTerm,
     Arg,
@@ -796,7 +796,7 @@ pub enum BuiltInClauseType {
     Eq,
     Functor,
     Ground,
-    Is,
+    Is(RegType, ArithmeticTerm),
     KeySort,
     NotEq,
     Sort,
@@ -881,7 +881,7 @@ impl BuiltInClauseType {
     fn fixity(&self) -> Option<Fixity> {
         match self {
             &BuiltInClauseType::Compare | &BuiltInClauseType::CompareTerm(_)
-          | &BuiltInClauseType::NotEq   | &BuiltInClauseType::Is | &BuiltInClauseType::Eq
+          | &BuiltInClauseType::NotEq   | &BuiltInClauseType::Is(..) | &BuiltInClauseType::Eq
                 => Some(Fixity::In),
             _ => None
         }
@@ -899,7 +899,7 @@ impl BuiltInClauseType {
             &BuiltInClauseType::Eq => clause_name!("=="),
             &BuiltInClauseType::Functor => clause_name!("functor"),
             &BuiltInClauseType::Ground  => clause_name!("ground"),
-            &BuiltInClauseType::Is => clause_name!("is"),
+            &BuiltInClauseType::Is(..)  => clause_name!("is"),
             &BuiltInClauseType::KeySort => clause_name!("keysort"),
             &BuiltInClauseType::NotEq => clause_name!("\\=="),
             &BuiltInClauseType::Sort => clause_name!("sort"),
@@ -918,7 +918,7 @@ impl BuiltInClauseType {
             &BuiltInClauseType::Eq => 2,
             &BuiltInClauseType::Functor => 3,
             &BuiltInClauseType::Ground  => 1,
-            &BuiltInClauseType::Is => 2,
+            &BuiltInClauseType::Is(..) => 2,
             &BuiltInClauseType::KeySort => 2,
             &BuiltInClauseType::NotEq => 2,
             &BuiltInClauseType::Sort => 2,
@@ -942,7 +942,7 @@ impl BuiltInClauseType {
             ("==", 2) => Some(BuiltInClauseType::Eq),
             ("functor", 3) => Some(BuiltInClauseType::Functor),
             ("ground", 1) => Some(BuiltInClauseType::Ground),
-            ("is", 2) => Some(BuiltInClauseType::Is),
+            ("is", 2) => Some(BuiltInClauseType::Is(temp_v!(1), ArithmeticTerm::Reg(temp_v!(2)))),
             ("keysort", 2) => Some(BuiltInClauseType::KeySort),
             ("\\==", 2) => Some(BuiltInClauseType::NotEq),
             ("sort", 2) => Some(BuiltInClauseType::Sort),
@@ -965,7 +965,7 @@ impl ClauseType {
     pub fn name(&self) -> ClauseName {
         match self {
             &ClauseType::CallN => clause_name!("call"),
-            &ClauseType::BuiltIn(built_in) => built_in.name(),
+            &ClauseType::BuiltIn(ref built_in) => built_in.name(),
             &ClauseType::Inlined(ref inlined) => clause_name!(inlined.name()),
             &ClauseType::Op(ref name, ..) => name.clone(),
             &ClauseType::Named(ref name, ..) => name.clone(),
@@ -1374,7 +1374,6 @@ pub enum ControlInstruction {
     CheckCpExecute,
     Deallocate,
     GetCleanerCall,
-    IsClause(bool, RegType, ArithmeticTerm), // last call, register of var, term.
     JmpBy(usize, usize, usize, bool), // arity, global_offset, perm_vars after threshold, last call.
     Proceed
 }
@@ -1384,7 +1383,6 @@ impl ControlInstruction {
         match self {
             &ControlInstruction::CallClause(..)  => true,
             &ControlInstruction::GetCleanerCall => true,
-            &ControlInstruction::IsClause(..) => true,
             &ControlInstruction::JmpBy(..) => true,
             _ => false
         }
index 6a01d3489f837091dd3df3fc95d40528c8218d79..1b1703e89f31c33bcd40b49c76ce3cdc727a6d8f 100644 (file)
@@ -195,7 +195,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
                         GenContext::Last(chunk_num)
                     }
                 };
-                
+
                 self.update_var_count(chunked_term.post_order_iter());
                 vs.mark_vars_in_chunk(chunked_term.post_order_iter(), lt_arity, term_loc);
             }
@@ -234,8 +234,6 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
                         *ctrl = ControlInstruction::CallClause(ct, arity, pvs, true),
                     ControlInstruction::JmpBy(arity, offset, pvs, false) =>
                         *ctrl = ControlInstruction::JmpBy(arity, offset, pvs, true),
-                    ControlInstruction::IsClause(false, r, at) =>
-                        *ctrl = ControlInstruction::IsClause(true, r, at),
                     ControlInstruction::Proceed => {},
                     _ => dealloc_index += 1
                 },
@@ -258,7 +256,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
 
                 code.append(&mut lcode);
                 code.append(&mut rcode);
-                
+
                 code.push(compare_number_instr!(cmp,
                                                 at_1.unwrap_or(interm!(1)),
                                                 at_2.unwrap_or(interm!(2))));
@@ -414,7 +412,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
                         } else {
                             Line::Cut(CutInstruction::Cut(perm_v!(1)))
                         }),
-                    &QueryTerm::Clause(_, ClauseType::BuiltIn(BuiltInClauseType::Is), ref terms) =>
+                    &QueryTerm::Clause(_, ClauseType::BuiltIn(BuiltInClauseType::Is(..)), ref terms)
+                        =>
                     {
                         let (mut acode, at) = self.call_arith_eval(terms[1].as_ref(), 1)?;
                         code.append(&mut acode);
index 41e75b5392deb19edfacf51099c894baef6aab12..9aa942b62cf37e443b34ff5b8179641e2004557b 100644 (file)
@@ -139,10 +139,6 @@ impl fmt::Display for ControlInstruction {
                 write!(f, "deallocate"),
             &ControlInstruction::GetCleanerCall =>
                 write!(f, "get_cleaner_call"),
-            &ControlInstruction::IsClause(false, r, ref at) =>
-                write!(f, "is_call {}, {}", r, at),
-            &ControlInstruction::IsClause(true, r, ref at) =>
-                write!(f, "is_execute {}, {}", r, at),
             &ControlInstruction::JmpBy(arity, offset, pvs, false) =>
                 write!(f, "jmp_by_call {}/{}, {}", offset, arity, pvs),
             &ControlInstruction::JmpBy(arity, offset, pvs, true) =>
index 8f9a9727f553e44a12e953d1d7d498b858fbc1ae..7321182ff71b328e19a0bcb7224df893fadc4db1 100644 (file)
@@ -324,7 +324,7 @@ pub(crate) trait CallPolicy: Any {
         let b = machine_st.b - 1;
         let n = machine_st.or_stack[b].num_args();
 
-        for i in 1 .. n + 1 {            
+        for i in 1 .. n + 1 {
             machine_st.registers[i] = machine_st.or_stack[b][i].clone();
         }
 
@@ -510,11 +510,11 @@ pub(crate) trait CallPolicy: Any {
 
                 return_from_clause!(machine_st.last_call, machine_st)
             },
-            &BuiltInClauseType::Is => {
-                let a = machine_st[temp_v!(1)].clone();
-                let result = machine_st.arith_eval_by_metacall(temp_v!(2))?;
+            &BuiltInClauseType::Is(r, ref at) => {
+                let a1 = machine_st[r].clone();
+                let a2 = machine_st.get_number(at)?;
 
-                machine_st.unify(a, Addr::Con(Constant::Number(result)));
+                machine_st.unify(a1, Addr::Con(Constant::Number(a2)));
                 return_from_clause!(machine_st.last_call, machine_st)
             },
         }
index e37a70587431ed58677faa177910ad52afd5e78d..0adc75d067435fec358ead12a9de61061a4ddca6 100644 (file)
@@ -323,7 +323,7 @@ impl MachineState {
         };
     }
 
-    fn get_number(&self, at: &ArithmeticTerm) -> Result<Number, MachineError> {
+    pub(super) fn get_number(&self, at: &ArithmeticTerm) -> Result<Number, MachineError> {
         match at {
             &ArithmeticTerm::Reg(r)        => self.arith_eval_by_metacall(r),
             &ArithmeticTerm::Interm(i)     => Ok(self.interms[i-1].clone()),
@@ -1879,15 +1879,6 @@ impl MachineState {
 
                 self.fail = true;
             },
-            &ControlInstruction::IsClause(lco, r, ref at) => {
-                self.last_call = lco;
-
-                let a1 = self[r].clone();
-                let a2 = try_or_fail!(self, self.get_number(at));
-
-                self.unify(a1, Addr::Con(Constant::Number(a2)));
-                try_or_fail!(self, return_from_clause!(self.last_call, self));
-            },
             &ControlInstruction::JmpBy(arity, offset, _, lco) => {
                 if !lco {
                     self.cp.assign_if_local(self.p.clone() + 1);
index e1112fae9acd299d797f4d53804b8419a675570f..d1848238efae6546e4126912e769c40da6fa6172 100644 (file)
@@ -233,7 +233,7 @@ impl Machine {
             CodePtr::Local(LocalCodePtr::DirEntry(p, _)) =>
                 Some(self.code[p].clone()),
             CodePtr::BuiltInClause(built_in, _) =>
-                Some(call_clause!(ClauseType::BuiltIn(built_in), built_in.arity(),
+                Some(call_clause!(ClauseType::BuiltIn(built_in.clone()), built_in.arity(),
                                   0, self.ms.last_call)),
             CodePtr::CallN(arity, _) =>
                 Some(call_clause!(ClauseType::CallN, arity, 0, self.ms.last_call))            
index 79ecb6f5d8a827eb3c52f71ea9995ae39dfd440d..4124becaa1e92fef515c2451242414a729f75e76 100644 (file)
@@ -147,8 +147,8 @@ macro_rules! proceed {
 }
 
 macro_rules! is_call {
-    ($r:expr, $at:expr) => (        
-        Line::Control(ControlInstruction::IsClause(false, $r, $at))
+    ($r:expr, $at:expr) => (
+        call_clause!(ClauseType::BuiltIn(BuiltInClauseType::Is($r, $at)), 2, 0)
     )
 }