]> Repositorios git - scryer-prolog.git/commitdiff
fix additional tests (#2293)
authorMark <[email protected]>
Sat, 13 Jan 2024 05:01:01 +0000 (22:01 -0700)
committerMark <[email protected]>
Sat, 13 Jan 2024 05:01:01 +0000 (22:01 -0700)
src/machine/unify.rs

index 6415c8f15097f625938fe8e4e7554f850bed24f8..91845887f11f8b85e9cb207edcdb635c5e543e72 100644 (file)
@@ -229,39 +229,32 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
                                     break 'outer;
                                 }
                             }
-                            (HeapCellValueTag::CStr, cstr) => {
-                                let cstr_str = cstr.as_str();
-                                let mut cstr_chars_iter = cstr_str.chars();
-                                let mut char_len = 0;
-
-                                while let Some(c) = chars_iter.next() {
-                                    if Some(c) != cstr_chars_iter.next() {
-                                        machine_st.fail = true;
-                                        break 'outer;
-                                    }
-
-                                    char_len += c.len_utf8();
-                                }
+                            (HeapCellValueTag::CStr | HeapCellValueTag::PStrLoc) => {
+                                machine_st.pdl.push(focus);
 
-                                let chars_iter_focus = chars_iter.iter.focus;
+                                match chars_iter.item.unwrap() {
+                                    PStrIteratee::Char(focus, _) |
+                                    PStrIteratee::PStrSegment(focus, _, 0) => {
+                                        machine_st.pdl.push(machine_st.heap[focus]);
 
-                                machine_st.heap.pop();
-                                machine_st.heap.pop();
+                                        machine_st.heap.pop();
+                                        machine_st.heap.pop();
+                                    }
+                                    PStrIteratee::PStrSegment(focus, _, n) => {
+                                        let segment = machine_st.heap[focus];
 
-                                let pstr_loc = if cstr_str.len() > char_len {
-                                    let h = machine_st.heap.len();
+                                        machine_st.heap.pop();
+                                        machine_st.heap.pop();
 
-                                    machine_st.heap.push(string_as_cstr_cell!(cstr));
-                                    machine_st.heap.push(pstr_offset_as_cell!(h));
-                                    machine_st.heap.push(fixnum_as_cell!(Fixnum::build_with(char_len as i64)));
+                                        let h = machine_st.heap.len();
 
-                                    pstr_loc_as_cell!(h+1)
-                                } else {
-                                    empty_list_as_cell!()
-                                };
+                                        machine_st.pdl.push(pstr_loc_as_cell!(h+1));
 
-                                machine_st.pdl.push(chars_iter_focus);
-                                machine_st.pdl.push(pstr_loc);
+                                        machine_st.heap.push(segment);
+                                        machine_st.heap.push(pstr_offset_as_cell!(h));
+                                        machine_st.heap.push(fixnum_as_cell!(Fixnum::build_with(n as i64)));
+                                    }
+                                }
 
                                 return;
                             }