From 439668e9c4f0a5292332dd24ca7dffaaf267aa36 Mon Sep 17 00:00:00 2001
From: Shugo Maeda <shugo@ruby-lang.org>
Date: Sat, 30 Oct 2010 02:54:11 +0900
Subject: [PATCH 41/51] removed Refinement, and use Module instead of Refinement.

---
 class.c               |   21 ------
 compile.c             |   15 -----
 defs/keywords         |    1 -
 defs/lex.c.src        |    1 -
 eval.c                |   74 ++++++++++-----------
 gc.c                  |    1 -
 include/ruby/intern.h |    2 -
 include/ruby/ruby.h   |    1 -
 insns.def             |   24 +-------
 lex.c.blt             |  169 ++++++++++++++++++++++++-------------------------
 node.c                |    9 ---
 node.h                |    3 -
 object.c              |    6 +--
 parse.y               |   31 +---------
 vm_eval.c             |    6 +-
 vm_insnhelper.c       |   42 +++++++------
 16 files changed, 146 insertions(+), 260 deletions(-)

diff --git a/class.c b/class.c
index 38321c8..5c7835b 100644
--- a/class.c
+++ b/class.c
@@ -1532,27 +1532,6 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
 		 argc, n_mand, f_var ? "+" : "");
 }
 
-VALUE
-rb_classbox_new(void)
-{
-    VALUE classbox = class_alloc(T_MODULE, rb_cClassbox);
-
-    RCLASS_M_TBL(classbox) = st_init_numtable();
-
-    return (VALUE) classbox;
-}
-
-VALUE
-rb_define_classbox_id(ID id)
-{
-    VALUE mdl;
-
-    mdl = rb_classbox_new();
-    rb_name_class(mdl, id);
-
-    return mdl;
-}
-
 /*!
  * \}
  */
diff --git a/compile.c b/compile.c
index e04d5f8..8875e57 100644
--- a/compile.c
+++ b/compile.c
@@ -4686,21 +4686,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
 	}
 	break;
       }
