]> Repositorios git - scryer-prolog.git/commitdiff
move several builtins to control.
authorMark Thom <[email protected]>
Tue, 13 Feb 2018 01:30:44 +0000 (18:30 -0700)
committerMark Thom <[email protected]>
Tue, 13 Feb 2018 01:30:44 +0000 (18:30 -0700)
src/prolog/ast.rs
src/prolog/io.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/macros.rs

index 79f726429b0eea9c8e023a212f99bb558321337c..14b035b259cee70043b776807f1d66cea355da38 100644 (file)
@@ -820,28 +820,17 @@ pub enum ArithmeticInstruction {
 }
 
 pub enum BuiltInInstruction {
-    CleanUpBlock,
-    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
+    CleanUpBlock,    
     EraseBall,
     Fail,
     GetArgCall,
     GetArgExecute,
     GetBall,
     GetCurrentBlock,
-    GetCutPoint(RegType),
-    DynamicCompareNumber(CompareNumberQT),
-    DynamicIs,
+    GetCutPoint(RegType),    
     InstallCleaner,
     InstallNewBlock,
-    InternalCallN,
-    IsAtomic(RegType),
-    IsCompound(RegType),
-    IsFloat(RegType),
-    IsInteger(RegType),
-    IsNonVar(RegType),
-    IsRational(RegType),
-    IsString(RegType),
-    IsVar(RegType),
+    InternalCallN,    
     ResetBlock,
     RestoreCutPolicy,
     SetBall,
@@ -861,11 +850,14 @@ pub enum ControlInstruction {
     CatchCall,
     CatchExecute,
     CheckCpExecute,
+    CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
     DisplayCall,
     DisplayExecute,
     Deallocate,
     DuplicateTermCall,
     DuplicateTermExecute,
+    DynamicCompareNumber(CompareNumberQT),
+    DynamicIs,
     EqCall,
     EqExecute,
     Execute(TabledRc<Atom>, usize),
@@ -876,10 +868,18 @@ pub enum ControlInstruction {
     GotoCall(usize, usize),    // p, arity.
     GotoExecute(usize, usize), // p, arity.
     GroundCall,
-    GroundExecute,
+    GroundExecute,    
     JmpByCall(usize, usize),    // arity, global_offset.
     JmpByExecute(usize, usize),
     IsCall(RegType, ArithmeticTerm),
+    IsAtomic(RegType),
+    IsCompound(RegType),
+    IsFloat(RegType),
+    IsInteger(RegType),
+    IsNonVar(RegType),
+    IsRational(RegType),
+    IsString(RegType),
+    IsVar(RegType),
     IsExecute(RegType, ArithmeticTerm),
     NotEqCall,
     NotEqExecute,
@@ -896,10 +896,13 @@ impl ControlInstruction {
             &ControlInstruction::Call(_, _, _)  => true,
             &ControlInstruction::CatchCall => true,
             &ControlInstruction::CatchExecute => true,
+            &ControlInstruction::CompareNumber(..) => true,             
             &ControlInstruction::DisplayCall => true,
             &ControlInstruction::DisplayExecute => true,
             &ControlInstruction::DuplicateTermCall => true,
             &ControlInstruction::DuplicateTermExecute => true,
+            &ControlInstruction::DynamicCompareNumber(_) => true,
+            &ControlInstruction::DynamicIs => true,
             &ControlInstruction::EqCall => true,
             &ControlInstruction::EqExecute => true,
             &ControlInstruction::Execute(_, _)  => true,
@@ -916,6 +919,14 @@ impl ControlInstruction {
             &ControlInstruction::GotoExecute(..) => true,
             &ControlInstruction::GroundCall => true,
             &ControlInstruction::GroundExecute => true,
+            &ControlInstruction::IsAtomic(_) => true,
+            &ControlInstruction::IsCompound(_) => true,
+            &ControlInstruction::IsFloat(_) => true,
+            &ControlInstruction::IsInteger(_) => true,
+            &ControlInstruction::IsNonVar(_) => true,
+            &ControlInstruction::IsRational(_) => true,
+            &ControlInstruction::IsString(_) => true,
+            &ControlInstruction::IsVar(_) => true,
             &ControlInstruction::IsCall(..) => true,
             &ControlInstruction::IsExecute(..) => true,
             &ControlInstruction::JmpByCall(..) => true,
index 55d0d9eed8f7f98535fb2147a51c8bf662ccf554..1562dd0cd9d08f1f36b3d19658fc02ba355b4e58 100644 (file)
@@ -151,6 +151,24 @@ impl fmt::Display for ControlInstruction {
                 write!(f, "is_call {}, {}", r, at),
             &ControlInstruction::IsExecute(r, ref at) =>
                 write!(f, "is_execute {}, {}", r, at),
+            &ControlInstruction::IsAtomic(r) =>
+                write!(f, "is_atomic {}", r),
+            &ControlInstruction::IsCompound(r) =>
+                write!(f, "is_compound {}", r),
+            &ControlInstruction::IsFloat(r) =>
+                write!(f, "is_float {}", r),
+            &ControlInstruction::IsRational(r) =>
+                write!(f, "is_rational {}", r),
+            &ControlInstruction::IsNonVar(r) =>
+                write!(f, "is_non_var {}", r),
+            &ControlInstruction::IsString(r) =>
+                write!(f, "is_string {}", r),
+            &ControlInstruction::IsInteger(r) =>
+                write!(f, "is_integer {}", r),
+            &ControlInstruction::DynamicIs =>
+                write!(f, "call_is"),
+            &ControlInstruction::IsVar(r) =>
+                write!(f, "is_var {}", r),
             &ControlInstruction::JmpByCall(arity, offset) =>
                 write!(f, "jmp_by_call {}/{}", offset, arity),
             &ControlInstruction::JmpByExecute(arity, offset) =>
@@ -165,6 +183,10 @@ impl fmt::Display for ControlInstruction {
                 write!(f, "call_throw"),
             &ControlInstruction::ThrowExecute =>
                 write!(f, "execute_throw"),
+            &ControlInstruction::CompareNumber(cmp, ref at_1, ref at_2) =>
+                write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
+            &ControlInstruction::DynamicCompareNumber(cmp) =>
+                write!(f, "dynamic_number_test {}", cmp),
         }
     }
 }
@@ -186,11 +208,7 @@ impl fmt::Display for BuiltInInstruction {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
             &BuiltInInstruction::CleanUpBlock =>
-                write!(f, "clean_up_block"),
-            &BuiltInInstruction::CompareNumber(cmp, ref at_1, ref at_2) =>
-                write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
-            &BuiltInInstruction::DynamicCompareNumber(cmp) =>
-                write!(f, "dynamic_number_test {}", cmp),
+                write!(f, "clean_up_block"),            
             &BuiltInInstruction::EraseBall =>
                 write!(f, "erase_ball"),
             &BuiltInInstruction::Fail =>
@@ -210,25 +228,7 @@ impl fmt::Display for BuiltInInstruction {
             &BuiltInInstruction::InstallNewBlock =>
                 write!(f, "install_new_block"),
             &BuiltInInstruction::InternalCallN =>
-                write!(f, "internal_call_N"),
-            &BuiltInInstruction::IsAtomic(r) =>
-                write!(f, "is_atomic {}", r),
-            &BuiltInInstruction::IsCompound(r) =>
-                write!(f, "is_compound {}", r),
-            &BuiltInInstruction::IsFloat(r) =>
-                write!(f, "is_float {}", r),
-            &BuiltInInstruction::IsRational(r) =>
-                write!(f, "is_rational {}", r),
-            &BuiltInInstruction::IsNonVar(r) =>
-                write!(f, "is_non_var {}", r),
-            &BuiltInInstruction::IsString(r) =>
-                write!(f, "is_string {}", r),
-            &BuiltInInstruction::IsInteger(r) =>
-                write!(f, "is_integer {}", r),
-            &BuiltInInstruction::DynamicIs =>
-                write!(f, "call_is"),
-            &BuiltInInstruction::IsVar(r) =>
-                write!(f, "is_var {}", r),
+                write!(f, "internal_call_N"),            
             &BuiltInInstruction::ResetBlock =>
                 write!(f, "reset_block"),
             &BuiltInInstruction::RestoreCutPolicy =>
index a9c594b8a479943a6f33554c0ad9efe3fd44b80e..2a29445141791e1981f6169a13bf75a0badec744 100644 (file)
@@ -1128,26 +1128,7 @@ impl MachineState {
                                          cut_policy: &mut Box<CutPolicy>,
                                          instr: &BuiltInInstruction)
     {
-        match instr {
-            &BuiltInInstruction::CompareNumber(cmp, ref at_1, ref at_2) => {
-                let n1 = try_or_fail!(self, self.get_number(at_1));
-                let n2 = try_or_fail!(self, self.get_number(at_2));
-
-                self.compare_numbers(cmp, n1, n2);
-            },
-            &BuiltInInstruction::DynamicCompareNumber(cmp) => {
-                let n1 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(1)));
-                let n2 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
-
-                self.compare_numbers(cmp, n1, n2);
-            },
-            &BuiltInInstruction::DynamicIs => {
-                let a = self[temp_v!(1)].clone();
-                let result = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
-
-                self.unify(a, Addr::Con(Constant::Number(result)));
-                self.p += 1;
-            },
+        match instr {            
             &BuiltInInstruction::GetArgCall =>
                 try_or_fail!(self, {
                     let val = self.try_get_arg();
@@ -1292,71 +1273,7 @@ SetupCallCleanupCutPolicy.")
                 self.or_stack.truncate(self.b);
 
                 self.fail = true;
-            },
-            &BuiltInInstruction::IsAtomic(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Con(_) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsInteger(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Con(Constant::Number(Number::Integer(_))) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsCompound(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Str(_) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsFloat(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Con(Constant::Number(Number::Float(_))) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsRational(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Con(Constant::Number(Number::Rational(_))) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsString(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::Con(Constant::String(_)) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::IsNonVar(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::HeapCell(_) | Addr::StackCell(..) => self.fail = true,
-                    _ => self.p += 1
-                };
-            },
-            &BuiltInInstruction::IsVar(r) => {
-                let d = self.store(self.deref(self[r].clone()));
-
-                match d {
-                    Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
-                    _ => self.fail = true
-                };
-            },
+            },            
             &BuiltInInstruction::InternalCallN =>
                 self.handle_internal_call_n(code_dir),
             &BuiltInInstruction::Fail => {
@@ -1615,6 +1532,89 @@ SetupCallCleanupCutPolicy.")
                 self.duplicate_term();
                 self.p = self.cp;
             },
+            &ControlInstruction::CompareNumber(cmp, ref at_1, ref at_2) => {
+                let n1 = try_or_fail!(self, self.get_number(at_1));
+                let n2 = try_or_fail!(self, self.get_number(at_2));
+
+                self.compare_numbers(cmp, n1, n2);
+            },
+            &ControlInstruction::DynamicCompareNumber(cmp) => {
+                let n1 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(1)));
+                let n2 = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
+
+                self.compare_numbers(cmp, n1, n2);
+            },
+            &ControlInstruction::DynamicIs => {
+                let a = self[temp_v!(1)].clone();
+                let result = try_or_fail!(self, self.arith_eval_by_metacall(temp_v!(2)));
+
+                self.unify(a, Addr::Con(Constant::Number(result)));
+                self.p += 1;
+            },
+            &ControlInstruction::IsAtomic(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Con(_) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsInteger(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Con(Constant::Number(Number::Integer(_))) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsCompound(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Str(_) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsFloat(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Con(Constant::Number(Number::Float(_))) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsRational(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Con(Constant::Number(Number::Rational(_))) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsString(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::Con(Constant::String(_)) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
+            &ControlInstruction::IsNonVar(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::HeapCell(_) | Addr::StackCell(..) => self.fail = true,
+                    _ => self.p += 1
+                };
+            },
+            &ControlInstruction::IsVar(r) => {
+                let d = self.store(self.deref(self[r].clone()));
+
+                match d {
+                    Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
+                    _ => self.fail = true
+                };
+            },
             &ControlInstruction::EqCall => {
                 self.fail = self.eq_test();
                 self.p += 1;
index 281129a8f899b45ae2b77e0beb0bdeb4a13ed632..07fc9f1d0aa18373e9261ee7bb7f556cecb5411d 100644 (file)
@@ -30,7 +30,7 @@ macro_rules! deallocate {
 
 macro_rules! compare_number_instr {
     ($cmp: expr, $at_1: expr, $at_2: expr) => (
-        Line::BuiltIn(BuiltInInstruction::CompareNumber($cmp, $at_1, $at_2))
+        Line::Control(ControlInstruction::CompareNumber($cmp, $at_1, $at_2))
     )
 }
 
@@ -158,50 +158,50 @@ macro_rules! retry_me_else {
 
 macro_rules! is_atomic {
     ($reg:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsAtomic($reg))
+        Line::Control(ControlInstruction::IsAtomic($reg))
     )
 }
 
 macro_rules! is_integer {
     ($reg:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsInteger($reg))
+        Line::Control(ControlInstruction::IsInteger($reg))
     )
 }
 
 macro_rules! is_compound {
     ($r:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsCompound($r))
+        Line::Control(ControlInstruction::IsCompound($r))
     )
 }
 
 macro_rules! is_float {
     ($r:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsFloat($r))
+        Line::Control(ControlInstruction::IsFloat($r))
     )
 }
 
 macro_rules! is_rational {
     ($r:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsRational($r))
+        Line::Control(ControlInstruction::IsRational($r))
     )
 }
 
 
 macro_rules! is_nonvar {
     ($r:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsNonVar($r))
+        Line::Control(ControlInstruction::IsNonVar($r))
     )
 }
 
 macro_rules! is_string {
     ($r:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsString($r))
+        Line::Control(ControlInstruction::IsString($r))
     )
 }
 
 macro_rules! is_var {
     ($reg:expr) => (
-        Line::BuiltIn(BuiltInInstruction::IsVar($reg))
+        Line::Control(ControlInstruction::IsVar($reg))
     )
 }
 
@@ -469,13 +469,13 @@ macro_rules! display {
 
 macro_rules! dynamic_is {
     () => (
-        Line::BuiltIn(BuiltInInstruction::DynamicIs)
+        Line::Control(ControlInstruction::DynamicIs)
     )
 }
 
 macro_rules! dynamic_num_test {
     ($cmp:expr) => (
-        Line::BuiltIn(BuiltInInstruction::DynamicCompareNumber($cmp))
+        Line::Control(ControlInstruction::DynamicCompareNumber($cmp))
     )
 }