コード例 #1
0
ファイル: range.c プロジェクト: anandkumaragrawal/mruby
mrb_value
mrb_range_eq(mrb_state *mrb, mrb_value range)
{
  struct RRange *rr;
  struct RRange *ro;
  mrb_value obj;

  mrb_get_args(mrb, "o", &obj);

  if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();

  /* same class? */
  //  if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
  if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range)))
    return mrb_false_value();

  rr = mrb_range_ptr(range);
  ro = mrb_range_ptr(obj);
  if (!mrb_obj_equal(mrb, rr->edges->beg, ro->edges->beg))
    return mrb_false_value();
  if (!mrb_obj_equal(mrb, rr->edges->end, ro->edges->end))
    return mrb_false_value();
  if (rr->excl != ro->excl)
    return mrb_false_value();

  return mrb_true_value();
}
コード例 #2
0
void mrb_http2_config_define_flag(mrb_state *mrb, mrb_value args,
    mrb_http2_config_flag *config_flag, void (*func_ptr)(), const char *key)
{
  mrb_value val = mrb_http2_config_get_obj_cstr(mrb, args, key);

  if (func_ptr != NULL) {
    (*func_ptr)(mrb, args, config_flag, val);
  } else {
    if (!mrb_nil_p(val) && mrb_obj_equal(mrb, val, mrb_true_value())) {
      *config_flag = MRB_HTTP2_CONFIG_ENABLED;
    } else if (!mrb_nil_p(val) && mrb_obj_equal(mrb, val, mrb_false_value())) {
      *config_flag = MRB_HTTP2_CONFIG_DISABLED;
    }
  }
}
コード例 #3
0
static mrb_value
mrb_uefi_pointer_initialize_copy(mrb_state *mrb, mrb_value copy)
{
    mrb_value src;
    struct MRB_UEFI_POINTER_DATA *pd;

    mrb_get_args(mrb, "o", &src);

    if (mrb_obj_equal(mrb, copy, src)){
        return copy;
    }
    if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))){
        mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }
    if (DATA_PTR(copy)){
        pd = (struct MRB_UEFI_POINTER_DATA *)mrb_get_datatype(mrb, copy, &mrb_uefi_pointer_type);
    }else{
        pd = mrb_uefi_pointer_alloc(mrb, NULL);
        DATA_PTR(copy) = pd;
        DATA_TYPE(copy) = &mrb_uefi_pointer_type;
    }
    if (!pd){
        mrb_raise(mrb, E_RUNTIME_ERROR, "allocation error");
    }
    pd->pointer = ((struct MRB_UEFI_POINTER_DATA *)DATA_TYPE(src))->pointer;
    return copy;
}
コード例 #4
0
ファイル: array.c プロジェクト: galois17/mruby
static mrb_value
mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_obj_equal(mrb, ary1,ary2)) return mrb_true_value();
  if (mrb_type(ary2) != MRB_TT_ARRAY) {
    if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) {
        return mrb_false_value();
    }
    if (mrb_equal(mrb, ary2, ary1)){
      return mrb_true_value();
    }
    else {
      return mrb_false_value();
    }
  }
  if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
  else {
    int i;

    for (i=0; i<RARRAY_LEN(ary1); i++) {
      if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i)))
        return mrb_false_value();
    }
    return mrb_true_value();
  }
}
コード例 #5
0
ファイル: error.cpp プロジェクト: Prashant-Jonny/red_tint
static mrb_value exc_equal(mrb_state *mrb, mrb_value exc)
{
    mrb_value mesg;
    mrb_bool equal_p;
    mrb_sym id_mesg = mrb_intern(mrb, "mesg", 4);
    mrb_value obj = mrb->get_arg<mrb_value>();
    if (mrb_obj_equal(exc, obj)) {
        equal_p = 1;
    }
    else {
        if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
            if (obj.respond_to(mrb, mrb->intern2("message", 7))) {
                mesg = mrb->funcall(obj, "message", 0);
            }
            else
                return mrb_value::_false();
        }
        else {
            mesg = mrb_attr_get(obj, id_mesg);
        }

        equal_p = mrb_equal(mrb, mrb_attr_get(exc, id_mesg), mesg);
    }

    return mrb_value::wrap(equal_p);
}
コード例 #6
0
ファイル: array.c プロジェクト: chancelab/mruby
static mrb_value
mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;
  mrb_bool eql_p;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_obj_equal(mrb, ary1, ary2)) {
    eql_p = 1;
  }
  else if (!mrb_array_p(ary2)) {
    eql_p = 0;
  }
  else if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) {
    eql_p = 0;
  }
  else {
    mrb_int i;
    eql_p = 1;
    for (i=0; i<RARRAY_LEN(ary1); i++) {
      if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
        eql_p = 0;
        break;
      }
    }
  }

  return mrb_bool_value(eql_p);
}
コード例 #7
0
ファイル: array.c プロジェクト: CaptainJet/mruby
static mrb_value
mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;
  mrb_int i;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
  if (mrb_special_const_p(ary2)) return mrb_false_value();
  if (!mrb_array_p(ary2)) {
    if (!mrb_respond_to(mrb, ary2, mrb_intern2(mrb, "to_ary", 6))) {
      return mrb_false_value();
    }
    else {
      return mrb_bool_value(mrb_equal(mrb, ary2, ary1));
    }
  }
  if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
  for (i=0; i<RARRAY_LEN(ary1); i++) {
    if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
      return mrb_false_value();
    }
  }
  return mrb_true_value();
}
コード例 #8
0
ファイル: struct.c プロジェクト: nyanp/mruby
/*
 * code-seq:
 *   struct.eql?(other)   -> true or false
 *
 * Two structures are equal if they are the same object, or if all their
 * fields are equal (using <code>eql?</code>).
 */