-      case NODE_CLASSBOX:{
-	VALUE iseqval = NEW_CHILD_ISEQVAL(
-	    node->nd_body,
-	    rb_sprintf("<module:%s>", rb_id2name(node->nd_cpath->nd_mid)),
-	    ISEQ_TYPE_CLASS, nd_line(node));
-
-	compile_cpath(ret, iseq, node->nd_cpath);
-	ADD_INSN (ret, nd_line(node), putnil); /* dummy */
-	ADD_INSN3(ret, nd_line(node), defineclass,
-		  ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(3));
-	if (poped) {
-	    ADD_INSN(ret, nd_line(node), pop);
-	}
-	break;
-      }
       case NODE_COLON2:{
 	if (rb_is_const_id(node->nd_mid)) {
 	    /* constant */
diff --git a/defs/keywords b/defs/keywords
index f5d56c0..1b5719a 100644
--- a/defs/keywords
+++ b/defs/keywords
@@ -19,7 +19,6 @@ begin, {keyword_begin, keyword_begin}, EXPR_BEG
 break, {keyword_break, keyword_break}, EXPR_MID
 case, {keyword_case, keyword_case}, EXPR_VALUE
 class, {keyword_class, keyword_class}, EXPR_CLASS
-refinement, {keyword_classbox, keyword_classbox}, EXPR_VALUE
 def, {keyword_def, keyword_def}, EXPR_FNAME
 defined?, {keyword_defined, keyword_defined}, EXPR_ARG
 do, {keyword_do, keyword_do}, EXPR_BEG
diff --git a/defs/lex.c.src b/defs/lex.c.src
index f5d56c0..1b5719a 100644
--- a/defs/lex.c.src
+++ b/defs/lex.c.src
@@ -19,7 +19,6 @@ begin, {keyword_begin, keyword_begin}, EXPR_BEG
 break, {keyword_break, keyword_break}, EXPR_MID
 case, {keyword_case, keyword_case}, EXPR_VALUE
 class, {keyword_class, keyword_class}, EXPR_CLASS
-refinement, {keyword_classbox, keyword_classbox}, EXPR_VALUE
 def, {keyword_def, keyword_def}, EXPR_FNAME
 defined?, {keyword_defined, keyword_defined}, EXPR_ARG
 do, {keyword_do, keyword_do}, EXPR_BEG
diff --git a/eval.c b/eval.c
index f69444a..857e229 100644
--- a/eval.c
+++ b/eval.c
@@ -899,7 +899,7 @@ rb_overlay_module(NODE *cref, VALUE klass, VALUE module)
 }
 
 static int
-import_classbox_i(VALUE klass, VALUE modules, VALUE arg)
+use_module_i(VALUE klass, VALUE modules, VALUE arg)
 {
     NODE *cref = (NODE *) arg;
     int i;
@@ -911,53 +911,49 @@ import_classbox_i(VALUE klass, VALUE modules, VALUE arg)
 }
 
 void
-rb_import_classbox(NODE *cref, VALUE classbox)
+rb_use_module(NODE *cref, VALUE module)
 {
     ID id_overlayed_modules;
     VALUE overlayed_modules;
 
-    if (TYPE(classbox) != T_MODULE ||
-	!rb_obj_is_kind_of(classbox, rb_cClassbox)) {
-	rb_raise(rb_eTypeError, "wrong argument type %s (expected Classbox)",
-		 rb_obj_classname(classbox));
-    }
-
+    Check_Type(module, T_MODULE);
     CONST_ID(id_overlayed_modules, "__overlayed_modules__");
-    overlayed_modules = rb_attr_get(classbox, id_overlayed_modules);
+    overlayed_modules = rb_attr_get(module, id_overlayed_modules);
     if (NIL_P(overlayed_modules)) return;
-    rb_hash_foreach(overlayed_modules, import_classbox_i, (VALUE) cref);
+    rb_hash_foreach(overlayed_modules, use_module_i, (VALUE) cref);
 }
 
 /*
  *  call-seq:
- *     import(classbox)    -> self
+ *     use(module)    -> self
  *
- *  Import <i>classbox</i> into the receiver.
+ *  Import class refinements from <i>module</i> into the receiver.
  */
 
 static VALUE
-rb_mod_import(VALUE module, VALUE classbox)
+rb_mod_use(VALUE self, VALUE module)
 {
     NODE *cref = rb_vm_cref();
-    ID id_imported_classboxes;
-    VALUE imported_classboxes;
-
-    CONST_ID(id_imported_classboxes, "__imported_classboxes__");
-    imported_classboxes = rb_attr_get(module, id_imported_classboxes);
-    if (NIL_P(imported_classboxes)) {
-	imported_classboxes = rb_hash_new();
-	rb_funcall(imported_classboxes, rb_intern("compare_by_identity"), 0);
-	rb_ivar_set(module, id_imported_classboxes, imported_classboxes);
-    }
-    rb_hash_aset(imported_classboxes, classbox, Qtrue);
-    rb_import_classbox(cref, classbox);
-    return module;
+    ID id_used_modules;
+    VALUE used_modules;
+
+    CONST_ID(id_used_modules, "__used_modules__");
+    used_modules = rb_attr_get(self, id_used_modules);
+    if (NIL_P(used_modules)) {
+	used_modules = rb_hash_new();
+	rb_funcall(used_modules, rb_intern("compare_by_identity"), 0);
+	rb_ivar_set(self, id_used_modules, used_modules);
+    }
+    rb_hash_aset(used_modules, module, Qtrue);
+    rb_use_module(cref, module);
+    rb_funcall(module, rb_intern("used"), 1, self);
+    return self;
 }
 
 void rb_redefine_opt_method(VALUE, ID);
 
 static VALUE
-classbox_module_method_added(VALUE mod, VALUE mid)
+refinement_module_method_added(VALUE mod, VALUE mid)
 {
     ID id = SYM2ID(mid);
     ID id_refined_class;
@@ -972,11 +968,11 @@ classbox_module_method_added(VALUE mod, VALUE mid)
  *  call-seq:
  *     refine(klass) { block }   -> self
  *
- *  Refine <i>klass</i> in the receiver classbox.
+ *  Refine <i>klass</i> in the receiver.
  */
 
 static VALUE
-rb_classbox_refine(VALUE classbox, VALUE klass)
+rb_mod_refine(VALUE module, VALUE klass)
 {
     NODE *cref = rb_vm_cref();
     VALUE mod = rb_module_new();
@@ -985,11 +981,11 @@ rb_classbox_refine(VALUE classbox, VALUE klass)
 
     Check_Type(klass, T_CLASS);
     CONST_ID(id_overlayed_modules, "__overlayed_modules__");
-    overlayed_modules = rb_attr_get(classbox, id_overlayed_modules);
+    overlayed_modules = rb_attr_get(module, id_overlayed_modules);
     if (NIL_P(overlayed_modules)) {
 	overlayed_modules = rb_hash_new();
 	rb_funcall(overlayed_modules, rb_intern("compare_by_identity"), 0);
-	rb_ivar_set(classbox, id_overlayed_modules, overlayed_modules);
+	rb_ivar_set(module, id_overlayed_modules, overlayed_modules);
     }
     modules = rb_hash_aref(overlayed_modules, klass);
     if (NIL_P(modules)) {
@@ -1000,7 +996,7 @@ rb_classbox_refine(VALUE classbox, VALUE klass)
     CONST_ID(id_refined_class, "__refined_class__");
     rb_ivar_set(mod, id_refined_class, klass);
     rb_define_singleton_method(mod, "method_added",
-			       classbox_module_method_added, 1);
+			       refinement_module_method_added, 1);
     rb_overlay_module(cref, klass, mod);
     rb_mod_module_eval(0, NULL, mod);
     return Qnil;
@@ -1155,17 +1151,17 @@ f_overlay_module(int argc, VALUE *argv, VALUE self)
 
 /*
  *  call-seq:
- *     import(classbox)    -> self
+ *     use(module)    -> self
  *
- *  Import <i>classbox</i> into the scope where <code>import</code> is called.
+ *  Import class refinements from <i>module</i> into the scope where <code>use</code> is called.
  */
 
 static VALUE
-f_import(VALUE self, VALUE classbox)
+f_use(VALUE self, VALUE module)
 {
     NODE *cref = rb_vm_cref();
 
-    rb_import_classbox(cref, classbox);
+    rb_use_module(cref, module);
     return self;
 }
 
@@ -1321,8 +1317,8 @@ Init_eval(void)
     rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
     rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
     rb_define_private_method(rb_cModule, "include", rb_mod_include, -1);
-    rb_define_private_method(rb_cModule, "import", rb_mod_import, 1);
-    rb_define_private_method(rb_cClassbox, "refine", rb_classbox_refine, 1);
+    rb_define_private_method(rb_cModule, "use", rb_mod_use, 1);
+    rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1);
 
     rb_undef_method(rb_cClass, "module_function");
 
@@ -1339,7 +1335,7 @@ Init_eval(void)
     rb_define_singleton_method(rb_vm_top_self(), "include", top_include, -1);
 
     rb_define_global_function("overlay_module", f_overlay_module, -1);
-    rb_define_global_function("import", f_import, 1);
+    rb_define_global_function("use", f_use, 1);
 
     rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
 
diff --git a/gc.c b/gc.c
index b7805a7..c3309ee 100644
--- a/gc.c
+++ b/gc.c
@@ -1615,7 +1615,6 @@ gc_mark_children(rb_objspace_t *objspace, VALUE ptr, int lev)
 	  case NODE_OP_ASGN_OR:
 	  case NODE_OP_ASGN_AND:
 	  case NODE_MODULE:
-	  case NODE_CLASSBOX:
 	  case NODE_ALIAS:
 	  case NODE_VALIAS:
 	  case NODE_ARGSCAT:
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index d2cb771..b7b0648 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -186,8 +186,6 @@ void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
 void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
 void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int);
 VALUE rb_singleton_class(VALUE);
-VALUE rb_classbox_new(void);
-VALUE rb_define_classbox_id(ID);
 /* compar.c */
 int rb_cmpint(VALUE, VALUE, VALUE);
 NORETURN(void rb_cmperr(VALUE, VALUE));
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 4bb6068..3e1d08f 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1222,7 +1222,6 @@ RUBY_EXTERN VALUE rb_cArray;
 RUBY_EXTERN VALUE rb_cBignum;
 RUBY_EXTERN VALUE rb_cBinding;
 RUBY_EXTERN VALUE rb_cClass;
-RUBY_EXTERN VALUE rb_cClassbox;
 RUBY_EXTERN VALUE rb_cCont;
 RUBY_EXTERN VALUE rb_cDir;
 RUBY_EXTERN VALUE rb_cData;
diff --git a/insns.def b/insns.def
index 98300c1..f452924 100644
--- a/insns.def
+++ b/insns.def
@@ -956,28 +956,6 @@ defineclass
 	    rb_const_set(cbase, id, klass);
 	}
 	break;
