visitUnaryPostfixExpr method

  1. @override
Uint8List visitUnaryPostfixExpr(
  1. UnaryPostfixExpr expr
)
override

Implementation

@override
Uint8List visitUnaryPostfixExpr(UnaryPostfixExpr expr) {
  final bytesBuilder = BytesBuilder();
  final value = compileAST(expr.object);
  bytesBuilder.add(value);
  bytesBuilder.addByte(HTOpCode.register);
  bytesBuilder.addByte(HTRegIdx.postfixObject);
  if (expr.op == _lexicon.postIncrement) {
    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 subtract = BinaryExpr(group, _lexicon.subtract, constOne);
    final group2 = GroupExpr(subtract);
    final bytes = compileAST(group2);
    bytesBuilder.add(bytes);
  } else if (expr.op == _lexicon.postDecrement) {
    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 add = BinaryExpr(group, _lexicon.add, constOne);
    final group2 = GroupExpr(add);
    final bytes = compileAST(group2);
    bytesBuilder.add(bytes);
  }
  return bytesBuilder.toBytes();
}