static mrb_value
mrb_struct_eql(mrb_state *mrb, mrb_value s)
{
  mrb_value s2;
  mrb_value *ptr, *ptr2;
  mrb_int i, len;
  mrb_bool eql_p;

  mrb_get_args(mrb, "o", &s2);
  if (mrb_obj_equal(mrb, s, s2)) {
    eql_p = 1;
  }
  else if (strcmp(mrb_class_name(mrb, mrb_obj_class(mrb, s2)), "Struct") ||
           mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) {
    eql_p = 0;
  }
  else if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
    mrb_bug(mrb, "inconsistent struct"); /* should never happen */
    eql_p = 0; /* This substuture is just to suppress warnings. never called. */
  }
  else {
    ptr = RSTRUCT_PTR(s);
    ptr2 = RSTRUCT_PTR(s2);
    len = RSTRUCT_LEN(s);
    eql_p = 1;
    for (i=0; i<len; i++) {
      if (!mrb_eql(mrb, ptr[i], ptr2[i])) {
        eql_p = 0;
        break;
      }
    }
  }

  return mrb_bool_value(eql_p);
}
コード例 #9
0
ファイル: error.c プロジェクト: Blorgus/mruby
static mrb_value
exc_equal(mrb_state *mrb, mrb_value exc)
{
  mrb_value obj;
  mrb_value mesg;
  mrb_sym id_mesg = mrb_intern(mrb, "mesg");

  mrb_get_args(mrb, "o", &obj);
  if (mrb_obj_equal(mrb, exc, obj)) return mrb_true_value();

  if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
    if ( mrb_respond_to(mrb, obj, mrb_intern(mrb, "message")) ) {
      mesg = mrb_funcall(mrb, obj, "message", 0);
    }
    else
      return mrb_false_value();
  }
  else {
    mesg = mrb_attr_get(mrb, obj, id_mesg);
  }

  if (!mrb_equal(mrb, mrb_attr_get(mrb, exc, id_mesg), mesg))
    return mrb_false_value();
  return mrb_true_value();
}
コード例 #10
0
ファイル: error.c プロジェクト: koie/mruby
static mrb_value
exc_equal(mrb_state *mrb, mrb_value exc)
{
  mrb_value obj;
  mrb_value mesg;
  mrb_bool equal_p;
  mrb_sym id_mesg = mrb_intern2(mrb, "mesg", 4);

  mrb_get_args(mrb, "o", &obj);
  if (mrb_obj_equal(mrb, exc, obj)) {
    equal_p = 1;
  }
  else {
    if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
      if (mrb_respond_to(mrb, obj, mrb_intern2(mrb, "message", 7))) {
        mesg = mrb_funcall(mrb, obj, "message", 0);
      }
      else
        return mrb_false_value();
    }
    else {
      mesg = mrb_attr_get(mrb, obj, id_mesg);
    }

    equal_p = mrb_equal(mrb, mrb_attr_get(mrb, exc, id_mesg), mesg);
  }

  return mrb_bool_value(equal_p);
}
コード例 #11
0
static mrb_value
hs_regexp_equal(mrb_state *mrb, mrb_value self)
{
    mrb_value other;
    struct mrb_hs_regexp *self_reg, *other_reg;

    mrb_get_args(mrb, "o", &other);

    if (mrb_obj_equal(mrb, self, other)){
        return mrb_true_value();
    }

    if (mrb_type(other) != MRB_TT_DATA || DATA_TYPE(other) != &mrb_hs_regexp_type){
        return mrb_false_value();
    }

    self_reg = (struct mrb_hs_regexp *)DATA_PTR(self);
    other_reg = (struct mrb_hs_regexp *)DATA_PTR(other);
    if (!self_reg || !other_reg){
        mrb_raise(mrb, E_RUNTIME_ERROR, "Invalid HsRegexp");
    }

    if (self_reg->flag != other_reg->flag){
        return mrb_false_value();
    }

    return mrb_str_equal(mrb, mrb_iv_get(mrb, self, INTERN("@source")), mrb_iv_get(mrb, other, INTERN("@source"))) ?
        mrb_true_value() : mrb_false_value();
}
コード例 #12
0
ファイル: hash.c プロジェクト: denji/mruby
static mrb_value
mrb_hash_replace(mrb_state *mrb, mrb_value hash)
{
  mrb_value hash2, ifnone;
  khash_t(ht) *h2;
  khiter_t k;

  mrb_get_args(mrb, "o", &hash2);
  hash2 = to_hash(mrb, hash2);
  if (mrb_obj_equal(mrb, hash, hash2)) return hash;
  mrb_hash_clear(mrb, hash);

  h2 = RHASH_TBL(hash2);
  if (h2) {
    for (k = kh_begin(h2); k != kh_end(h2); k++) {
      if (kh_exist(h2, k))
        mrb_hash_set(mrb, hash, kh_key(h2, k), kh_value(h2, k));
    }
  }

  if (MRB_RHASH_PROCDEFAULT_P(hash2)) {
    RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
    ifnone = RHASH_PROCDEFAULT(hash2);
  }
  else {
    ifnone = RHASH_IFNONE(hash2);
  }
  mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);

  return hash;
}
コード例 #13
0
static mrb_value
regexp_equal(mrb_state *mrb, mrb_value self)
{
  mrb_value other;
  struct mrb_regexp_pcre *self_reg, *other_reg;

  mrb_get_args(mrb, "o", &other);
  if (mrb_obj_equal(mrb, self, other)) {
    return mrb_true_value();
  }

  if (mrb_type(other) != MRB_TT_DATA || DATA_TYPE(other) != &mrb_regexp_type) {
    return mrb_false_value();
  }

  self_reg = (struct mrb_regexp_pcre *)DATA_PTR(self);
  other_reg = (struct mrb_regexp_pcre *)DATA_PTR(other);
  if (!self_reg || !other_reg) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "Invalid Regexp");
  }

  if (mrb_str_equal(mrb, mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@source")),
                         mrb_iv_get(mrb, other, mrb_intern_lit(mrb, "@source")))) {
    return mrb_true_value();
  }

  return mrb_false_value();
}
コード例 #14
0
static mrb_value
pcre_regexp_equal(mrb_state *mrb, mrb_value self) {
  mrb_value other, regexp_self, regexp_other;
  struct mrb_pcre_regexp *self_reg, *other_reg;

  mrb_get_args(mrb, "o", &other);
  if (mrb_obj_equal(mrb, self, other)){
    return mrb_true_value();
  }
  if (mrb_nil_p(other)) {
    return mrb_false_value();
  }
  regexp_self = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@regexp"));
  regexp_other = mrb_iv_get(mrb, other, mrb_intern_lit(mrb, "@regexp"));
  Data_Get_Struct(mrb, regexp_self, &mrb_pcre_regexp_type, self_reg);
  Data_Get_Struct(mrb, regexp_other, &mrb_pcre_regexp_type, other_reg);

  if (!self_reg || !other_reg){
      mrb_raise(mrb, E_RUNTIME_ERROR, "Invalid PcreRegexp");
  }
  if (self_reg->flag != other_reg->flag){
      return mrb_false_value();
  }
  return mrb_str_equal(mrb, mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@source")), mrb_iv_get(mrb, other, mrb_intern_lit(mrb, "@source"))) ?
      mrb_true_value() : mrb_false_value();
}
コード例 #15
0
ファイル: struct.c プロジェクト: Birdflying1005/h2o
/*
 * code-seq:
 *   struct.eql?(other)   -> true or false
 *
 * Two structures are equal if they are the same object, or if all their
 * fields are equal (using <code>eql?</code>).
 */
static mrb_value
mrb_struct_eql(mrb_state *mrb, mrb_value s)
{
  mrb_value s2;
  mrb_value *ptr, *ptr2;
  mrb_int i, len;

  mrb_get_args(mrb, "o", &s2);
  if (mrb_obj_equal(mrb, s, s2)) {
    return mrb_true_value();
  }
  if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) {
    return mrb_false_value();
  }
  if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
    mrb_bug(mrb, "inconsistent struct"); /* should never happen */
  }
  ptr = RSTRUCT_PTR(s);
  ptr2 = RSTRUCT_PTR(s2);
  len = RSTRUCT_LEN(s);
  for (i=0; i<len; i++) {
    if (!mrb_eql(mrb, ptr[i], ptr2[i])) {
      return mrb_false_value();
    }
  }

  return mrb_true_value();
}
コード例 #16
0
ファイル: kernel.c プロジェクト: kou/mruby
/*
 *  call-seq:
 *     obj == other        -> true or false
 *     obj.equal?(other)   -> true or false
 *     obj.eql?(other)     -> true or false
 *
 *  Equality---At the <code>Object</code> level, <code>==</code> returns
 *  <code>true</code> only if <i>obj</i> and <i>other</i> are the
 *  same object. Typically, this method is overridden in descendant
 *  classes to provide class-specific meaning.
 *
 *  Unlike <code>==</code>, the <code>equal?</code> method should never be
 *  overridden by subclasses: it is used to determine object identity
 *  (that is, <code>a.equal?(b)</code> iff <code>a</code> is the same
 *  object as <code>b</code>).
 *
 *  The <code>eql?</code> method returns <code>true</code> if
 *  <i>obj</i> and <i>anObject</i> have the same value. Used by
 *  <code>Hash</code> to test members for equality.  For objects of
 *  class <code>Object</code>, <code>eql?</code> is synonymous with
 *  <code>==</code>. Subclasses normally continue this tradition, but
 *  there are exceptions. <code>Numeric</code> types, for example,
 *  perform type conversion across <code>==</code>, but not across
 *  <code>eql?</code>, so:
 *
 *     1 == 1.0     #=> true
 *     1.eql? 1.0   #=> false
 */
