Index: EcnlProtoTool/trunk/mruby-2.1.1/src/kernel.c
===================================================================
--- EcnlProtoTool/trunk/mruby-1.3.0/src/kernel.c	(revision 331)
+++ EcnlProtoTool/trunk/mruby-2.1.1/src/kernel.c	(revision 439)
@@ -15,23 +15,16 @@
 #include <mruby/istruct.h>
 
-typedef enum {
-  NOEX_PUBLIC    = 0x00,
-  NOEX_NOSUPER   = 0x01,
-  NOEX_PRIVATE   = 0x02,
-  NOEX_PROTECTED = 0x04,
-  NOEX_MASK      = 0x06,
-  NOEX_BASIC     = 0x08,
-  NOEX_UNDEF     = NOEX_NOSUPER,
-  NOEX_MODFUNC   = 0x12,
-  NOEX_SUPER     = 0x20,
-  NOEX_VCALL     = 0x40,
-  NOEX_RESPONDS  = 0x80
-} mrb_method_flag_t;
-
 MRB_API mrb_bool
 mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func)
 {
-  struct RProc *me = mrb_method_search(mrb, mrb_class(mrb, obj), mid);
-  if (MRB_PROC_CFUNC_P(me) && (me->body.func == func))
+  struct RClass *c = mrb_class(mrb, obj);
+  mrb_method_t m = mrb_method_search_vm(mrb, &c, mid);
+  struct RProc *p;
+
+  if (MRB_METHOD_UNDEF_P(m)) return FALSE;
+  if (MRB_METHOD_FUNC_P(m))
+    return MRB_METHOD_FUNC(m) == func;
+  p = MRB_METHOD_PROC(m);
+  if (MRB_PROC_CFUNC_P(p) && (MRB_PROC_CFUNC(p) == func))
     return TRUE;
   return FALSE;
@@ -61,5 +54,5 @@
 mrb_obj_inspect(mrb_state *mrb, mrb_value obj)
 {
-  if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) {
+  if (mrb_object_p(obj) && mrb_obj_basic_to_s_p(mrb, obj)) {
     return mrb_obj_iv_inspect(mrb, mrb_obj_ptr(obj));
   }
@@ -135,34 +128,50 @@
 mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
 {
-  mrb_callinfo *ci = mrb->c->ci;
+  mrb_callinfo *ci = &mrb->c->ci[-1];
+  mrb_callinfo *cibase = mrb->c->cibase;
   mrb_value *bp;
-
-  bp = ci->stackent + 1;
-  ci--;
-  if (ci <= mrb->c->cibase) {
+  struct RProc *p;
+
+  if (ci <= cibase) {
+    /* toplevel does not have block */
     return mrb_false_value();
   }
-  /* block_given? called within block; check upper scope */
-  if (ci->proc->env) {
-    struct REnv *e = ci->proc->env;
-
-    while (e->c) {
-      e = (struct REnv*)e->c;
-    }
+  p = ci->proc;
+  /* search method/class/module proc */
+  while (p) {
+    if (MRB_PROC_SCOPE_P(p)) break;
+    p = p->upper;
+  }
+  if (p == NULL) return mrb_false_value();
+  /* search ci corresponding to proc */
+  while (cibase < ci) {
+    if (ci->proc == p) break;
+    ci--;
+  }
+  if (ci == cibase) {
+    return mrb_false_value();
+  }
+  else if (ci->env) {
+    struct REnv *e = ci->env;
+    int bidx;
+
     /* top-level does not have block slot (always false) */
     if (e->stack == mrb->c->stbase)
       return mrb_false_value();
-    if (e->stack && e->cioff < 0) {
-      /* use saved block arg position */
-      bp = &e->stack[-e->cioff];
-      ci = 0;                 /* no callinfo available */
+    /* use saved block arg position */
+    bidx = MRB_ENV_BIDX(e);
+    /* bidx may be useless (e.g. define_method) */
+    if (bidx >= MRB_ENV_STACK_LEN(e))
+      return mrb_false_value();
+    bp = &e->stack[bidx];
+  }
+  else {
+    bp = ci[1].stackent+1;
+    if (ci->argc >= 0) {
+      bp += ci->argc;
     }
     else {
-      ci = e->cxt.c->cibase + e->cioff;
-      bp = ci[1].stackent + 1;
-    }
-  }
-  if (ci && ci->argc > 0) {
-    bp += ci->argc;
+      bp++;
+    }
   }
   if (mrb_nil_p(*bp))
@@ -231,10 +240,10 @@
   /* if the origin is not the same as the class, then the origin and
      the current class need to be copied */
-  if (sc->flags & MRB_FLAG_IS_PREPENDED) {
+  if (sc->flags & MRB_FL_CLASS_IS_PREPENDED) {
     struct RClass *c0 = sc->super;
     struct RClass *c1 = dc;
 
     /* copy prepended iclasses */
-    while (!(c0->flags & MRB_FLAG_IS_ORIGIN)) {
+    while (!(c0->flags & MRB_FL_CLASS_IS_ORIGIN)) {
       c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
       c1 = c1->super;
@@ -242,5 +251,5 @@
     }
     c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
-    c1->super->flags |= MRB_FLAG_IS_ORIGIN;
+    c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
   }
   if (sc->mt) {
@@ -258,8 +267,13 @@
 {
   switch (mrb_type(obj)) {
+    case MRB_TT_ICLASS:
+      copy_class(mrb, dest, obj);
+      return;
     case MRB_TT_CLASS:
     case MRB_TT_MODULE:
       copy_class(mrb, dest, obj);
-      /* fall through */
+      mrb_iv_copy(mrb, dest, obj);
+      mrb_iv_remove(mrb, dest, mrb_intern_lit(mrb, "__classname__"));
+      break;
     case MRB_TT_OBJECT:
     case MRB_TT_SCLASS:
@@ -312,13 +326,15 @@
 
   if (mrb_immediate_p(self)) {
-    mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %S", self);
-  }
-  if (mrb_type(self) == MRB_TT_SCLASS) {
+    mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %v", self);
+  }
+  if (mrb_sclass_p(self)) {
     mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
   }
   p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
   p->c = mrb_singleton_class_clone(mrb, self);
+  mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
   clone = mrb_obj_value(p);
   init_copy(mrb, clone, self);
+  p->flags |= mrb_obj_ptr(self)->flags & MRB_FL_OBJ_IS_FROZEN;
 
   return clone;
@@ -351,7 +367,7 @@
 
   if (mrb_immediate_p(obj)) {
-    mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %S", obj);
-  }
-  if (mrb_type(obj) == MRB_TT_SCLASS) {
+    mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %v", obj);
+  }
+  if (mrb_sclass_p(obj)) {
     mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
   }
@@ -369,5 +385,5 @@
 
   if (argc == 0) {
-    mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (at least 1)");
+    mrb_argnum_error(mrb, argc, 1, -1);
   }
   for (i = 0; i < argc; i++) {
@@ -411,31 +427,18 @@
   mrb_value *argv;
   mrb_int argc;
-  mrb_value args;
 
   mrb_get_args(mrb, "*", &argv, &argc);
-  args = mrb_ary_new_from_values(mrb, argc, argv);
-  argv = (mrb_value*)RARRAY_PTR(args);
   return mrb_obj_extend(mrb, argc, argv, self);
 }
 
-static mrb_value
+MRB_API mrb_value
 mrb_obj_freeze(mrb_state *mrb, mrb_value self)
 {
-  struct RBasic *b;
-
-  switch (mrb_type(self)) {
-    case MRB_TT_FALSE:
-    case MRB_TT_TRUE:
-    case MRB_TT_FIXNUM:
-    case MRB_TT_SYMBOL:
-    case MRB_TT_FLOAT:
-      return self;
-    default:
-      break;
-  }
-
-  b = mrb_basic_ptr(self);
-  if (!MRB_FROZEN_P(b)) {
-    MRB_SET_FROZEN_FLAG(b);
+  if (!mrb_immediate_p(self)) {
+    struct RBasic *b = mrb_basic_ptr(self);
+    if (!mrb_frozen_p(b)) {
+      MRB_SET_FROZEN_FLAG(b);
+      if (b->c->tt == MRB_TT_SCLASS) MRB_SET_FROZEN_FLAG(b->c);
+    }
   }
   return self;
@@ -445,22 +448,5 @@
 mrb_obj_frozen(mrb_state *mrb, mrb_value self)
 {
-  struct RBasic *b;
-
-  switch (mrb_type(self)) {
-    case MRB_TT_FALSE:
-    case MRB_TT_TRUE:
-    case MRB_TT_FIXNUM:
-    case MRB_TT_SYMBOL:
-    case MRB_TT_FLOAT:
-      return mrb_true_value();
-    default:
-      break;
-  }
-
-  b = mrb_basic_ptr(self);
-  if (!MRB_FROZEN_P(b)) {
-    return mrb_false_value();
-  }
-  return mrb_true_value();
+  return mrb_bool_value(mrb_immediate_p(self) || mrb_frozen_p(mrb_basic_ptr(self)));
 }
 
@@ -476,5 +462,5 @@
  *  <code>Fixnum</code> will be truncated before being used.
  */
-MRB_API mrb_value
+static mrb_value
 mrb_obj_hash(mrb_state *mrb, mrb_value self)
 {
@@ -520,94 +506,4 @@
 
   return mrb_bool_value(mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg)));
-}
-
-/* 15.3.1.3.20 */
-/*
- *  call-seq:
- *     obj.instance_variable_defined?(symbol)    -> true or false
- *
- *  Returns <code>true</code> if the given instance variable is
- *  defined in <i>obj</i>.
- *
- *     class Fred
- *       def initialize(p1, p2)
- *         @a, @b = p1, p2
- *       end
- *     end
- *     fred = Fred.new('cat', 99)
- *     fred.instance_variable_defined?(:@a)    #=> true
- *     fred.instance_variable_defined?("@b")   #=> true
- *     fred.instance_variable_defined?("@c")   #=> false
- */
-static mrb_value
-mrb_obj_ivar_defined(mrb_state *mrb, mrb_value self)
-{
-  mrb_sym sym;
-
-  mrb_get_args(mrb, "n", &sym);
-  mrb_iv_check(mrb, sym);
-  return mrb_bool_value(mrb_iv_defined(mrb, self, sym));
-}
-
-/* 15.3.1.3.21 */
-/*
- *  call-seq:
- *     obj.instance_variable_get(symbol)    -> obj
- *
- *  Returns the value of the given instance variable, or nil if the
- *  instance variable is not set. The <code>@</code> part of the
- *  variable name should be included for regular instance
- *  variables. Throws a <code>NameError</code> exception if the
- *  supplied symbol is not valid as an instance variable name.
- *
- *     class Fred
- *       def initialize(p1, p2)
- *         @a, @b = p1, p2
- *       end
- *     end
- *     fred = Fred.new('cat', 99)
- *     fred.instance_variable_get(:@a)    #=> "cat"
- *     fred.instance_variable_get("@b")   #=> 99
- */
-static mrb_value
-mrb_obj_ivar_get(mrb_state *mrb, mrb_value self)
-{
-  mrb_sym iv_name;
-
-  mrb_get_args(mrb, "n", &iv_name);
-  mrb_iv_check(mrb, iv_name);
-  return mrb_iv_get(mrb, self, iv_name);
-}
-
-/* 15.3.1.3.22 */
-/*
- *  call-seq:
- *     obj.instance_variable_set(symbol, obj)    -> obj
- *
- *  Sets the instance variable names by <i>symbol</i> to
- *  <i>object</i>, thereby frustrating the efforts of the class's
- *  author to attempt to provide proper encapsulation. The variable
- *  did not have to exist prior to this call.
- *
- *     class Fred
- *       def initialize(p1, p2)
- *         @a, @b = p1, p2
- *       end
- *     end
- *     fred = Fred.new('cat', 99)
- *     fred.instance_variable_set(:@a, 'dog')   #=> "dog"
- *     fred.instance_variable_set(:@c, 'cat')   #=> "cat"
- *     fred.inspect                             #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
- */
-static mrb_value
-mrb_obj_ivar_set(mrb_state *mrb, mrb_value self)
-{
-  mrb_sym iv_name;
-  mrb_value val;
-
-  mrb_get_args(mrb, "no", &iv_name, &val);
-  mrb_iv_check(mrb, iv_name);
-  mrb_iv_set(mrb, self, iv_name, val);
-  return val;
 }
 
@@ -652,120 +548,4 @@
 KHASH_DEFINE(st, mrb_sym, char, FALSE, kh_int_hash_func, kh_int_hash_equal)
 
-static void
-method_entry_loop(mrb_state *mrb, struct RClass* klass, khash_t(st)* set)
-{
-  khint_t i;
-
-  khash_t(mt) *h = klass->mt;
-  if (!h) return;
-  for (i=0;i<kh_end(h);i++) {
-    if (kh_exist(h, i) && kh_value(h, i)) {
-      kh_put(st, mrb, set, kh_key(h, i));
-    }
-  }
-}
-
-mrb_value
-mrb_class_instance_method_list(mrb_state *mrb, mrb_bool recur, struct RClass* klass, int obj)
-{
-  khint_t i;
-  mrb_value ary;
-  mrb_bool prepended = FALSE;
-  struct RClass* oldklass;
-  khash_t(st)* set = kh_init(st, mrb);
-
-  if (!recur && (klass->flags & MRB_FLAG_IS_PREPENDED)) {
-    MRB_CLASS_ORIGIN(klass);
-    prepended = TRUE;
-  }
-
-  oldklass = 0;
-  while (klass && (klass != oldklass)) {
-    method_entry_loop(mrb, klass, set);
-    if ((klass->tt == MRB_TT_ICLASS && !prepended) ||
-        (klass->tt == MRB_TT_SCLASS)) {
-    }
-    else {
-      if (!recur) break;
-    }
-    oldklass = klass;
-    klass = klass->super;
-  }
-
-  ary = mrb_ary_new(mrb);
-  for (i=0;i<kh_end(set);i++) {
-    if (kh_exist(set, i)) {
-      mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(set, i)));
-    }
-  }
-  kh_destroy(st, mrb, set);
-
-  return ary;
-}
-
-static mrb_value
-mrb_obj_singleton_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj)
-{
-  khint_t i;
-  mrb_value ary;
-  struct RClass* klass;
-  khash_t(st)* set = kh_init(st, mrb);
-
-  klass = mrb_class(mrb, obj);
-
-  if (klass && (klass->tt == MRB_TT_SCLASS)) {
-      method_entry_loop(mrb, klass, set);
-      klass = klass->super;
-  }
-  if (recur) {
-      while (klass && ((klass->tt == MRB_TT_SCLASS) || (klass->tt == MRB_TT_ICLASS))) {
-        method_entry_loop(mrb, klass, set);
-        klass = klass->super;
-      }
-  }
-
-  ary = mrb_ary_new(mrb);
-  for (i=0;i<kh_end(set);i++) {
-    if (kh_exist(set, i)) {
-      mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(set, i)));
-    }
-  }
-  kh_destroy(st, mrb, set);
-
-  return ary;
-}
-
-static mrb_value
-mrb_obj_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj, mrb_method_flag_t flag)
-{
-  return mrb_class_instance_method_list(mrb, recur, mrb_class(mrb, obj), 0);
-}
-/* 15.3.1.3.31 */
-/*
- *  call-seq:
- *     obj.methods    -> array
- *
- *  Returns a list of the names of methods publicly accessible in
- *  <i>obj</i>. This will include all the methods accessible in
- *  <i>obj</i>'s ancestors.
- *
- *     class Klass
- *       def kMethod()
- *       end
- *     end
- *     k = Klass.new
- *     k.methods[0..9]    #=> [:kMethod, :respond_to?, :nil?, :is_a?,
- *                        #    :class, :instance_variable_set,
- *                        #    :methods, :extend, :__send__, :instance_eval]
- *     k.methods.length   #=> 42
- */
-static mrb_value
-mrb_obj_methods_m(mrb_state *mrb, mrb_value self)
-{
-  mrb_bool recur = TRUE;
-  mrb_get_args(mrb, "|b", &recur);
-  return mrb_obj_methods(mrb, recur, self, (mrb_method_flag_t)0); /* everything but private */
-}
-
 /* 15.3.1.3.32 */
 /*
@@ -780,55 +560,4 @@
 {
   return mrb_false_value();
-}
-
-/* 15.3.1.3.36 */
-/*
- *  call-seq:
- *     obj.private_methods(all=true)   -> array
- *
- *  Returns the list of private methods accessible to <i>obj</i>. If
- *  the <i>all</i> parameter is set to <code>false</code>, only those methods
- *  in the receiver will be listed.
- */
-static mrb_value
-mrb_obj_private_methods(mrb_state *mrb, mrb_value self)
-{
-  mrb_bool recur = TRUE;
-  mrb_get_args(mrb, "|b", &recur);
-  return mrb_obj_methods(mrb, recur, self, NOEX_PRIVATE); /* private attribute not define */
-}
-
-/* 15.3.1.3.37 */
-/*
- *  call-seq:
- *     obj.protected_methods(all=true)   -> array
- *
- *  Returns the list of protected methods accessible to <i>obj</i>. If
- *  the <i>all</i> parameter is set to <code>false</code>, only those methods
- *  in the receiver will be listed.
- */
-static mrb_value
-mrb_obj_protected_methods(mrb_state *mrb, mrb_value self)
-{
-  mrb_bool recur = TRUE;
-  mrb_get_args(mrb, "|b", &recur);
-  return mrb_obj_methods(mrb, recur, self, NOEX_PROTECTED); /* protected attribute not define */
-}
-
-/* 15.3.1.3.38 */
-/*
- *  call-seq:
- *     obj.public_methods(all=true)   -> array
- *
- *  Returns the list of public methods accessible to <i>obj</i>. If
- *  the <i>all</i> parameter is set to <code>false</code>, only those methods
- *  in the receiver will be listed.
- */
-static mrb_value
-mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
-{
-  mrb_bool recur = TRUE;
-  mrb_get_args(mrb, "|b", &recur);
-  return mrb_obj_methods(mrb, recur, self, NOEX_PUBLIC); /* public attribute not define */
 }
 
@@ -858,5 +587,5 @@
 {
   mrb_value a[2], exc;
-  int argc;
+  mrb_int argc;
 
 
@@ -910,8 +639,8 @@
 
   mrb_get_args(mrb, "n", &sym);
-  mrb_iv_check(mrb, sym);
+  mrb_iv_name_sym_check(mrb, sym);
   val = mrb_iv_remove(mrb, self, sym);
   if (mrb_undef_p(val)) {
-    mrb_name_error(mrb, sym, "instance variable %S not defined", mrb_sym2str(mrb, sym));
+    mrb_name_error(mrb, sym, "instance variable %n not defined", sym);
   }
   return val;
@@ -921,24 +650,5 @@
 mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args)
 {
-  mrb_sym inspect;
-  mrb_value repr;
-
-  inspect = mrb_intern_lit(mrb, "inspect");
-  if (mrb->c->ci > mrb->c->cibase && mrb->c->ci[-1].mid == inspect) {
-    /* method missing in inspect; avoid recursion */
-    repr = mrb_any_to_s(mrb, self);
-  }
-  else if (mrb_respond_to(mrb, self, inspect) && mrb->c->ci - mrb->c->cibase < 16) {
-    repr = mrb_funcall_argv(mrb, self, inspect, 0, 0);
-    if (mrb_string_p(repr) && RSTRING_LEN(repr) > 64) {
-      repr = mrb_any_to_s(mrb, self);
-    }
-  }
-  else {
-    repr = mrb_any_to_s(mrb, self);
-  }
-
-  mrb_no_method_error(mrb, name, args, "undefined method '%S' for %S",
-                      mrb_sym2str(mrb, name), repr);
+  mrb_no_method_error(mrb, name, args, "undefined method '%n'", name);
 }
 
@@ -976,5 +686,4 @@
  *     r.mm      #=> 2000
  */
-#ifdef MRB_DEFAULT_METHOD_MISSING
 static mrb_value
 mrb_obj_missing(mrb_state *mrb, mrb_value mod)
@@ -984,10 +693,9 @@
   mrb_int alen;
 
-  mrb_get_args(mrb, "n*", &name, &a, &alen);
+  mrb_get_args(mrb, "n*!", &name, &a, &alen);
   mrb_method_missing(mrb, name, mod, mrb_ary_new_from_values(mrb, alen, a));
   /* not reached */
   return mrb_nil_value();
 }
-#endif
 
 static inline mrb_bool
@@ -996,4 +704,5 @@
   return mrb_respond_to(mrb, obj, id);
 }
+
 /* 15.3.1.3.43 */
 /*
@@ -1015,43 +724,14 @@
 obj_respond_to(mrb_state *mrb, mrb_value self)
 {
-  mrb_value mid;
   mrb_sym id, rtm_id;
-  mrb_bool priv = FALSE, respond_to_p = TRUE;
-
-  mrb_get_args(mrb, "o|b", &mid, &priv);
-
-  if (mrb_symbol_p(mid)) {
-    id = mrb_symbol(mid);
-  }
-  else {
-    mrb_value tmp;
-    if (mrb_string_p(mid)) {
-      tmp = mrb_check_intern_str(mrb, mid);
-    }
-    else {
-      tmp = mrb_check_string_type(mrb, mid);
-      if (mrb_nil_p(tmp)) {
-        tmp = mrb_inspect(mrb, mid);
-        mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a symbol", tmp);
-      }
-      tmp = mrb_check_intern_str(mrb, tmp);
-    }
-    if (mrb_nil_p(tmp)) {
-      respond_to_p = FALSE;
-    }
-    else {
-      id = mrb_symbol(tmp);
-    }
-  }
-
-  if (respond_to_p) {
-    respond_to_p = basic_obj_respond_to(mrb, self, id, !priv);
-  }
-
+  mrb_bool priv = FALSE, respond_to_p;
+
+  mrb_get_args(mrb, "n|b", &id, &priv);
+  respond_to_p = basic_obj_respond_to(mrb, self, id, !priv);
   if (!respond_to_p) {
     rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
     if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) {
       mrb_value args[2], v;
-      args[0] = mid;
+      args[0] = mrb_symbol_value(id);
       args[1] = mrb_bool_value(priv);
       v = mrb_funcall_argv(mrb, self, rtm_id, 2, args);
@@ -1060,63 +740,4 @@
   }
   return mrb_bool_value(respond_to_p);
-}
-
-/* 15.3.1.3.45 */
-/*
- *  call-seq:
- *     obj.singleton_methods(all=true)    -> array
- *
- *  Returns an array of the names of singleton methods for <i>obj</i>.
- *  If the optional <i>all</i> parameter is true, the list will include
- *  methods in modules included in <i>obj</i>.
- *  Only public and protected singleton methods are returned.
- *
- *     module Other
- *       def three() end
- *     end
- *
- *     class Single
- *       def Single.four() end
- *     end
- *
- *     a = Single.new
- *
- *     def a.one()
- *     end
- *
- *     class << a
- *       include Other
- *       def two()
- *       end
- *     end
- *
- *     Single.singleton_methods    #=> [:four]
- *     a.singleton_methods(false)  #=> [:two, :one]
- *     a.singleton_methods         #=> [:two, :one, :three]
- */
-static mrb_value
-mrb_obj_singleton_methods_m(mrb_state *mrb, mrb_value self)
-{
-  mrb_bool recur = TRUE;
-  mrb_get_args(mrb, "|b", &recur);
-  return mrb_obj_singleton_methods(mrb, recur, self);
-}
-
-static mrb_value
-mod_define_singleton_method(mrb_state *mrb, mrb_value self)
-{
-  struct RProc *p;
-  mrb_sym mid;
-  mrb_value blk = mrb_nil_value();
-
-  mrb_get_args(mrb, "n&", &mid, &blk);
-  if (mrb_nil_p(blk)) {
-    mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
-  }
-  p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class);
-  mrb_proc_copy(p, mrb_proc_ptr(blk));
-  p->flags |= MRB_PROC_STRICT;
-  mrb_define_method_raw(mrb, mrb_class_ptr(mrb_singleton_class(mrb, self)), mid, p);
-  return mrb_symbol_value(mid);
 }
 
@@ -1138,51 +759,6 @@
 }
 
