]> Repositorios git - scryer-prolog.git/commitdiff
fix attempted bind to bound StackVar (#3089)
authorMark Thom <[email protected]>
Thu, 18 Sep 2025 02:43:37 +0000 (19:43 -0700)
committerMark Thom <[email protected]>
Thu, 18 Sep 2025 02:43:37 +0000 (19:43 -0700)
src/machine/dispatch.rs
src/types.rs

index 4d3c7666ca2f642ff5b105b910a2e6ed1f3c4188..c1b394c6aa1565f110fc3931c46df1eebce36986 100644 (file)
@@ -2802,6 +2802,28 @@ impl Machine {
                         let mut h = 0;
                         let mut string_cursor = string.as_str();
 
+                        if self.machine_st.heap[0].is_stack_var() {
+                            let cell = self
+                                .machine_st
+                                .store(self.machine_st.deref(self.machine_st.heap[0]));
+
+                            if let Some(r) = cell.as_var() {
+                                let target_cell = backtrack_on_resource_error!(
+                                    self.machine_st,
+                                    self.machine_st.heap.allocate_pstr(string_cursor)
+                                );
+
+                                self.machine_st.bind(r, target_cell);
+                                self.machine_st.mode = MachineMode::Write;
+
+                                debug_assert!(!self.machine_st.fail);
+
+                                continue;
+                            }
+
+                            self.machine_st.heap[0] = cell;
+                        }
+
                         while let Some(c) = string_cursor.chars().next() {
                             read_heap_cell!(self.machine_st.heap[h],
                                 (HeapCellValueTag::PStrLoc, pstr_loc) => {
@@ -2911,22 +2933,6 @@ impl Machine {
                                         h = v;
                                     }
                                 }
-                                (HeapCellValueTag::StackVar, s) => {
-                                    debug_assert_eq!(h, 0);
-
-                                    let target_cell = backtrack_on_resource_error!(
-                                        self.machine_st,
-                                        self.machine_st.heap.allocate_pstr(string_cursor)
-                                    );
-
-                                    self.machine_st.bind(
-                                        Ref::stack_cell(s),
-                                        target_cell,
-                                    );
-
-                                    self.machine_st.mode = MachineMode::Write;
-                                    break;
-                                }
                                 _ => {
                                     self.machine_st.fail = true;
                                     break;
index 5cd9591169681167e07bf30215f06cbcd59a4e90..97df4bc4d4d1fe40ab46c103d0dff65a43fc7ac8 100644 (file)
@@ -125,9 +125,9 @@ pub(crate) enum RefTag {
 pub struct Ref {
     val: B56,
     #[allow(unused)]
-    m: bool,
-    #[allow(unused)]
     f: bool,
+    #[allow(unused)]
+    m: bool,
     tag: RefTag,
 }