Skip to content
Browse files

implemented module_function as a scope + fixed a couple of eval-relat…

…ed bugs

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2379 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent e1b1ac7 commit 90a3eb6496d1f45e2170e6b9a214b622abf554a1 Laurent Sansonetti committed Aug 25, 2009
Showing with 35 additions and 4 deletions.
  1. +9 −0 vm.cpp
  2. +26 −4 vm_eval.c
View
9 vm.cpp
@@ -1531,6 +1531,7 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
const char *sel_name = sel_getName(sel);
const bool genuine_selector = sel_name[strlen(sel_name) - 1] == ':';
bool redefined = false;
+ bool added_modfunc = false;
SEL orig_sel = sel;
Method m;
IMP imp = NULL;
@@ -1591,6 +1592,14 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
}
}
}
+
+ if (!added_modfunc && (v & RCLASS_SCOPE_MOD_FUNC)) {
+ added_modfunc = true;
+ redefined = false;
+ klass = *(Class *)klass;
+ flags = 0;
+ goto prepare_method;
+ }
}
extern "C"
View
30 vm_eval.c
@@ -355,11 +355,18 @@ eval_string(VALUE self, VALUE klass, VALUE src, VALUE scope, const char *file,
static VALUE
specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
{
+ VALUE retval;
+
+ // XXX: not exception-safe
+ const long old_version = RCLASS_VERSION(klass);
+
if (rb_block_given_p()) {
if (argc > 0) {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)",
+ argc);
}
- return rb_vm_yield_under(klass, self, 0, NULL);
+ rb_vm_set_current_scope(klass, SCOPE_PUBLIC);
+ retval = rb_vm_yield_under(klass, self, 0, NULL);
}
else {
const char *file = "(eval)";
@@ -386,8 +393,13 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
if (argc > 1) {
file = StringValuePtr(argv[1]);
}
- return eval_string(self, klass, argv[0], Qnil, file, line);
+ rb_vm_set_current_scope(klass, SCOPE_PUBLIC);
+ retval = eval_string(self, klass, argv[0], Qnil, file, line);
}
+
+ RCLASS_SET_VERSION(klass, old_version);
+
+ return retval;
}
/*
@@ -436,7 +448,17 @@ rb_f_eval(VALUE self, SEL sel, int argc, VALUE *argv)
if (!NIL_P(vfile)) {
file = RSTRING_PTR(vfile);
}
- return eval_string(self, 0, src, scope, file, line);
+ VALUE klass;
+ switch (TYPE(self)) {
+ case T_CLASS:
+ case T_MODULE:
+ klass = self;
+ break;
+ default:
+ klass = 0;
+ break;
+ }
+ return eval_string(self, klass, src, scope, file, line);
}
VALUE

0 comments on commit 90a3eb6

Please sign in to comment.
Something went wrong with that request. Please try again.