-static mrb_value
-mrb_local_variables(mrb_state *mrb, mrb_value self)
-{
-  struct RProc *proc;
-  mrb_value vars;
-  struct mrb_irep *irep;
-  size_t i;
-
-  proc = mrb->c->ci[-1].proc;
-
-  if (MRB_PROC_CFUNC_P(proc)) {
-    return mrb_ary_new(mrb);
-  }
-
-  irep = proc->body.irep;
-  if (!irep->lv) {
-    return mrb_ary_new(mrb);
-  }
-  vars = mrb_hash_new(mrb);
-  for (i = 0; i + 1 < irep->nlocals; ++i) {
-    if (irep->lv[i].name) {
-      mrb_hash_set(mrb, vars, mrb_symbol_value(irep->lv[i].name), mrb_true_value());
-    }
-  }
-  if (proc->env) {
-    struct REnv *e = proc->env;
-
-    while (e) {
-      if (MRB_ENV_STACK_SHARED_P(e) &&
-          !MRB_PROC_CFUNC_P(e->cxt.c->cibase[e->cioff].proc)) {
-        irep = e->cxt.c->cibase[e->cioff].proc->body.irep;
-        if (irep->lv) {
-          for (i = 0; i + 1 < irep->nlocals; ++i) {
-            if (irep->lv[i].name) {
-              mrb_hash_set(mrb, vars, mrb_symbol_value(irep->lv[i].name), mrb_true_value());
-            }
-          }
-        }
-      }
-      e = (struct REnv*)e->c;
-    }
-  }
-
-  return mrb_hash_keys(mrb, vars);
-}
-
 mrb_value mrb_obj_equal_m(mrb_state *mrb, mrb_value);
