Commit dc2e1c1c authored by Yukihiro Matz Matsumoto's avatar Yukihiro Matz Matsumoto

Merge branch 'pr-add-new-api-mrb_true_or_false_value' of...

Merge branch 'pr-add-new-api-mrb_true_or_false_value' of https://github.com/monaka/mruby into monaka-pr-add-new-api-mrb_true_or_false_value
parents 5217d889 6ab9c389
...@@ -274,4 +274,20 @@ mrb_undef_value(void) ...@@ -274,4 +274,20 @@ mrb_undef_value(void)
return v; return v;
} }
static inline mrb_value
mrb_true_or_false_value(mrb_bool boolean)
{
mrb_value v;
v.value.i = 1;
if (boolean) {
v.tt = MRB_TT_TRUE;
}
else {
v.tt = MRB_TT_FALSE;
}
return v;
}
#endif /* MRUBY_OBJECT_H */ #endif /* MRUBY_OBJECT_H */
...@@ -691,21 +691,34 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s) ...@@ -691,21 +691,34 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s)
mrb_value s2; mrb_value s2;
mrb_value *ptr, *ptr2; mrb_value *ptr, *ptr2;
mrb_int i, len; mrb_int i, len;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &s2); mrb_get_args(mrb, "o", &s2);
if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value(); if (mrb_obj_equal(mrb, s, s2)) {
if (!strcmp(mrb_class_name(mrb, mrb_obj_class(mrb, s)), "Struct")) return mrb_false_value(); equal_p = 1;
if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) return mrb_false_value(); }
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { else if (!strcmp(mrb_class_name(mrb, mrb_obj_class(mrb, s)), "Struct") ||
mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) {
equal_p = 0;
}
else if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
mrb_bug("inconsistent struct"); /* should never happen */ mrb_bug("inconsistent struct"); /* should never happen */
equal_p = 0; /* This substuture is just to suppress warnings. never called. */
} }
else {
ptr = RSTRUCT_PTR(s); ptr = RSTRUCT_PTR(s);
ptr2 = RSTRUCT_PTR(s2); ptr2 = RSTRUCT_PTR(s2);
len = RSTRUCT_LEN(s); len = RSTRUCT_LEN(s);
equal_p = 1;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
if (!mrb_equal(mrb, ptr[i], ptr2[i])) return mrb_false_value(); if (!mrb_equal(mrb, ptr[i], ptr2[i])) {
equal_p = 0;
break;
}
} }
return mrb_true_value(); }
return mrb_true_or_false_value(equal_p);
} }
/* 15.2.18.4.12(x) */ /* 15.2.18.4.12(x) */
...@@ -722,22 +735,34 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s) ...@@ -722,22 +735,34 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
mrb_value s2; mrb_value s2;
mrb_value *ptr, *ptr2; mrb_value *ptr, *ptr2;
mrb_int i, len; mrb_int i, len;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &s2); mrb_get_args(mrb, "o", &s2);
if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value(); if (mrb_obj_equal(mrb, s, s2)) {
if (strcmp(mrb_class_name(mrb, mrb_obj_class(mrb, s2)), "Struct")) return mrb_false_value(); eql_p = 1;
if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) return mrb_false_value(); }
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { 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("inconsistent struct"); /* should never happen */ mrb_bug("inconsistent struct"); /* should never happen */
eql_p = 0; /* This substuture is just to suppress warnings. never called. */
} }
else {
ptr = RSTRUCT_PTR(s); ptr = RSTRUCT_PTR(s);
ptr2 = RSTRUCT_PTR(s2); ptr2 = RSTRUCT_PTR(s2);
len = RSTRUCT_LEN(s); len = RSTRUCT_LEN(s);
eql_p = 1;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
if (!mrb_eql(mrb, ptr[i], ptr2[i])) return mrb_false_value(); if (!mrb_eql(mrb, ptr[i], ptr2[i])) {
eql_p = 0;
break;
} }
return mrb_true_value(); }
}
return mrb_true_or_false_value(eql_p);
} }
/* /*
......
...@@ -86,11 +86,6 @@ timegm(struct tm *tm) ...@@ -86,11 +86,6 @@ timegm(struct tm *tm)
* second level. Also, there are only 2 timezones, namely UTC and LOCAL. * second level. Also, there are only 2 timezones, namely UTC and LOCAL.
*/ */
#ifndef mrb_bool_value
#define mrb_bool_value(val) ((val) ? mrb_true_value() : mrb_false_value())
#endif
enum mrb_timezone { enum mrb_timezone {
MRB_TIMEZONE_NONE = 0, MRB_TIMEZONE_NONE = 0,
MRB_TIMEZONE_UTC = 1, MRB_TIMEZONE_UTC = 1,
...@@ -300,15 +295,14 @@ mrb_time_eq(mrb_state *mrb, mrb_value self) ...@@ -300,15 +295,14 @@ mrb_time_eq(mrb_state *mrb, mrb_value self)
{ {
mrb_value other; mrb_value other;
struct mrb_time *tm1, *tm2; struct mrb_time *tm1, *tm2;
mrb_bool eq_p;
mrb_get_args(mrb, "o", &other); mrb_get_args(mrb, "o", &other);
tm1 = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type); tm1 = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type);
tm2 = (struct mrb_time *)mrb_get_datatype(mrb, other, &mrb_time_type); tm2 = (struct mrb_time *)mrb_get_datatype(mrb, other, &mrb_time_type);
if (!tm1 || !tm2) return mrb_false_value(); eq_p = tm1 && tm2 && tm1->sec == tm2->sec && tm1->usec == tm2->usec;
if (tm1->sec == tm2->sec && tm1->usec == tm2->usec) {
return mrb_true_value(); return mrb_true_or_false_value(eq_p);
}
return mrb_false_value();
} }
static mrb_value static mrb_value
...@@ -465,7 +459,7 @@ mrb_time_dstp(mrb_state *mrb, mrb_value self) ...@@ -465,7 +459,7 @@ mrb_time_dstp(mrb_state *mrb, mrb_value self)
tm = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type); tm = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type);
if (!tm) return mrb_nil_value(); if (!tm) return mrb_nil_value();
return mrb_bool_value(tm->datetime.tm_isdst); return mrb_true_or_false_value(tm->datetime.tm_isdst);
} }
/* 15.2.19.7.8 */ /* 15.2.19.7.8 */
...@@ -684,7 +678,7 @@ mrb_time_utcp(mrb_state *mrb, mrb_value self) ...@@ -684,7 +678,7 @@ mrb_time_utcp(mrb_state *mrb, mrb_value self)
struct mrb_time *tm; struct mrb_time *tm;
tm = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type); tm = (struct mrb_time *)mrb_get_datatype(mrb, self, &mrb_time_type);
if (!tm) return mrb_nil_value(); if (!tm) return mrb_nil_value();
return mrb_bool_value(tm->timezone == MRB_TIMEZONE_UTC); return mrb_true_or_false_value(tm->timezone == MRB_TIMEZONE_UTC);
} }
......
...@@ -878,7 +878,7 @@ mrb_ary_empty_p(mrb_state *mrb, mrb_value self) ...@@ -878,7 +878,7 @@ mrb_ary_empty_p(mrb_state *mrb, mrb_value self)
{ {
struct RArray *a = mrb_ary_ptr(self); struct RArray *a = mrb_ary_ptr(self);
return ((a->len == 0)? mrb_true_value(): mrb_false_value()); return mrb_true_or_false_value(a->len == 0);
} }
mrb_value mrb_value
...@@ -1059,31 +1059,39 @@ static mrb_value ...@@ -1059,31 +1059,39 @@ static mrb_value
mrb_ary_equal(mrb_state *mrb, mrb_value ary1) mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
{ {
mrb_value ary2; mrb_value ary2;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &ary2); mrb_get_args(mrb, "o", &ary2);
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value(); if (mrb_obj_equal(mrb, ary1, ary2)) {
if (mrb_special_const_p(ary2)) return mrb_false_value(); equal_p = 1;
if (!mrb_array_p(ary2)) { }
if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) { else if (mrb_special_const_p(ary2)) {
return mrb_false_value(); equal_p = 0;
} }
if (mrb_equal(mrb, ary2, ary1)){ else if (!mrb_array_p(ary2)) {
return mrb_true_value(); if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) {
equal_p = 0;
} }
else { else {
return mrb_false_value(); equal_p = mrb_equal(mrb, ary2, ary1);
}
} }
else if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) {
equal_p = 0;
} }
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value();
else { else {
mrb_int i; mrb_int i;
equal_p = 1;
for (i=0; i<RARRAY_LEN(ary1); i++) { for (i=0; i<RARRAY_LEN(ary1); i++) {
if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) if (!mrb_equal(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
return mrb_false_value(); equal_p = 0;
break;
}
} }
return mrb_true_value();
} }
return mrb_true_or_false_value(equal_p);
} }
/* 15.2.12.5.34 (x) */ /* 15.2.12.5.34 (x) */
...@@ -1099,20 +1107,30 @@ static mrb_value ...@@ -1099,20 +1107,30 @@ static mrb_value
mrb_ary_eql(mrb_state *mrb, mrb_value ary1) mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
{ {
mrb_value ary2; mrb_value ary2;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &ary2); mrb_get_args(mrb, "o", &ary2);
if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value(); if (mrb_obj_equal(mrb, ary1, ary2)) {
if (!mrb_array_p(ary2)) return mrb_false_value(); eql_p = 1;
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return mrb_false_value(); }
else if (!mrb_array_p(ary2)) {
eql_p = 0;
}
else if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) {
eql_p = 0;
}
else { else {
mrb_int i; mrb_int i;
eql_p = 1;
for (i=0; i<RARRAY_LEN(ary1); i++) { for (i=0; i<RARRAY_LEN(ary1); i++) {
if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) if (!mrb_eql(mrb, ary_elt(ary1, i), ary_elt(ary2, i))) {
return mrb_false_value(); eql_p = 0;
break;
}
} }
return mrb_true_value();
} }
return mrb_true_or_false_value(eql_p);
} }
void void
......
...@@ -1090,9 +1090,7 @@ mrb_bob_init(mrb_state *mrb, mrb_value cv) ...@@ -1090,9 +1090,7 @@ mrb_bob_init(mrb_state *mrb, mrb_value cv)
static mrb_value static mrb_value
mrb_bob_not(mrb_state *mrb, mrb_value cv) mrb_bob_not(mrb_state *mrb, mrb_value cv)
{ {
if (mrb_test(cv)) return mrb_true_or_false_value(!mrb_test(cv));
return mrb_false_value();
return mrb_true_value();
} }
/* 15.3.1.3.30 */ /* 15.3.1.3.30 */
...@@ -1495,12 +1493,12 @@ static mrb_value ...@@ -1495,12 +1493,12 @@ static mrb_value
mrb_mod_cvar_defined(mrb_state *mrb, mrb_value mod) mrb_mod_cvar_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_sym id; mrb_sym id;
mrb_bool defined_p;
mrb_get_args(mrb, "n", &id); mrb_get_args(mrb, "n", &id);
check_cv_name(mrb, id); check_cv_name(mrb, id);
if(mrb_cv_defined(mrb, mod, id)) defined_p = mrb_cv_defined(mrb, mod, id);
return mrb_true_value(); return mrb_true_or_false_value(defined_p);
return mrb_false_value();
} }
/* 15.2.2.4.17 */ /* 15.2.2.4.17 */
...@@ -1636,12 +1634,11 @@ static mrb_value ...@@ -1636,12 +1634,11 @@ static mrb_value
mrb_mod_method_defined(mrb_state *mrb, mrb_value mod) mrb_mod_method_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_sym id; mrb_sym id;
mrb_bool method_defined_p;
mrb_get_args(mrb, "n", &id); mrb_get_args(mrb, "n", &id);
if (mrb_obj_respond_to(mrb_class_ptr(mod), id)) { method_defined_p = mrb_obj_respond_to(mrb_class_ptr(mod), id);
return mrb_true_value(); return mrb_true_or_false_value(method_defined_p);
}
return mrb_false_value();
} }
static void static void
...@@ -1702,13 +1699,13 @@ mrb_value ...@@ -1702,13 +1699,13 @@ mrb_value
mrb_mod_const_defined(mrb_state *mrb, mrb_value mod) mrb_mod_const_defined(mrb_state *mrb, mrb_value mod)
{ {
mrb_sym id; mrb_sym id;
mrb_bool const_defined_p;
mrb_get_args(mrb, "n", &id); mrb_get_args(mrb, "n", &id);
check_const_name(mrb, id); check_const_name(mrb, id);
if(mrb_const_defined(mrb, mod, id)) { const_defined_p = mrb_const_defined(mrb, mod, id);
return mrb_true_value();
} return mrb_true_or_false_value(const_defined_p);
return mrb_false_value();
} }
mrb_value mrb_value
...@@ -1752,11 +1749,12 @@ static mrb_value ...@@ -1752,11 +1749,12 @@ static mrb_value
mrb_mod_eqq(mrb_state *mrb, mrb_value mod) mrb_mod_eqq(mrb_state *mrb, mrb_value mod)
{ {
mrb_value obj; mrb_value obj;
mrb_bool eqq;
mrb_get_args(mrb, "o", &obj); mrb_get_args(mrb, "o", &obj);
if (!mrb_obj_is_kind_of(mrb, obj, mrb_class_ptr(mod))) eqq = mrb_obj_is_kind_of(mrb, obj, mrb_class_ptr(mod));
return mrb_false_value();
return mrb_true_value(); return mrb_true_or_false_value(eqq);
} }
void void
......
...@@ -160,11 +160,14 @@ exc_equal(mrb_state *mrb, mrb_value exc) ...@@ -160,11 +160,14 @@ exc_equal(mrb_state *mrb, mrb_value exc)
{ {
mrb_value obj; mrb_value obj;
mrb_value mesg; mrb_value mesg;
mrb_bool equal_p;
mrb_sym id_mesg = mrb_intern(mrb, "mesg"); mrb_sym id_mesg = mrb_intern(mrb, "mesg");
mrb_get_args(mrb, "o", &obj); mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, exc, obj)) return mrb_true_value(); if (mrb_obj_equal(mrb, exc, obj)) {
equal_p = 1;
}
else {
if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) { if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
if (mrb_respond_to(mrb, obj, mrb_intern(mrb, "message"))) { if (mrb_respond_to(mrb, obj, mrb_intern(mrb, "message"))) {
mesg = mrb_funcall(mrb, obj, "message", 0); mesg = mrb_funcall(mrb, obj, "message", 0);
...@@ -176,9 +179,10 @@ exc_equal(mrb_state *mrb, mrb_value exc) ...@@ -176,9 +179,10 @@ exc_equal(mrb_state *mrb, mrb_value exc)
mesg = mrb_attr_get(mrb, obj, id_mesg); mesg = mrb_attr_get(mrb, obj, id_mesg);
} }
if (!mrb_equal(mrb, mrb_attr_get(mrb, exc, id_mesg), mesg)) equal_p = mrb_equal(mrb, mrb_attr_get(mrb, exc, id_mesg), mesg);
return mrb_false_value(); }
return mrb_true_value();
return mrb_true_or_false_value(equal_p);
} }
static void static void
......
...@@ -982,8 +982,8 @@ gc_enable(mrb_state *mrb, mrb_value obj) ...@@ -982,8 +982,8 @@ gc_enable(mrb_state *mrb, mrb_value obj)
int old = mrb->gc_disabled; int old = mrb->gc_disabled;
mrb->gc_disabled = FALSE; mrb->gc_disabled = FALSE;
if (old) return mrb_true_value();
return mrb_false_value(); return mrb_true_or_false_value(old);
} }
/* /*
...@@ -1004,8 +1004,8 @@ gc_disable(mrb_state *mrb, mrb_value obj) ...@@ -1004,8 +1004,8 @@ gc_disable(mrb_state *mrb, mrb_value obj)
int old = mrb->gc_disabled; int old = mrb->gc_disabled;
mrb->gc_disabled = TRUE; mrb->gc_disabled = TRUE;
if (old) return mrb_true_value();
return mrb_false_value(); return mrb_true_or_false_value(old);
} }
/* /*
...@@ -1101,10 +1101,7 @@ change_gen_gc_mode(mrb_state *mrb, mrb_int enable) ...@@ -1101,10 +1101,7 @@ change_gen_gc_mode(mrb_state *mrb, mrb_int enable)
static mrb_value static mrb_value
gc_generational_mode_get(mrb_state *mrb, mrb_value self) gc_generational_mode_get(mrb_state *mrb, mrb_value self)
{ {
if (mrb->is_generational_gc_mode) return mrb_true_or_false_value(mrb->is_generational_gc_mode);
return mrb_true_value();
else
return mrb_false_value();
} }
/* /*
...@@ -1124,10 +1121,7 @@ gc_generational_mode_set(mrb_state *mrb, mrb_value self) ...@@ -1124,10 +1121,7 @@ gc_generational_mode_set(mrb_state *mrb, mrb_value self)
if (mrb->is_generational_gc_mode != enable) if (mrb->is_generational_gc_mode != enable)
change_gen_gc_mode(mrb, enable); change_gen_gc_mode(mrb, enable);
if (enable) return mrb_true_or_false_value(enable);
return mrb_true_value();
else
return mrb_false_value();
} }
#ifdef GC_TEST #ifdef GC_TEST
......
...@@ -801,13 +801,16 @@ static mrb_value ...@@ -801,13 +801,16 @@ static mrb_value
mrb_hash_empty_p(mrb_state *mrb, mrb_value self) mrb_hash_empty_p(mrb_state *mrb, mrb_value self)
{ {
khash_t(ht) *h = RHASH_TBL(self); khash_t(ht) *h = RHASH_TBL(self);
mrb_bool empty_p;
if (h) { if (h) {
if (kh_size(h) == 0) empty_p = (kh_size(h) == 0);
return mrb_true_value();
return mrb_false_value();
} }
return mrb_true_value(); else {
empty_p = 1;
}
return mrb_true_or_false_value(empty_p);
} }
/* 15.2.13.4.11 */ /* 15.2.13.4.11 */
...@@ -1010,14 +1013,17 @@ mrb_hash_has_keyWithKey(mrb_state *mrb, mrb_value hash, mrb_value key) ...@@ -1010,14 +1013,17 @@ mrb_hash_has_keyWithKey(mrb_state *mrb, mrb_value hash, mrb_value key)
{ {
khash_t(ht) *h = RHASH_TBL(hash); khash_t(ht) *h = RHASH_TBL(hash);
khiter_t k; khiter_t k;
mrb_bool result;
if (h) { if (h) {
k = kh_get(ht, h, key); k = kh_get(ht, h, key);
if (k != kh_end(h)) result = (k != kh_end(h));
return mrb_true_value(); }
else {
result = 0;
} }
return mrb_false_value(); return mrb_true_or_false_value(result);
} }
/* 15.2.13.4.13 */ /* 15.2.13.4.13 */
...@@ -1109,8 +1115,7 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql) ...@@ -1109,8 +1115,7 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
h1 = RHASH_TBL(hash1); h1 = RHASH_TBL(hash1);
h2 = RHASH_TBL(hash2); h2 = RHASH_TBL(hash2);
if (!h1) { if (!h1) {
if (!h2) return mrb_true_value(); return mrb_true_or_false_value(!h2);
return mrb_false_value();
} }
if (!h2) return mrb_false_value(); if (!h2) return mrb_false_value();
if (kh_size(h1) != kh_size(h2)) return mrb_false_value(); if (kh_size(h1) != kh_size(h2)) return mrb_false_value();
......
...@@ -96,28 +96,24 @@ static mrb_value ...@@ -96,28 +96,24 @@ static mrb_value
mrb_obj_equal_m(mrb_state *mrb, mrb_value self) mrb_obj_equal_m(mrb_state *mrb, mrb_value self)
{ {
mrb_value arg; mrb_value arg;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &arg); mrb_get_args(mrb, "o", &arg);
if (mrb_obj_equal(mrb, self, arg)) { eql_p = mrb_obj_equal(mrb, self, arg);
return mrb_true_value();
} return mrb_true_or_false_value(eql_p);
else {
return mrb_false_value();
}
} }
static mrb_value static mrb_value
mrb_obj_not_equal_m(mrb_state *mrb, mrb_value self) mrb_obj_not_equal_m(mrb_state *mrb, mrb_value self)
{ {
mrb_value arg; mrb_value arg;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &arg); mrb_get_args(mrb, "o", &arg);
if (mrb_equal(mrb, self, arg)) { eql_p = mrb_obj_equal(mrb, self, arg);
return mrb_false_value();
} return mrb_true_or_false_value(!eql_p);
else {
return mrb_true_value();
}
} }
/* 15.3.1.3.2 */ /* 15.3.1.3.2 */
...@@ -133,14 +129,12 @@ static mrb_value ...@@ -133,14 +129,12 @@ static mrb_value
mrb_equal_m(mrb_state *mrb, mrb_value self) mrb_equal_m(mrb_state *mrb, mrb_value self)
{ {
mrb_value arg; mrb_value arg;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &arg); mrb_get_args(mrb, "o", &arg);
if (mrb_equal(mrb, self, arg)){ equal_p = mrb_equal(mrb, self, arg);
return mrb_true_value();
} return mrb_true_or_false_value(equal_p);
else {
return mrb_false_value();
}
} }
/* 15.3.1.3.3 */ /* 15.3.1.3.3 */
...@@ -225,21 +219,28 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self) ...@@ -225,21 +219,28 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
{ {
mrb_callinfo *ci = mrb->ci; mrb_callinfo *ci = mrb->ci;
mrb_value *bp; mrb_value *bp;
mrb_bool given_p;
bp = mrb->stbase + ci->stackidx + 1; bp = mrb->stbase + ci->stackidx + 1;
ci--; ci--;
if (ci <= mrb->cibase) return mrb_false_value(); if (ci <= mrb->cibase) {
given_p = 0;
}
else {
/* block_given? called within block; check upper scope */ /* block_given? called within block; check upper scope */
if (ci->proc->env && ci->proc->env->stack) { if (ci->proc->env && ci->proc->env->stack) {
if (ci->proc->env->stack == mrb->stbase || mrb_nil_p(ci->proc->env->stack[1])) given_p = !(ci->proc->env->stack == mrb->stbase ||
return mrb_false_value(); mrb_nil_p(ci->proc->env->stack[1]));
return mrb_true_value();
} }
else {
if (ci->argc > 0) { if (ci->argc > 0) {
bp += ci->argc; bp += ci->argc;
} }
if (mrb_nil_p(*bp)) return mrb_false_value(); given_p = !mrb_nil_p(*bp);
return mrb_true_value(); }
}
return mrb_true_or_false_value(given_p);
} }
/* 15.3.1.3.7 */ /* 15.3.1.3.7 */
...@@ -542,14 +543,12 @@ static mrb_value ...@@ -542,14 +543,12 @@ static mrb_value
obj_is_instance_of(mrb_state *mrb, mrb_value self) obj_is_instance_of(mrb_state *mrb, mrb_value self)
{ {
mrb_value arg; mrb_value arg;
mrb_bool instance_of_p;
mrb_get_args(mrb, "o", &arg); mrb_get_args(mrb, "o", &arg);
if (mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg))){ instance_of_p = mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg));
return mrb_true_value();
} return mrb_true_or_false_value(instance_of_p);
else {
return mrb_false_value();
}
} }
static void static void
...@@ -586,12 +585,13 @@ mrb_value ...@@ -586,12 +585,13 @@ mrb_value
mrb_obj_ivar_defined(mrb_state *mrb, mrb_value self) mrb_obj_ivar_defined(mrb_state *mrb, mrb_value self)
{ {
mrb_sym mid; mrb_sym mid;
mrb_bool defined_p;
mrb_get_args(mrb, "n", &mid); mrb_get_args(mrb, "n", &mid);
check_iv_name(mrb, mid); check_iv_name(mrb, mid);
if (mrb_obj_iv_defined(mrb, mrb_obj_ptr(self), mid)) defined_p = mrb_obj_iv_defined(mrb, mrb_obj_ptr(self), mid);
return mrb_true_value();
return mrb_false_value(); return mrb_true_or_false_value(defined_p);
} }
/* 15.3.1.3.21 */ /* 15.3.1.3.21 */
...@@ -688,14 +688,12 @@ mrb_value ...@@ -688,14 +688,12 @@ mrb_value
mrb_obj_is_kind_of_m(mrb_state *mrb, mrb_value self) mrb_obj_is_kind_of_m(mrb_state *mrb, mrb_value self)
{ {
mrb_value arg; mrb_value arg;
mrb_bool kind_of_p;
mrb_get_args(mrb, "o", &arg); mrb_get_args(mrb, "o", &arg);
if (mrb_obj_is_kind_of(mrb, self, mrb_class_ptr(arg))) { kind_of_p = mrb_obj_is_kind_of(mrb, self, mrb_class_ptr(arg));
return mrb_true_value();
} return mrb_true_or_false_value(kind_of_p);
else {
return mrb_false_value();
}
} }
static void static void
...@@ -1002,15 +1000,17 @@ obj_respond_to(mrb_state *mrb, mrb_value self) ...@@ -1002,15 +1000,17 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
int argc; int argc;
mrb_value mid, priv; mrb_value mid, priv;
mrb_sym id; mrb_sym id;
mrb_bool respond_to_p;
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
mid = argv[0]; mid = argv[0];
if (argc > 1) priv = argv[1]; if (argc > 1) priv = argv[1];
else priv = mrb_nil_value(); else priv = mrb_nil_value();
id = mrb_to_id(mrb, mid); id = mrb_to_id(mrb, mid);
if (basic_obj_respond_to(mrb, self, id, !mrb_test(priv)))
return mrb_true_value(); respond_to_p = basic_obj_respond_to(mrb, self, id, !mrb_test(priv));
return mrb_false_value();
return mrb_true_or_false_value(respond_to_p);
} }
/* 15.3.1.3.45 */ /* 15.3.1.3.45 */
......
...@@ -380,15 +380,17 @@ static mrb_value ...@@ -380,15 +380,17 @@ static mrb_value
num_eql(mrb_state *mrb, mrb_value x) num_eql(mrb_state *mrb, mrb_value x)
{ {
mrb_value y; mrb_value y;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &y); mrb_get_args(mrb, "o", &y);
if (mrb_type(x) != mrb_type(y)) return mrb_false_value(); if (mrb_type(x) != mrb_type(y)) {
if (mrb_equal(mrb, x, y)) { eql_p = 0;
return mrb_true_value();
} }
else { else {
return mrb_false_value(); eql_p = mrb_equal(mrb, x, y);
} }
return mrb_true_or_false_value(eql_p);
} }
static mrb_value static mrb_value
...@@ -430,7 +432,7 @@ flo_eq(mrb_state *mrb, mrb_value x) ...@@ -430,7 +432,7 @@ flo_eq(mrb_state *mrb, mrb_value x)
return num_equal(mrb, x, y); return num_equal(mrb, x, y);
} }
a = mrb_float(x); a = mrb_float(x);
return (a == b)?mrb_true_value():mrb_false_value(); return mrb_true_or_false_value(a == b);
} }
/* 15.2.8.3.18 */ /* 15.2.8.3.18 */
...@@ -511,10 +513,11 @@ static mrb_value ...@@ -511,10 +513,11 @@ static mrb_value
flo_finite_p(mrb_state *mrb, mrb_value num) flo_finite_p(mrb_state *mrb, mrb_value num)
{ {
mrb_float value = mrb_float(num); mrb_float value = mrb_float(num);
mrb_bool finite_p;
finite_p = !(isinf(value) || isnan(value));
if (isinf(value) || isnan(value)) return mrb_true_or_false_value(finite_p);
return mrb_false_value();
return mrb_true_value();
} }
/* 15.2.9.3.10 */ /* 15.2.9.3.10 */
...@@ -923,19 +926,15 @@ static mrb_value ...@@ -923,19 +926,15 @@ static mrb_value
fix_equal(mrb_state *mrb, mrb_value x) fix_equal(mrb_state *mrb, mrb_value x)
{ {
mrb_value y; mrb_value y;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &y); mrb_get_args(mrb, "o", &y);
if (mrb_obj_equal(mrb, x, y)) return mrb_true_value(); equal_p = mrb_obj_equal(mrb, x, y) ||
switch (mrb_type(y)) { (mrb_type(y) == MRB_TT_FLOAT &&
case MRB_TT_FLOAT: (mrb_float)mrb_fixnum(x) == mrb_float(y));
if ((mrb_float)mrb_fixnum(x) == mrb_float(y))
return mrb_true_value(); return mrb_true_or_false_value(equal_p);
/* fall through */
case MRB_TT_FIXNUM:
default:
return mrb_false_value();
}
} }
/* 15.2.8.3.8 */ /* 15.2.8.3.8 */
......
...@@ -114,7 +114,8 @@ true_and(mrb_state *mrb, mrb_value obj) ...@@ -114,7 +114,8 @@ true_and(mrb_state *mrb, mrb_value obj)
int obj2; int obj2;
mrb_get_args(mrb, "b", &obj2); mrb_get_args(mrb, "b", &obj2);
return obj2 ? mrb_true_value() : mrb_false_value();
return mrb_true_or_false_value(obj2);
} }
/* 15.2.5.3.2 */ /* 15.2.5.3.2 */
...@@ -133,7 +134,7 @@ true_xor(mrb_state *mrb, mrb_value obj) ...@@ -133,7 +134,7 @@ true_xor(mrb_state *mrb, mrb_value obj)
int obj2; int obj2;
mrb_get_args(mrb, "b", &obj2); mrb_get_args(mrb, "b", &obj2);
return obj2 ? mrb_false_value() : mrb_true_value(); return mrb_true_or_false_value(!obj2);
} }
/* 15.2.5.3.3 */ /* 15.2.5.3.3 */
...@@ -226,7 +227,7 @@ false_xor(mrb_state *mrb, mrb_value obj) ...@@ -226,7 +227,7 @@ false_xor(mrb_state *mrb, mrb_value obj)
int obj2; int obj2;
mrb_get_args(mrb, "b", &obj2); mrb_get_args(mrb, "b", &obj2);
return obj2 ? mrb_true_value() : mrb_false_value(); return mrb_true_or_false_value(obj2);
} }
/* 15.2.4.3.3 */ /* 15.2.4.3.3 */
...@@ -246,7 +247,7 @@ false_or(mrb_state *mrb, mrb_value obj) ...@@ -246,7 +247,7 @@ false_or(mrb_state *mrb, mrb_value obj)
int obj2; int obj2;
mrb_get_args(mrb, "b", &obj2); mrb_get_args(mrb, "b", &obj2);
return obj2 ? mrb_true_value() : mrb_false_value(); return mrb_true_or_false_value(obj2);
} }
/* 15.2.6.3.3 */ /* 15.2.6.3.3 */
......
...@@ -91,7 +91,7 @@ mrb_range_excl(mrb_state *mrb, mrb_value range) ...@@ -91,7 +91,7 @@ mrb_range_excl(mrb_state *mrb, mrb_value range)
{ {
struct RRange *r = mrb_range_ptr(range); struct RRange *r = mrb_range_ptr(range);
return r->excl ? mrb_true_value() : mrb_false_value(); return mrb_true_or_false_value(r->excl);
} }
static void static void
...@@ -152,25 +152,30 @@ mrb_range_eq(mrb_state *mrb, mrb_value range) ...@@ -152,25 +152,30 @@ mrb_range_eq(mrb_state *mrb, mrb_value range)
struct RRange *rr; struct RRange *rr;
struct RRange *ro; struct RRange *ro;
mrb_value obj; mrb_value obj;
mrb_bool eq_p;
mrb_get_args(mrb, "o", &obj); mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value(); if (mrb_obj_equal(mrb, range, obj)) {
eq_p = 1;
/* same class? */ }
if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) else if (!mrb_obj_is_instance_of(mrb, obj, mrb_obj_class(mrb, range))) { /* same class? */
return mrb_false_value(); eq_p = 0;
}
else {
rr = mrb_range_ptr(range); rr = mrb_range_ptr(range);
ro = mrb_range_ptr(obj); ro = mrb_range_ptr(obj);
if (!mrb_obj_equal(mrb, rr->edges->beg, ro->edges->beg)) if (!mrb_obj_equal(mrb, rr->edges->beg, ro->edges->beg) ||
return mrb_false_value(); !mrb_obj_equal(mrb, rr->edges->end, ro->edges->end) ||
if (!mrb_obj_equal(mrb, rr->edges->end, ro->edges->end)) rr->excl != ro->excl) {
return mrb_false_value(); eq_p = 0;
if (rr->excl != ro->excl) }
return mrb_false_value(); else {
eq_p = 1;
return mrb_true_value(); }
}
return mrb_true_or_false_value(eq_p);
} }
static int static int
...@@ -227,21 +232,17 @@ mrb_range_include(mrb_state *mrb, mrb_value range) ...@@ -227,21 +232,17 @@ mrb_range_include(mrb_state *mrb, mrb_value range)
mrb_value val; mrb_value val;
struct RRange *r = mrb_range_ptr(range); struct RRange *r = mrb_range_ptr(range);
mrb_value beg, end; mrb_value beg, end;
mrb_bool include_p;
mrb_get_args(mrb, "o", &val); mrb_get_args(mrb, "o", &val);
beg = r->edges->beg; beg = r->edges->beg;
end = r->edges->end; end = r->edges->end;
if (r_le(mrb, beg, val)) { include_p = r_le(mrb, beg, val) && /* beg <= val */
/* beg <= val */ ((r->excl && r_gt(mrb, end, val)) || /* end > val */
if (r->excl) { (r_ge(mrb, end, val))); /* end >= val */
if (r_gt(mrb, end, val)) return mrb_true_value(); /* end > val */
} return mrb_true_or_false_value(include_p);
else {
if (r_ge(mrb, end, val)) return mrb_true_value(); /* end >= val */
}
}
return mrb_false_value();
} }
/* /*
...@@ -384,23 +385,34 @@ range_eql(mrb_state *mrb, mrb_value range) ...@@ -384,23 +385,34 @@ range_eql(mrb_state *mrb, mrb_value range)
{ {
mrb_value obj; mrb_value obj;
struct RRange *r, *o; struct RRange *r, *o;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &obj); mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, range, obj)) if (mrb_obj_equal(mrb, range, obj)) {
return mrb_true_value(); eql_p = 1;
if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS)) }
return mrb_false_value(); else if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS)) {
eql_p = 0;
}
else {
r = mrb_range_ptr(range); r = mrb_range_ptr(range);
if (mrb_type(obj) != MRB_TT_RANGE) return mrb_false_value(); if (mrb_type(obj) != MRB_TT_RANGE) {
eql_p = 0;
}
else {
o = mrb_range_ptr(obj); o = mrb_range_ptr(obj);
if (!mrb_eql(mrb, r->edges->beg, o->edges->beg)) if (!mrb_eql(mrb, r->edges->beg, o->edges->beg) ||
return mrb_false_value(); !mrb_eql(mrb, r->edges->end, o->edges->end) ||
if (!mrb_eql(mrb, r->edges->end, o->edges->end)) (r->excl != o->excl)) {
return mrb_false_value(); eql_p = 0;
if (r->excl != o->excl) }
return mrb_false_value(); else {
return mrb_true_value(); eql_p = 1;
}
}
}
return mrb_true_or_false_value(eql_p);
} }
/* 15.2.14.4.15(x) */ /* 15.2.14.4.15(x) */
......
...@@ -596,11 +596,12 @@ static mrb_value ...@@ -596,11 +596,12 @@ static mrb_value
mrb_str_equal_m(mrb_state *mrb, mrb_value str1) mrb_str_equal_m(mrb_state *mrb, mrb_value str1)
{ {
mrb_value str2; mrb_value str2;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &str2); mrb_get_args(mrb, "o", &str2);
if (mrb_str_equal(mrb, str1, str2)) equal_p = mrb_str_equal(mrb, str1, str2);
return mrb_true_value();
return mrb_false_value(); return mrb_true_or_false_value(equal_p);
} }
/* ---------------------------------- */ /* ---------------------------------- */
mrb_value mrb_value
...@@ -1134,9 +1135,7 @@ mrb_str_empty_p(mrb_state *mrb, mrb_value self) ...@@ -1134,9 +1135,7 @@ mrb_str_empty_p(mrb_state *mrb, mrb_value self)
{ {
struct RString *s = mrb_str_ptr(self); struct RString *s = mrb_str_ptr(self);
if (s->len == 0) return mrb_true_or_false_value(s->len == 0);
return mrb_true_value();
return mrb_false_value();
} }
/* 15.2.10.5.17 */ /* 15.2.10.5.17 */
...@@ -1150,13 +1149,12 @@ static mrb_value ...@@ -1150,13 +1149,12 @@ static mrb_value
mrb_str_eql(mrb_state *mrb, mrb_value self) mrb_str_eql(mrb_state *mrb, mrb_value self)
{ {
mrb_value str2; mrb_value str2;
mrb_bool eql_p;
mrb_get_args(mrb, "o", &str2); mrb_get_args(mrb, "o", &str2);
if (mrb_type(str2) != MRB_TT_STRING) eql_p = (mrb_type(str2) == MRB_TT_STRING) && str_eql(mrb, self, str2);
return mrb_false_value();
if (str_eql(mrb, self, str2)) return mrb_true_or_false_value(eql_p);
return mrb_true_value();
return mrb_false_value();
} }
static mrb_value static mrb_value
...@@ -1314,18 +1312,20 @@ mrb_str_include(mrb_state *mrb, mrb_value self) ...@@ -1314,18 +1312,20 @@ mrb_str_include(mrb_state *mrb, mrb_value self)
{ {
mrb_int i; mrb_int i;
mrb_value str2; mrb_value str2;
mrb_bool include_p;
mrb_get_args(mrb, "o", &str2); mrb_get_args(mrb, "o", &str2);
if (mrb_type(str2) == MRB_TT_FIXNUM) { if (mrb_type(str2) == MRB_TT_FIXNUM) {
if (memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self))) include_p = memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self));
return mrb_true_value();
return mrb_false_value();
} }
else {
mrb_string_value(mrb, &str2); mrb_string_value(mrb, &str2);
i = mrb_str_index(mrb, self, str2, 0); i = mrb_str_index(mrb, self, str2, 0);
if (i == -1) return mrb_false_value(); include_p = (i != -1);
return mrb_true_value(); }
return mrb_true_or_false_value(include_p);
} }
/* 15.2.10.5.22 */ /* 15.2.10.5.22 */
......
...@@ -158,10 +158,12 @@ static mrb_value ...@@ -158,10 +158,12 @@ static mrb_value
sym_equal(mrb_state *mrb, mrb_value sym1) sym_equal(mrb_state *mrb, mrb_value sym1)
{ {
mrb_value sym2; mrb_value sym2;
mrb_bool equal_p;
mrb_get_args(mrb, "o", &sym2); mrb_get_args(mrb, "o", &sym2);
if (mrb_obj_equal(mrb, sym1, sym2)) return mrb_true_value(); equal_p = mrb_obj_equal(mrb, sym1, sym2);
return mrb_false_value();
return mrb_true_or_false_value(equal_p);
} }
/* 15.2.11.3.2 */ /* 15.2.11.3.2 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment