visitDestructuringDecl method

  1. @override
Uint8List visitDestructuringDecl(
  1. DestructuringDecl stmt
)
override

Implementation

@override
Uint8List visitDestructuringDecl(DestructuringDecl stmt) {
  final bytesBuilder = BytesBuilder();
  bytesBuilder.addByte(HTOpCode.destructuringDecl);
  bytesBuilder.addByte(stmt.isTopLevel ? 1 : 0);
  bytesBuilder.addByte(stmt.ids.length);
  for (final id in stmt.ids.keys) {
    bytesBuilder.add(_parseIdentifier(id.id));
    final typeExpr = stmt.ids[id];
    if (typeExpr != null) {
      bytesBuilder.addByte(1); // bool: has type decl
      final typeDecl = compileAST(typeExpr);
      bytesBuilder.add(typeDecl);
    } else {
      bytesBuilder.addByte(0); // bool: has type decl
    }
  }
  bytesBuilder.addByte(stmt.isVector ? 1 : 0);
  bytesBuilder.addByte(stmt.isMutable ? 1 : 0);
  final initializer = compileAST(stmt.initializer, endOfExec: true);
  bytesBuilder.add(initializer);
  bytesBuilder.addByte(HTOpCode.endOfStmt);
  return bytesBuilder.toBytes();
}