+
 void
 mrb_init_kernel(mrb_state *mrb)
@@ -1192,11 +768,8 @@
   mrb->kernel_module = krn = mrb_define_module(mrb, "Kernel");                                                    /* 15.3.1 */
   mrb_define_class_method(mrb, krn, "block_given?",         mrb_f_block_given_p_m,           MRB_ARGS_NONE());    /* 15.3.1.2.2  */
-  mrb_define_class_method(mrb, krn, "global_variables",     mrb_f_global_variables,          MRB_ARGS_NONE());    /* 15.3.1.2.4  */
   mrb_define_class_method(mrb, krn, "iterator?",            mrb_f_block_given_p_m,           MRB_ARGS_NONE());    /* 15.3.1.2.5  */
-  mrb_define_class_method(mrb, krn, "local_variables",      mrb_local_variables,             MRB_ARGS_NONE());    /* 15.3.1.2.7  */
 ;     /* 15.3.1.2.11 */
   mrb_define_class_method(mrb, krn, "raise",                mrb_f_raise,                     MRB_ARGS_OPT(2));    /* 15.3.1.2.12 */
 
-  mrb_define_method(mrb, krn, "singleton_class",            mrb_singleton_class,             MRB_ARGS_NONE());
 
   mrb_define_method(mrb, krn, "===",                        mrb_equal_m,                     MRB_ARGS_REQ(1));    /* 15.3.1.3.2  */
