mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
merges r21079 from trunk into ruby_1_9_1.
* vm.c (Init_VM): create and define TOPLEVEL_BINDING at first. * vm.c (vm_set_main_stack, rb_iseq_eval_main): added. * parse.y (rb_parser_compile_file): fix to check parse_in_eval flag. * eval.c (ruby_exec_node): use rb_iseq_eval_main() instead of rb_iseq_eval(). * iseq.c (rb_iseq_new_main), vm_core.h: added. main script (specified by -e or script name) should be run under TOPLEVEL_BINDING using Kernel#eval. Above changes simulate Kernel#eval behaviour. [ruby-dev:37240] * compile.c (make_name_for_block): skip iseq except block type. this fix is needed for [ruby-dev:37240], and also fixes [ruby-dev:35392]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
63e21a7195
commit
846ca98acf
9 changed files with 120 additions and 16 deletions
41
vm.c
41
vm.c
|
@ -97,6 +97,27 @@ vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vm_set_main_stack(rb_thread_t *th, VALUE iseqval)
|
||||
{
|
||||
VALUE toplevel_binding = rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING"));
|
||||
rb_binding_t *bind;
|
||||
rb_iseq_t *iseq;
|
||||
rb_env_t *env;
|
||||
|
||||
GetBindingPtr(toplevel_binding, bind);
|
||||
GetEnvPtr(bind->env, env);
|
||||
th->base_block = &env->block;
|
||||
vm_set_eval_stack(th, iseqval, 0);
|
||||
th->base_block = 0;
|
||||
|
||||
/* save binding */
|
||||
GetISeqPtr(iseqval, iseq);
|
||||
if (bind && iseq->local_size > 0) {
|
||||
bind->env = vm_make_env_object(th, th->cfp);
|
||||
}
|
||||
}
|
||||
|
||||
rb_control_frame_t *
|
||||
vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||
{
|
||||
|
@ -1241,9 +1262,20 @@ rb_iseq_eval(VALUE iseqval)
|
|||
|
||||
vm_set_top_stack(th, iseqval);
|
||||
|
||||
if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) {
|
||||
rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new());
|
||||
val = vm_exec(th);
|
||||
tmp = iseqval; /* prohibit tail call optimization */
|
||||
return val;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_iseq_eval_main(VALUE iseqval)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
VALUE val;
|
||||
volatile VALUE tmp;
|
||||
|
||||
vm_set_main_stack(th, iseqval);
|
||||
|
||||
val = vm_exec(th);
|
||||
tmp = iseqval; /* prohibit tail call optimization */
|
||||
return val;
|
||||
|
@ -1860,7 +1892,7 @@ Init_VM(void)
|
|||
{
|
||||
rb_vm_t *vm = ruby_current_vm;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
VALUE filename = rb_str_new2("<dummy toplevel>");
|
||||
VALUE filename = rb_str_new2("<main>");
|
||||
volatile VALUE iseqval = rb_iseq_new(0, filename, filename, 0, ISEQ_TYPE_TOP);
|
||||
volatile VALUE th_self;
|
||||
rb_iseq_t *iseq;
|
||||
|
@ -1884,6 +1916,9 @@ Init_VM(void)
|
|||
GetISeqPtr(iseqval, iseq);
|
||||
th->cfp->iseq = iseq;
|
||||
th->cfp->pc = iseq->iseq_encoded;
|
||||
th->cfp->self = th->top_self;
|
||||
|
||||
rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new());
|
||||
}
|
||||
vm_init_redefined_flag();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue