Permalink
Browse files

fixed singleton class definition, when passing a non-Array object as …

…a splat argument inside an Array definition make sure to call #to_a if possible, fixed compilation under a given class/outer

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1116 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 237a6fd commit ae48953dd23e5f2fd65486bbc5cfe18456ca87ca @lrz lrz committed Mar 24, 2009
Showing with 30 additions and 14 deletions.
  1. +26 −13 roxor.cpp
  2. +4 −1 vm_eval.c
View
@@ -392,7 +392,7 @@ class RoxorVM
public:
static RoxorVM *current;
- Class current_opened_class;
+ Class current_class;
VALUE current_top_object;
VALUE current_exception;
VALUE loaded_features;
@@ -2791,7 +2791,7 @@ RoxorCompiler::compile_node(NODE *node)
Value *classVal;
if (nd_type(node) == NODE_SCLASS) {
- classVal = compile_singleton_class(compile_current_class());
+ classVal = compile_singleton_class(compile_node(node->nd_recv));
}
else {
assert(node->nd_cpath->nd_mid > 0);
@@ -4012,8 +4012,8 @@ extern "C"
void
rb_vm_set_const(VALUE outer, ID id, VALUE obj)
{
- if (outer == 0) {
- outer = (VALUE)GET_VM()->current_opened_class;
+ if (GET_VM()->current_class != NULL) {
+ outer = (VALUE)GET_VM()->current_class;
}
rb_const_set(outer, id, obj);
GET_VM()->const_defined(id);
@@ -4045,8 +4045,8 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, unsigned char is_module)
{
assert(path > 0);
- if (outer == 0) {
- outer = (VALUE)GET_VM()->current_opened_class;
+ if (GET_VM()->current_class != NULL) {
+ outer = (VALUE)GET_VM()->current_class;
}
VALUE klass;
@@ -4124,7 +4124,13 @@ rb_vm_ary_cat(VALUE ary, VALUE obj)
rb_ary_concat(ary, obj);
}
else {
- rb_ary_push(ary, obj);
+ VALUE ary2 = rb_check_convert_type(obj, T_ARRAY, "Array", "to_a");
+ if (!NIL_P(ary2)) {
+ rb_ary_concat(ary, ary2);
+ }
+ else {
+ rb_ary_push(ary, obj);
+ }
}
return ary;
}
@@ -4256,8 +4262,8 @@ extern "C"
void
rb_vm_prepare_method(Class klass, SEL sel, Function *func, NODE *node)
{
- if (klass == NULL) {
- klass = GET_VM()->current_opened_class;
+ if (GET_VM()->current_class != NULL) {
+ klass = GET_VM()->current_class;
}
IMP imp = GET_VM()->compile(func);
@@ -5297,13 +5303,14 @@ rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv)
GET_VM()->current_block = NULL;
VALUE old_self = b->self;
b->self = self;
-
- // TODO set klass as the default outer!
+ //Class old_class = GET_VM()->current_class;
+ //GET_VM()->current_class = (Class)klass;
VALUE retval = rb_vm_block_eval0(b, argc, argv);
b->self = old_self;
GET_VM()->current_block = b;
+ //GET_VM()->current_class = old_class;
return retval;
}
@@ -5637,13 +5644,19 @@ extern "C"
VALUE
rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node)
{
- // TODO honor klass
+ assert(klass != 0);
+ assert(self != 0);
+
VALUE old_top_object = GET_VM()->current_top_object;
GET_VM()->current_top_object = self;
+ Class old_class = GET_VM()->current_class;
+ GET_VM()->current_class = (Class)klass;
+
VALUE val = rb_vm_run(fname, node);
GET_VM()->current_top_object = old_top_object;
+ GET_VM()->current_class = old_class;
return val;
}
@@ -5756,7 +5769,7 @@ Init_VM(void)
{
rb_cTopLevel = rb_define_class("TopLevel", rb_cObject);
- GET_VM()->current_opened_class = (Class)rb_cObject;
+ GET_VM()->current_class = NULL;
VALUE top_self = rb_obj_alloc(rb_cTopLevel);
rb_objc_retain((void *)top_self);
View
@@ -318,6 +318,9 @@ eval_string(VALUE self, VALUE klass, VALUE src, VALUE scope, const char *file, i
if (node == NULL) {
rb_raise(rb_eSyntaxError, "compile error");
}
+ if (klass == 0) {
+ klass = rb_cObject;
+ }
return rb_vm_run_under(klass, self, file, node);
}
@@ -498,7 +501,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
VALUE klass;
if (SPECIAL_CONST_P(self)) {
- klass = Qnil;
+ klass = 0;
}
else {
klass = rb_singleton_class(self);

0 comments on commit ae48953

Please sign in to comment.