visitDoStmt method

  1. @override
Uint8List visitDoStmt(
  1. DoStmt stmt
)
override

Implementation

@override
Uint8List visitDoStmt(DoStmt stmt) {
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(_lineInfo(stmt.line, stmt.column));
  bytesBuilder.addByte(HTOpCode.loopPoint);
  final loop = compileAST(stmt.loop);
  Uint8List? condition;
  if (stmt.condition != null) {
    condition = compileAST(stmt.condition!);
  }
  final loopLength = loop.length + (condition?.length ?? 0) + 2;
  bytesBuilder.add(_uint16(0)); // while loop continue ip
  bytesBuilder.add(_uint16(loopLength)); // while loop break ip
  bytesBuilder.add(loop);
  if (condition != null) {
    bytesBuilder.add(condition);
    bytesBuilder.addByte(HTOpCode.doStmt);
    bytesBuilder.addByte(1); // bool: has condition
  } else {
    bytesBuilder.addByte(HTOpCode.doStmt);
    bytesBuilder.addByte(0); // bool: has condition
  }
  return bytesBuilder.toBytes();
}