static mrb_value
mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
{
  mrb_value arg;

  mrb_get_args(mrb, "o", &arg);
  return mrb_bool_value(mrb_obj_equal(mrb, self, arg));
}
コード例 #17
0
ファイル: symbol.c プロジェクト: Kazu-zamasu/mruby_efi_shell
static mrb_value
sym_equal(mrb_state *mrb, mrb_value sym1)
{
  mrb_value sym2;

  mrb_get_args(mrb, "o", &sym2);
  if (mrb_obj_equal(mrb, sym1, sym2)) return mrb_true_value();
    return mrb_false_value();
}
コード例 #18
0
ファイル: symbol.c プロジェクト: retrage/mruby
static mrb_value
sym_equal(mrb_state *mrb, mrb_value sym1)
{
  mrb_value sym2;

  mrb_get_args(mrb, "o", &sym2);

  return mrb_bool_value(mrb_obj_equal(mrb, sym1, sym2));
}
コード例 #19
0
ファイル: method.c プロジェクト: chasonr/mruby
static mrb_value
method_eql(mrb_state *mrb, mrb_value self)
{
  mrb_value other, receiver, orig_proc, other_proc;
  struct RClass *owner, *klass;
  struct RProc *orig_rproc, *other_rproc;

  mrb_get_args(mrb, "o", &other);
  if (!mrb_obj_is_instance_of(mrb, other, mrb_class(mrb, self)))
    return mrb_false_value();

  if (mrb_class(mrb, self) != mrb_class(mrb, other))
    return mrb_false_value();

  klass = mrb_class_ptr(IV_GET(self, "@klass"));
  if (klass != mrb_class_ptr(IV_GET(other, "@klass")))
    return mrb_false_value();

  owner = mrb_class_ptr(IV_GET(self, "@owner"));
  if (owner != mrb_class_ptr(IV_GET(other, "@owner")))
    return mrb_false_value();

  receiver = IV_GET(self, "@recv");
  if (!mrb_obj_equal(mrb, receiver, IV_GET(other, "@recv")))
    return mrb_false_value();

  orig_proc = IV_GET(self, "proc");
  other_proc = IV_GET(other, "proc");
  if (mrb_nil_p(orig_proc) && mrb_nil_p(other_proc)) {
    if (mrb_symbol(IV_GET(self, "@name")) == mrb_symbol(IV_GET(other, "@name")))
      return mrb_true_value();
    else
      return mrb_false_value();
  }

  if (mrb_nil_p(orig_proc))
    return mrb_false_value();
  if (mrb_nil_p(other_proc))
    return mrb_false_value();

  orig_rproc = mrb_proc_ptr(orig_proc);
  other_rproc = mrb_proc_ptr(other_proc);
  if (MRB_PROC_CFUNC_P(orig_rproc)) {
    if (!MRB_PROC_CFUNC_P(other_rproc))
      return mrb_false_value();
    if (orig_rproc->body.func != other_rproc->body.func)
      return mrb_false_value();
  }
  else {
    if (MRB_PROC_CFUNC_P(other_rproc))
      return mrb_false_value();
    if (orig_rproc->body.irep != other_rproc->body.irep)
      return mrb_false_value();
  }

  return mrb_true_value();
}
コード例 #20
0
ファイル: range.c プロジェクト: anandkumaragrawal/mruby
static int
r_ge(mrb_state *mrb, mrb_value a, mrb_value b)
{
  //int c;
  mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */
  /* output :a < b => -1, a = b =>  0, a > b => +1 */

  if (mrb_nil_p(r)) return FALSE;

  /* mrb_value -> int */
  //c = mrb_cmpint(mrb, r);
  //if (c == 0) return TRUE;
  //if (c > 0)  return TRUE;
  //return FALSE;
  if (mrb_obj_equal(mrb, r, mrb_fixnum_value(0))) return TRUE;
  if (mrb_obj_equal(mrb, r, mrb_fixnum_value(1))) return TRUE;
  return FALSE;
}
コード例 #21
0
ファイル: array.c プロジェクト: TJ-Hidetaka-Takano/mruby
static mrb_value
join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list)
{
  mrb_int i;
  mrb_value result, val, tmp;

  /* check recursive */
  for (i=0; i<RARRAY_LEN(list); i++) {
    if (mrb_obj_equal(mrb, ary, RARRAY_PTR(list)[i])) {
      mrb_raise(mrb, E_ARGUMENT_ERROR, "recursive array join");
    }
  }

  mrb_ary_push(mrb, list, ary);

  result = mrb_str_buf_new(mrb, 64);

  for (i=0; i<RARRAY_LEN(ary); i++) {
    if (i > 0 && !mrb_nil_p(sep)) {
      mrb_str_cat_str(mrb, result, sep);
    }

    val = RARRAY_PTR(ary)[i];
    switch (mrb_type(val)) {
    case MRB_TT_ARRAY:
    ary_join:
      val = join_ary(mrb, val, sep, list);
      /* fall through */

    case MRB_TT_STRING:
    str_join:
      mrb_str_cat_str(mrb, result, val);
      break;

    default:
      if (!mrb_immediate_p(val)) {
        tmp = mrb_check_string_type(mrb, val);
        if (!mrb_nil_p(tmp)) {
          val = tmp;
          goto str_join;
        }
        tmp = mrb_check_convert_type(mrb, val, MRB_TT_ARRAY, "Array", "to_ary");
        if (!mrb_nil_p(tmp)) {
          val = tmp;
          goto ary_join;
        }
      }
      val = mrb_obj_as_string(mrb, val);
      goto str_join;
    }
  }

  mrb_ary_pop(mrb, list);

  return result;
}
コード例 #22
0
ファイル: range.c プロジェクト: anandkumaragrawal/mruby
static mrb_value
range_eql(mrb_state *mrb, mrb_value range)
{
  mrb_value obj;
  mrb_get_args(mrb, "o", &obj);

  if (mrb_obj_equal(mrb, range, obj))
    return mrb_true_value();
  if (!mrb_obj_is_kind_of(mrb, obj, mrb->range_class))
    return mrb_false_value();
  return mrb_exec_recursive_paired(mrb, recursive_eql, range, obj, &obj);
}
コード例 #23
0
ファイル: kernel.c プロジェクト: Bovi-Li/mruby
/* 15.3.1.3.16 */
mrb_value
mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
{
  mrb_value orig;

  mrb_get_args(mrb, "o", &orig);
  if (mrb_obj_equal(mrb, self, orig)) return self;
  if ((mrb_type(self) != mrb_type(orig)) || (mrb_obj_class(mrb, self) != mrb_obj_class(mrb, orig))) {
      mrb_raise(mrb, E_TYPE_ERROR, "initialize_copy should take same class object");
  }
  return self;
}
コード例 #24
0
ファイル: array.c プロジェクト: fmutant/scriptorium
static mrb_value
mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_fixnum_value(0);
  if (!mrb_array_p(ary2)) {
    return mrb_nil_value();
  }

  return ary2;
}
コード例 #25
0
ファイル: error.cpp プロジェクト: Prashant-Jonny/red_tint
static mrb_value exc_exception(mrb_state *mrb, mrb_value self)
{
    mrb_value a;
    int argc = mrb_get_args(mrb, "|o", &a);
    if (argc == 0)
        return self;
    if (mrb_obj_equal(self, a))
        return self;
    mrb_value exc = mrb_obj_clone(mrb, self);
    mrb_iv_set(mrb, exc, mrb_intern(mrb, "mesg", 4), a);

    return exc;
}
コード例 #26
0
ファイル: kernel.c プロジェクト: kimhmadsen/mruby
/*
 *  call-seq:
 *     obj == other        -> true or false
 *     obj.equal?(other)   -> true or false
 *     obj.eql?(other)     -> true or false
 *
 *  Equality---At the <code>Object</code> level, <code>==</code> returns
 *  <code>true</code> only if <i>obj</i> and <i>other</i> are the
 *  same object. Typically, this method is overridden in descendant
 *  classes to provide class-specific meaning.
 *
 *  Unlike <code>==</code>, the <code>equal?</code> method should never be
 *  overridden by subclasses: it is used to determine object identity
 *  (that is, <code>a.equal?(b)</code> iff <code>a</code> is the same
 *  object as <code>b</code>).
 *
 *  The <code>eql?</code> method returns <code>true</code> if
 *  <i>obj</i> and <i>anObject</i> have the same value. Used by
 *  <code>Hash</code> to test members for equality.  For objects of
 *  class <code>Object</code>, <code>eql?</code> is synonymous with
 *  <code>==</code>. Subclasses normally continue this tradition, but
 *  there are exceptions. <code>Numeric</code> types, for example,
 *  perform type conversion across <code>==</code>, but not across
 *  <code>eql?</code>, so:
 *
 *     1 == 1.0     #=> true
 *     1.eql? 1.0   #=> false
 */