@@ -1206,40 +779,26 @@
   mrb_define_method(mrb, krn, "dup",                        mrb_obj_dup,                     MRB_ARGS_NONE());    /* 15.3.1.3.9  */
   mrb_define_method(mrb, krn, "eql?",                       mrb_obj_equal_m,                 MRB_ARGS_REQ(1));    /* 15.3.1.3.10 */
-  mrb_define_method(mrb, krn, "equal?",                     mrb_obj_equal_m,                 MRB_ARGS_REQ(1));    /* 15.3.1.3.11 */
   mrb_define_method(mrb, krn, "extend",                     mrb_obj_extend_m,                MRB_ARGS_ANY());     /* 15.3.1.3.13 */
   mrb_define_method(mrb, krn, "freeze",                     mrb_obj_freeze,                  MRB_ARGS_NONE());
   mrb_define_method(mrb, krn, "frozen?",                    mrb_obj_frozen,                  MRB_ARGS_NONE());
-  mrb_define_method(mrb, krn, "global_variables",           mrb_f_global_variables,          MRB_ARGS_NONE());    /* 15.3.1.3.14 */
   mrb_define_method(mrb, krn, "hash",                       mrb_obj_hash,                    MRB_ARGS_NONE());    /* 15.3.1.3.15 */
   mrb_define_method(mrb, krn, "initialize_copy",            mrb_obj_init_copy,               MRB_ARGS_REQ(1));    /* 15.3.1.3.16 */
   mrb_define_method(mrb, krn, "inspect",                    mrb_obj_inspect,                 MRB_ARGS_NONE());    /* 15.3.1.3.17 */
   mrb_define_method(mrb, krn, "instance_of?",               obj_is_instance_of,              MRB_ARGS_REQ(1));    /* 15.3.1.3.19 */
