summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-10 11:43:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-10 11:43:02 +0000
commitf53bd45d6f65e75a53538d31f8bbb90fbe373f1a (patch)
tree23fbb17c6a73c922752262776bb46e624b72e999
parent6e610f5ea717c824b232fc5f3052dd9d5c1a25e3 (diff)
AST.of -e script
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ast.c5
-rw-r--r--ruby.c5
2 files changed, 10 insertions, 0 deletions
diff --git a/ast.c b/ast.c
index 7a037d1..7e7ec9e 100644
--- a/ast.c
+++ b/ast.c
@@ -184,6 +184,8 @@ node_find(VALUE self, const int node_id)
return Qnil;
}
+extern VALUE rb_e_script;
+
static VALUE
script_lines(VALUE path)
{
@@ -223,6 +225,9 @@ rb_ast_s_of(VALUE module, VALUE body)
if (!NIL_P(lines = script_lines(path))) {
node = rb_ast_parse_array(lines);
}
+ else if (RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0) {
+ node = rb_ast_parse_str(rb_e_script);
+ }
else {
node = rb_ast_parse_file(path);
}
diff --git a/ruby.c b/ruby.c
index a791371..ec2282c 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1429,6 +1429,7 @@ opt_enc_index(VALUE enc_name)
#define rb_progname (GET_VM()->progname)
#define rb_orig_progname (GET_VM()->orig_progname)
VALUE rb_argv0;
+VALUE rb_e_script;
static VALUE
false_value(void)
@@ -1856,6 +1857,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
rb_define_readonly_boolean("$-l", opt->do_line);
rb_define_readonly_boolean("$-a", opt->do_split);
+ if ((rb_e_script = opt->e_script) != 0) {
+ rb_gc_register_mark_object(opt->e_script);
+ }
+
rb_set_safe_level(opt->safe_level);
return (VALUE)iseq;