summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-27 02:16:28 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-27 02:16:28 +0000
commit846ca98acfdc83f645e619ff8d9f1f794dcc7adc (patch)
treeb4591151b2a55fe2428f276d106f4de2ca43f2d0 /ruby.c
parent63e21a7195ee434acd5de4d48556dbf20eba312b (diff)
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
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/ruby.c b/ruby.c
index 33cf0cc109..8b6cc4cb90 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1194,6 +1194,8 @@ process_options(VALUE arg)
const char *s;
char fbuf[MAXPATHLEN];
int i = proc_options(argc, argv, opt, 0);
+ rb_thread_t *th = GET_THREAD();
+ rb_env_t *env = 0;
argc -= i;
argv += i;
@@ -1303,6 +1305,18 @@ process_options(VALUE arg)
ruby_set_argv(argc, argv);
process_sflag(opt);
+ {
+ /* set eval context */
+ VALUE toplevel_binding = rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING"));
+ rb_binding_t *bind;
+
+ GetBindingPtr(toplevel_binding, bind);
+ GetEnvPtr(bind->env, env);
+
+ th->parse_in_eval++;
+ th->mild_compile_error++;
+ }
+
if (opt->e_script) {
rb_encoding *eenc;
if (opt->src.enc.index >= 0) {
@@ -1313,12 +1327,16 @@ process_options(VALUE arg)
}
rb_enc_associate(opt->e_script, eenc);
require_libraries(opt);
+
+ th->base_block = &env->block;
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
}
else {
if (opt->script[0] == '-' && !opt->script[1]) {
forbid_setid("program input from stdin");
}
+
+ th->base_block = &env->block;
tree = load_file(parser, opt->script, 1, opt);
}
@@ -1357,8 +1375,10 @@ process_options(VALUE arg)
rb_define_global_function("chomp", rb_f_chomp, -1);
}
- iseq = rb_iseq_new_top(tree, rb_str_new2("<main>"),
- opt->script_name, Qfalse);
+ iseq = rb_iseq_new_main(tree, opt->script_name);
+ th->parse_in_eval--;
+ th->mild_compile_error--;
+ th->base_block = 0;
if (opt->dump & DUMP_BIT(insns)) {
rb_io_write(rb_stdout, ruby_iseq_disasm(iseq));