static mrb_value
mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
{
  mrb_value arg;

  mrb_get_args(mrb, "o", &arg);
  if (mrb_obj_equal(mrb, self, arg)) {
    return mrb_true_value();
  }
  else {
    return mrb_false_value();
  }
}
コード例 #27
0
ファイル: hash.c プロジェクト: denji/mruby
static mrb_value
hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, mrb_bool eql)
{
  khash_t(ht) *h1, *h2;
  mrb_bool eq;

  if (mrb_obj_equal(mrb, hash1, hash2)) return mrb_true_value();
  if (!mrb_hash_p(hash2)) {
      if (!mrb_respond_to(mrb, hash2, mrb_intern_lit(mrb, "to_hash"))) {
          return mrb_false_value();
      }
      else {
        if (eql) {
          eq = mrb_eql(mrb, hash2, hash1);
        }
        else {
          eq = mrb_equal(mrb, hash2, hash1);
        }
        return mrb_bool_value(eq);
      }
  }
  h1 = RHASH_TBL(hash1);
  h2 = RHASH_TBL(hash2);
  if (!h1) {
    return mrb_bool_value(!h2);
  }
  if (!h2) return mrb_false_value();
  if (kh_size(h1) != kh_size(h2)) return mrb_false_value();
  else {
    khiter_t k1, k2;
    mrb_value key;

    for (k1 = kh_begin(h1); k1 != kh_end(h1); k1++) {
      if (!kh_exist(h1, k1)) continue;
      key = kh_key(h1,k1);
      k2 = kh_get(ht, mrb, h2, key);
      if (k2 != kh_end(h2)) {
        if (eql)
          eq = mrb_eql(mrb, kh_value(h1,k1), kh_value(h2,k2));
        else
          eq = mrb_equal(mrb, kh_value(h1,k1), kh_value(h2,k2));
        if (eq) {
          continue; /* next key */
        }
      }
      return mrb_false_value();
    }
  }
  return mrb_true_value();
}
コード例 #28
0
ファイル: numeric.c プロジェクト: denji/mruby
static mrb_value
fix_equal(mrb_state *mrb, mrb_value x)
{
  mrb_value y;
  mrb_bool equal_p;

  mrb_get_args(mrb, "o", &y);

  equal_p = mrb_obj_equal(mrb, x, y) ||
      (mrb_type(y) == MRB_TT_FLOAT &&
       (mrb_float)mrb_fixnum(x) == mrb_float(y));

  return mrb_bool_value(equal_p);
}
コード例 #29
0
ファイル: array.c プロジェクト: fmutant/scriptorium
static mrb_value
mrb_ary_eq(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
  if (!mrb_array_p(ary2)) {
    return mrb_false_value();
  }
  if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();

  return ary2;
}
コード例 #30
0
ファイル: range.c プロジェクト: anandkumaragrawal/mruby
/* 15.2.14.4.15(x) */
mrb_value
range_initialize_copy(mrb_state *mrb, mrb_value copy)
{
  mrb_value src;
  mrb_get_args(mrb, "o", &src);

    if (mrb_obj_equal(mrb, copy, src)) return copy;
    //mrb_check_frozen(copy);
    if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
      mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
    }
    memcpy(mrb_range_ptr(copy), mrb_range_ptr(src), sizeof(struct RRange));

    return copy;
}