-  mrb_define_method(mrb, krn, "instance_variable_defined?", mrb_obj_ivar_defined,            MRB_ARGS_REQ(1));    /* 15.3.1.3.20 */
-  mrb_define_method(mrb, krn, "instance_variable_get",      mrb_obj_ivar_get,                MRB_ARGS_REQ(1));    /* 15.3.1.3.21 */
-  mrb_define_method(mrb, krn, "instance_variable_set",      mrb_obj_ivar_set,                MRB_ARGS_REQ(2));    /* 15.3.1.3.22 */
-  mrb_define_method(mrb, krn, "instance_variables",         mrb_obj_instance_variables,      MRB_ARGS_NONE());    /* 15.3.1.3.23 */
+
   mrb_define_method(mrb, krn, "is_a?",                      mrb_obj_is_kind_of_m,            MRB_ARGS_REQ(1));    /* 15.3.1.3.24 */
   mrb_define_method(mrb, krn, "iterator?",                  mrb_f_block_given_p_m,           MRB_ARGS_NONE());    /* 15.3.1.3.25 */
   mrb_define_method(mrb, krn, "kind_of?",                   mrb_obj_is_kind_of_m,            MRB_ARGS_REQ(1));    /* 15.3.1.3.26 */
-  mrb_define_method(mrb, krn, "local_variables",            mrb_local_variables,             MRB_ARGS_NONE());    /* 15.3.1.3.28 */
-#ifdef MRB_DEFAULT_METHOD_MISSING
   mrb_define_method(mrb, krn, "method_missing",             mrb_obj_missing,                 MRB_ARGS_ANY());     /* 15.3.1.3.30 */
