]> Repositorios git - scryer-prolog.git/commitdiff
don't compile is instruction if bound to anonymous variable (#1974)
authorMark <[email protected]>
Tue, 29 Aug 2023 21:26:08 +0000 (15:26 -0600)
committerMark <[email protected]>
Tue, 29 Aug 2023 21:50:04 +0000 (15:50 -0600)
src/codegen.rs

index 7d4b92d39e80a523201ee7af5da39927e8d9c1e7..f69fa2a9ba8240b6e568883fe804e279df3bb60b 100644 (file)
@@ -804,15 +804,27 @@ impl<'b> CodeGenerator<'b> {
             &Term::Var(ref vr, ref name) => {
                 let var_num = name.to_var_num().unwrap();
 
-                self.marker.mark_var::<QueryInstruction>(
-                    var_num,
-                    Level::Shallow,
-                    vr,
-                    term_loc,
-                    code,
-                );
-
-                self.marker.mark_safe_var_unconditionally(var_num);
+                if self.marker.var_data.records[var_num].num_occurrences > 1 {
+                    self.marker.mark_var::<QueryInstruction>(
+                        var_num,
+                        Level::Shallow,
+                        vr,
+                        term_loc,
+                        code,
+                    );
+
+                    self.marker.mark_safe_var_unconditionally(var_num);
+                } else {
+                    if self.marker.in_tail_position {
+                        if self.marker.var_data.allocates {
+                            code.push_back(instr!("deallocate"));
+                        }
+
+                        code.push_back(instr!("proceed"));
+                    }
+
+                    return Ok(());
+                }
 
                 compile_expr!(self, &terms[1], term_loc, code)
             }