nodes: 0, module; 1, function_definition; 2, function_name:percolate_declares; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, identifier:Program; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, expression_statement; 14, return_statement; 15, identifier:program; 16, type; 17, comment:"""
      Move all the DECLARE statements to the top of the program. Return a fresh obejct.
  
      :param program: Perhaps jumbled program.
      :return: Program with DECLAREs all at the top and otherwise the same sorted contents.
      """; 18, assignment; 19, assignment; 20, identifier:instr; 21, identifier:program; 22, block; 23, assignment; 24, assignment; 25, identifier:p; 26, identifier:Program; 27, identifier:declare_program; 28, call; 29, identifier:instrs_program; 30, call; 31, if_statement; 32, identifier:p; 33, binary_operator:declare_program + instrs_program; 34, attribute; 35, attribute; 36, identifier:Program; 37, argument_list; 38, identifier:Program; 39, argument_list; 40, call; 41, block; 42, else_clause; 43, identifier:declare_program; 44, identifier:instrs_program; 45, identifier:p; 46, identifier:_defined_gates; 47, identifier:program; 48, identifier:_defined_gates; 49, identifier:isinstance; 50, argument_list; 51, expression_statement; 52, block; 53, identifier:instr; 54, identifier:Declare; 55, augmented_assignment; 56, expression_statement; 57, identifier:declare_program; 58, identifier:instr; 59, augmented_assignment; 60, identifier:instrs_program; 61, identifier:instr
code: def percolate_declares(program: Program) -> Program:
      """
      Move all the DECLARE statements to the top of the program. Return a fresh obejct.
  
      :param program: Perhaps jumbled program.
      :return: Program with DECLAREs all at the top and otherwise the same sorted contents.
      """
      declare_program = Program()
      instrs_program = Program()
  
      for instr in program:
          if isinstance(instr, Declare):
              declare_program += instr
          else:
              instrs_program += instr
  
      p = declare_program + instrs_program
      p._defined_gates = program._defined_gates
  
      return p