-#endif
-  mrb_define_method(mrb, krn, "methods",                    mrb_obj_methods_m,               MRB_ARGS_OPT(1));    /* 15.3.1.3.31 */
   mrb_define_method(mrb, krn, "nil?",                       mrb_false,                       MRB_ARGS_NONE());    /* 15.3.1.3.32 */
   mrb_define_method(mrb, krn, "object_id",                  mrb_obj_id_m,                    MRB_ARGS_NONE());    /* 15.3.1.3.33 */
-  mrb_define_method(mrb, krn, "private_methods",            mrb_obj_private_methods,         MRB_ARGS_OPT(1));    /* 15.3.1.3.36 */
-  mrb_define_method(mrb, krn, "protected_methods",          mrb_obj_protected_methods,       MRB_ARGS_OPT(1));    /* 15.3.1.3.37 */
-  mrb_define_method(mrb, krn, "public_methods",             mrb_obj_public_methods,          MRB_ARGS_OPT(1));    /* 15.3.1.3.38 */
   mrb_define_method(mrb, krn, "raise",                      mrb_f_raise,                     MRB_ARGS_ANY());     /* 15.3.1.3.40 */
   mrb_define_method(mrb, krn, "remove_instance_variable",   mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1));    /* 15.3.1.3.41 */
