Skip to content

Commit 05dc447

Browse files
committed
feat(compiler): Generate Dec opcode when subracting by one
1 parent 3f8a996 commit 05dc447

File tree

1 file changed

+14
-4
lines changed
  • core/engine/src/bytecompiler/expression

1 file changed

+14
-4
lines changed

core/engine/src/bytecompiler/expression/binary.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use crate::{
44
};
55
use boa_ast::{
66
Expression,
7-
expression::operator::{
8-
Binary, BinaryInPrivate,
9-
binary::{ArithmeticOp, BinaryOp, BitwiseOp, LogicalOp, RelationalOp},
7+
expression::{
8+
literal::LiteralKind,
9+
operator::{
10+
Binary, BinaryInPrivate,
11+
binary::{ArithmeticOp, BinaryOp, BitwiseOp, LogicalOp, RelationalOp},
12+
},
1013
},
1114
};
1215

@@ -15,7 +18,14 @@ impl ByteCompiler<'_> {
1518
match binary.op() {
1619
BinaryOp::Arithmetic(op) => {
1720
self.compile_expr_operand(binary.lhs(), |self_, lhs| {
18-
self_.compile_binary_arithmetic(op, binary.rhs(), dst, lhs);
21+
if op == ArithmeticOp::Sub
22+
&& let Expression::Literal(literal) = binary.rhs().flatten()
23+
&& let LiteralKind::Int(1) = literal.kind()
24+
{
25+
self_.bytecode.emit_dec(dst.variable(), lhs);
26+
} else {
27+
self_.compile_binary_arithmetic(op, binary.rhs(), dst, lhs);
28+
}
1929
});
2030
}
2131
BinaryOp::Bitwise(op) => {

0 commit comments

Comments
 (0)