visitUnaryPrefixExpr method
-e, !e,++e, --e
Implementation
@override
Uint8List visitUnaryPrefixExpr(UnaryPrefixExpr expr) {
final bytesBuilder = BytesBuilder();
final value = compileAST(expr.object);
if (expr.op == _lexicon.negative) {
bytesBuilder.add(value);
bytesBuilder.addByte(HTOpCode.negative);
} else if (expr.op == _lexicon.logicalNot) {
bytesBuilder.add(value);
bytesBuilder.addByte(HTOpCode.logicalNot);
} else if (expr.op == _lexicon.preIncrement) {
final constOne = ASTLiteralInteger(1);
late final ASTNode value;
final add = BinaryExpr(expr.object, _lexicon.add, constOne);
value = AssignExpr(expr.object, _lexicon.assign, add);
final group = GroupExpr(value);
final bytes = compileAST(group);
bytesBuilder.add(bytes);
} else if (expr.op == _lexicon.preDecrement) {
final constOne = ASTLiteralInteger(1);
late final ASTNode value;
final subtract = BinaryExpr(expr.object, _lexicon.subtract, constOne);
value = AssignExpr(expr.object, _lexicon.assign, subtract);
final group = GroupExpr(value);
final bytes = compileAST(group);
bytesBuilder.add(bytes);
} else if (expr.op == _lexicon.kTypeof) {
bytesBuilder.add(value);
bytesBuilder.addByte(HTOpCode.typeOf);
} else if (expr.op == _lexicon.kAwait) {
bytesBuilder.add(value);
bytesBuilder.addByte(HTOpCode.awaitedValue);
}
return bytesBuilder.toBytes();
}