-  mrb_define_method(mrb, krn, "respond_to?",                obj_respond_to,                  MRB_ARGS_ANY());     /* 15.3.1.3.43 */
-  mrb_define_method(mrb, krn, "send",                       mrb_f_send,                      MRB_ARGS_ANY());     /* 15.3.1.3.44 */
-  mrb_define_method(mrb, krn, "singleton_methods",          mrb_obj_singleton_methods_m,     MRB_ARGS_OPT(1));    /* 15.3.1.3.45 */
-  mrb_define_method(mrb, krn, "define_singleton_method",    mod_define_singleton_method,     MRB_ARGS_ANY());
+  mrb_define_method(mrb, krn, "respond_to?",                obj_respond_to,                  MRB_ARGS_ARG(1,1));     /* 15.3.1.3.43 */
   mrb_define_method(mrb, krn, "to_s",                       mrb_any_to_s,                    MRB_ARGS_NONE());    /* 15.3.1.3.46 */
   mrb_define_method(mrb, krn, "__case_eqq",                 mrb_obj_ceqq,                    MRB_ARGS_REQ(1));    /* internal */
+  mrb_define_method(mrb, krn, "__to_int",                   mrb_to_int,                      MRB_ARGS_NONE()); /* internal */
+  mrb_define_method(mrb, krn, "__to_str",                   mrb_to_str,                      MRB_ARGS_NONE()); /* internal */
 
   mrb_include_module(mrb, mrb->object_class, mrb->kernel_module);
-  mrb_alias_method(mrb, mrb->module_class, mrb_intern_lit(mrb, "dup"), mrb_intern_lit(mrb, "clone"));
-}
+}