-      case 3:
-	/* val is dummy.  classdef returns class scope value */
-	/* super is dummy */
-
-	vm_check_if_namespace(cbase);
-
-	/* find klass */
-	if (rb_const_defined_at(cbase, id)) {
-	    klass = rb_const_get_at(cbase, id);
-	    /* already exist */
-	    if (TYPE(klass) != T_MODULE ||
-		!rb_obj_is_kind_of(klass, rb_cClassbox)) {
-		rb_raise(rb_eTypeError, "%s is not a classbox", rb_id2name(id));
-	    }
-	}
-	else {
-	    /* new classbox declaration */
-	    klass = rb_define_classbox_id(id);
-	    rb_set_class_path_string(klass, cbase, rb_id2str(id));
-	    rb_const_set(cbase, id, klass);
-	}
-	break;
       default:
 	rb_bug("unknown defineclass type: %d", (int)define_type);
     }
@@ -989,7 +967,7 @@ defineclass
 		  VM_FRAME_MAGIC_CLASS, klass, 0, (VALUE) GET_BLOCK_PTR(),
 		  class_iseq->iseq_encoded, GET_SP(), 0,
 		  class_iseq->local_size);
-    rb_vm_import_classboxes(class_iseq->cref_stack, klass);
+    rb_vm_use_modules(class_iseq->cref_stack, klass);
     RESTORE_REGS();
 
     INC_VM_STATE_VERSION();
