code: def sort(expr, field = None, keytype=None, ascending=True):
      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:
          key_str = key_str + "* %s(-1)" % keytype
      weld_template =
      weld_obj.weld_code = weld_template % {"expr":expr_var, "key":key_str}
      return weld_obj