From: Mark Date: Tue, 29 Aug 2023 21:26:08 +0000 (-0600) Subject: don't compile is instruction if bound to anonymous variable (#1974) X-Git-Tag: remove~121 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=53a1be78cc2cc90af7f20989fa05c5e518c07bf8;p=scryer-prolog.git don't compile is instruction if bound to anonymous variable (#1974) --- diff --git a/src/codegen.rs b/src/codegen.rs index 7d4b92d3..f69fa2a9 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -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::( - 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::( + 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) }