nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:expr; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, if_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, identifier:field; 19, None; 20, identifier:keytype; 21, None; 22, identifier:ascending; 23, True; 24, comment:"""
      Sorts the vector.
      If the field parameter is provided then the sort
      operators on a vector of structs where the sort key
      is the field of the struct.
  
      Args:
        expr (WeldObject)
        field (Int)
      """; 25, assignment; 26, assignment; 27, call; 28, block; 29, comparison_operator:field is not None; 30, block; 31, else_clause; 32, not_operator; 33, comment:# The type is not necessarily f64.; 34, block; 35, assignment; 36, assignment; 37, identifier:weld_obj; 38, identifier:weld_obj; 39, call; 40, identifier:expr_var; 41, call; 42, identifier:isinstance; 43, argument_list; 44, expression_statement; 45, expression_statement; 46, identifier:field; 47, None; 48, expression_statement; 49, block; 50, identifier:ascending; 51, expression_statement; 52, identifier:weld_template; 53, comment:"""
      sort(%(expr)s, |x| %(key)s)
      """; 54, attribute; 55, binary_operator:weld_template % {"expr":expr_var, "key":key_str}; 56, identifier:WeldObject; 57, argument_list; 58, attribute; 59, argument_list; 60, identifier:expr; 61, identifier:WeldObject; 62, assignment; 63, assignment; 64, assignment; 65, expression_statement; 66, assignment; 67, identifier:weld_obj; 68, identifier:weld_code; 69, identifier:weld_template; 70, dictionary; 71, identifier:encoder_; 72, identifier:decoder_; 73, identifier:weld_obj; 74, identifier:update; 75, identifier:expr; 76, identifier:expr_var; 77, attribute; 78, subscript; 79, identifier:expr; 80, identifier:key_str; 81, binary_operator:"x.$%s" % field; 82, assignment; 83, identifier:key_str; 84, binary_operator:key_str + "* %s(-1)" % keytype; 85, pair; 86, pair; 87, identifier:expr; 88, identifier:obj_id; 89, attribute; 90, identifier:expr_var; 91, string:"x.$%s"; 92, identifier:field; 93, identifier:key_str; 94, string:"x"; 95, identifier:key_str; 96, binary_operator:"* %s(-1)" % keytype; 97, string:"expr"; 98, identifier:expr_var; 99, string:"key"; 100, identifier:key_str; 101, identifier:weld_obj; 102, identifier:dependencies; 103, string:"* %s(-1)"; 104, identifier:keytype
code: def sort(expr, field = None, keytype=None, ascending=True):
      """
      Sorts the vector.
      If the field parameter is provided then the sort
      operators on a vector of structs where the sort key
      is the field of the struct.
  
      Args:
        expr (WeldObject)
        field (Int)
      """
      weld_obj = WeldObject(encoder_, decoder_)
  
      expr_var = weld_obj.update(expr)
      if isinstance(expr, WeldObject):
          expr_var = expr.obj_id
          weld_obj.dependencies[expr_var] = expr
  
      if field is not None:
          key_str = "x.$%s" % field
      else:
          key_str = "x"
  
      if not ascending:
          # The type is not necessarily f64.
          key_str = key_str + "* %s(-1)" % keytype
  
      weld_template = """
      sort(%(expr)s, |x| %(key)s)
      """
      weld_obj.weld_code = weld_template % {"expr":expr_var, "key":key_str}
      return weld_obj