From d6b6eda77d5d31ec0564d05434c14bb9ab37c7c4 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 28 Apr 2025 23:39:52 -0700 Subject: [PATCH] fix cont function crashes (#2920) --- src/machine/compile.rs | 4 ---- src/machine/machine_state.rs | 18 ------------------ src/machine/system_calls.rs | 17 +++++++++++------ 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/machine/compile.rs b/src/machine/compile.rs index 4f0fb1b6..1b2f6bff 100644 --- a/src/machine/compile.rs +++ b/src/machine/compile.rs @@ -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); diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index 7c8f1abe..941d9f4d 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -186,26 +186,8 @@ impl IndexMut for MachineState { pub type CallResult = Result<(), Vec>; -/* -#[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, diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index d47b36e9..6875edfb 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -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)])); -- 2.54.0