Skip to content

Commit

Permalink
rune: Avoid clobbering unary expressions (fixes #838)
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 26, 2024
1 parent 7365e7c commit 680e732
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions crates/rune/src/compile/v1/assemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2920,18 +2920,16 @@ fn expr_unary<'a, 'hir>(
span: &'hir dyn Spanned,
needs: &mut dyn Needs<'a, 'hir>,
) -> compile::Result<Asm<'hir>> {
converge!(expr(cx, &hir.expr, needs)?);

let Some(addr) = needs.try_as_addr()? else {
return Ok(Asm::new(span, ()));
};
let mut addr = cx.scopes.defer(span);
converge!(expr(cx, &hir.expr, &mut addr)?, free(addr));
let addr = addr.into_addr()?;

match hir.op {
ast::UnOp::Not(..) => {
cx.asm.push(
Inst::Not {
addr: addr.addr(),
out: addr.output(),
out: needs.alloc_output()?,
},
span,
)?;
Expand All @@ -2940,7 +2938,7 @@ fn expr_unary<'a, 'hir>(
cx.asm.push(
Inst::Neg {
addr: addr.addr(),
out: addr.output(),
out: needs.alloc_output()?,
},
span,
)?;
Expand All @@ -2953,6 +2951,7 @@ fn expr_unary<'a, 'hir>(
}
}

addr.free()?;
Ok(Asm::new(span, ()))
}

Expand Down

0 comments on commit 680e732

Please sign in to comment.