summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-11 03:25:16 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-11 03:25:16 +0000
commit64ef091a64d61dc0cef4508b70e64f91e4db865d (patch)
tree61c91ecf6b79271ce664a0bd02d43125cebbc680 /ruby.c
parent7bca2f031ae387f979397f73640f0c5b07dc313d (diff)
Reverts a half of r36079. As we discussed on ruby-dev@ and IRC,
we do not need to disclose intermediate representation of program. The program embedding CRuby should use rb_eval_string family. * include/ruby/ruby.h (ruby_opaque_t): removed. (ruby_compile_main_from_file, ruby_compile_main_from_string, ruby_eval_main): removed. * eval.c (ruby_eval_main_internal): became ruby_exec_internal() again. (ruby_eval_main): removed. * ruby.c (PREPARE_PARSE_MAIN) reverted. (parse_and_compile_main, ruby_compile_main_from_file, ruby_compile_main_from_string): removed git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c123
1 files changed, 13 insertions, 110 deletions
diff --git a/ruby.c b/ruby.c
index 5aa93504b0..ab4b6747aa 100644
--- a/ruby.c
+++ b/ruby.c
@@ -505,14 +505,6 @@ toplevel_context(void)
return env;
}
-#define PREPARE_PARSE_MAIN(th, env, expr) do { \
- (th)->parse_in_eval--; \
- (th)->base_block = &(env)->block; \
- expr; \
- (th)->parse_in_eval++; \
- (th)->base_block = 0; \
-} while (0)
-
static void
process_sflag(int *sflag)
{
@@ -1381,6 +1373,14 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
env = toplevel_context();
+#define PREPARE_PARSE_MAIN(expr) do { \
+ th->parse_in_eval--; \
+ th->base_block = &env->block; \
+ expr; \
+ th->parse_in_eval++; \
+ th->base_block = 0; \
+} while (0)
+
if (opt->e_script) {
VALUE progname = rb_progname;
rb_encoding *eenc;
@@ -1395,7 +1395,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
require_libraries(&opt->req_list);
ruby_set_script_name(progname);
- PREPARE_PARSE_MAIN(th, env, {
+ PREPARE_PARSE_MAIN({
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
});
}
@@ -1404,7 +1404,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
forbid_setid("program input from stdin");
}
- PREPARE_PARSE_MAIN(th, env, {
+ PREPARE_PARSE_MAIN({
tree = load_file(parser, opt->script_name, 1, opt);
});
}
@@ -1444,12 +1444,12 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
}
if (opt->do_print) {
- PREPARE_PARSE_MAIN(th, env, {
+ PREPARE_PARSE_MAIN({
tree = rb_parser_append_print(parser, tree);
});
}
if (opt->do_loop) {
- PREPARE_PARSE_MAIN(th, env, {
+ PREPARE_PARSE_MAIN({
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
});
rb_define_global_function("sub", rb_f_sub, -1);
@@ -1464,7 +1464,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
return Qtrue;
}
- PREPARE_PARSE_MAIN(th, env, {
+ PREPARE_PARSE_MAIN({
VALUE path = Qnil;
if (!opt->e_script && strcmp(opt->script, "-"))
path = rb_realpath_internal(Qnil, opt->script_name, 1);
@@ -1687,103 +1687,6 @@ rb_load_file(const char *fname)
return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
}
-struct ruby_compile_main_arg {
- int is_string;
- union {
- VALUE path;
- VALUE string;
- } source;
-};
-
-static ruby_opaque_t
-parse_and_compile_main(VALUE fname, const struct ruby_compile_main_arg* arg, VALUE* error)
-{
- rb_env_t *const env = toplevel_context();
- rb_thread_t *const th = GET_THREAD();
- NODE* tree;
- VALUE iseq;
- VALUE path;
- int state;
-
- PUSH_TAG();
- if ((state = EXEC_TAG()) == 0) {
- PREPARE_PARSE_MAIN(th, env, {
- VALUE parser = rb_parser_new();
- th->mild_compile_error++;
- if (arg->is_string) {
- FilePathValue(fname);
- path = fname;
- tree = rb_parser_compile_string(parser, RSTRING_PTR(fname), arg->source.string, 1);
- }
- else {
- struct cmdline_options opt;
- path = arg->source.path;
- tree = load_file(parser, path, 0, cmdline_options_init(&opt));
- }
- th->mild_compile_error--;
- });
- if (!tree) rb_exc_raise(th->errinfo);
-
- ruby_set_script_name(fname);
-
- PREPARE_PARSE_MAIN(th, env, {
- iseq = rb_iseq_new_main(tree, fname, path);
- });
- }
- POP_TAG();
- if (state) {
- *error = th->errinfo;
- return NULL;
- } else {
- *error = Qnil;
- return (ruby_opaque_t)iseq;
- }
-}
-
-/**
- * Compiles a main Ruby script file into the internal a data structure.
- *
- * This function:
- * @li loads the file specified by path.
- * @li parses the source and compiles it
- *
- * @param fname <code>$0</code> is set to this value.
- * If nil,
- * uses the given path instead.
- * @param path path to the source
- * @param error where to store the exception if an error occured.
- * @return The compiled source code. Or NULL if an error occured.
- */
-ruby_opaque_t
-ruby_compile_main_from_file(VALUE fname, const char* path, VALUE* error)
-{
- struct ruby_compile_main_arg arg;
- arg.is_string = FALSE;
- arg.source.path = rb_str_new_cstr(path);
-
- if (NIL_P(fname)) fname = arg.source.path;
- return parse_and_compile_main(fname, &arg, error);
-}
-
-/**
- * Compiles a main Ruby script in a string into the internal a data structure.
- *
- * This function parses the given source and compiles it
- *
- * @param fname <code>$0</code> is set to this value.
- * @param source Ruby source string
- * @param error where to store the exception if an error occured.
- * @return The compiled source code. Or NULL if an error occured.
- */
-ruby_opaque_t
-ruby_compile_main_from_string(VALUE fname, VALUE source, VALUE* error)
-{
- struct ruby_compile_main_arg arg;
- arg.is_string = TRUE;
- arg.source.string = source;
- return parse_and_compile_main(fname, &arg, error);
-}
-
static void
set_arg0(VALUE val, ID id)
{