Permalink
Browse files

introduce toplevel object main; close #327

  • Loading branch information...
1 parent 9c12b47 commit fd3af6aec88fe8ad01efb23f69a075f83ac91063 @matz matz committed Sep 2, 2012
Showing with 14 additions and 5 deletions.
  1. +2 −0 include/mruby/class.h
  2. +4 −2 include/mruby/value.h
  3. +3 −0 src/kernel.c
  4. +4 −2 src/state.c
  5. +1 −1 test/t/kernel.rb
View
@@ -39,6 +39,8 @@ mrb_class(mrb_state *mrb, mrb_value v)
return mrb->fixnum_class;
case MRB_TT_FLOAT:
return mrb->float_class;
+ case MRB_TT_MAIN:
+ return mrb->object_class;
#ifdef ENABLE_REGEXP
case MRB_TT_REGEX:
View
@@ -34,7 +34,8 @@ enum mrb_vtype {
MRB_TT_FILE, /* 21 */
MRB_TT_ENV, /* 22 */
MRB_TT_DATA, /* 23 */
- MRB_TT_MAXDEFINE /* 24 */
+ MRB_TT_MAIN, /* 24 */
+ MRB_TT_MAXDEFINE /* 25 */
};
typedef struct mrb_value {
@@ -94,7 +95,8 @@ enum mrb_vtype {
MRB_TT_FILE, /* 22 */
MRB_TT_ENV, /* 23 */
MRB_TT_DATA, /* 24 */
- MRB_TT_MAXDEFINE /* 25 */
+ MRB_TT_MAIN, /* 25 */
+ MRB_TT_MAXDEFINE /* 26 */
};
#ifdef MRB_ENDIAN_BIG
View
@@ -64,6 +64,9 @@ mrb_obj_inspect(mrb_state *mrb, mrb_value obj)
else if (mrb_nil_p(obj)) {
return mrb_str_new(mrb, "nil", 3);
}
+ else if (mrb_type(obj) == MRB_TT_MAIN) {
+ return mrb_str_new(mrb, "main", 4);
+ }
return mrb_funcall(mrb, obj, "to_s", 0, 0);
}
View
@@ -97,6 +97,8 @@ mrb_add_irep(mrb_state *mrb, int idx)
mrb_value
mrb_top_self(mrb_state *mrb)
{
- // for now
- return mrb_nil_value();
+ mrb_value v;
+
+ MRB_SET_VALUE(v, MRB_TT_MAIN, value.i, 0);
+ return v;
}
View
@@ -338,5 +338,5 @@ def test_method; end
assert('Kernel#to_s', '15.3.1.3.46') do
# TODO looks strange..
- to_s == ''
+ nil.to_s == ''
end

0 comments on commit fd3af6a

Please sign in to comment.