diff --git a/lex.c.blt b/lex.c.blt
index 01b1374..a7de0fb 100644
--- a/lex.c.blt
+++ b/lex.c.blt
@@ -38,12 +38,12 @@ static const struct kwtable *reserved_word(const char *, unsigned int);
 #line 9 "../defs/keywords"
 struct kwtable;
 
-#define TOTAL_KEYWORDS 42
+#define TOTAL_KEYWORDS 41
 #define MIN_WORD_LENGTH 2
 #define MAX_WORD_LENGTH 12
 #define MIN_HASH_VALUE 8
-#define MAX_HASH_VALUE 49
-/* maximum key range = 42, duplicates = 0 */
+#define MAX_HASH_VALUE 50
+/* maximum key range = 43, duplicates = 0 */
 
 #ifdef __GNUC__
 __inline
@@ -59,32 +59,32 @@ hash (str, len)
 {
   static const unsigned char asso_values[] =
     {
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 24, 50, 50, 15, 50, 17, 10,
-      12, 14, 50, 50, 50, 50, 11, 50, 14, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 12, 50,  8, 16, 28,
-       9,  2,  8, 12, 50, 17, 50, 16,  4, 21,
-       7, 19,  1, 50,  1,  1,  1, 14, 50, 21,
-      25, 25, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
-      50, 50, 50, 50, 50, 50
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 26, 51, 51, 14, 51, 16,  8,
+      11, 13, 51, 51, 51, 51, 10, 51, 13, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 11, 51, 13,  1, 26,
+       4,  1,  8, 28, 51, 23, 51,  1,  1, 27,
+       5, 19, 21, 51,  8,  3,  3, 11, 51, 21,
+      24, 16, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
+      51, 51, 51, 51, 51, 51
     };
   register int hval = len;
 
@@ -115,90 +115,89 @@ rb_reserved_word (str, len)
   static const struct kwtable wordlist[] =
     {
       {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
-#line 44 "../defs/keywords"
-      {"super", {keyword_super, keyword_super}, EXPR_ARG},
-#line 26 "../defs/keywords"
+#line 19 "../defs/keywords"
+      {"break", {keyword_break, keyword_break}, EXPR_MID},
+#line 25 "../defs/keywords"
       {"else", {keyword_else, keyword_else}, EXPR_BEG},
-#line 40 "../defs/keywords"
-      {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
-#line 29 "../defs/keywords"
+#line 35 "../defs/keywords"
+      {"nil", {keyword_nil, keyword_nil}, EXPR_END},
+#line 28 "../defs/keywords"
       {"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
-#line 37 "../defs/keywords"
-      {"not", {keyword_not, keyword_not}, EXPR_ARG},
-#line 31 "../defs/keywords"
-      {"for", {keyword_for, keyword_for}, EXPR_VALUE},
-#line 45 "../defs/keywords"
-      {"then", {keyword_then, keyword_then}, EXPR_BEG},
-#line 42 "../defs/keywords"
-      {"return", {keyword_return, keyword_return}, EXPR_MID},
 #line 27 "../defs/keywords"
-      {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
-#line 43 "../defs/keywords"
-      {"self", {keyword_self, keyword_self}, EXPR_END},
+      {"end", {keyword_end, keyword_end}, EXPR_END},
+#line 44 "../defs/keywords"
+      {"then", {keyword_then, keyword_then}, EXPR_BEG},
 #line 36 "../defs/keywords"
-      {"nil", {keyword_nil, keyword_nil}, EXPR_END},
-#line 30 "../defs/keywords"
+      {"not", {keyword_not, keyword_not}, EXPR_ARG},
+#line 29 "../defs/keywords"
       {"false", {keyword_false, keyword_false}, EXPR_END},
-#line 22 "../defs/keywords"
-      {"refinement", {keyword_classbox, keyword_classbox}, EXPR_VALUE},
-#line 46 "../defs/keywords"
+#line 42 "../defs/keywords"
+      {"self", {keyword_self, keyword_self}, EXPR_END},
+#line 26 "../defs/keywords"
+      {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
+#line 39 "../defs/keywords"
+      {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
+#line 45 "../defs/keywords"
       {"true", {keyword_true, keyword_true}, EXPR_END},
-#line 38 "../defs/keywords"
-      {"or", {keyword_or, keyword_or}, EXPR_VALUE},
-#line 28 "../defs/keywords"
-      {"end", {keyword_end, keyword_end}, EXPR_END},
-#line 49 "../defs/keywords"
-      {"until", {keyword_until, modifier_until}, EXPR_VALUE},
 #line 48 "../defs/keywords"
+      {"until", {keyword_until, modifier_until}, EXPR_VALUE},
+#line 47 "../defs/keywords"
       {"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
-#line 33 "../defs/keywords"
-      {"in", {keyword_in, keyword_in}, EXPR_VALUE},
-#line 32 "../defs/keywords"
-      {"if", {keyword_if, modifier_if}, EXPR_VALUE},
-#line 23 "../defs/keywords"
+#line 41 "../defs/keywords"
+      {"return", {keyword_return, keyword_return}, EXPR_MID},
+#line 22 "../defs/keywords"
       {"def", {keyword_def, keyword_def}, EXPR_FNAME},
 #line 17 "../defs/keywords"
       {"and", {keyword_and, keyword_and}, EXPR_VALUE},
-#line 25 "../defs/keywords"
+#line 24 "../defs/keywords"
       {"do", {keyword_do, keyword_do}, EXPR_BEG},
-#line 16 "../defs/keywords"
-      {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
-#line 41 "../defs/keywords"
-      {"retry", {keyword_retry, keyword_retry}, EXPR_END},
-#line 39 "../defs/keywords"
-      {"redo", {keyword_redo, keyword_redo}, EXPR_END},
-#line 50 "../defs/keywords"
+#line 51 "../defs/keywords"
+      {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
+#line 30 "../defs/keywords"
+      {"for", {keyword_for, keyword_for}, EXPR_VALUE},
+#line 46 "../defs/keywords"
+      {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
+#line 37 "../defs/keywords"
+      {"or", {keyword_or, keyword_or}, EXPR_VALUE},
+#line 32 "../defs/keywords"
+      {"in", {keyword_in, keyword_in}, EXPR_VALUE},
+#line 49 "../defs/keywords"
       {"when", {keyword_when, keyword_when}, EXPR_VALUE},
+#line 40 "../defs/keywords"
+      {"retry", {keyword_retry, keyword_retry}, EXPR_END},
+#line 31 "../defs/keywords"
+      {"if", {keyword_if, modifier_if}, EXPR_VALUE},
 #line 20 "../defs/keywords"
       {"case", {keyword_case, keyword_case}, EXPR_VALUE},
-#line 47 "../defs/keywords"
-      {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
-#line 35 "../defs/keywords"
-      {"next", {keyword_next, keyword_next}, EXPR_MID},
+#line 38 "../defs/keywords"
+      {"redo", {keyword_redo, keyword_redo}, EXPR_END},
 #line 34 "../defs/keywords"
+      {"next", {keyword_next, keyword_next}, EXPR_MID},
+#line 43 "../defs/keywords"
+      {"super", {keyword_super, keyword_super}, EXPR_ARG},
+#line 33 "../defs/keywords"
       {"module", {keyword_module, keyword_module}, EXPR_VALUE},
-#line 19 "../defs/keywords"
-      {"break", {keyword_break, keyword_break}, EXPR_MID},
 #line 18 "../defs/keywords"
       {"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
-#line 52 "../defs/keywords"
-      {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
-#line 21 "../defs/keywords"
-      {"class", {keyword_class, keyword_class}, EXPR_CLASS},
 #line 12 "../defs/keywords"
       {"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
 #line 13 "../defs/keywords"
       {"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
-#line 51 "../defs/keywords"
-      {"while", {keyword_while, modifier_while}, EXPR_VALUE},
 #line 11 "../defs/keywords"
       {"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
 #line 15 "../defs/keywords"
       {"END", {keyword_END, keyword_END}, EXPR_END},
+#line 16 "../defs/keywords"
+      {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
 #line 14 "../defs/keywords"
       {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
-#line 24 "../defs/keywords"
-      {"defined?", {keyword_defined, keyword_defined}, EXPR_ARG}
+#line 23 "../defs/keywords"
+      {"defined?", {keyword_defined, keyword_defined}, EXPR_ARG},
+#line 21 "../defs/keywords"
+      {"class", {keyword_class, keyword_class}, EXPR_CLASS},
+      {""}, {""},
+#line 50 "../defs/keywords"
+      {"while", {keyword_while, modifier_while}, EXPR_VALUE}
     };
 
   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -215,6 +214,6 @@ rb_reserved_word (str, len)
     }
   return 0;
 }
-#line 53 "../defs/keywords"
+#line 52 "../defs/keywords"
 
 #endif
diff --git a/node.c b/node.c
index e761d72..65bc541 100644
--- a/node.c
+++ b/node.c
@@ -696,15 +696,6 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
 	F_NODE(nd_body, "singleton class definition");
 	break;
 
-      case NODE_CLASSBOX:
-	ANN("classbox definition");
-	ANN("format: classbox [nd_cpath]; [nd_body]; end");
-	ANN("example: classbox M; ..; end");
-	F_NODE(nd_cpath, "classbox path");
-	LAST_NODE;
-	F_NODE(nd_body, "classbox definition");
-	break;
-
       case NODE_COLON2:
 	ANN("scoped constant reference");
 	ANN("format: [nd_head]::[nd_mid]");
diff --git a/node.h b/node.h
index 89d424c..405a469 100644
--- a/node.h
+++ b/node.h
@@ -184,8 +184,6 @@ enum node_type {
 #define NODE_MODULE      NODE_MODULE
     NODE_SCLASS,
 #define NODE_SCLASS      NODE_SCLASS
-    NODE_CLASSBOX,
-#define NODE_CLASSBOX    NODE_CLASSBOX
     NODE_COLON2,
 #define NODE_COLON2      NODE_COLON2
     NODE_COLON3,
@@ -443,7 +441,6 @@ typedef struct RNode {
 #define NEW_CLASS(n,b,s) NEW_NODE(NODE_CLASS,n,NEW_SCOPE(0,b),(s))
 #define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(0,b),0)
 #define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(0,b),0)
-#define NEW_CLASSBOX(n,b) NEW_NODE(NODE_CLASSBOX,n,NEW_SCOPE(0,b),0)
 #define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
 #define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
 #define NEW_CREF(a) NEW_NODE(NODE_CREF,a,0,0)
diff --git a/object.c b/object.c
index 227f735..480266a 100644
--- a/object.c
+++ b/object.c
@@ -26,7 +26,6 @@ VALUE rb_mKernel;
 VALUE rb_cObject;
 VALUE rb_cModule;
 VALUE rb_cClass;
-VALUE rb_cClassbox;
 VALUE rb_cData;
 
 VALUE rb_cNilClass;
@@ -2532,6 +2531,7 @@ Init_Object(void)
     rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
     rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
     rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
+    rb_define_private_method(rb_cModule, "used", rb_obj_dummy, 1);
     rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
     rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
     rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
@@ -2661,10 +2661,6 @@ Init_Object(void)
     rb_undef_method(rb_cClass, "extend_object");
     rb_undef_method(rb_cClass, "append_features");
 
-    rb_cClassbox = rb_define_class("Refinement", rb_cModule);
-    rb_undef_method(rb_cClassbox, "extend_object");
-    rb_undef_method(rb_cClassbox, "append_features");
-
     rb_cData = rb_define_class("Data", rb_cObject);
     rb_undef_alloc_func(rb_cData);
 
diff --git a/parse.y b/parse.y
index 670d921..67ca1f1 100644
--- a/parse.y
+++ b/parse.y
@@ -627,7 +627,6 @@ static void token_info_pop(struct parser_params*, const char *token);
 %*/
 	keyword_class
 	keyword_module
-	keyword_classbox
 	keyword_def
 	keyword_undef
 	keyword_begin
@@ -1865,8 +1864,7 @@ op		: '|'		{ ifndef_ripper($$ = '|'); }
 reswords	: keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
 		| keyword_BEGIN | keyword_END
 		| keyword_alias | keyword_and | keyword_begin
-		| keyword_break | keyword_case
-		| keyword_class | keyword_classbox | keyword_def
+		| keyword_break | keyword_case | keyword_class | keyword_def
 		| keyword_defined | keyword_do | keyword_else | keyword_elsif
 		| keyword_end | keyword_ensure | keyword_false
 		| keyword_for | keyword_in | keyword_module | keyword_next
@@ -2953,27 +2951,6 @@ primary		: literal
 		    %*/
 			local_pop();
 		    }
-		| k_classbox cpath
-		    {
-			if (in_def || in_single)
-			    yyerror("module definition in method body");
-			local_push(0);
-		    /*%%%*/
-			$<num>$ = ruby_sourceline;
-		    /*%
-		    %*/
-		    }
-		  bodystmt
-		  k_end
-		    {
-		    /*%%%*/
-			$$ = NEW_CLASSBOX($2, $4);
-			nd_set_line($$, $<num>3);
-		    /*%
-			$$ = dispatch2(module, $2, $4);
-		    %*/
-			local_pop();
-		    }
 		| k_def fname
 		    {
 			$<id>$ = cur_mid;
@@ -3120,12 +3097,6 @@ k_module	: keyword_module
 		    }
 		;
 
-k_classbox	: keyword_classbox
-		    {
-			token_info_push("classbox");
-		    }
-		;
-
 k_def		: keyword_def
 		    {
 			token_info_push("def");
diff --git a/vm_eval.c b/vm_eval.c
index a9038ad..119bae4 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1213,7 +1213,7 @@ yield_under(VALUE under, VALUE self, VALUE values)
     }
     cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr);
     cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL;
-    rb_vm_import_classboxes(cref, under);
+    rb_vm_use_modules(cref, under);
 
     if (values == Qundef) {
 	return vm_yield_with_cref(th, 1, &self, cref);
@@ -1235,7 +1235,7 @@ eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
     else {
 	SafeStringValue(src);
     }
-    rb_vm_import_classboxes(cref, under);
+    rb_vm_use_modules(cref, under);
 
     return eval_string_with_cref(self, src, Qnil, cref, file, line);
 }
@@ -1783,10 +1783,8 @@ Init_vm_eval(void)
 
     rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
     rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
-    rb_define_method(rb_cModule, "refinement_exec", rb_mod_module_exec, -1);
     rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
     rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
-    rb_define_method(rb_cModule, "refinement_eval", rb_mod_module_eval, -1);
 
     rb_define_global_function("caller", rb_f_caller, -1);
 }
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 0b8abe3..b72d7aa 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1746,40 +1746,42 @@ opt_eq_func(VALUE recv, VALUE obj, IC ic)
     return Qundef;
 }
 
-void rb_import_classbox(NODE *cref, VALUE classbox);
+void rb_use_module(NODE *cref, VALUE module);
 
 static int
-vm_import_classbox_i(VALUE classbox, VALUE value, VALUE arg)
+vm_use_module_i(VALUE module, VALUE value, VALUE arg)
 {
     NODE *cref = (NODE *) arg;
 
-    rb_import_classbox(cref, classbox);
+    rb_use_module(cref, module);
     return ST_CONTINUE;
 }
 
-void
-rb_vm_import_classboxes(NODE *cref, VALUE klass)
+static void
+rb_vm_use_modules(NODE *cref, VALUE klass)
 {
-    ID id_imported_classboxes;
-    VALUE imported_classboxes;
+    ID id_used_modules;
+    VALUE used_modules;
 
-    CONST_ID(id_imported_classboxes, "__imported_classboxes__");
-    imported_classboxes = rb_attr_get(klass, id_imported_classboxes);
-    if (TYPE(klass) == T_CLASS) {
-	if (NIL_P(imported_classboxes)) {
+    CONST_ID(id_used_modules, "__used_modules__");
+    used_modules = rb_attr_get(klass, id_used_modules);
+    switch (TYPE(klass)) {
+    case T_CLASS:
+	if (NIL_P(used_modules)) {
 	    VALUE super = rb_class_real(RCLASS_SUPER(klass));
-	    imported_classboxes = rb_attr_get(super, id_imported_classboxes);
-	    if (!NIL_P(imported_classboxes)) {
-		imported_classboxes = rb_hash_dup(imported_classboxes);
-		rb_ivar_set(klass, id_imported_classboxes, imported_classboxes);
+	    used_modules = rb_attr_get(super, id_used_modules);
+	    if (!NIL_P(used_modules)) {
+		used_modules = rb_hash_dup(used_modules);
+		rb_ivar_set(klass, id_used_modules, used_modules);
 	    }
 	}
+	break;
+    case T_MODULE:
+	rb_use_module(cref, klass);
+	break;
     }
-    else if (rb_obj_is_kind_of(klass, rb_cClassbox)) {
-	rb_import_classbox(cref, klass);
-    }
-    if (!NIL_P(imported_classboxes)) {
-	rb_hash_foreach(imported_classboxes, vm_import_classbox_i,
+    if (!NIL_P(used_modules)) {
+	rb_hash_foreach(used_modules, vm_use_module_i,
 		       	(VALUE) cref);
     }
 }
-- 
1.7.0.4

