]> Repositorios git - scryer-prolog.git/commitdiff
port remaining builtins to SystemClauseType
authorMark Thom <[email protected]>
Fri, 11 May 2018 04:40:01 +0000 (22:40 -0600)
committerMark Thom <[email protected]>
Fri, 11 May 2018 04:40:01 +0000 (22:40 -0600)
src/prolog/ast.rs
src/prolog/io.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/system_calls.rs

index 2e50706aac4d9af6b1796dae5c5d9e95417c5bac..ac62082ae494438ae93342b7ea170e013cf69257 100644 (file)
@@ -714,6 +714,8 @@ pub struct Rule {
 
 #[derive(Copy, Clone, PartialEq)]
 pub enum SystemClauseType {
+    GetArg,
+    InferenceLevel(RegType, RegType),
     CleanUpBlock,
     EraseBall,
     Fail,
@@ -731,6 +733,8 @@ pub enum SystemClauseType {
 impl SystemClauseType {
     pub fn arity(&self) -> usize {
         match self {
+            &SystemClauseType::GetArg => 3,
+            &SystemClauseType::InferenceLevel(..) => 2,
             &SystemClauseType::CleanUpBlock => 1,
             &SystemClauseType::EraseBall => 0,
             &SystemClauseType::Fail => 0,
@@ -752,6 +756,8 @@ impl SystemClauseType {
     
     pub fn name(&self) -> ClauseName {
         match self {
+            &SystemClauseType::GetArg => clause_name!("$get_arg"),
+            &SystemClauseType::InferenceLevel(..) => clause_name!("$inference_level"),
             &SystemClauseType::CleanUpBlock => clause_name!("$clean_up_block"),
             &SystemClauseType::EraseBall => clause_name!("$erase_ball"),
             &SystemClauseType::Fail => clause_name!("$fail"),
@@ -769,6 +775,8 @@ impl SystemClauseType {
 
     pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> {
         match (name, arity) {
+            ("$get_arg", 3) => Some(SystemClauseType::GetArg),
+            ("$inference_level", 2) => Some(SystemClauseType::InferenceLevel(temp_v!(0), temp_v!(0))),
             ("$clean_up_block", 1) => Some(SystemClauseType::CleanUpBlock),
             ("$erase_ball", 0) => Some(SystemClauseType::EraseBall),
             ("$fail", 0) => Some(SystemClauseType::Fail),
@@ -1361,8 +1369,6 @@ pub enum ArithmeticInstruction {
 
 #[derive(Clone)]
 pub enum BuiltInInstruction {
-    GetArg(bool), // last call.
-    InferenceLevel(RegType, RegType),
     InstallCleaner,
     InstallInferenceCounter(RegType, RegType, RegType),
     RemoveCallPolicyCheck,
index 576fa8001f4fd65cc2fffa2871fdf23cfd2d89cb..68659c79a632ab71ba1cb64ceb57ce7bb88b943a 100644 (file)
@@ -171,12 +171,6 @@ impl fmt::Display for BuiltInInstruction {
         match self {
             &BuiltInInstruction::InstallInferenceCounter(r1, r2, r3) =>
                 write!(f, "install_inference_counter {}, {}, {}", r1, r2, r3),
-            &BuiltInInstruction::GetArg(false) =>
-                write!(f, "get_arg_call X1, X2, X3"),
-            &BuiltInInstruction::GetArg(true) =>
-                write!(f, "get_arg_execute X1, X2, X3"),
-            &BuiltInInstruction::InferenceLevel(r1, r2) =>
-                write!(f, "inference_level {}, {}", r1, r2),
             &BuiltInInstruction::InstallCleaner =>
                 write!(f, "install_cleaner"),
             &BuiltInInstruction::RemoveCallPolicyCheck =>
index c81551207da004a6620ff950209d5cdf60d4b59e..9abe45be5ff83396e7064444fb165351fbd7a64b 100644 (file)
@@ -1137,7 +1137,7 @@ impl MachineState {
         fail
     }
 
-    fn try_get_arg(&mut self) -> Result<(), MachineError>
+    pub(super) fn try_get_arg(&mut self) -> CallResult
     {
         let a1 = self.store(self.deref(self[temp_v!(1)].clone()));
 
@@ -1407,36 +1407,6 @@ impl MachineState {
                                   instr: &BuiltInInstruction)
     {
         match instr {            
-            &BuiltInInstruction::GetArg(lco) =>
-                try_or_fail!(self, {
-                    let val = self.try_get_arg();
-
-                    if lco {
-                        self.p = CodePtr::Local(self.cp.clone());
-                    } else {
-                        self.p += 1;
-                    }
-
-                    val
-                }),
-            &BuiltInInstruction::InferenceLevel(r1, r2) => { // X1 = R, X2 = B.
-                let a1 = self[r1].clone();
-                let a2 = self.store(self.deref(self[r2].clone()));
-
-                match a2 {
-                    Addr::Con(Constant::Usize(bp)) =>
-                        if self.b <= bp + 1 {
-                            let a2 = Addr::Con(atom!("!", self.atom_tbl));
-                            self.unify(a1, a2);
-                        } else {
-                            let a2 = Addr::Con(atom!("true", self.atom_tbl));
-                            self.unify(a1, a2);
-                        },
-                    _ => self.fail = true
-                };
-
-                self.p += 1;
-            },
             &BuiltInInstruction::InstallCleaner => {
                 let addr = self[temp_v!(1)].clone();
                 let b = self.b;
index 715969e78b3009e17037cd16406eb0262029b74a..d9500de0382aea663df51cdb9fbcf765c472f57e 100644 (file)
@@ -3,6 +3,7 @@ use prolog::machine::machine_errors::*;
 use prolog::machine::machine_state::*;
 use prolog::num::{ToPrimitive, Zero};
 use prolog::num::bigint::BigInt;
+use prolog::tabled_rc::*;
 
 use std::rc::Rc;
 
@@ -155,6 +156,26 @@ impl MachineState {
     pub(super) fn system_call(&mut self, ct: &SystemClauseType) -> CallResult
     {
         match ct {
+            &SystemClauseType::GetArg =>
+                self.try_get_arg(),
+            &SystemClauseType::InferenceLevel(r1, r2) => {
+                let a1 = self[r1].clone();
+                let a2 = self.store(self.deref(self[r2].clone()));
+
+                match a2 {
+                    Addr::Con(Constant::Usize(bp)) =>
+                        if self.b <= bp + 1 {
+                            let a2 = Addr::Con(atom!("!", self.atom_tbl));
+                            self.unify(a1, a2);
+                        } else {
+                            let a2 = Addr::Con(atom!("true", self.atom_tbl));
+                            self.unify(a1, a2);
+                        },
+                    _ => self.fail = true
+                };
+
+                Ok(())
+            },            
             &SystemClauseType::CleanUpBlock => {
                 let nb = self.store(self.deref(self[temp_v!(1)].clone()));