]> Repositorios git - scryer-prolog.git/commitdiff
remove string/1, use a more general test for the partial_string/1 type test (#328)
authorMark Thom <[email protected]>
Sun, 12 Apr 2020 04:47:52 +0000 (22:47 -0600)
committerMark Thom <[email protected]>
Sun, 12 Apr 2020 04:47:52 +0000 (22:47 -0600)
src/prolog/clause_types.rs
src/prolog/codegen.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/system_calls.rs
src/prolog/macros.rs

index 4abdd8fd5e6ac5dd5ce3fbec6d469bbabfbf015c..3a021d00cc929a3a10351c03eacde653a3a3d895 100644 (file)
@@ -75,7 +75,6 @@ pub enum InlinedClauseType {
     IsCompound(RegType),
     IsInteger(RegType),
     IsRational(RegType),
-    IsString(RegType),
     IsFloat(RegType),
     IsNonVar(RegType),
     IsVar(RegType),
@@ -105,7 +104,6 @@ ref_thread_local! {
         m.insert(("compound", 1), ClauseType::Inlined(InlinedClauseType::IsCompound(r1)));
         m.insert(("integer", 1), ClauseType::Inlined(InlinedClauseType::IsInteger(r1)));
         m.insert(("rational", 1), ClauseType::Inlined(InlinedClauseType::IsRational(r1)));
-        m.insert(("string", 1), ClauseType::Inlined(InlinedClauseType::IsString(r1)));
         m.insert(("float", 1), ClauseType::Inlined(InlinedClauseType::IsFloat(r1)));
         m.insert(("nonvar", 1), ClauseType::Inlined(InlinedClauseType::IsNonVar(r1)));
         m.insert(("var", 1), ClauseType::Inlined(InlinedClauseType::IsVar(r1)));
@@ -140,7 +138,6 @@ impl InlinedClauseType {
             &InlinedClauseType::IsCompound(..) => "compound",
             &InlinedClauseType::IsInteger(..) => "integer",
             &InlinedClauseType::IsRational(..) => "rational",
-            &InlinedClauseType::IsString(..) => "string",
             &InlinedClauseType::IsFloat(..) => "float",
             &InlinedClauseType::IsNonVar(..) => "nonvar",
             &InlinedClauseType::IsVar(..) => "var",
index 35430cef2ce9ee402c4a5bdc74b8b8f41ffbc17a..34d5a1f2b59d8f129906aa78e4eec3a890f55add 100644 (file)
@@ -443,18 +443,6 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker> {
                     code.push(fail!());
                 }
             },
-            &InlinedClauseType::IsString(..) => match terms[0].as_ref() {
-                &Term::Constant(_, Constant::String(..)) => {
-                    code.push(succeed!());
-                }
-                &Term::Var(ref vr, ref name) => {
-                    let r = self.mark_non_callable(name.clone(), 1, term_loc, vr, code);
-                    code.push(is_string!(r));
-                }
-                _ => {
-                    code.push(fail!());
-                }
-            },
             &InlinedClauseType::IsNonVar(..) => match terms[0].as_ref() {
                 &Term::AnonVar => {
                     code.push(fail!());
index 79c84bdf95b77a2a5f946fd8d720c32d6df8f011..52d4e757ded74b4f56fef9787519d52ea05aec24 100644 (file)
@@ -2364,14 +2364,16 @@ impl MachineState {
         Some(iter.first_to_expire)
     }
 
-    pub(super) fn reset_block(&mut self, addr: Addr) {
+    pub(super)
+    fn reset_block(&mut self, addr: Addr) {
         match self.store(addr) {
             Addr::Usize(b) => self.block = b,
             _ => self.fail = true,
         };
     }
 
-    pub(super) fn execute_inlined(&mut self, inlined: &InlinedClauseType) {
+    pub(super)
+    fn execute_inlined(&mut self, inlined: &InlinedClauseType) {
         match inlined {
             &InlinedClauseType::CompareNumber(cmp, ref at_1, ref at_2) => {
                 let n1 = try_or_fail!(self, self.get_number(at_1));
@@ -2466,14 +2468,6 @@ impl MachineState {
                     }
                 };
             }
-            &InlinedClauseType::IsString(r1) => {
-                let d = self.store(self.deref(self[r1]));
-
-                match d {
-                    Addr::PStrLocation(..) => self.p += 1,
-                    _ => self.fail = true,
-                };
-            }
             &InlinedClauseType::IsNonVar(r1) => {
                 let d = self.store(self.deref(self[r1]));
 
index b6e81a0930cf26a69d3e1ea89349c54f5b2f9e8b..9083e275112fcf9dea8a5f2673a29f512f88b850 100644 (file)
@@ -1196,15 +1196,20 @@ impl MachineState {
                 }
             }
             &SystemClauseType::IsPartialString => {
-                let pstr = self.store(self.deref(self[temp_v!(1)]));
+                let mut heap_pstr_iter = self.heap_pstr_iter(self[temp_v!(1)]);
 
-                match pstr {
-                    Addr::PStrLocation(..) => {
-                    }
-                    _ => {
-                        self.fail = true;
-                    }
-                }
+                while let Some(_) = heap_pstr_iter.next() {}
+
+                self.fail =
+                    match heap_pstr_iter.focus() {
+                        Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(..) |
+                        Addr::EmptyList => {
+                            false
+                        }
+                        _ => {
+                            true
+                        }
+                    };
             }
             &SystemClauseType::PartialStringTail => {
                 let pstr = self.store(self.deref(self[temp_v!(1)]));
index dda7d4ba8b7e7ec27fb34c60b25717ca2404ff0a..834ad9f8a2cbbb9919ab1cd6f11355f9c72caf49 100644 (file)
@@ -225,12 +225,6 @@ macro_rules! is_nonvar {
     };
 }
 
-macro_rules! is_string {
-    ($r:expr) => {
-        call_clause!(ClauseType::Inlined(InlinedClauseType::IsString($r)), 1, 0)
-    };
-}
-
 macro_rules! is_var {
     ($r:expr) => {
         call_clause!(ClauseType::Inlined(InlinedClauseType::IsVar($r)), 1, 0)