Permalink
Browse files

implemented #instance_eval with a string + disabled the inline #eval …

…optimization, since it brings more negative things than positive ones

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1112 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent e96105c commit 4fcff256450c71cd0e849e41383d925f85de3c19 @lrz lrz committed Mar 23, 2009
Showing with 58 additions and 23 deletions.
  1. +0 −1 TODO
  2. +1 −1 eval.c
  3. +1 −1 load.c
  4. +22 −3 roxor.cpp
  5. +3 −2 roxor.h
  6. +1 −1 tool/compile_prelude.rb
  7. +30 −14 vm_eval.c
View
1 TODO
@@ -13,7 +13,6 @@
[X] constant caching
[X] fast ivar access
[X] zero-cost exceptions
-[X] fast eval (inlining)
[X] fast #send
[ ] fast regexp =~
[X] fast break
View
2 eval.c
@@ -195,7 +195,7 @@ ruby_run_node(void *n)
return FIX2INT(n);
}
rb_vm_set_running(true);
- rb_vm_run_node(RSTRING_PTR(rb_progname), (NODE *)n);
+ rb_vm_run(RSTRING_PTR(rb_progname), (NODE *)n);
return ruby_cleanup(0);
}
View
2 load.c
@@ -270,7 +270,7 @@ rb_load(VALUE fname, int wrap)
if (node == NULL) {
rb_raise(rb_eSyntaxError, "compile error");
}
- rb_vm_run_node(fname_str, node);
+ rb_vm_run(fname_str, node);
}
void
View
@@ -1611,6 +1611,9 @@ RoxorCompiler::compile_optimized_dispatch_call(SEL sel, int argc, std::vector<Va
return pn;
}
+#if 0
+ // XXX this optimization is disabled because it's buggy and not really
+ // interesting
// #eval
else if (sel == selEval) {
@@ -1667,6 +1670,7 @@ RoxorCompiler::compile_optimized_dispatch_call(SEL sel, int argc, std::vector<Va
return pn;
}
+#endif
#if 0
// TODO: block inlining optimization
else if (current_block_func != NULL) {
@@ -5551,7 +5555,7 @@ rb_vm_print_exception(VALUE exc)
extern "C"
IMP
-rb_vm_compile_imp(const char *fname, NODE *node)
+rb_vm_compile(const char *fname, NODE *node)
{
assert(node != NULL);
@@ -5594,9 +5598,9 @@ rb_vm_compile_imp(const char *fname, NODE *node)
extern "C"
VALUE
-rb_vm_run_node(const char *fname, NODE *node)
+rb_vm_run(const char *fname, NODE *node)
{
- IMP imp = rb_vm_compile_imp(fname, node);
+ IMP imp = rb_vm_compile(fname, node);
try {
return ((VALUE(*)(VALUE, SEL))imp)(GET_VM()->current_top_object, 0);
@@ -5615,6 +5619,21 @@ rb_vm_run_node(const char *fname, NODE *node)
extern "C"
VALUE
+rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node)
+{
+ // TODO honor klass
+ VALUE old_top_object = GET_VM()->current_top_object;
+ GET_VM()->current_top_object = self;
+
+ VALUE val = rb_vm_run(fname, node);
+
+ GET_VM()->current_top_object = old_top_object;
+
+ return val;
+}
+
+extern "C"
+VALUE
rb_vm_top_self(void)
{
return GET_VM()->current_top_object;
View
@@ -5,8 +5,9 @@
extern "C" {
#endif
-VALUE rb_vm_run_node(const char *fname, NODE *node);
-IMP rb_vm_compile_imp(const char *fname, NODE *node);
+VALUE rb_vm_run(const char *fname, NODE *node);
+VALUE rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node);
+IMP rb_vm_compile(const char *fname, NODE *node);
bool rb_vm_running(void);
void rb_vm_set_running(bool flag);
View
@@ -77,7 +77,7 @@ def c_esc(str)
Init_<%=init_name%>(void)
{
% lines_list.each_with_index {|(setup_lines, lines), i|
- rb_vm_run_node(prelude_name<%=i%>, rb_compile_string(
+ rb_vm_run(prelude_name<%=i%>, rb_compile_string(
prelude_name<%=i%>,
rb_str_new(prelude_code<%=i%>, sizeof(prelude_code<%=i%>) - 1),
1));
View
@@ -311,20 +311,14 @@ rb_each(VALUE obj)
}
static VALUE
-eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *file, int line)
+eval_string(VALUE self, VALUE klass, VALUE src, VALUE scope, const char *file, int line)
{
// TODO honor scope
NODE *node = rb_compile_string(file, src, line);
if (node == NULL) {
rb_raise(rb_eSyntaxError, "compile error");
}
- return rb_vm_run_node(file, node);
-}
-
-static VALUE
-eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line)
-{
- return eval_string_with_cref(self, src, scope, 0, file, line);
+ return rb_vm_run_under(klass, self, file, node);
}
static VALUE
@@ -337,8 +331,31 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
return rb_vm_yield_under(klass, self, 0, NULL);
}
else {
- // TODO
- abort();
+ const char *file = "(eval)";
+ int line = 1;
+
+ if (argc == 0) {
+ rb_raise(rb_eArgError, "block not supplied");
+ }
+ if (rb_safe_level() >= 4) {
+ StringValue(argv[0]);
+ }
+ else {
+ SafeStringValue(argv[0]);
+ }
+ if (argc > 3) {
+ const char *name = rb_id2name(rb_frame_callee());
+ rb_raise(rb_eArgError,
+ "wrong number of arguments: %s(src) or %s{..}",
+ name, name);
+ }
+ if (argc > 2) {
+ line = NUM2INT(argv[2]);
+ }
+ if (argc > 1) {
+ file = StringValuePtr(argv[1]);
+ }
+ return eval_string(self, klass, argv[0], Qnil, file, line);
}
}
@@ -385,17 +402,16 @@ rb_f_eval(VALUE self, SEL sel, int argc, VALUE *argv)
if (argc >= 4) {
line = NUM2INT(vline);
}
-
if (!NIL_P(vfile)) {
file = RSTRING_PTR(vfile);
}
- return eval_string(self, src, scope, file, line);
+ return eval_string(0, self, src, scope, file, line);
}
VALUE
rb_eval_string(const char *str)
{
- return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1);
+ return eval_string(0, rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1);
}
VALUE
@@ -416,7 +432,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
return val;
}
- val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
+ val = eval_string(0, rb_vm_top_self(), cmd, Qnil, 0, 0);
rb_set_safe_level_force(safe);
return val;
}

0 comments on commit 4fcff25

Please sign in to comment.