Revision: 1112 http://trac.macosforge.org/projects/ruby/changeset/1112 Author: lsansonetti@apple.com Date: 2009-03-23 13:40:22 -0700 (Mon, 23 Mar 2009) Log Message: ----------- implemented #instance_eval with a string + disabled the inline #eval optimization, since it brings more negative things than positive ones Modified Paths: -------------- MacRuby/branches/experimental/TODO MacRuby/branches/experimental/eval.c MacRuby/branches/experimental/load.c MacRuby/branches/experimental/roxor.cpp MacRuby/branches/experimental/roxor.h MacRuby/branches/experimental/tool/compile_prelude.rb MacRuby/branches/experimental/vm_eval.c Modified: MacRuby/branches/experimental/TODO =================================================================== --- MacRuby/branches/experimental/TODO 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/TODO 2009-03-23 20:40:22 UTC (rev 1112) @@ -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 Modified: MacRuby/branches/experimental/eval.c =================================================================== --- MacRuby/branches/experimental/eval.c 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/eval.c 2009-03-23 20:40:22 UTC (rev 1112) @@ -195,7 +195,7 @@ 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); } Modified: MacRuby/branches/experimental/load.c =================================================================== --- MacRuby/branches/experimental/load.c 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/load.c 2009-03-23 20:40:22 UTC (rev 1112) @@ -270,7 +270,7 @@ if (node == NULL) { rb_raise(rb_eSyntaxError, "compile error"); } - rb_vm_run_node(fname_str, node); + rb_vm_run(fname_str, node); } void Modified: MacRuby/branches/experimental/roxor.cpp =================================================================== --- MacRuby/branches/experimental/roxor.cpp 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/roxor.cpp 2009-03-23 20:40:22 UTC (rev 1112) @@ -1611,6 +1611,9 @@ 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 @@ return pn; } +#endif #if 0 // TODO: block inlining optimization else if (current_block_func != NULL) { @@ -5551,7 +5555,7 @@ 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 @@ 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 @@ 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; Modified: MacRuby/branches/experimental/roxor.h =================================================================== --- MacRuby/branches/experimental/roxor.h 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/roxor.h 2009-03-23 20:40:22 UTC (rev 1112) @@ -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); Modified: MacRuby/branches/experimental/tool/compile_prelude.rb =================================================================== --- MacRuby/branches/experimental/tool/compile_prelude.rb 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/tool/compile_prelude.rb 2009-03-23 20:40:22 UTC (rev 1112) @@ -77,7 +77,7 @@ 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)); Modified: MacRuby/branches/experimental/vm_eval.c =================================================================== --- MacRuby/branches/experimental/vm_eval.c 2009-03-23 19:06:25 UTC (rev 1111) +++ MacRuby/branches/experimental/vm_eval.c 2009-03-23 20:40:22 UTC (rev 1112) @@ -311,23 +311,17 @@ } 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); + return rb_vm_run_under(klass, self, 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); -} - -static VALUE specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) { if (rb_block_given_p()) { @@ -337,8 +331,31 @@ 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 @@ 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 @@ 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; }
participants (1)
-
source_changes@macosforge.org