Example #1
0
File: proc.c Project: kmasa/mruby
static mrb_value
mrb_proc_inspect(mrb_state *mrb, mrb_value self)
{
    struct RProc *p = mrb_proc_ptr(self);
    mrb_value str = mrb_str_new_lit(mrb, "#<Proc:");
    mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(self)));

    if (!MRB_PROC_CFUNC_P(p)) {
        mrb_irep *irep = p->body.irep;
        mrb_str_cat_lit(mrb, str, "@");

        if (irep->filename) {
            mrb_str_cat_cstr(mrb, str, irep->filename);
        }
        else {
            mrb_str_cat_lit(mrb, str, "-");
        }
        mrb_str_cat_lit(mrb, str, ":");

        if (irep->lines) {
            mrb_str_append(mrb, str, mrb_fixnum_value(*irep->lines));
        }
        else {
            mrb_str_cat_lit(mrb, str, "-");
        }
    }

    if (MRB_PROC_STRICT_P(p)) {
        mrb_str_cat_lit(mrb, str, " (lambda)");
    }

    mrb_str_cat_lit(mrb, str, ">");
    return str;
}
Example #2
0
static mrb_value
mrb_proc_inspect(mrb_state *mrb, mrb_value self)
{
  struct RProc *p = mrb_proc_ptr(self);
  mrb_value str = mrb_str_new_lit(mrb, "#<Proc:");
  mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(self)));

  if (!MRB_PROC_CFUNC_P(p)) {
    mrb_irep *irep = p->body.irep;
    const char *filename;
    int32_t line;
    mrb_str_cat_lit(mrb, str, "@");

    filename = mrb_debug_get_filename(irep, 0);
    mrb_str_cat_cstr(mrb, str, filename ? filename : "-");
    mrb_str_cat_lit(mrb, str, ":");

    line = mrb_debug_get_line(irep, 0);
    if (line != -1) {
      mrb_str_append(mrb, str, mrb_fixnum_value(line));
    }
    else {
      mrb_str_cat_lit(mrb, str, "-");
    }
  }

  if (MRB_PROC_STRICT_P(p)) {
    mrb_str_cat_lit(mrb, str, " (lambda)");
  }

  mrb_str_cat_lit(mrb, str, ">");
  return str;
}
Example #3
0
static mrb_value
mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
{
  mrb_value str;

  if (mrb_type(klass) == MRB_TT_SCLASS) {
    mrb_value v = mrb_iv_get(mrb, klass, mrb_intern2(mrb, "__attached__", 12));

    str = mrb_str_new(mrb, "#<Class:", 8);

    switch (mrb_type(v)) {
      case MRB_TT_CLASS:
      case MRB_TT_MODULE:
      case MRB_TT_SCLASS:
        mrb_str_append(mrb, str, mrb_inspect(mrb, v));
        break;
      default:
        mrb_str_append(mrb, str, mrb_any_to_s(mrb, v));
        break;
    }
    mrb_str_cat(mrb, str, ">", 1);
  }
  else {
    struct RClass *c;
    mrb_value path;

    str = mrb_str_buf_new(mrb, 32);
    c = mrb_class_ptr(klass);
    path = mrb_class_path(mrb, c);

    if (mrb_nil_p(path)) {
      switch (mrb_type(klass)) {
        case MRB_TT_CLASS:
          mrb_str_cat(mrb, str, "#<Class:", 8);
          break;

        case MRB_TT_MODULE:
          mrb_str_cat(mrb, str, "#<Module:", 9);
          break;

        default:
          /* Shouldn't be happened? */
          mrb_str_cat(mrb, str, "#<??????:", 9);
          break;
      }
      mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, c));
      mrb_str_cat(mrb, str, ">", 1);
    }
    else {
      str = path;
    }
  }

  return str;
}
Example #4
0
const char*
mrb_class_name(mrb_state *mrb, struct RClass* c)
{
  mrb_value path = mrb_class_path(mrb, c);
  if (mrb_nil_p(path)) {
    path = mrb_str_new(mrb, "#<Class:", 8);
    mrb_str_concat(mrb, path, mrb_ptr_to_str(mrb, c));
    mrb_str_cat(mrb, path, ">", 1);
  }
  return mrb_str_ptr(path)->ptr;
}
Example #5
0
mrb_value
mrb_any_to_s(mrb_state *mrb, mrb_value obj)
{
  mrb_value str = mrb_str_buf_new(mrb, 20);
  const char *cname = mrb_obj_classname(mrb, obj);

  mrb_str_buf_cat(mrb, str, "#<", 2);
  mrb_str_cat2(mrb, str, cname);
  mrb_str_cat(mrb, str, ":", 1);
  mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(obj)));
  mrb_str_buf_cat(mrb, str, ">", 1);

  return str;
}
Example #6
0
mrb_value
mrb_obj_iv_inspect(mrb_state *mrb, struct RObject *obj)
{
    iv_tbl *t = obj->iv;
    size_t len = iv_size(mrb, t);

    if (len > 0) {
        const char *cn = mrb_obj_classname(mrb, mrb_obj_value(obj));
        mrb_value str = mrb_str_buf_new(mrb, 30);

        mrb_str_buf_cat(mrb, str, "-<", 2);
        mrb_str_cat2(mrb, str, cn);
        mrb_str_cat(mrb, str, ":", 1);
        mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, obj));

        iv_foreach(mrb, t, inspect_i, &str);
        mrb_str_cat(mrb, str, ">", 1);
        return str;
    }
    return mrb_any_to_s(mrb, mrb_obj_value(obj));
}
Example #7
0
static mrb_value
mrb_grn_expr_code_inspect(mrb_state *mrb, mrb_value self)
{
  grn_ctx *ctx = (grn_ctx *)mrb->ud;
  grn_expr_code *code;
  mrb_value inspected;

  code = DATA_PTR(self);

  inspected = mrb_str_buf_new(mrb, 48);

  mrb_str_cat_lit(mrb, inspected, "#<");
  mrb_str_cat_cstr(mrb, inspected, mrb_obj_classname(mrb, self));
  mrb_str_cat_lit(mrb, inspected, ":");
  mrb_str_concat(mrb, inspected, mrb_ptr_to_str(mrb, mrb_cptr(self)));

  {
    int32_t weight;
    uint32_t offset;

    weight = grn_expr_code_get_weight(ctx, DATA_PTR(self), &offset);

    mrb_str_cat_lit(mrb, inspected, " weight=");
    mrb_str_concat(mrb, inspected,
                   mrb_funcall(mrb,
                               mrb_fixnum_value(weight),
                               "inspect",
                               0));
    mrb_str_cat_lit(mrb, inspected, ", offset=");
    mrb_str_concat(mrb, inspected,
                   mrb_funcall(mrb,
                               mrb_fixnum_value(offset),
                               "inspect",
                               0));
  }

  mrb_str_cat_lit(mrb, inspected, ", modify=");
  mrb_str_concat(mrb, inspected,
                 mrb_funcall(mrb,
                             mrb_fixnum_value(code->modify),
                             "inspect",
                             0));

  mrb_str_cat_lit(mrb, inspected, ", op=");
  mrb_str_concat(mrb, inspected,
                 mrb_funcall(mrb,
                             grn_mrb_value_from_operator(mrb, code->op),
                             "inspect",
                             0));

  mrb_str_cat_lit(mrb, inspected, ", flags=");
  mrb_str_concat(mrb, inspected,
                 mrb_funcall(mrb,
                             mrb_fixnum_value(code->flags),
                             "inspect",
                             0));

  mrb_str_cat_lit(mrb, inspected, ", value=");
  mrb_str_concat(mrb, inspected,
                 mrb_funcall(mrb,
                             grn_mrb_value_from_grn_obj(mrb, code->value),
                             "inspect",
                             0));

  mrb_str_cat_lit(mrb, inspected, ">");

  return inspected;
}