8000 rune: Avoid clobbering unary expressions (fixes #838) · rune-rs/rune@8894eab · GitHub
[go: up one dir, main page]

Skip to content

Commit 8894eab

Browse files
committed
rune: Avoid clobbering unary expressions (fixes #838)
1 parent 71fe1c9 commit 8894eab

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

crates/rune/src/compile/v1/assemble.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,18 +2920,16 @@ fn expr_unary<'a, 'hir>(
29202920
span: &'hir dyn Spanned,
29212921
needs: &mut dyn Needs<'a, 'hir>,
29222922
) -> compile::Result<Asm<'hir>> {
2923-
converge!(expr(cx, &hir.expr, needs)?);
2924-
2925-
let Some(addr) = needs.try_as_addr()? else {
2926-
return Ok(Asm::new(span, ()));
2927-
};
2923+
let mut addr = cx.scopes.defer(span);
2924+
converge!(expr(cx, &hir.expr, &mut addr)?, free(addr));
2925+
let addr = addr.into_addr()?;
29282926

29292927
match hir.op {
29302928
ast::UnOp::Not(..) => {
29312929
cx.asm.push(
29322930
Inst::Not {
29332931
addr: addr.addr(),
2934-
out: addr.output(),
2932+
out: needs.alloc_output()?,
29352933
},
29362934
span,
29372935
)?;
@@ -2940,7 +2938,7 @@ fn expr_unary<'a, 'hir>(
29402938
cx.asm.push(
29412939
Inst::Neg {
29422940
addr: addr.addr(),
2943-
out: addr.output(),
2941+
out: needs.alloc_output()?,
29442942
},
29452943
span,
29462944
)?;
@@ -2953,6 +2951,7 @@ fn expr_unary<'a, 'hir>(
29532951
}
29542952
}
29552953

2954+
addr.free()?;
29562955
Ok(Asm::new(span, ()))
29572956
}
29582957

0 commit comments

Comments
 (0)
0