Permalink
Browse files

experimental implementation of instance_eval/instance_exec/module_eva…

…l/module_exec (works only with blocks and outer const lookup doesn't work yet)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1037 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 1b74bff commit 1827cf43414aaeda82be3f4cce1f0d98797392bf @lrz lrz committed Mar 21, 2009
Showing with 42 additions and 14 deletions.
  1. +20 −0 roxor.cpp
  2. +1 −0 roxor.h
  3. +21 −14 vm_eval.c
View
@@ -5175,6 +5175,26 @@ rb_vm_yield(int argc, const VALUE *argv)
}
extern "C"
+VALUE
+rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv)
+{
+ rb_vm_block_t *b = GET_VM()->top_block();
+
+ GET_VM()->pop_block();
+ VALUE old_self = b->self;
+ b->self = self;
+
+ // TODO set klass as the default outer!
+
+ VALUE retval = rb_vm_block_eval0(b, argc, argv);
+
+ b->self = old_self;
+ GET_VM()->push_block(b);
+
+ return retval;
+}
+
+extern "C"
VALUE
rb_vm_yield_args(int argc, ...)
{
View
@@ -26,6 +26,7 @@ VALUE rb_vm_call_with_cache(void *cache, VALUE self, SEL sel, int argc, const VA
VALUE rb_vm_call_with_cache2(void *cache, VALUE self, VALUE klass, SEL sel, int argc, const VALUE *argv);
void *rb_vm_get_call_cache(SEL sel);
VALUE rb_vm_yield(int argc, const VALUE *argv);
+VALUE rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv);
bool rb_vm_respond_to(VALUE obj, SEL sel, bool priv);
VALUE rb_vm_method_missing(VALUE obj, int argc, const VALUE *argv);
int rb_vm_find_class_ivar_slot(VALUE klass, ID name);
View
@@ -324,6 +324,21 @@ eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line)
return eval_string_with_cref(self, src, scope, 0, file, line);
}
+static VALUE
+specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
+{
+ if (rb_block_given_p()) {
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ }
+ return rb_vm_yield_under(klass, self, 0, NULL);
+ }
+ else {
+ // TODO
+ abort();
+ }
+}
+
/*
* call-seq:
* eval(string [, binding [, filename [,lineno]]]) => obj
@@ -435,11 +450,9 @@ rb_obj_instance_eval(VALUE self, SEL sel, int argc, VALUE *argv)
klass = Qnil;
}
else {
- klass = rb_singleton_class(self);
+ klass = CLASS_OF(self);
}
- // TODO
- abort();
- return Qnil;
+ return specific_eval(argc, argv, klass, self);
}
/*
@@ -471,9 +484,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
else {
klass = rb_singleton_class(self);
}
- // TODO
- abort();
- return Qnil;
+ return rb_vm_yield_under(klass, self, argc, argv);
}
/*
@@ -503,9 +514,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
VALUE
rb_mod_module_eval(VALUE mod, SEL sel, int argc, VALUE *argv)
{
- // TODO
- abort();
- return Qnil;
+ return specific_eval(argc, argv, mod, mod);
}
/*
@@ -529,11 +538,9 @@ rb_mod_module_eval(VALUE mod, SEL sel, int argc, VALUE *argv)
*/
VALUE
-rb_mod_module_exec(VALUE recv, SEL sel, int argc, VALUE *argv)
+rb_mod_module_exec(VALUE mod, SEL sel, int argc, VALUE *argv)
{
- // TODO
- abort();
- return Qnil;
+ return rb_vm_yield_under(mod, mod, argc, argv);
}
/*

0 comments on commit 1827cf4

Please sign in to comment.