2 ** kernel.c - Kernel module
4 ** See Copyright Notice in mruby.h
8 #include <mruby/array.h>
9 #include <mruby/hash.h>
10 #include <mruby/class.h>
11 #include <mruby/proc.h>
12 #include <mruby/string.h>
13 #include <mruby/variable.h>
14 #include <mruby/error.h>
15 #include <mruby/istruct.h>
18 mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func)
20 struct RClass *c = mrb_class(mrb, obj);
21 mrb_method_t m = mrb_method_search_vm(mrb, &c, mid);
24 if (MRB_METHOD_UNDEF_P(m)) return FALSE;
25 if (MRB_METHOD_FUNC_P(m))
26 return MRB_METHOD_FUNC(m) == func;
27 p = MRB_METHOD_PROC(m);
28 if (MRB_PROC_CFUNC_P(p) && (MRB_PROC_CFUNC(p) == func))
34 mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj)
36 return mrb_func_basic_p(mrb, obj, mrb_intern_lit(mrb, "to_s"), mrb_any_to_s);
42 * obj.inspect -> string
44 * Returns a string containing a human-readable representation of
45 * <i>obj</i>. If not overridden and no instance variables, uses the
46 * <code>to_s</code> method to generate the string.
47 * <i>obj</i>. If not overridden, uses the <code>to_s</code> method to
48 * generate the string.
50 * [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
51 * Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
54 mrb_obj_inspect(mrb_state *mrb, mrb_value obj)
56 if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) {
57 return mrb_obj_iv_inspect(mrb, mrb_obj_ptr(obj));
59 return mrb_any_to_s(mrb, obj);
65 * obj === other -> true or false
67 * Case Equality---For class <code>Object</code>, effectively the same
68 * as calling <code>#==</code>, but typically overridden by descendants
69 * to provide meaningful semantics in <code>case</code> statements.
72 mrb_equal_m(mrb_state *mrb, mrb_value self)
76 mrb_get_args(mrb, "o", &arg);
77 return mrb_bool_value(mrb_equal(mrb, self, arg));
83 * Document-method: __id__
84 * Document-method: object_id
87 * obj.__id__ -> fixnum
88 * obj.object_id -> fixnum
90 * Returns an integer identifier for <i>obj</i>. The same number will
91 * be returned on all calls to <code>id</code> for a given object, and
92 * no two active objects will share an id.
93 * <code>Object#object_id</code> is a different concept from the
94 * <code>:name</code> notation, which returns the symbol id of
95 * <code>name</code>. Replaces the deprecated <code>Object#id</code>.
98 mrb_obj_id_m(mrb_state *mrb, mrb_value self)
100 return mrb_fixnum_value(mrb_obj_id(self));
109 * block_given? -> true or false
110 * iterator? -> true or false
112 * Returns <code>true</code> if <code>yield</code> would execute a
113 * block in the current context. The <code>iterator?</code> form
114 * is mildly deprecated.
124 * try { "hello" } #=> "hello"
125 * try do "hello" end #=> "hello"
128 mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
130 mrb_callinfo *ci = &mrb->c->ci[-1];
131 mrb_callinfo *cibase = mrb->c->cibase;
136 /* toplevel does not have block */
137 return mrb_false_value();
140 /* search method/class/module proc */
142 if (MRB_PROC_SCOPE_P(p)) break;
145 if (p == NULL) return mrb_false_value();
146 /* search ci corresponding to proc */
147 while (cibase < ci) {
148 if (ci->proc == p) break;
152 return mrb_false_value();
155 struct REnv *e = ci->env;
158 /* top-level does not have block slot (always false) */
159 if (e->stack == mrb->c->stbase)
160 return mrb_false_value();
161 /* use saved block arg position */
162 bidx = MRB_ENV_BIDX(e);
163 /* bidx may be useless (e.g. define_method) */
164 if (bidx >= MRB_ENV_STACK_LEN(e))
165 return mrb_false_value();
166 bp = &e->stack[bidx];
169 bp = ci[1].stackent+1;
178 return mrb_false_value();
179 return mrb_true_value();
187 * Returns the class of <i>obj</i>. This method must always be
188 * called with an explicit receiver, as <code>class</code> is also a
189 * reserved word in Ruby.
192 * self.class #=> Object
195 mrb_obj_class_m(mrb_state *mrb, mrb_value self)
197 return mrb_obj_value(mrb_obj_class(mrb, self));
200 static struct RClass*
201 mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
203 struct RClass *klass = mrb_basic_ptr(obj)->c;
205 if (klass->tt != MRB_TT_SCLASS)
208 /* copy singleton(unnamed) class */
209 struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class);
211 switch (mrb_type(obj)) {
216 clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass));
219 clone->super = klass->super;
221 mrb_iv_copy(mrb, mrb_obj_value(clone), mrb_obj_value(klass));
222 mrb_obj_iv_set(mrb, (struct RObject*)clone, mrb_intern_lit(mrb, "__attached__"), obj);
225 clone->mt = kh_copy(mt, mrb, klass->mt);
228 clone->mt = kh_init(mt, mrb);
230 clone->tt = MRB_TT_SCLASS;
236 copy_class(mrb_state *mrb, mrb_value dst, mrb_value src)
238 struct RClass *dc = mrb_class_ptr(dst);
239 struct RClass *sc = mrb_class_ptr(src);
240 /* if the origin is not the same as the class, then the origin and
241 the current class need to be copied */
242 if (sc->flags & MRB_FL_CLASS_IS_PREPENDED) {
243 struct RClass *c0 = sc->super;
244 struct RClass *c1 = dc;
246 /* copy prepended iclasses */
247 while (!(c0->flags & MRB_FL_CLASS_IS_ORIGIN)) {
248 c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
252 c1->super = mrb_class_ptr(mrb_obj_dup(mrb, mrb_obj_value(c0)));
253 c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
256 dc->mt = kh_copy(mt, mrb, sc->mt);
259 dc->mt = kh_init(mt, mrb);
261 dc->super = sc->super;
262 MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc));
266 init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
268 switch (mrb_type(obj)) {
270 copy_class(mrb, dest, obj);
274 copy_class(mrb, dest, obj);
275 mrb_iv_copy(mrb, dest, obj);
276 mrb_iv_remove(mrb, dest, mrb_intern_lit(mrb, "__classname__"));
282 case MRB_TT_EXCEPTION:
283 mrb_iv_copy(mrb, dest, obj);
286 mrb_istruct_copy(dest, obj);
292 mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
298 * obj.clone -> an_object
300 * Produces a shallow copy of <i>obj</i>---the instance variables of
301 * <i>obj</i> are copied, but not the objects they reference. Copies
302 * the frozen state of <i>obj</i>. See also the discussion
303 * under <code>Object#dup</code>.
308 * s1 = Klass.new #=> #<Klass:0x401b3a38>
309 * s1.str = "Hello" #=> "Hello"
310 * s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
311 * s2.str[1,4] = "i" #=> "i"
312 * s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
313 * s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
315 * This method may have class-specific behavior. If so, that
316 * behavior will be documented under the #+initialize_copy+ method of
319 * Some Class(True False Nil Symbol Fixnum Float) Object cannot clone.
322 mrb_obj_clone(mrb_state *mrb, mrb_value self)
327 if (mrb_immediate_p(self)) {
328 mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %S", self);
330 if (mrb_type(self) == MRB_TT_SCLASS) {
331 mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
333 p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
334 p->c = mrb_singleton_class_clone(mrb, self);
335 mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
336 clone = mrb_obj_value(p);
337 init_copy(mrb, clone, self);
338 p->flags |= mrb_obj_ptr(self)->flags & MRB_FL_OBJ_IS_FROZEN;
346 * obj.dup -> an_object
348 * Produces a shallow copy of <i>obj</i>---the instance variables of
349 * <i>obj</i> are copied, but not the objects they reference.
350 * <code>dup</code> copies the frozen state of <i>obj</i>. See also
351 * the discussion under <code>Object#clone</code>. In general,
352 * <code>clone</code> and <code>dup</code> may have different semantics
353 * in descendant classes. While <code>clone</code> is used to duplicate
354 * an object, including its internal state, <code>dup</code> typically
355 * uses the class of the descendant object to create the new instance.
357 * This method may have class-specific behavior. If so, that
358 * behavior will be documented under the #+initialize_copy+ method of
363 mrb_obj_dup(mrb_state *mrb, mrb_value obj)
368 if (mrb_immediate_p(obj)) {
369 mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %S", obj);
371 if (mrb_type(obj) == MRB_TT_SCLASS) {
372 mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
374 p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
375 dup = mrb_obj_value(p);
376 init_copy(mrb, dup, obj);
382 mrb_obj_extend(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value obj)
387 mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (at least 1)");
389 for (i = 0; i < argc; i++) {
390 mrb_check_type(mrb, argv[i], MRB_TT_MODULE);
393 mrb_funcall(mrb, argv[argc], "extend_object", 1, obj);
394 mrb_funcall(mrb, argv[argc], "extended", 1, obj);
402 * obj.extend(module, ...) -> obj
404 * Adds to _obj_ the instance methods from each module given as a
409 * "Hello from Mod.\n"
415 * "Hello from Klass.\n"
420 * k.hello #=> "Hello from Klass.\n"
421 * k.extend(Mod) #=> #<Klass:0x401b3bc8>
422 * k.hello #=> "Hello from Mod.\n"
425 mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
430 mrb_get_args(mrb, "*", &argv, &argc);
431 return mrb_obj_extend(mrb, argc, argv, self);
435 mrb_obj_freeze(mrb_state *mrb, mrb_value self)
439 switch (mrb_type(self)) {
444 #ifndef MRB_WITHOUT_FLOAT
452 b = mrb_basic_ptr(self);
453 if (!MRB_FROZEN_P(b)) {
454 MRB_SET_FROZEN_FLAG(b);
460 mrb_obj_frozen(mrb_state *mrb, mrb_value self)
464 switch (mrb_type(self)) {
469 #ifndef MRB_WITHOUT_FLOAT
472 return mrb_true_value();
477 b = mrb_basic_ptr(self);
478 if (!MRB_FROZEN_P(b)) {
479 return mrb_false_value();
481 return mrb_true_value();
489 * Generates a <code>Fixnum</code> hash value for this object. This
490 * function must have the property that <code>a.eql?(b)</code> implies
491 * <code>a.hash == b.hash</code>. The hash value is used by class
492 * <code>Hash</code>. Any hash value that exceeds the capacity of a
493 * <code>Fixnum</code> will be truncated before being used.
496 mrb_obj_hash(mrb_state *mrb, mrb_value self)
498 return mrb_fixnum_value(mrb_obj_id(self));
503 mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
507 mrb_get_args(mrb, "o", &orig);
508 if (mrb_obj_equal(mrb, self, orig)) return self;
509 if ((mrb_type(self) != mrb_type(orig)) || (mrb_obj_class(mrb, self) != mrb_obj_class(mrb, orig))) {
510 mrb_raise(mrb, E_TYPE_ERROR, "initialize_copy should take same class object");
517 mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c)
519 if (mrb_obj_class(mrb, obj) == c) return TRUE;
526 * obj.instance_of?(class) -> true or false
528 * Returns <code>true</code> if <i>obj</i> is an instance of the given
529 * class. See also <code>Object#kind_of?</code>.
532 obj_is_instance_of(mrb_state *mrb, mrb_value self)
536 mrb_get_args(mrb, "C", &arg);
538 return mrb_bool_value(mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg)));
545 * obj.is_a?(class) -> true or false
546 * obj.kind_of?(class) -> true or false
548 * Returns <code>true</code> if <i>class</i> is the class of
549 * <i>obj</i>, or if <i>class</i> is one of the superclasses of
550 * <i>obj</i> or modules included in <i>obj</i>.
559 * b.instance_of? A #=> false
560 * b.instance_of? B #=> true
561 * b.instance_of? C #=> false
562 * b.instance_of? M #=> false
563 * b.kind_of? A #=> true
564 * b.kind_of? B #=> true
565 * b.kind_of? C #=> false
566 * b.kind_of? M #=> true
569 mrb_obj_is_kind_of_m(mrb_state *mrb, mrb_value self)
573 mrb_get_args(mrb, "C", &arg);
575 return mrb_bool_value(mrb_obj_is_kind_of(mrb, self, mrb_class_ptr(arg)));
578 KHASH_DECLARE(st, mrb_sym, char, FALSE)
579 KHASH_DEFINE(st, mrb_sym, char, FALSE, kh_int_hash_func, kh_int_hash_equal)
585 * <anything_else>.nil? -> false
587 * Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>.
590 mrb_false(mrb_state *mrb, mrb_value self)
592 return mrb_false_value();
601 * raise(exception [, string])
603 * With no arguments, raises a <code>RuntimeError</code>
604 * With a single +String+ argument, raises a
605 * +RuntimeError+ with the string as a message. Otherwise,
606 * the first parameter should be the name of an +Exception+
607 * class (or an object that returns an +Exception+ object when sent
608 * an +exception+ message). The optional second parameter sets the
609 * message associated with the exception, and the third parameter is an
610 * array of callback information. Exceptions are caught by the
611 * +rescue+ clause of <code>begin...end</code> blocks.
613 * raise "Failed to create socket"
614 * raise ArgumentError, "No parameters", caller
617 mrb_f_raise(mrb_state *mrb, mrb_value self)
623 argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]);
626 mrb_raise(mrb, E_RUNTIME_ERROR, "");
629 if (mrb_string_p(a[0])) {
632 a[0] = mrb_obj_value(E_RUNTIME_ERROR);
636 exc = mrb_make_exception(mrb, argc, a);
637 mrb_exc_raise(mrb, exc);
640 return mrb_nil_value(); /* not reached */
646 * obj.remove_instance_variable(symbol) -> obj
648 * Removes the named instance variable from <i>obj</i>, returning that
657 * remove_instance_variable(:@var)
666 mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self)
671 mrb_get_args(mrb, "n", &sym);
672 mrb_iv_name_sym_check(mrb, sym);
673 val = mrb_iv_remove(mrb, self, sym);
674 if (mrb_undef_p(val)) {
675 mrb_name_error(mrb, sym, "instance variable %S not defined", mrb_sym2str(mrb, sym));
681 mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args)
683 mrb_no_method_error(mrb, name, args, "undefined method '%S'", mrb_sym2str(mrb, name));
689 * obj.method_missing(symbol [, *args] ) -> result
691 * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
692 * <i>symbol</i> is the symbol for the method called, and <i>args</i>
693 * are any arguments that were passed to it. By default, the interpreter
694 * raises an error when this method is called. However, it is possible
695 * to override the method to provide more dynamic behavior.
696 * If it is decided that a particular method should not be handled, then
697 * <i>super</i> should be called, so that ancestors can pick up the
699 * The example below creates
700 * a class <code>Roman</code>, which responds to methods with names
701 * consisting of roman numerals, returning the corresponding integer
705 * def romanToInt(str)
708 * def method_missing(methId)
709 * str = methId.id2name
719 #ifdef MRB_DEFAULT_METHOD_MISSING
721 mrb_obj_missing(mrb_state *mrb, mrb_value mod)
727 mrb_get_args(mrb, "n*!", &name, &a, &alen);
728 mrb_method_missing(mrb, name, mod, mrb_ary_new_from_values(mrb, alen, a));
730 return mrb_nil_value();
734 static inline mrb_bool
735 basic_obj_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym id, int pub)
737 return mrb_respond_to(mrb, obj, id);
743 * obj.respond_to?(symbol, include_private=false) -> true or false
745 * Returns +true+ if _obj_ responds to the given
746 * method. Private methods are included in the search only if the
747 * optional second parameter evaluates to +true+.
749 * If the method is not implemented,
750 * as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
753 * If the method is not defined, <code>respond_to_missing?</code>
754 * method is called and the result is returned.
757 obj_respond_to(mrb_state *mrb, mrb_value self)
760 mrb_bool priv = FALSE, respond_to_p;
762 mrb_get_args(mrb, "n|b", &id, &priv);
763 respond_to_p = basic_obj_respond_to(mrb, self, id, !priv);
765 rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
766 if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) {
767 mrb_value args[2], v;
768 args[0] = mrb_symbol_value(id);
769 args[1] = mrb_bool_value(priv);
770 v = mrb_funcall_argv(mrb, self, rtm_id, 2, args);
771 return mrb_bool_value(mrb_bool(v));
774 return mrb_bool_value(respond_to_p);
778 mrb_obj_ceqq(mrb_state *mrb, mrb_value self)
782 mrb_sym eqq = mrb_intern_lit(mrb, "===");
783 mrb_value ary = mrb_ary_splat(mrb, self);
785 mrb_get_args(mrb, "o", &v);
786 len = RARRAY_LEN(ary);
787 for (i=0; i<len; i++) {
788 mrb_value c = mrb_funcall_argv(mrb, mrb_ary_entry(ary, i), eqq, 1, &v);
789 if (mrb_test(c)) return mrb_true_value();
791 return mrb_false_value();
794 mrb_value mrb_obj_equal_m(mrb_state *mrb, mrb_value);
797 mrb_init_kernel(mrb_state *mrb)
801 mrb->kernel_module = krn = mrb_define_module(mrb, "Kernel"); /* 15.3.1 */
802 mrb_define_class_method(mrb, krn, "block_given?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.2 */
803 mrb_define_class_method(mrb, krn, "iterator?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.2.5 */
805 mrb_define_class_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_OPT(2)); /* 15.3.1.2.12 */
808 mrb_define_method(mrb, krn, "===", mrb_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.2 */
809 mrb_define_method(mrb, krn, "block_given?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.6 */
810 mrb_define_method(mrb, krn, "class", mrb_obj_class_m, MRB_ARGS_NONE()); /* 15.3.1.3.7 */
811 mrb_define_method(mrb, krn, "clone", mrb_obj_clone, MRB_ARGS_NONE()); /* 15.3.1.3.8 */
812 mrb_define_method(mrb, krn, "dup", mrb_obj_dup, MRB_ARGS_NONE()); /* 15.3.1.3.9 */
813 mrb_define_method(mrb, krn, "eql?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.10 */
814 mrb_define_method(mrb, krn, "equal?", mrb_obj_equal_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.11 */
815 mrb_define_method(mrb, krn, "extend", mrb_obj_extend_m, MRB_ARGS_ANY()); /* 15.3.1.3.13 */
816 mrb_define_method(mrb, krn, "freeze", mrb_obj_freeze, MRB_ARGS_NONE());
817 mrb_define_method(mrb, krn, "frozen?", mrb_obj_frozen, MRB_ARGS_NONE());
818 mrb_define_method(mrb, krn, "global_variables", mrb_f_global_variables, MRB_ARGS_NONE()); /* 15.3.1.3.14 */
819 mrb_define_method(mrb, krn, "hash", mrb_obj_hash, MRB_ARGS_NONE()); /* 15.3.1.3.15 */
820 mrb_define_method(mrb, krn, "initialize_copy", mrb_obj_init_copy, MRB_ARGS_REQ(1)); /* 15.3.1.3.16 */
821 mrb_define_method(mrb, krn, "inspect", mrb_obj_inspect, MRB_ARGS_NONE()); /* 15.3.1.3.17 */
822 mrb_define_method(mrb, krn, "instance_of?", obj_is_instance_of, MRB_ARGS_REQ(1)); /* 15.3.1.3.19 */
824 mrb_define_method(mrb, krn, "is_a?", mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.24 */
825 mrb_define_method(mrb, krn, "iterator?", mrb_f_block_given_p_m, MRB_ARGS_NONE()); /* 15.3.1.3.25 */
826 mrb_define_method(mrb, krn, "kind_of?", mrb_obj_is_kind_of_m, MRB_ARGS_REQ(1)); /* 15.3.1.3.26 */
827 #ifdef MRB_DEFAULT_METHOD_MISSING
828 mrb_define_method(mrb, krn, "method_missing", mrb_obj_missing, MRB_ARGS_ANY()); /* 15.3.1.3.30 */
830 mrb_define_method(mrb, krn, "nil?", mrb_false, MRB_ARGS_NONE()); /* 15.3.1.3.32 */
831 mrb_define_method(mrb, krn, "object_id", mrb_obj_id_m, MRB_ARGS_NONE()); /* 15.3.1.3.33 */
832 mrb_define_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.3.40 */
833 mrb_define_method(mrb, krn, "remove_instance_variable", mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1)); /* 15.3.1.3.41 */
834 mrb_define_method(mrb, krn, "respond_to?", obj_respond_to, MRB_ARGS_ANY()); /* 15.3.1.3.43 */
835 mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */
836 mrb_define_method(mrb, krn, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */
837 mrb_define_method(mrb, krn, "__to_int", mrb_to_int, MRB_ARGS_NONE()); /* internal */
838 mrb_define_method(mrb, krn, "__to_str", mrb_to_str, MRB_ARGS_NONE()); /* internal */
840 mrb_include_module(mrb, mrb->object_class, mrb->kernel_module);
841 mrb_define_alias(mrb, mrb->module_class, "dup", "clone"); /* XXX */