]> Repositorios git - scryer-prolog.git/commitdiff
fix cont function crashes (#2920)
authorMark Thom <[email protected]>
Tue, 29 Apr 2025 06:39:52 +0000 (23:39 -0700)
committerMark Thom <[email protected]>
Tue, 8 Jul 2025 05:38:12 +0000 (22:38 -0700)
src/machine/compile.rs
src/machine/machine_state.rs
src/machine/system_calls.rs

index 4f0fb1b64bb324575781da7324d1bf211cc6cc01..1b2f6bffb980cf77ea389d504754ac3bc98462d1 100644 (file)
@@ -1261,10 +1261,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         let code_len = self.wam_prelude.code.len();
         let mut code_ptr = code_len;
 
-        if key == (atom!("..."), 2) {
-            print!("");
-        }
-
         let mut clauses = vec![];
         let mut preprocessor = Preprocessor::new(settings);
 
index 7c8f1abe1bff3cf617c41c0402ad7198481e564d..941d9f4d86b01e8c10aa0620a700308ce4b5c913 100644 (file)
@@ -186,26 +186,8 @@ impl IndexMut<RegType> for MachineState {
 
 pub type CallResult = Result<(), Vec<FunctorElement>>;
 
-/*
-#[inline(always)]
-pub fn pstr_loc_and_offset(heap: &[HeapCellValue], index: usize) -> (usize, Fixnum) {
-    read_heap_cell!(heap[index],
-        (HeapCellValueTag::PStr | HeapCellValueTag::CStr) => {
-            (index, Fixnum::build_with(0))
-        }
-        (HeapCellValueTag::PStrOffset, h) => {
-            (h, cell_as_fixnum!(heap[index+1]))
-        }
-        _ => {
-            unreachable!()
-        }
-    )
-}
-*/
-
 // size may be an upper bound.
 // true_size is calculated to compute the exact offset.
-
 fn push_var_eq_functors<'a>(
     heap: &mut Heap,
     size: usize,
index d47b36e90b68c5132fbd9d680499a464eea94b92..6875edfbb91659e119417f7995bcf00eaf96432c 100644 (file)
@@ -5711,7 +5711,6 @@ impl Machine {
 
                 if addr.get_tag() == HeapCellValueTag::StackVar {
                     section.push_cell(heap_loc_as_cell!(h + 1 + idx));
-
                     self.machine_st.stack[stack_offset] = heap_loc_as_cell!(h + 1 + idx);
 
                     // have to inline the TrailRef::Ref(RefTag::StackCell) case of MachineState::trail
@@ -5730,7 +5729,7 @@ impl Machine {
             }
         });
 
-        let chunk = str_loc_as_cell!(self.machine_st.heap.cell_len());
+        let chunk = str_loc_as_cell!(h);
         unify!(self.machine_st, self.machine_st.registers[3], chunk);
     }
 
@@ -6317,13 +6316,13 @@ impl Machine {
             let e = and_frame.prelude.e;
             let e = Fixnum::build_with(i64::try_from(e).unwrap());
 
-            let mut writer = Heap::functor_writer(functor!(atom!("dir_entry"), [fixnum(cp)]));
-
-            let p_functor_cell = step_or_resource_error!(machine_st, writer(&mut machine_st.heap));
-
             machine_st.unify_fixnum(e, machine_st.registers[2]);
 
             if !machine_st.fail {
+                let mut writer = Heap::functor_writer(functor!(atom!("dir_entry"), [fixnum(cp)]));
+                let p_functor_cell =
+                    step_or_resource_error!(machine_st, writer(&mut machine_st.heap));
+
                 unify!(machine_st, p_functor_cell, machine_st.registers[3]);
             }
         };
@@ -6350,6 +6349,12 @@ impl Machine {
                 // active permanent variables can be read from
                 // it later.
                 let and_frame = self.machine_st.stack.index_and_frame(e);
+
+                if and_frame.prelude.cp == 0 {
+                    self.machine_st.fail = true;
+                    return;
+                }
+
                 let cp = and_frame.prelude.cp - 1;
                 let mut writer = Heap::functor_writer(functor!(atom!("dir_entry"), [fixnum(cp)]));